带有Jersey 2.25的WebSphere 8.5.5.9

时间:2018-11-23 21:56:08

标签: rest web-applications jersey-2.0 websphere-8

我正在WebSphere 8.5.5.9上部署具有jersey 2.25的Web应用程序。我们正在通过下面的类注册资源。

public class ApplicationResourceConfig extends ResourceConfig {

/**
 * 
 */
public ApplicationResourceConfig() {
    packages(verifyAndLoadResources());
}

/**
 * @return
 */
private String[] getAllResources() {
    List<String> resources = new ArrayList<>();
    resources.add("com.ofs.fsapps.commonapps.appPreferences.resource.AppPreferencesResource");  

    resources.add("com.ofs.fsapps.commonapps.summary.rest.Summary");
    return resources.toArray(new String[0]);
}

/**
 * @return
 */
private String[] verifyAndLoadResources() {
    List<String> packageResourceList = new ArrayList<>();
    for (String resource : getAllResources()) {
        try {
            Class<?> result = Class.forName(resource);
            if (result != null) {
                register(StringUtils.substringAfterLast(resource, ".") + ".class");
                packageResourceList.add(StringUtils.substringBeforeLast(resource, "."));
            }
        } catch (ClassNotFoundException e) {
            System.out.println("Package/Class not Found : "+resource);
        }catch(Exception e) {
            System.out.println("Exception in loading Package/Class : "+resource);
        }
    }
    return packageResourceList.toArray(new String[0]);
}

}

使用上述方法,其余的调用均无法正常工作并以404响应。如果我们在web.xml中输入包/类,则一切正常。

    <servlet>
    <servlet-name>CommonRESTServlet</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>

    <init-param>
        <param-name>jersey.config.server.provider.classnames</param-name>
        <param-value>com.ofs.fsapps.commonapps.summary.rest.Summary, com.ofs.fsapps.commonapps.appPreferences.resource.AppPreferencesResource</param-value>
    </init-param>
</servlet>

请注意,已创建共享库,并且该库也与EAR链接。

下面是SystemErr.log中的异常。

  

java.lang.NullPointerException       在com.sun.xml.ws.transport.http.servlet.WSServletContextListener.existsServletForUrlPattern(WSServletContextListener.java:186)       在com.sun.xml.ws.transport.http.servlet.WSServletContextListener.registerWSServlet(WSServletContextListener.java:168)       在com.sun.xml.ws.transport.http.servlet.WSServletContextListener.parseAdaptersAndCreateDelegate(WSServletContextListener.java:132)       在com.sun.xml.ws.transport.http.servlet.WSServletContainerInitializer.onStartup(WSServletContainerInitializer.java:65)       在com.ibm.ws.webcontainer.webapp.WebAppImpl.initializeServletContainerInitializers(WebAppImpl.java:619)       在com.ibm.ws.webcontainer.webapp.WebAppImpl.initialize(WebAppImpl.java:409)       在com.ibm.ws.webcontainer.webapp.WebGroupImpl.addWebApplication(WebGroupImpl.java:88)       在com.ibm.ws.webcontainer.VirtualHostImpl.addWebApplication(VirtualHostImpl.java:170)       在com.ibm.ws.webcontainer.WSWebContainer.addWebApp(WSWebContainer.java:904)       在com.ibm.ws.webcontainer.WSWebContainer.addWebApplication(WSWebContainer.java:789)       在com.ibm.ws.webcontainer.component.WebContainerImpl.install(WebContainerImpl.java:427)       在com.ibm.ws.webcontainer.component.WebContainerImpl.start(WebContainerImpl.java:719)

0 个答案:

没有答案