- 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.
- Created Shared Library in WAS. Applications can reference this rather than having to deploy the jars each time.
Web Application Configuration
- 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.
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.
- 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>
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.
- Overview of IBM JAX-RS in WebSphere InfoCenter
- Apache Wink : JAX-RS Getting Started
- Apache Wink : 5.5 Spring Integration
- RESTful Web services with Apache Wink, Part 1: Build an Apache Wink REST service
- RESTful Web services with Apache Wink, Part 2: Advanced topics in Apache Wink REST development (including Spring integration)
- Overview of JAX-RS 1.0 Features (includes quick overview of most common Annotations)