无法在派生的MVC项目中公开Web服务

时间:2017-02-07 17:57:43

标签: java spring web-services spring-mvc wsdl

我正在开发一个源自基于Spring-MVC的框架的Spring MVC项目。我可以在我的项目中定义任意数量的Spring XML上下文文件,平台提供的文件将自动加载。

我已经定义了一个WSDL(首先是契约优先),然后使用CXF的wsdl2java工具将这个WSDL编译成带注释的SEI

我可以立即使用CXF 3,但作为一项实验,我被要求使用spring-ws公开服务。

为简单起见,此服务没有身份验证或特殊内容。 我试图关注spring-ws指南,但完全迷失了。关键点在于,我不了解我的@Endpoint响应的URL。如果我知道的话,我可以轻松地用soapui查询它。

到目前为止,我已经使用简单的操作定义定义了WSDL(为简单起见,详细信息已经过编辑)

<wsdl:portType name="SgaRuotaService">
    <wsdl:operation name="UploadModelloUnico">
        <wsdl:input message="sgaws:UploadModelloUnicoRequest" />
        <wsdl:output message="sgaws:UploadModelloUnicoResponse" />
        <wsdl:fault name="fault" message="sgaws:UploadModelloUnicoFault"></wsdl:fault>
    </wsdl:operation>
</wsdl:portType>

SEI如下

@WebService(targetNamespace = "http://www.acme.com/schemas/sgaws/v1", name = "SgaRuotaService")
@XmlSeeAlso({ObjectFactory.class})
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
@Generated(value = "org.apache.cxf.tools.wsdlto.WSDLToJava", date = "2017-02-07T15:33:48.958+01:00", comments = "Apache CXF 3.1.9")
public interface SgaRuotaService {

    @WebMethod(operationName = "UploadModelloUnico", action = "http://www.acme.com/schemas/sga-ruota-push/UploadModelloUnico")
    @WebResult(name = "UploadModelloUnicoResponse", targetNamespace = "http://www.acme.com/schemas/sgaws/v1", partName = "parameters")
    @Generated(value = "org.apache.cxf.tools.wsdlto.WSDLToJava", date = "2017-02-07T15:33:48.958+01:00")
    public UploadModelloUnicoResponseType uploadModelloUnico(
        @WebParam(partName = "parameters", name = "UploadModelloUnicoRequest", targetNamespace = "http://www.acme.com/schemas/sgaws/v1")
        UploadModelloUnicoRequestType parameters
    ) throws UploadModelloUnicoFault;
}

我已经衍生出来了..

@Endpoint("sgaRuotaService")
@RequestMapping("/pub/sgaRuotaService") //further attempt to make it work
public class RuotaServiceEndpoint implements SgaRuotaService
{

    private final static Logger log = LogManager.getLogger();

    @Override
    //@PayloadRoot(namespace = "http://www.acme.com/schemas/sgaruota/v1", localPart = "UploadModelloUnicoRequestType")
    @ResponsePayload
    @SoapAction("http://www.acme.com/schemas/sga-ruota-push/UploadModelloUnico")
    public UploadModelloUnicoResponseType uploadModelloUnico(@RequestPayload UploadModelloUnicoRequestType parameters) throws UploadModelloUnicoFault
    {
        log.info("Ruota service");
        return null;
    }

}

然后是上下文文件。在使用配置弄乱了很多之后我得到了以下内容

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:sws="http://www.springframework.org/schema/web-services"
    xmlns:util="http://www.springframework.org/schema/util" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:oxm="http://www.springframework.org/schema/oxm"
    xsi:schemaLocation="
      http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context-4.3.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/util
      http://www.springframework.org/schema/util/spring-util.xsd
      http://www.springframework.org/schema/mvc
      http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
      http://www.springframework.org/schema/oxm
      http://www.springframework.org/schema/oxm/spring-oxm-4.3.xsd"
>

    <oxm:jaxb2-marshaller id="oxmMarshaller" context-path="com.acme.sga.ws.ruota" />

    <!-- WEB SERVICE -->

    <sws:annotation-driven marshaller="oxmMarshaller" unmarshaller="oxmMarshaller" />
    <sws:interceptors>
        <bean class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor" />
    </sws:interceptors>
    <sws:static-wsdl id="/pub/sgaRuota.wsdl" location="classpath:META-INF/wsdl/sga-ruota-service.wsdl" />

    <!-- <bean class="org.springframework.oxm.jaxb.Jaxb2Marshaller" id="oxmMarshaller"> -->
    <!-- <property name="packagesToScan"> -->
    <!-- <array> -->
    <!-- <value>com.acme.sga</value> -->
    <!-- </array> -->
    <!-- </property> -->
    <!-- </bean> -->

    <bean class="org.springframework.ws.transport.http.WsdlDefinitionHandlerAdapter" />

    <bean class="org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter">
        <property name="messageFactory">
            <bean class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
                <constructor-arg>
                    <bean class="javax.xml.soap.MessageFactory" factory-method="newInstance" />
                </constructor-arg>
            </bean>
        </property>
    </bean>

    <bean class="org.springframework.ws.transport.http.WsdlDefinitionHandlerAdapter" />



    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <props>
                <prop key="/pub/sgaRuota.wsdl">/pub/sgaRuota.wsdl</prop>
            </props>
        </property>
    </bean>


    <bean id="messageDispatcher" class="org.springframework.ws.soap.server.SoapMessageDispatcher" />
    <bean class="org.springframework.ws.soap.server.endpoint.mapping.SoapActionAnnotationMethodEndpointMapping" />

<!--     <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter" /> -->


</beans>

Web应用程序启动并运行(网页部分......)但我无法以任何方式加载WSDL,也无法ping服务端点。

我可以根据需要发布其他片段,但问题是:如何在上下文/pub目录下公开服务端点,这是&#34;顺便提及&#34;不在spring-security下?

0 个答案:

没有答案