java WebServiceTransportException:未找到 [404]

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12892068/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 10:40:03  来源:igfitidea点击:

WebServiceTransportException: Not Found [404]

javaspringservicewebjaxb

提问by plandi07

I'm currently implementing a spring web service using jaxb. But when I trying to consume the web service created a WebServiceTransportException: Not Found [404]error is encountered. I did try to search the net but could not able to find a possible root cause. Below I have show my source codes.

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

application-context.xml

应用程序上下文.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>

Client for 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;
}
}

definition of my web service

我的网络服务的定义

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

And below is the error stack:

下面是错误堆栈:

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)

回答by RicardoGonzales

Maybe your URI:

也许您的 URI:

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

Check this value:

检查此值:

"http://mylocal:8080/mywebservice"

“http://mylocal:8080/mywebservice”

回答by Bongani Khumalo

Here is how I resolved this error:

这是我解决此错误的方法:

  1. Declare a SoapActionCallback.
  2. Use this callback in the marshalSendAndReceive() as follows.

    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();
    
  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();
    

回答by hiergiltdiestfu

In my case, the solution was to pay attention to the case in the URI. I had it in all lower case, but the webservice was expecting a CamelCase action name.

就我而言,解决方案是注意 URI 中的大小写。我用的都是小写的,但是网络服务需要一个 CamelCase 操作名称。