我刚刚在Manning Publications Co.的Craig Walls的第二版"Spring in Action"中阅读了关于SOAP的文章.他们写了一篇关于契约优先的文章,就像Spring文档一样,编写了一个消息和方法XML和然后将其转换为XSD,然后再转换为WSDL,同时在Spring中连接编组和服务路径.
我必须承认,我不相信.为什么这比制作服务接口并基于该接口生成服务更好?这与在Spring3中定义我的REST @Controllers非常接近.通过使用Spring制作SOAP Web服务,我是否可以选择这样的路径?
另外:我想复制已经存在的Web服务.我有它的WSDL,我可以放置我的服务而不是它.这是推荐的吗?如果是这样,推荐的方法是什么?
干杯
Nik
Run Code Online (Sandbox Code Playgroud) 我写了spring webservice cleint示例这对springws1.5工作正常但是当使用spring ws 1.0.4运行时,我得到的是异常.请帮助我,为什么我们会得到这个例外以及如何解决.我只需使用down版本,因为我的弹簧版本是2.0.4.请尽可能尽快回复.
Unhandled exception:
org.springframework.oxm.jaxb.JaxbUnmarshallingFailureException: JAXB unmarshalling exception: unexpected element (uri:"http://yyy.org", local:"xxxResponse"). Expected elements are <{}xxx>,<{}xxxResponse>; nested exception is javax.xml.bind.UnmarshalException: unexpected element (uri:"yyy.org", local:"xxxResponse"). Expected elements are <{}xxx>,<{}xxxResponse>
Caused by:
javax.xml.bind.UnmarshalException: unexpected element (uri:"http://yyy.org", local:"xxxResponse"). Expected elements are <{}xxx>,<{}xxxResponse>
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:603)
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:244)
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:239)
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:116)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext$DefaultRootLoader.childElement(UnmarshallingContext.java:1009)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:446)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:427)
at com.sun.xml.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(InterningXmlVisitor.java:71)
at com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:137)
at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:240)
at com.sun.xml.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:123)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:314)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:297)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:107)
at org.springframework.oxm.jaxb.Jaxb2Marshaller.unmarshal(Jaxb2Marshaller.java:395)
at org.springframework.ws.support.MarshallingUtils.unmarshal(MarshallingUtils.java:62)
at org.springframework.ws.client.core.WebServiceTemplate$2.extractData(WebServiceTemplate.java:276)
at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:417)
at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:265) …Run Code Online (Sandbox Code Playgroud) 我正在试图找出为Spring的WebService Template类编写单元测试的最佳方法.我要做的是检查以确保我为我的客户端生成的每个请求/响应类型正确连接这些类.我还想确保如果返回异常,则正确处理异常.
我想我想要做的是找出一种方法来进行实际的发送/接收呼叫.
有什么建议?
我在 spring-ws 中使用 DynamicWsdl11Definition 来生成我的 wsdl 规范。最终,我得到了一个没有附加到 wsdl 操作的 wsdl 错误的规范,因为我不知道如何自动将特定的 wsdl/soap 操作与特定的 wsdl 错误关联起来。我怎样才能做到这一点?有没有办法将 wsdl 错误与 XSD 模式中的 wsdl 操作相关联?
这是我的 XSD 的一部分:
<xs:element name="setContextRequest">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="usageContext" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="setContextResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
Run Code Online (Sandbox Code Playgroud)
这是我的例外:
<xs:element name="InvalidSessionException">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="InvalidSessionException" nillable="true" type="fault:InvalidSession"/>
</xs:sequence>
</xs:complexType>
</xs:element>
Run Code Online (Sandbox Code Playgroud)
这是 WSDL 规范:
<wsdl:operation name="setContext">
<soap:operation soapAction=""/>
<wsdl:input name="setContextRequest">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="setContextResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
Run Code Online (Sandbox Code Playgroud)
我的问题是如何将错误与该操作相关联,最终以: …
我有一个Web应用程序,它充当使用Spring WS实现的Jax-WS Web服务的客户端.Spring WS配置为在SOAP标头中需要用户名标记.在Web应用程序中,我计划使用Spring Web服务模板,但我似乎找不到任何显示如何将UsernameToken添加到传出请求的示例.
有人能指出我正确的方向吗?
谢谢.
我使用spring-ws生成了webservice.我已经在tomcat中部署了我的应用程序并且没有任何错误地部署.我无法找到WSDL的路径.请帮我讲述如何为wsdl创建路径.
我的web.xml:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>listener><servlet><servlet-name>spring-ws</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class></servlet><servlet-mapping><servlet-name>sprig-ws</servlet-name><url-pattern>/</url-pattern></servlet-mapping> <context-param><param-name>contextConfigLocation</param-name><param-value>/WEB-INF/spring-ws--servlet.xml</param-value></context-param>
Run Code Online (Sandbox Code Playgroud)
弹簧-WS-servlet.xml中
<bean class="org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter">
<constructor-arg ref="marshaller" />
</bean>
<bean id="marshaller"
class="org.springframework.oxm.xmlbeans.XmlBeansMarshaller">
</bean>
<bean id="loginEndpoint" class="com.cloudexult.endpoint.LoginEndpoint">
</bean>
<sws:dynamic-wsdl id="loginmanager" portTypeName="LoginService" locationUri="/loginService/"
targetNamespace="http://www.example.org/Login/definitions">
<sws:xsd location="/WEB-INF/schema/Login.xsd"/>
</sws:dynamic-wsdl>
Run Code Online (Sandbox Code Playgroud) JVM 1.8.0_45
apache-camel 2.15.2
spring-ws 2.2.1
spring-boot 1.2.4
我试图在spring-boot应用程序中使用apache-camel(2.15.2)来处理传入的Web服务调用.
我根据这里的指南创建了一个初始工作的春季启动项目(没有骆驼)http://spring.io/guides/gs/producing-web-service/
然后我尝试将Camel:Spring Web Services组件集成为Consumer来处理传入的Web服务请求,遵循"公开Web服务"部分中的指导原则http://camel.apache.org/spring-web-services.html
WebServiceConfig.java
import org.apache.camel.component.spring.ws.bean.CamelEndpointMapping;
@EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {
@Bean
public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean(servlet, "/ws/*");
}
// default wsdl stuff here...
// exposing the endpoint mapping bean here rather than in spring-ws-servlet.xml (seems to work)
@Bean public CamelEndpointMapping endpointMapping() {
return new CamelEndpointMapping();
}
}
Run Code Online (Sandbox Code Playgroud)
ClaimRouter.java
import org.apache.camel.LoggingLevel;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.dataformat.JaxbDataFormat; …Run Code Online (Sandbox Code Playgroud) 我正在使用Spring Boot(1.2.4.RELEASE)构建一个Web服务,我对这个框架很新.特别是,我正在尝试在抛出异常时自定义SoapFault内容(添加"detail"标记).
我按照这篇文章这样做:http://www.stevideter.com/2009/02/18/of-exceptionresolvers-and-xmlbeans/
这是我的例外:
package foo.bar.exception;
import org.springframework.ws.soap.server.endpoint.annotation.FaultCode;
import org.springframework.ws.soap.server.endpoint.annotation.SoapFault;
@SoapFault(faultCode = FaultCode.SERVER)
public class ServiceException extends Exception {
private static final long serialVersionUID = -1804604596179996724L;
private String tempFaultDetail;
public ServiceException(){
super("ServiceException");
}
public ServiceException(String message) {
super(message);
}
public ServiceException(String message, Throwable cause) {
super(message, cause);
}
public ServiceException(String message, Throwable cause, String fautDetail) {
super(message, cause);
setTempFaultDetail( fautDetail );
}
public String getTempFaultDetail() {
return tempFaultDetail;
}
public void setTempFaultDetail(String tempFaultDetail) {
this.tempFaultDetail …Run Code Online (Sandbox Code Playgroud) 我有一个SOAP Web服务端点URL(比如说:“ EP1”),我们只能通过代理服务器进行连接。
我们正在使用org.springframework.ws.client.core.WebServiceTemplate类使用Web服务。
我的问题是,有没有一种方法可以传递/设置WebServiceTemplate上的代理服务器详细信息以连接到端点URL“ EP1”?
在我的架构中,我具有以下元素:
<xs:element name="deletePokemonsRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="pokemonId" type="xs:int" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
Run Code Online (Sandbox Code Playgroud)
我有终点:
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "deletePokemonsRequest")
@ResponsePayload
public DeletePokemonsRequest deletePokemons(@RequestPayload DeletePokemonsRequest deletePokemons){
pokemonDAO.deletePokemons(deletePokemons.getPokemonId());
return deletePokemons;
}
Run Code Online (Sandbox Code Playgroud)
当我发送此端点时:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pok="www">
<soapenv:Header/>
<soapenv:Body>
<pok:deletePokemonsRequest>
</pok:deletePokemonsRequest>
</soapenv:Body>
</soapenv:Envelope>
Run Code Online (Sandbox Code Playgroud)
它被接受,但在验证阶段应被拒绝。为什么呢 因为我设置了minOccurs=1,但是它接受了带有0元素的信封。
如何根据WSDL打开验证?
spring-ws ×10
spring ×7
java ×5
web-services ×5
soap ×3
spring-boot ×3
wsdl ×2
apache-camel ×1
jax-ws ×1
jaxb2 ×1
unit-testing ×1