简体   繁体   中英

Websphere Application Server Servlet Initialization Error

We need to migrate an app that runs on Glassfish to Websphere Application Server (WAS) 8.5.x version.

To see that things are working correctly with a simple setup, I created a sample project with a single rest service.

I did not extend javax.ws.rs.core.Application with my own class, and I only have a class with path annotations. I defined a servlet in web.xml named "javax.ws.rs.core.Application" so that the annotations are scanned and services are expected to be reachable from given servlet url mapping.

When I try to access the service, I get a 404 message. But the real problem is the Apache Wink that comes with standard IBM Websphere libraries.

In the library source code (class DefaultLifecycleManager), there is a part like this:

79        if (ApplicationMetadataCollector.isApplication(cls)) {
80            // by default application subclasses are singletons
81            return LifecycleManagerUtils.createSingletonObjectFactory(cls);
82        }

The isApplication(cls) method should return true, and the singleton factory for it should then be created. However, it returns false. The body of the method is as following:

76    public static boolean More ...isApplication(Class cls) {
77        return Application.class.isAssignableFrom(cls);
78    }

I put a breakpoint there and checked the values. cls is exactly javax.ws.rs.core.Application, which is the same class in the 77th line.

This leads the servlet to not start correctly and return 404 to every request that maps to it.

I don't know how this method returns false, and I need your help.

Something must be wrong with your application, maybe you have some conflicting libraries.

I have very simple class:

@Path("/HelloRest")
public class Hello {

    @GET
    public String hello() {
        System.out.println("Rest called");
        return "Hello  " + new Date();
    }
}

with following web.xml , which is starting and working fine on WAS 8.5.5:

<servlet>
    <servlet-name>javax.ws.rs.core.Application</servlet-name>
</servlet>

<servlet-mapping>
    <servlet-name>javax.ws.rs.core.Application</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

when called http://localhost:9080/JAXRSTestWeb/rest/HelloRest

如果您的应用程序中捆绑了眨眼或运动衫或任何其他jaxrs库,请将其删除。

I recently did the almost same thing when I migrate form WAS 7.0 to WAS 8.5 . WAS 8.5 comes with inbuilt Apache Wink 1.1. You can follow these steps to migrate your application on WAS 8.5:

1) Remove all the apache wink jar from your application lib folder.

2) For building your application you can use these two websphere jar, com.ibm.ws.prereq.jaxrs.jar and com.ibm.ws.prereq.jackson.jar. you can find these jars in WAS_HOME/plugins folder.

3) Build your application with these jars but do not package these jars into your application EAR or WAR.

4) If your application type is EAR then Make sure all the restful resources and the class which extends Application class are part of war.

5) Redeploy your application, it should work fine now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM