简体   繁体   English

在Websphere Application Server 7上运行简单的JAX-RS应用程序时出现null错误

[英]Getting null error when running a simple JAX-RS app on Websphere Application Server 7

I have no compilation errors and my app launches fine on my testing server. 我没有编译错误,我的应用程序在我的测试服务器上启动正常。 However, I get an error when trying a GET request: 但是,我在尝试GET请求时遇到错误:

[1/2/14 10:23:13:248 EST] 00000022 RequestProces I org.apache.wink.server.internal.RequestProcessor logException The following error occurred during the invocation of the handlers chain: WebApplicationException (404 - Not Found) with message 'null' while processing GET request sent to http://localhost:9081/IDMWorkflowServices/resources/workflow

Here is my web.xml: 这是我的web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.5" 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_2_5.xsd">
<display-name>IDMWorkflowServices</display-name>
<servlet>
    <description>
    JAX-RS Tools Generated - Do not modify</description>
    <servlet-name>JAX-RS Servlet</servlet-name>
    <servlet-class>com.ibm.websphere.jaxrs.server.IBMRestServlet</servlet-class>
    <init-param>
        <param-name>javax.ws.rs.core.Application</param-name>
        <param-value>com.psg.itim.workflow.WorkflowResourceApplication</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>JAX-RS Servlet</servlet-name>
    <url-pattern>
    /resources/*</url-pattern>
</servlet-mapping>
</web-app>

Here is WorkflowResource: 这是WorkflowResource:

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

// The Java class will be hosted at the URI path "/workflow"
@Path("/workflow")
public class WorkflowResource {
    @GET
    @Produces("text/plain")
    public String getClichedMessage() {
        // Return some cliched textual content
        return "Hello World";
    }
}

Here is WorflowResourceApplication: 这是WorflowResourceApplication:

import javax.ws.rs.core.Application;
import java.util.HashSet;
import java.util.Set;

public class WorkflowResourceApplication extends Application{
    @Override
    public Set<Class<?>> getClasses() {
        Set<Class<?>> classes = new HashSet<Class<?>>();
        classes.add(WorkflowResource.class);
        return classes;
    }
}

If it's not painfully obvious, this is my first attempt using JAX-RS. 如果不是很明显,这是我第一次尝试使用JAX-RS。 I'm not exactly sure what I do or do not need from the above code to get this to work. 我不完全确定我从上面的代码中做了什么或不需要什么来让它工作。 It seems simple, but when I go to this url 看起来很简单,但是当我去这个网址时

http://localhost:9081/IDMWorkflowServices/resources/workflow

the 404 happens. 404发生了。 Any ideas of what I am doing wrong? 我做错了什么想法?

Resolved! 解决! The only thing that was wrong was this line: 唯一错误的是这条线:

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

I changed it to: 我改成了:

<param-name>javax.ws.rs.Application</param-name>

I assumed it should have been the same Class I was calling from WorflowResourceApplication.java, but this was not the case. 我假设它应该与我从WorflowResourceApplication.java调用的类相同,但事实并非如此。 Everything works fine now. 现在一切都很好。 Apparently the application recognized the class error as a client side issue and registered a 404. 显然,应用程序将类错误识别为客户端问题并注册了404。

The first step to debug this would be to see if you have the correct port. 调试这个的第一步是看看你是否有正确的端口。 So do this - Try accessing just - http: //localhost:9081 . 这样做 - 尝试访问 - http:// localhost:9081。 see if you get to default page or blank page or hello page if there is default index.jsp. 如果有默认的index.jsp,请查看是否进入默认页面或空白页面或hello页面。 If you get 404 then that means that you serever is running but your port number is incorrect. 如果你得到404那么这意味着你的serever正在运行,但你的端口号是不正确的。

If you are unsure what your port settings are(If I am correct then default port should be 9080) then follow this documentation - http://pic.dhe.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=%2Fcom.ibm.websphere.migration.nd.doc%2Finfo%2Fae%2Fae%2Frmig_portnumber.html 如果你不确定你的端口设置是什么(如果我是正确的,那么默认端口应该是9080)然后按照这个文档 - http://pic.dhe.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic= %2Fcom.ibm.websphere.migration.nd.doc%2Finfo%2Fae%2Fae%2Frmig_portnumber.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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