Topic
  • 3 replies
  • Latest Post - ‏2013-07-30T14:08:30Z by VB3C_Wendy_Raschke
weixinlu
weixinlu
5 Posts

Pinned topic RAX-RS failed in WAS Liberty

‏2013-07-30T08:47:14Z |

I met a very strange problem. I promise that my project worked yesterday. But today, it doesn't work any more. I downloaded a new WAS Liberty, created a new workspace and created new project! They were not able to solve the problem.

In one word, once I added the jaxrs-1.1 support in server.xml or added the com.ibm.websphere.jaxrs.server.IBMRestServlet in web.xml, I would get below exception:

Context Root Not Found

and warning in console: [WARNING ] SRVE0274W: Error while adding servlet mapping for path-->/*, wrapper-->ServletWrapper[test:[/]], application-->Test.

The project is very simple and the server is simple too.

 

server.xml:

<server description="new server">
    <!-- Enable features -->
    <featureManager>
        <feature>jsp-2.2</feature>
        <feature>localConnector-1.0</feature>
        <feature>jaxrs-1.1</feature>
    </featureManager>
    <httpEndpoint host="localhost" httpPort="9083" httpsPort="9446" id="defaultHttpEndpoint"/>
    <applicationMonitor updateTrigger="mbean"/>
    <application id="Test" location="Test.war" name="Test" type="war"/>
</server>

 

I create the project in RAD and I'm sure I added the project facets: Dynamic Web Module, Java, JavaScript and JAX-RS

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <display-name>Test</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
    <servlet>
      <servlet-name>test</servlet-name>  
      <servlet-class>com.ibm.websphere.jaxrs.server.IBMRestServlet</servlet-class>  
      <init-param>
         <param-name>javax.ws.rs.Application</param-name>
         <param-value>com.ibm.jax.resource.DemoApplication</param-value>
     </init-param>
      <load-on-startup>1</load-on-startup>


     <!--  <servlet-class>com.ibm.test.servlet.TestServlet</servlet-class>
      <load-on-startup>1</load-on-startup>   -->    <!-- If I use this servlet and remove jaxrs-1.1 from server.xml, this servlet works.-->


    </servlet>
    <servlet-mapping>  
        <servlet-name>test</servlet-name>  
        <url-pattern>/</url-pattern>  
    </servlet-mapping>
</web-app>

 

I have only one resource class

package com.ibm.jax.resource;

import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/cat")
public class CatResource {
    
    @javax.ws.rs.GET
    @Path("/name")
    public String getCat() {
        String str = "I'm a cat";
        return str;
    }
    
    @javax.ws.rs.GET
    @Path("/type")
    public String getCatType() {
        return "tumao";
    }
    
    @Produces(MediaType.APPLICATION_JSON)
    @javax.ws.rs.GET
    @Path("/object")
    public Cat getCatObject(){
        Cat cat = new Cat();
        cat.setName("dami");
        cat.setType("tumao");
        return cat;
    }

}

Application:

package com.ibm.jax.resource;

import java.util.HashSet;
import java.util.Set;

import javax.ws.rs.core.Application;

@ApplicationPath("/rest")
public class DemoApplication extends Application {
     public Set<Class<?>> getClasses() {
            Set<Class<?>> classes = new HashSet<Class<?>>();
            classes.add(CatResource.class);
            return classes;
        }
}

I have below jars in my WebContent/WEB-INF/lib

ibm-wink-jaxrs.jar

jsr311-api.jar

slf4j-api-1.5.6.jar

slf4j-jdk4-1.5.6.jar

slf4j-log4j12-1.6.2.jar

I also tried to replace  ibm-wink-jaxrs.jar and jsr311-api.jar by:

com.ibm.websphere.appserver.api.jaxrs_1.0.2.jar

com.ibm.websphere.appserver.thirdparty.jaxrs_1.0.2.jar

com.ibm.ws.javaee.jaxrs.1.1_1.0.1.jar

Doesn't work neither...

The url I tested is: http://localhost:9083/Test/rest/cat/name

I also tested http://localhost:9083/Test/index.html  and got the same result (the index.html works if I remove jaxrs-1.1 from server.xml and remove IBMRestServlet in web.xml).

Did I missed any thing here? It worked yesterday. The only change is I added JPA support to the project and then removed it. But you know, I have created new server and new project and still have the problem. : (

  • weixinlu
    weixinlu
    5 Posts

    Re: RAX-RS failed in WAS Liberty

    ‏2013-07-30T09:19:42Z  

    I have no idea and I don't know what happened!

    I make the project work by doing below things:

    1. keep only below jars in WebContent/WEB-INF/lib

    slf4j-api-1.5.6.jar

    slf4j-jdk4-1.5.6.jar

    slf4j-log4j12-1.6.2.jar

    I remember very clearly that I had problems yesterday and the problems were solved after adding below 5 jars.

    ibm-wink-jaxrs.jar

    jsr311-api.jar

    slf4j-api-1.5.6.jar

    slf4j-jdk4-1.5.6.jar

    slf4j-log4j12-1.6.2.jar

    2. remove "@ApplicationPath("/rest")" in DemoApplication. and use http://localhost:9083/Test/cat/name 

       It seems that I removed this too yesterday but why it doesn't work? I tried to config this as instruction in below link (no web.xml), "@ApplicationPath("/rest")" works.

    http://pic.dhe.ibm.com/infocenter/wasinfo/v8r5/index.jsp?topic=%2Fcom.ibm.websphere.nd.doc%2Fae%2Ftwbs_jaxrs_configjaxrs11method.html

    I can understand maybe additional jars are not needed as I have set the targeted runtimes. But I'm so confused why I had to add those jars yesterday and the strange "@ApplicationPath("/rest")"...

  • weixinlu
    weixinlu
    5 Posts

    Re: RAX-RS failed in WAS Liberty

    ‏2013-07-30T09:26:37Z  
    • weixinlu
    • ‏2013-07-30T09:19:42Z

    I have no idea and I don't know what happened!

    I make the project work by doing below things:

    1. keep only below jars in WebContent/WEB-INF/lib

    slf4j-api-1.5.6.jar

    slf4j-jdk4-1.5.6.jar

    slf4j-log4j12-1.6.2.jar

    I remember very clearly that I had problems yesterday and the problems were solved after adding below 5 jars.

    ibm-wink-jaxrs.jar

    jsr311-api.jar

    slf4j-api-1.5.6.jar

    slf4j-jdk4-1.5.6.jar

    slf4j-log4j12-1.6.2.jar

    2. remove "@ApplicationPath("/rest")" in DemoApplication. and use http://localhost:9083/Test/cat/name 

       It seems that I removed this too yesterday but why it doesn't work? I tried to config this as instruction in below link (no web.xml), "@ApplicationPath("/rest")" works.

    http://pic.dhe.ibm.com/infocenter/wasinfo/v8r5/index.jsp?topic=%2Fcom.ibm.websphere.nd.doc%2Fae%2Ftwbs_jaxrs_configjaxrs11method.html

    I can understand maybe additional jars are not needed as I have set the targeted runtimes. But I'm so confused why I had to add those jars yesterday and the strange "@ApplicationPath("/rest")"...

    Oh. I read http://pic.dhe.ibm.com/infocenter/wasinfo/v8r5/topic/com.ibm.websphere.nd.doc/ae/twbs_jaxrs_configwebxml.html again understand the "@ApplicationPath("/rest")" issue.

    OK. : (

  • VB3C_Wendy_Raschke
    VB3C_Wendy_Raschke
    14 Posts

    Re: RAX-RS failed in WAS Liberty

    ‏2013-07-30T14:08:30Z  
    • weixinlu
    • ‏2013-07-30T09:26:37Z

    Oh. I read http://pic.dhe.ibm.com/infocenter/wasinfo/v8r5/topic/com.ibm.websphere.nd.doc/ae/twbs_jaxrs_configwebxml.html again understand the "@ApplicationPath("/rest")" issue.

    OK. : (

    I can't tell if you resolved your issue.

     

    If you are enabling the jaxrs-1.1 feature, you should not package ibm-wink-jaxrs.jar, jsr311-api.jar, slf4j-api-1.5.6.jar, slf4j-jdk4-1.5.6.jar, and slf4j-log4j12-1.6.2.jar libraries in your application. That was only necessary in the Web 2.0 Feature Pack; if you do that in Liberty (pkg those JARs *and* enable the JAX-RS feature) or you do that in WebSphere V8, you could actually run into problems.

     

    As for the context root not found problem, I think you should use one method of configuring the JAX-RS application--not both. In other words, do this:

     

        <servlet>
          <servlet-name>test</servlet-name>  
          <servlet-class>com.ibm.websphere.jaxrs.server.IBMRestServlet</servlet-class>  
          <init-param>
             <param-name>javax.ws.rs.Application</param-name>
             <param-value>com.ibm.jax.resource.DemoApplication</param-value>
         </init-param>

        <servlet-mapping>
            <servlet-name>test</servlet-name>
            <url-pattern>/rest/*</url-pattern>
        </servlet-mapping>

     

    (Notice I added a servlet-mapping with a url-pattern of "/rest/*")

     

    OR use the @ApplicationPath annotation in your DemoApplication class. You shouldn't do both.