标签: spring-ws

当request-element没有以'Request'结尾时,spring-ws生成的wsdl无效

我必须准备一个web服务来接受已定义的wsdl结构.我按照这里的教程,在这里可以下载测试项目的源代码.

对于像这样的xsd:

<xs:element name="getCountryRequest">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="name" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>
Run Code Online (Sandbox Code Playgroud)

应用程序返回的请求的Wsdl操作正常,如下所示:

<wsdl:binding name="CountriesPortSoap11" type="tns:CountriesPort">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="getCountry">
        <soap:operation soapAction=""/>
        <wsdl:input name="getCountryRequest">
            <soap:body use="literal"/>
        </wsdl:input>
        <wsdl:output name="getCountryResponse">
            <soap:body use="literal"/>
        </wsdl:output>
    </wsdl:operation>
</wsdl:binding>
Run Code Online (Sandbox Code Playgroud)

但是当我将xsd更改为(元素名称中没有'Request')时:

<xs:element name="getCountry">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="name" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>
Run Code Online (Sandbox Code Playgroud)

wsdl无效,并且没有<input>指定:

<wsdl:binding name="CountriesPortSoap11" type="tns:CountriesPort">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="getCountry">
        <soap:operation soapAction=""/>
        <wsdl:output name="getCountryResponse">
            <soap:body use="literal"/>
        </wsdl:output>
    </wsdl:operation>
</wsdl:binding>
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?如何Request在wsdl中将无元素作为soap操作输入正确显示?

java wsdl web-services spring-ws cxf

8
推荐指数
1
解决办法
6378
查看次数

JDK17 + Spring Boot Starter Web 服务:在模块路径或类路径上未找到 JAXB-API 的实现

我有一个简单的 Spring Boot 应用程序,我想将请求发送到 SOAP 端点。不幸的是,每次我尝试这样做时,我都会收到:javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath。我非常有信心我拥有所有必需的库,但我不知道为什么会发生这种情况

Caused by: javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:177)
    at javax.xml.bind.ContextFinder.find(ContextFinder.java:364)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:508)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:465)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:366)
    at org.springframework.oxm.jaxb.Jaxb2Marshaller.createJaxbContextFromContextPath(Jaxb2Marshaller.java:540)
    at org.springframework.oxm.jaxb.Jaxb2Marshaller.getJaxbContext(Jaxb2Marshaller.java:500)
    ... 18 common frames omitted
Caused by: java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
    at javax.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:122)
    at javax.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:155)
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:174)
    ... 24 common frames omitted
Run Code Online (Sandbox Code Playgroud)

我使用的是JDK17

openjdk 17.0.2 2022-01-18
OpenJDK …
Run Code Online (Sandbox Code Playgroud)

java spring-ws jaxb spring-oxm spring-boot

8
推荐指数
1
解决办法
2万
查看次数

如何为Spring的WebServiceTemplate创建一个模拟对象?

我有一个调用现有Web服务的类.我的类正确处理有效的结果以及Web服务生成的错误字符串.对Web服务的基本调用看起来像这样(尽管这是简化的).

public String callWebService(final String inputXml)
{
  String result = null;

  try
  {
    StreamSource input = new StreamSource(new StringReader(inputXml));
    StringWriter output = new StringWriter();

    _webServiceTemplate.sendSourceAndReceiveToResult(_serviceUri, input, new StreamResult(output));

    result = output.toString();
  }
  catch (SoapFaultClientException ex)
  {
    result = ex.getFaultStringOrReason();
  }

  return result;
}
Run Code Online (Sandbox Code Playgroud)

现在我需要创建一些测试所有成功和失败条件的单元测试.它无法调用实际的Web服务,所以我希望有一些模拟对象可用于Spring-WS的客户端.有没有人知道可用于WebServiceTemplate或任何相关类的模拟对象?我是否应该尝试编写自己的类并修改我的类以使用WebServiceOperations接口与WebServiceTemplate?

java spring-ws mocking

7
推荐指数
2
解决办法
1万
查看次数

Spring WS DefaultWsdl11Definition错误

我正在使用Spring WS并声明一个DefaultWsdl11Definition bean来动态生成WSDL文件.

但是,当我启动webserver(tomcat)时,我得到一个bean实例错误,原因是:

    Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: javax/wsdl/extensions/ExtensibilityElement
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:141)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:74)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:958)
    ... 45 more
