Tuesday, November 17, 2015

Getting Started with ATG MVC Rest

1.    Installing ATG Rest

Include REST module in <custom module>/META-INF/MANIFEST.MF

ATG-Required: REST


2.    Creating Rest Sample Component


2.1       Create a component RestComponent
/com/company/RestComponent.properties
$class=com.company.RestComponent

2.2       Create class RestComponent.class

package com.tcc;
import atg.nucleus.GenericService;

public class RestComponent extends GenericService{
        public Address findAddress(String id){
                       //get the address from the database
                       Address address = new Address();

                       address.setState("TX");
                       address.setCity("Irving");
                       return address;
        }
}

      2.3    Create the Address bean class

      package com.tcc;
      public class Address{
        private String state = null;
        private String city = null;
        // generate setters/getters
      }

2.4       Create a rest actor component /com/company/SampleRestActor.properties
$class=atg.service.actor.ActorChainService
definitionFile=/com/company/sampleRestActor.xml

2.5       Create the definition file to define the actor chains /com/company/sampleRestActor.xml
<?xml version="1.0" encoding="UTF-8"?>
<actor-template default-chain-id="findAddress"
  xsi:noNamespaceSchemaLocation="http://www.atg.com/xsds/actorChain_1.0.xsd"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <actor-chain id="findAddress" transaction="TX_SUPPORTS">
     <component id="rc" name="/com/company/RestComponent" component-var="rc" method="findAddress"
     method-return-var="address">
          <input name="id" value="${param.id}" class-name="java.lang.String"/>
        <output id="address" name="address" value="${address}"/>
    </component>
  </actor-chain>
</actor-template>

2.6       Register the chain URL in /atg/rest/registry/ActorChainRestRegistry.properties
registeredUrls+=\
/com/company/SampleRestActor/findAddress


2.8 Add the below component to disable session confirmation number

     /atg/dynamo/service/actor/Configuration.properties
enforceSessionConfirmation=false

2.7       Access the URL in the browser or any REST client



            2.8   Create the /atg/dynamo/service/filter/bean/beanFilteringConfiguration.xml
<bean-filtering xml-combine="append">
<bean default-filter="detailed" name="com.company.Address" xml-combine="append">
   <filter id="summary">
       <property name="city"/>
       <property name="state"/>
</filter>
   <filter id="detailed">
      <property name="firstName"/>
<property name="lastName"/>
       <property name="city"/>
       <property name="state"/>
       <property name="zip"/>
</filter>
</bean>
</bean-filtering>

 2.9    Modify the action-chain to use the filter-id in the <output> tag in /com/company/sampleRestActor.xml
  <actor-chain id="findAddress" transaction="TX_SUPPORTS">
     <component id="rc" name="/com/company/RestComponent" component-var="rc" method="findAddress"
     method-return-var="address">
  <input name="id" value="${param.id}" class-name="java.lang.String"/>
        <output id="address" name="address" value="${address}" filter-id="detailed"/>
    </component>

2 comments: