org.springframework.ws.client.WebServiceTransportException:Not Found [404]

时间:2015-07-31 08:30:49

标签: java spring web-services soap spring-ws

我使用spring-ws创建了一个soap服务。当我尝试测试服务时,我收到以下错误:

Exception in thread "main" org.springframework.ws.client.WebServiceTransportException: Not Found [404]
at org.springframework.ws.client.core.WebServiceTemplate.handleError(WebServiceTemplate.java:695)
at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:606)
at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:555)
at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:506)
at org.springframework.ws.client.core.WebServiceTemplate.sendSourceAndReceiveToResult(WebServiceTemplate.java:446)
at org.springframework.ws.client.core.WebServiceTemplate.sendSourceAndReceiveToResult(WebServiceTemplate.java:429)
at com.yatra.products.air.service.hff.HFFUpdateFromMoTest.main(HFFUpdateFromMoTest.java:22)

下面是我的xsd:

    <?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
            targetNamespace="hffNamespce" 
            xmlns:tns="hffNamespce" elementFormDefault="qualified">

    <xs:element name="ParamRequest">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="SuperPnr" type="xs:string"/>
                <xs:element name = "MOBookingRef" type="xs:string"/>
                <xs:element name="Status" type="xs:string" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    <xs:element name="paramResponse">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="ParamUpdated" type="xs:string"></xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

</xs:schema>

这是我的端点以及spring-ws-servlet

    package com.hff.products.air.service.mo;

import javax.xml.parsers.DocumentBuilderFactory;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

@Endpoint
public class HFFUpdateFromMoEndPoint {

    private static Logger logger = Logger.getLogger(HFFUpdateFromMoEndPoint.class);

    @Autowired @Qualifier("hffextractDetail")
    ExtractDetail extractDetail;

    @Autowired @Qualifier("hffrequest")
    ParamRequest request;

    @PayloadRoot(localPart="ParamRequest" , namespace = "hffNamespce")
    @ResponsePayload
    public Element getData(@RequestPayload Element xml)
    {
        Element response = null;
        String result = "Failure";
        try{
            if(xml.getAttribute("BookingRef")!= null && xml.getAttribute("Status") != null )
            {
                result = "Success";
            }
            request.setPnr(xml.getAttribute("Pnr"));
            request.setBookingRef(xml.getAttribute("BookingRef"));
            request.setStatus(StatusEnum.valueOf(xml.getAttribute("Status")).toString());
            extractDetail.getDetail(request);

            Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
            response = document.createElement("paramResponse");
            response.appendChild(addElement(document,"ParamUpdated",result));

        }catch(Exception e)
        {
            logger.error("unable to parse input xml" + e.getStackTrace());
        }

        return response;        
    }

    private Element addElement(Document document, String element, String value) {

        Element child = document.createElement(element);
        child.appendChild(document.createTextNode(value));
        return child;

    }

}



    <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:sws="http://www.springframework.org/schema/web-services"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/web-services 
       http://www.springframework.org/schema/web-services/web-services-2.0.xsd
       http://www.springframework.org/schema/context 
       http://www.springframework.org/schema/context/spring-context-3.0.xsd">


    <description>
        This web application context contains Spring-WS beans. The beans defined in this context are automatically
        detected by Spring-WS, similar to the way Controllers are picked up in Spring Web MVC.
    </description>

    <context:component-scan base-package="com.hff.products.air.service.mo"/>

    <sws:annotation-driven />

    <bean id="hffextractDetail" class="com.hff.products.air.service.mo.ExtractDetail"/> 
    <bean id="hffrequest" class="com.hff.products.air.service.mo.ParamRequest"/>

    <sws:interceptors>
        <bean class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor">
            <description>
                This interceptor validates both incoming and outgoing message contents according to the 'echo.xsd' XML
                Schema file.
            </description>
            <property name="schema" value="/WEB-INF/classes/xsd/hff.xsd"/>
            <property name="validateRequest" value="true"/>
            <property name="validateResponse" value="true"/>
        </bean>
        <bean class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor">
            <description>
                This interceptor logs the message payload.
            </description>
        </bean>
    </sws:interceptors>

    <sws:dynamic-wsdl id="hff" portTypeName="hff" locationUri="hffservices">
        <sws:xsd location="/WEB-INF/classes/xsd/hff.xsd"/>
    </sws:dynamic-wsdl>


</beans>

在我的web.xml中创建了2个servlet

    <?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>dynapack</display-name>

    <servlet>
        <servlet-name>spring-servlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                classpath:spring/root-context.xml,
                classpath:spring/servlet-context.xml
            </param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
        <async-supported>true</async-supported>
    </servlet>

    <servlet-mapping>
        <servlet-name>spring-servlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <filter>
        <filter-name>XSSFilter</filter-name>
        <filter-class>com.yatra.platform.xss.filter.XSSFilter</filter-class>
        <async-supported>true</async-supported>
    </filter>
     <filter-mapping>
      <filter-name>XSSFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <error-page>
        <error-code>500</error-code>
        <location>/WEB-INF/error/resourceUnavailable.jsp</location>
    </error-page>

    <servlet>
        <servlet-name>spring-ws</servlet-name>
        <servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
        <init-param>
            <param-name>transformWsdlLocations</param-name>
            <param-value>true</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring-ws</servlet-name>
        <url-pattern>/ws/*</url-pattern>
    </servlet-mapping>

</web-app>

我在网上搜索并发现如果我的有效负载根元素mappimg不正确,那么我可能会收到此错误。但在确定这一点后,我又得到了这个例外。现在我陷入了困境。请帮忙。

修改

这是我的build.xml

    <?xml version="1.0" encoding="UTF-8"?>
<project name="air-service" default="" basedir=".">

    <property file="build.properties" />
    <property environment="env"/>
    <condition property="environment" value="${env.environment}" else="DEV">
        <isset property="env.environment" />
    </condition>
    <condition property="server.deploy.dir" value="${env.server_deploy_dir}" else="${property.server.deploy.dir}">
        <isset property="env.environment" />
    </condition>
    <import file="build_artifact.xml"/>

    <echo>##############################</echo>
    <echo>Building for environment - ${environment}</echo>
    <echo>Minfication - ${env.minify}</echo>
    <echo>Deploy Directory - ${server.deploy.dir}</echo>
    <echo>##############################</echo>


    <taskdef resource="net/sf/antcontrib/antcontrib.properties" classpath="../libs/jars/other/antcontrib.jar"/>

    <target name="clean" >
        <ant antfile="${ant.templates.dir}/build.xml" target="clean_template" inheritall="true"/>
    </target>

    <target name="compile" depends="clean">
        <ant antfile="${ant.templates.dir}/build.xml" target="compile_template" inheritall="true"/>
    </target>

    <target name="copy_resources" depends="clean,copy_jars">

        <ant antfile="${ant.templates.dir}/build.xml" target="copy_local_resources_template" inheritall="true"/>

        <ant antfile="${ant.templates.dir}/build.xml" target="copy_resources_template" inheritall="true">
            <property name="resources.project.dir" value="${air.resources.dir}"/>
        </ant>

        <ant antfile="${ant.templates.dir}/build.xml" target="copy_resources_template" inheritall="true">
            <property name="resources.project.dir" value="${global.resources.dir}"/>
        </ant>

    </target>

    <target name="decompile">

            <unjar src="${libs.dir}/jars/yatra/air_tenancy.jar"
                dest="${classes.dir}">
        </unjar>
    </target>

    <target name="copy_jars">
        <!-- All library jars except yatra's jars -->
        <copy todir="${libs.target.dir}" flatten="true">
            <fileset dir="${libs.dir}/jars">
                <include name="**/*.jar" />
                <exclude name="**yatra/*.jar"/>
            </fileset>
        </copy>

    </target>

    <target name="package" >
        <war destfile="${target.root}/${war.name}" basedir="${target.dir}"/>
    </target>

    <target name="build"
        depends="clean,compile,copy_resources,package">
    </target>

    <target name="deploy" depends="build">
        <copy todir="${server.deploy.dir}"  overwrite="true">
            <fileset file="${target.root}/${war.name}" />
        </copy>
    </target>


    <target name="buildAll" depends="build_dependent_projects,build" />

    <target name="test">
        <ant antfile="${ant.templates.dir}/build_test.xml" target="test" inheritall="true"/>
    </target>

</project>

0 个答案:

没有答案