Caused by: java.lang.NoClassDefFoundError: javax/wsdl/extensions/ExtensibilityElement
    at org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition.<init>(DefaultWsdl11Definition.java:56)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126)
    ... 47 more
Caused by: java.lang.ClassNotFoundException: javax.wsdl.extensions.ExtensibilityElement
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1671)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1516)
    ... 53 more
Run Code Online (Sandbox Code Playgroud)

SpringWS-Servlet.xml中的Bean

<bean id="beanWS" class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition">
        <property name="schema">
            <bean class="org.springframework.xml.xsd.SimpleXsdSchema">
                <property name="xsd" value="/WEB-INF/somexsd.xsd"/>
            </bean>
        </property>
        <property name="portTypeName" value="beanWS"/>
        <property name="locationUri"
                  value="http://localhost:8080/springws"/> …
Run Code Online (Sandbox Code Playgroud)

java spring web-services spring-ws

7
推荐指数
2
解决办法
2万
查看次数

Web服务与Spring远程处理

我完全没有通过spring或axis与Remoting实现常规Web服务之间的区别.

如果我的问题根本没有关系,我只是在春季网络服务与春季远程服务之间感到困惑.何时进行远程处理以及何时使用Web服务.

感谢你的回答

spring web-services spring-ws

7
推荐指数
2
解决办法
6255
查看次数

如何配置Spring-WS以使用JAXB Marshaller?

到目前为止,谢谢你的帮助,我正在更新问题,因为我没有显示我需要的所有内容,显示的更改显示.肥皂输出仍然不是我想要的.

servlet.xml中

<?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:context="http://www.springframework.org/schema/context"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:sws="http://www.springframework.org/schema/web-services"
    xmlns:oxm="http://www.springframework.org/schema/oxm"
    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
                        http://www.springframework.org/schema/oxm 
                        http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd"
                        >

<!--Enables @Endpoint and related Spring-WS annotations.-->
<sws:annotation-driven marshaller="marshaller" unmarshaller="marshaller"/> 

<bean id="weatherService"
    class="au.test.weather.ws.WeatherServiceImpl" />

<bean id="schema" class="org.springframework.xml.xsd.SimpleXsdSchema" 
    p:xsd = "classpath:au/test/weather/ws/schemas/Temperature.xsd"/>

<oxm:jaxb2-marshaller id="marshaller" >
    <oxm:class-to-be-bound name="au.test.weather.ws.GetTemperaturesResponse"/> 
    <oxm:class-to-be-bound name="au.test.weather.ws.GetTemperaturesRequest"/>
    <oxm:class-to-be-bound name="au.test.weather.ws.schemas.Jaxb2Marshaller"/>  
</oxm:jaxb2-marshaller> 

<bean id="temperatureEndpoint"
    class="au.test.weather.ws.TemperatureMarshallingEndpoint">
    <property name="weatherService" ref="weatherService" />
</bean>
Run Code Online (Sandbox Code Playgroud)

我的注释类看起来像什么

@XmlRootElement(name = "GetTemperaturesRequest")
public class GetTemperaturesRequest {

    @XmlElement(required = true)
    protected String city;
    @XmlElement(required = true)
    @XmlSchemaType(name = "date")
    protected List<XMLGregorianCalendar> …
Run Code Online (Sandbox Code Playgroud)

java spring spring-ws jaxb endpoint

7
推荐指数
1
解决办法
3万
查看次数

如何将具有相同名称空间和本地名称请求的两个单独Web服务路由到不同的端点?

我试图在一个弹簧部署中创建两个单独的Web服务,两者都使用相同的xsd模式生成wsdl,但是将它们路由到两个单独的端点,这样我就可以在不同的上下文中以不同的方式处理请求.

例如:

Webservice 1:访问子集,较低权限和安全性约束

Webservice 2:更高的权限

<sws:dynamic-wsdl id="spml-readonly" 
    portTypeName="SpmlReadOnlyService" 
    locationUri="SpmlReadOnly">
    <sws:xsd location="/WEB-INF/xsd/spml/pstc_spmlv2_core.xsd"/>
</sws:dynamic-wsdl>

<sws:dynamic-wsdl id="spml-crud" 
    portTypeName="SpmlCrudService" 
    locationUri="SpmlCrud">
    <sws:xsd location="/WEB-INF/xsd/spml/pstc_spmlv2_core.xsd"/>
    <sws:xsd location="/WEB-INF/xsd/spml/pstc_spmlv2_search.xsd"/>
    <sws:xsd location="/WEB-INF/xsd/spml/pstc_spmlv2_batch.xsd"/>
</sws:dynamic-wsdl>
Run Code Online (Sandbox Code Playgroud)

现在因为两个wsdl都基于相同的xsds,所以请求的'namespace'和'localPart'都是相同的,无论我正在点击哪个Web服务(/ SpmlReadOnly或/ SpmlCrud).

因此,由于localPart和命名空间仍然完全相同等,因此排除了已弃用的PayloadRootQNameEndpointMapping,并且我的当前配置只是将请求路由到同一端点方法处理程序,我无法区分调用哪个Web服务:

    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "lookupRequest")
    @ResponsePayload
    public Source handleLookupRequest(SoapMessage message) throws Exception {
        ...
    }
