Jersey to ATG Restfull webservices with multisite

This blog describes how ATG components can be exposed as RESTful web services using a JAX-RS implementation like Jersey. It is intended to give a step-by-step walkthrough on setting up Rest services in ATG mutisite application.

 Before going through this example,you need to understand/go through previous blog(https://sravankumarkema.blogspot.com/2014/11/rest-this-describes-rest-of-atg.html)

1. Context root should be updated in web.xml 

<context-param>

    <param-name>context-root</param-name>

    <param-value>root</param-value>

  </context-param>
2. NucleusJerseyServlet should be updated which is required to invoke jersey endpoint configured to have multisite.
     
<servlet>
        <servlet-name>NucleusJerseyREST</servlet-name>
        <servlet-class>com.texelz.atgrestful.NucleusJerseyServlet</servlet-class>
        <init-param>
            <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
            <param-value>com.texelz.atgrestful.NucleusResourceConfig</param-value>
        </init-param>
        <init-param>
            <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
            <param-value>true</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>NucleusJerseyREST</servlet-name>
        <url-pattern>/ws/ca/*</url-pattern>
    </servlet-mapping>
       <servlet-mapping>
        <servlet-name>NucleusJerseyREST</servlet-name>
        <url-pattern>/ws/us/*</url-pattern>
    </servlet-mapping>
    
Here,two servlet mappings are defined.One is for US site and other is for CA site.
Jersey endpoint should contains one of above servlet url to invoke corresponding site(CA/US).
3.Update siteBaseURL as matching with context root appended with one of servlet mapping as below in BCC and deploy the project.





7. Start the server

8. We can test REST multisite webservice using a web browser as follows:

To test our service we will be using the path http://localhost:7001/root/ws/ca/test/{input params}


http://localhost:7001 - Address of the weblogic server
/root– Context root of our ATG module
/ws/ca– URL pattern/sitebaseURL for our rest service specified in the web.xml to invoke CA site

/ws/us– URL pattern/sitebaseURL for our rest service specified in the web.xml to invoke US site

/test – Path for our resource specified as @Path annotation in the resource class TestResource.java(Which is created in old blog https://sravankumarkema.blogspot.com/2014/11/rest-this-describes-rest-of-atg.html)

Comments

Popular posts from this blog

how to generate classes from swagger

How to create new user/account in BCC