restjava-ee-6websphere-8myeclipseapache-wink

REST Resource FileNotFoundException in JEE 6 / WebSphere 8.5 using myEclipse


I have two small JEE 6 web applications deployed on a WebSphere 8.5.5.5 Server using the myEclipse IDE. Both each contain 1 simple REST endpoint. The endpoint is working on one of them and not on the other. I'm using the inherent Wink implementation of JAX-RS bundled with WAS 8.5. Here is the error I'm receiving on the second app:

Exception:java.io.FileNotFoundException SourceId:com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters -IOE ProbeId:1044
java.io.FileNotFoundException: SRVE0190E: File not found: /resources/tryme
    at com.ibm.ws.webcontainer.extension.DefaultExtensionProcessor._processEDR(DefaultExtensionProcessor.java:949)
    at com.ibm.ws.webcontainer.extension.DefaultExtensionProcessor.processEDR(DefaultExtensionProcessor.java:930)
    at com.ibm.ws.webcontainer.extension.DefaultExtensionProcessor.handleRequest(DefaultExtensionProcessor.java:484)
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1114)

Here are the two class files of the first app that has the working endpoint:

package com.somewhere.jee6.hello;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

@ApplicationPath("test-services")
public class HelloApplication extends Application {

}

package com.somewhere.jee6.hello.resource;

import javax.ws.rs.GET;
import javax.ws.rs.Path;

@Path("/hello")
public class HelloResource {

    @GET
    public String check() {
        return "Hello, it works";
    }
}

My classpath for the working app looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    <classpathentry kind="con" path="melibrary.com.genuitec.eclipse.j2eedt.core.MYECLIPSE_JAVAEE_6_CONTAINER"/>
    <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
    <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
    <classpathentry kind="output" path="WebContent/WEB-INF/classes"/>
</classpath>

The working endpoint that returns "Hello, it works" above is:

http://localhost:9081/hellosvc/test-services/hello

Here are the two class files of the second app that has the endpoint that doesn't work:

package com.somewhere.mdr.rest;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 

@ApplicationPath("resources")
public class MdrApplication extends Application {

   private static final Logger logger =
   LoggerFactory.getLogger(MdrApplication.class);
}

package com.somewhere.mdr.rest.resource;

import javax.ws.rs.GET;
import javax.ws.rs.Path;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

@Path("/tryme")
public class TrymeResource {

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String getTryMe() throws Exception {

     return "Hello, this doesn't work!!";
}

The classpath for the non-working app looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    <classpathentry kind="con" path="melibrary.com.genuitec.eclipse.j2eedt.core.MYECLIPSE_JAVAEE_6_CONTAINER"/>
    <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
    <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
    <classpathentry combineaccessrules="false" kind="src" path="/mdr-message"/>
    <classpathentry combineaccessrules="false" kind="src" path="/mbr-stub"/>
    <classpathentry combineaccessrules="false" kind="src" path="/mdr-config"/>
    <classpathentry kind="output" path="WebContent/WEB-INF/classes"/>
</classpath>

The endpoint that returns the error is:

http://localhost:9081/mdr/resources/tryme

My web.xml for both of the applications looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<web-app 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></display-name> 
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

Now, one of my colleagues suggested that the issue must be that the second app can't see the JEE 6 jars, which makes sense. But I can't seem to figure out how that is happening.

I would be happy to provide more information if needed. Also, I know the specific error is mentioned in other questions, but I have searched through those questions and tried those things to no avail. Hence I am posting a new question because it appears the root cause is different.

Many thanks!


Solution

  • First, of all...my apologies. The actual issue here was something that I originally neglected to include in the code snippet above:

     private static final Logger logger =    
     LoggerFactory.getLogger(MdrApplication.class);
    

    I have now made the edit and it appears above.

    So apparently the MdrApplication class doesn't play nicely with the instantiation of an slf4j logger. And I literally mean instantiation only. I'm not actually using the logger in the class at all...simply instantiating it. The removal of that single line above allows the rest endpoint to work correctly.

    If anyone has any insight into why that might be causing this issue that would be great, but at least the actual problem has been resolved.


    UPDATE: The issue with the slf4j logger was due to an apparent conflict of sorts with the inherent slf4j jar that is bundled with WebSphere. Apparently the WebSphere version was good enough for compilation through Eclipse but was either not found or causing issues at runtime, as evidenced from the error when instantiating the logger. I found this because I also ran into other odd issues when trying to include the logger in my Resource class. The fix for this was to actually add the slf4j-api-1.7.12.jar in my WEB-INF/lib folder. (I also have my WebSphere classloader set to parent last for what it's worth, although neither setting works without the jar in the lib folder.) So although the actual cause is still a bit unknown, at least it is more fully known than before. Feel free to weigh in on the jar conflict issue if you have more information!


    Again, apologies for not posting that line earlier...it never occurred to me that could be the issue. In the future...I'll be posting every line of code!

    Hope this helps someone.