Webservicetransportexception: Not Found [404]

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.

application-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>

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)
3

3 Answers

Maybe your URI:

 <bean name="webserviceTemplate"
 class="org.springframework.ws.client.core.WebServiceTemplate">
     <property name="defaultUri" value="" />

Check this value:

""

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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article
Twitter Facebook Pinterest