WebServiceTransportException:找不到[404]

时间:2012-10-15 08:46:30

标签: java spring service web jaxb

我目前正在使用jaxb实现spring web服务。但是当我尝试使用Web服务时,遇到了WebServiceTransportException: Not Found [404]错误。我确实尝试搜索网络,但无法找到可能的根本原因。下面我展示了我的源代码。

应用程序的context.xml                                

<bean
    class="org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter">
    <constructor-arg ref="marshaller" />
</bean>

<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    <property name="classesToBeBound">
        <list>
            <value>com.ph.domain.EightBallRequest</value>
            <value>com.ph.domain.EightBallResponse</value>
        </list>
    </property>
</bean>

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix">
        <value>/jsp/</value>
    </property>
    <property name="suffix">
        <value>.jsp</value>
    </property>
</bean>

<bean id="simpleUrlHandlerMapping"
    class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"
    lazy-init="true">
    <property name="mappings">
        <props>
            <prop key="/test.asp">LandingController</prop>
        </props>
    </property>
</bean>     

<bean name="LandingController" class="com.ph.controller.LandingController">
    <property name="stub" ref="eightBallClient"/>
</bean>

webservice客户端

public class EightBallClient extends WebServiceGatewaySupport {

private Resource request;

public void setRequest(Resource request) {
    this.request = request;
}

public String AskQuestion(String question) throws IOException {
    String responseString = null;

    EightBallRequest request = new EightBallRequest();
    request.setQuestion(question);

    EightBallResponse response = new EightBallResponse();

    response = (EightBallResponse) getWebServiceTemplate()
            .marshalSendAndReceive(request);
    responseString = response.getAnswer().toString();
    return responseString;
}
}

我的网络服务的定义

                                        

<bean id="schema" class="org.springframework.xml.xsd.SimpleXsdSchema">
    <property name="xsd" value="/WEB-INF/eightball.xsd" />
</bean>

以下是错误堆栈:

SEVERE: Servlet.service() for servlet dispatcher threw exception
org.springframework.ws.client.WebServiceTransportException: Not Found [404]
    at org.springframework.ws.client.core.WebServiceTemplate.handleError(WebServiceTemplate.java:626)
    at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:550)
    at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:501)
    at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:350)
    at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:344)
    at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:336)

3 个答案:

答案 0 :(得分:1)

也许你的URI:

 <bean name="webserviceTemplate"
 class="org.springframework.ws.client.core.WebServiceTemplate">
     <property name="defaultUri" value="http://localhost:8080/mywebservice" />

检查此值:

  

“HTTP:// mylocal:8080 /为MyWebService”

答案 1 :(得分:1)

以下是我解决此错误的方法:

  1. 声明一个SoapActionCallback。
  2. 在marshalSendAndReceive()中使用此回调,如下所示。

    final EightBallResponse response = new EightBallResponse();
    final SoapActionCallback soapActionCallback = new SoapActionCallback("<the operation name as defined in the WSDL>");
    response = (EightBallResponse) getWebServiceTemplate()
        .marshalSendAndReceive(request, soapActionCallback );
    responseString = response.getAnswer().toString();
    

答案 2 :(得分:1)

在我的情况下,解决方案是注意URI中的情况。我用小写字母表示,但是web服务期待CamelCase操作名称。