Run Code Online (Sandbox Code Playgroud)

我能做什么甚至可能?如果xsd是共享的并且在模式的根目录中具有相同的名称空间,并且相同的localPart方法请求,那么是否有办法区分它们并映射到两个不同的端点?有关这方面的任何信息都很有用!我希望我不必设置两个单独的.wars,并在服务器上使用自己的代码库单独部署它们!

谢谢,达米安

spring web-services spring-ws spml

7
推荐指数
1
解决办法
4527
查看次数

SOAP元素有两个元素

我正在尝试使用以下结构创建soap消息:

<SOAP:Envelope>
    <SOAP:Header/>
    <SOAP:Body>
        <Item1/>
        <Item2/>
    </SOAP:Body>
</SOAP:Envelope>
Run Code Online (Sandbox Code Playgroud)

我使用WebServiceMessageCallback来获取上述格式,但是当我尝试使用新源转换主体时,source具有以上格式:

TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.transform(source, soapBody.getPayloadResult());
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

[Fatal Error] :1:157: The markup in the document following the root element must be well-formed.
ERROR:  'The markup in the document following the root element must be well-formed.'
    Exception in thread "main" org.springframework.ws.client.WebServiceTransformerException:Transformation error: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 157; The markup in the document following the root element must be well-formed.; nested exception is javax.xml.transform.TransformerException: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 157; …
Run Code Online (Sandbox Code Playgroud)

java xml spring soap spring-ws

7
推荐指数
1
解决办法
1373
查看次数

如何在不使用Spring启动和使用单独的Apache tomcat服务器的情况下在Spring WS中配置双向SSL连接?

我需要以双向SSL连接安全机制向服务器发送soap请求消息,并且还处理来自服务器的Soap响应.我使用Spring MVC和Spring ws,它完全使用注释配置并需要配置用于向服务器发送soap请求的双向SSL连接.如何在我的Spring MVC Web服务应用程序中使用双向SSL连接,以便通过SSL将我的soap消息发送到服务器?

java security spring-ws spring-mvc tomcat7

7
推荐指数
1
解决办法
7989
查看次数

SOAPExceptionImpl:无效的内容类型:文本/html。这是错误消息而不是 SOAP 响应吗?

我需要有关调用 Web 服务的帮助。我org.springframework.ws.client用来调用WS,代码如下:

Response response = (Response) getWebServiceTemplate().marshalSendAndReceive(
                "http://ip:port/DefaultRequestListener?workflow=WsdlCPF&soapAction=Import",
                request,
                new SoapActionCallback("http://ip:port/DefaultRequestListener?workflow=WsdlCPF&soapAction=Import"));
Run Code Online (Sandbox Code Playgroud)

此外,我可以http://ip:port/DefaultRequestListener?workflow=WsdlCPF&soapAction=Import使用 SOAP UP调用 WS 并使用此链接(看起来很奇怪)接收响应。它工作正常。

从 IDE 运行代码后,我收到下一个堆栈跟踪:

Exception in thread "main" java.lang.IllegalStateException: Failed to execute CommandLineRunner
    at org.springframework.boot.SpringApplication.runCommandLineRunners(SpringApplication.java:677)
    at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:693)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:322)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:969)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:958)
    at com.mayacomp.feeder.Application.main(Application.java:33)
Caused by: org.springframework.ws.soap.SoapMessageCreationException: Could not create message from InputStream: Invalid Content-Type:text/html. Is this an error message instead of a SOAP response?; nested exception is com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Invalid Content-Type:text/html. Is this an error message instead of a …
Run Code Online (Sandbox Code Playgroud)

java soap spring-ws

6
推荐指数
1
解决办法
3万
查看次数