Liberty Repository[8.5.5.6 or later]
This topic applies to WebSphere Application Server Liberty V8.5.5.9 and earlier. For the latest Liberty topics, see the WebSphere Application Server Liberty documentation.

JAX-RS 2.0 behavior changes

The JAX-RS 2.0 implementation contains some behavior changes. These changes might cause applications to behave differently or fail on JAX-RS 2.0 if the applications are upgraded from JAX-RS 1.1.

The following list describes the differences between JAX-RS 1.1 and JAX-RS 2.0:
  • In JAX-RS 1.1 and Jersey, if an EJB or CDI class creates a new instance that is returned by the JAX-RS application.getSingletons() method, the engine uses the returned instance and does not try to access the instance from the EJB or CDI container. In JAX-RS 2.0, for the same scenario, the engine tries to access the instance from the EJB or CDI container. If the instance can be accessed, the retrieved instance is used. But if the instance cannot be accessed, the returned instance from the getSingletons() method is used. For example:
    @Override
    public SetObject getSingletons() {
        SetObject objs = new HashSetObject();
        objs.add(new CDIInjectResource());
        objs.add(new EJBInjectResource());
        return objs;
    }
  • [Updated in November 2015]JAX-RS 2.0 includes many API changes when it handles the MultiPart file. For example, in JAX-RS 1.1, the @FormParam can be used to handle the MultiPart file, but in JAX-RS 2.0, only @IMultipartBody or @IAttachment can be used to handle the MultiPart file. For more information, see Configuring a resource to receive multipart/form-data parts from an HTML form submission in JAX-RS 2.0.[Updated in November 2015]
  • The jackson packages that are displayed as a third-party API in JAX-RS 1.1 are no longer displayed in JAX-RS 2.0. If you want to use any org.codehaus.jackson APIs in your application, you need to compress the jackson packages in your application.
  • If you specify javax.ws.rs.core.Application for the servlet name in the web.xml file, the getClasses method in the Application object, which is injected by @Context, does not return the resource classes.
    	
           <servlet>
    		<servlet-name>javax.ws.rs.core.Application</servlet-name>
    	</servlet>
    	<servlet-mapping>
    		<servlet-name>javax.ws.rs.core.Application</servlet-name>
    		<url-pattern>/*</url-pattern>
    	</servlet-mapping>
  • The JAX-RS 2.0 specification states that a provider is a class that implements one or more JAX-RS interfaces and that can be annotated with @Provider for automatic discovery. In the scenario, a class has @Local annotation that refers to a provider interface, but it does not implement any POJO provider interface, and then it is an invalid provider. For example:
    @Stateless
    @Local(OneLocalInterfaceMyOtherStuffMessageBodyWriter.class)
    public class OneLocalInterfaceMyOtherStuffProvide
  • If you use the MessageBodyReader and MessageBodyWriter @Consumes and @Produces annotations, some supported media types might be restricted. Use the isReadable method or isWriteable method to check the media type. For example:
    @Provider
    @Consumes("<custom/type>")
    @Produces("<custom/type>")
    @Singleton
    public class MyMessageBodyReaderAndWriter implements MessageBodyReader,MessageBodyWriter {
                    
        public boolean isReadable(Class<?> type,
                                  Type genericType,
                                  Annotation[] annotations,
                                  MediaType mediaType) {
            if (mediaType.toString().equals("<custom/type>"))
                return true;
            return false;
        }
    
         public boolean isWriteable(Class<?> type,
                                  Type genericType,
                                  Annotation[] annotations,
                                  MediaType mediaType) {
            if (mediaType.toString().equals("<custom/type>"))
                return true;
            return false;
        }
    ...
    }
  • You can use asynchronous processing in JAX-RS 2.0 to process threads. For more information, see Asynchronous processing.
  • None of the Wink APIs that are displayed as third-party APIs in JAX-RS 1.1 are supported in JAX-RS 2.0. Here is a partial list:
    • [8.5.5.8 or later]org.apache.wink.common.model.atom.AtomEntry. For more information about integrating JAX-RS 2.0 with Atom, see JAX-RS 2.0 integration with Atom.
    • org.apache.wink.client.handlers.BasicAuthSecurityHandler. If you want to use basic authentication in JAX-RS 2.0, see the following code snippets:
      1. Use ClientRequestFilter through the JAX-RS 2.0 standard Client API as shown in the code example:
        import java.io.IOException;
        import java.io.UnsupportedEncodingException;
        import javax.ws.rs.client.ClientRequestContext;
        import javax.ws.rs.client.ClientRequestFilter;
        import javax.ws.rs.core.MultivaluedMap;
        import javax.xml.bind.DatatypeConverter;
        
        public class BasicAuthFilter implements ClientRequestFilter {
        
            private final String usr;
            private final String pwd;
        
            public BasicAuthFilter(String usr, String pwd) {
                this.usr = user;
                this.pwd = pwd;
            }
        
            public void filter(ClientRequestContext requestContext) throws IOException {
                MultivaluedMap<String, Object> headers = requestContext.getHeaders();
               
             String token = this.usr + ":" + this.pwd;
             final String basicAuthentication ="Basic " + DatatypeConverter.printBase64Binary(token.getBytes("UTF-8"));
             headers.add("Authorization", basicAuthentication);
            }
        }
      2. Register to the ClientBuilder:
        ClientBuilder cb = ClientBuilder.newBuilder();
        cb.register(new BasicAuthFilter("user","password"));
    • org.apache.wink.client.handlers.LtpaAuthSecurityHandler. If you want to use the LTPA-based security client to secure downstream resources, see Securing downstream JAX-RS resources.
    • org.apache.wink.server.internal.providers.exception.EJBAccessExceptionMapper. This API is no longer supported because it is the Wink-specified ExceptionMapper. You can define your own ExceptionMapper to map the EJBAccessException.
    • com.ibm.websphere.jaxrs.server.IBMRestFilter. This API is no longer supported because it is based on Wink Filter.
    Note: [Updated in September 2015]Detect if there are wink jar packages in your application. If there are any wink packages in your application, you must do the following steps:
    1. Make sure that there is Application subclass defined.
    2. At least one of getClasses and getSingletons must not return null.
    [Updated in September 2015]
  • For more information about the supported client properties that can be used in the JAX-RS 2.0 client, see Configuring JAX-RS 2.0 client.
  • If you want to use the Secure Sockets Layer (SSL) function in JAX-RS 2.0, do the following steps:
    1. Enable either the ssl-1.0 feature or the appSecurity-2.0 feature. For the LTPA token function, the appSecurity-2.0 feature is required.
      Note: The ssl-1.0 feature is a sub-feature of the appSecurity-2.0 feature. If you enable the jaxrsClient-2.0 feature and the ssl-1.0 feature, the appSecurity-2.0 feature is automatically enabled.
    2. Enable the com.ibm.ws.jaxrs.client.ssl.config property in the JAX-RS 2.0 client code as follows:
      ClientBuilder cb = ClientBuilder.newBuilder();
      Client c = cb.build();
      c.property("com.ibm.ws.jaxrs.client.ssl.config", "mySSLConfig"); //mySSLConfig is the ssl ref id in Liberty server.xml
      Note: This property can bind the Liberty SSL configuration to scopes of ClientBuilder, Client, and WebTarget.
  • If you want to use the Wink Client in the JAX-RS 2.0 server run time, do the following steps:
    1. Download the following files that can enable Wink Client in the JAX-RS 2.0 server run time.
      Note: If the JAX-RS 2.0 feature is not enabled, you must also download and add the JAX-RS API to the third-party lib. Download the JAX-RS API from https://jax-rs-spec.java.net/nonav/.
    2. Save all JAR files into the <third-party lib> directory.
    3. Add the location of <third-party lib> to the server.xml file:
      <library id="thirdPartyLib">
        <fileset dir=" <third-party lib>" includes="*.jar" scanInterval="5s"/>
      </library>
      <enterpriseApplication id="<Your Ear ID>" location="<Your Ear Name>" name="<Your Ear Name>">
        <classloader commonLibraryRef="thirdPartyLib"/>
      </enterpriseApplication>
Note: For more information about asynchronous processing in Client and Server APIs, see Chapter 8 of JSR 339: JAX-RS 2.0: The Java API for RESTful Web Services (the "Specification").

Icon that indicates the type of topic Concept topic



Timestamp icon Last updated: Tuesday, 12 December 2017
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=phil&product=was-libcore-mp&topic=cwlp_jaxrs_behavior
File name: cwlp_jaxrs_behavior.html