WebSphere Configuration

  1. Feature Pack for Web 2.0 installed into WebSphere. This simply copies a bunch of files, including the JAX-RS jar files, into $WAS_HOME/web2fep. The IBM JAX-RS implementation is based on Apache Wink, version 1.0 as of this writing.
  2. Created Shared Library in WAS. Applications can reference this rather than having to deploy the jars each time.

Web Application Configuration

  1. Add WebSphere REST Servlet to application’s web.xml
    <servlet>  
        <servlet-name>JAX-RS Servlet</servlet-name>  
        <servlet-class>com.ibm.websphere.jaxrs.server.IBMRestServlet</servlet-class>  
        <init-param>
            <param-name>javax.ws.rs.Application</param-name>
            <param-value>_Java_class_name_</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>  
    </servlet>  
    
    <servlet-mapping>  
        <servlet-name>JAX-RS Servlet</servlet-name>  
        <url-pattern>/*</url-pattern>  
    </servlet-mapping>  
    

    Note that the <init-param> text is only required, including creating a custom class which extends Application, if we don’t use the following Spring Wink support.

  2. Integrate Wink with Spring using a Spring-aware Wink Application subclass called Registrar. This class is not part of the WebSphere Feature Pack but works fine with it. This allows you to inject your “Resource” definitions rather than hardcode them in an Application subclass.

    Perhaps more importantly, it also allows you to more easily utilize the injected interface/implementation pattern for the rest of your supporting beans.

    <context-param>  
        <param-name>contextConfigLocation</param-name>  
        <param-value>classpath:META-INF/server/wink-core-context.xml  
    /WEB-INF/applicationContext.xml</param-value>  
    </context-param>
    

    This class and its supporting classes are part of an “extensions” jar (wink-spring-support-1.0-incubating.jar) provided in the Wink distribution file available from the Wink site.

    Where META-INF/server/wink-core-context.xml is provided by the Wink Spring library and applicationContext.xml is your application’s bean definitions.

  3. Configure your Resource classes in your application Spring configuration file.
    <bean class="org.apache.wink.spring.Registrar">  
        <property name="instances">  
            <set>  
                <ref bean="calendarResource" />  
            </set>  
        </property>  
    </bean>  
    
    <bean id="calendarResource"  
          class="com.ibm.gs.calendar.service.CalendarResource">  
        <property .../>  
    </bean>
    

Resource Implementation

This is the basic annotation-based JAX-RS coding. See the below “Getting Started” article, Part 1 of the “RESTful Web services” article, and the Developing JAX-RS Web applications section of the WebSphere Feature Pack documentation.

It’s a straightforward, portable way to define the URI Paths of your Resources, the HTTP Methods supported by them, the Parameters passed to them, the Content Types supplied by them, and more.

References