标签: spring-ws

如何使用Spring Web服务创建自定义soap故障消息

我正在尝试使用Spring Web服务库编写Web服务.我能够成功配置我的端点并且它工作正常,但我遇到了异常映射的一些问题.

我能够使用@SoapFault和SoapFaultAnnotationExceptionResolver映射异常,但wsdl定义如下

<xsd:schema elementFormDefault="qualified" targetNamespace="http://abc.com/soap/">
    <xsd:complexType name="ServiceException">
        <xsd:sequence>
            <xsd:element name="message" nillable="true" type="xsd:string"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="ValidationException">
        <xsd:complexContent>
            <xsd:extension base="tns:ServiceException">
                <xsd:sequence/>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="InternalException">
        <xsd:complexContent>
            <xsd:extension base="tns:ServiceException">
                <xsd:sequence/>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="AuthenticationException">
        <xsd:complexContent>
            <xsd:extension base="tns:ServiceException">
                <xsd:sequence/>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="LoginInput">
        <xsd:sequence>
            <xsd:element minOccurs="1" maxOccurs="1" name="UserName" nillable="false" type="xsd:string"/>
            <xsd:element minOccurs="1" maxOccurs="1" name="PassWord" nillable="false" type="xsd:string"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="LoginOutput">
        <xsd:sequence>
            <xsd:element minOccurs="1" maxOccurs="1" name="ValidTo" nillable="false" type="xsd:dateTime"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:element name="login" type="tns:LoginInput"/>
    <xsd:element name="loginResponse" type="tns:LoginOutput"/>

    <xsd:element name="ValidationException" type="tns:ValidationException"/>
    <xsd:element …
Run Code Online (Sandbox Code Playgroud)

spring-ws

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

如何在Spring-WS中为响应有效负载添加附件?

我正在构建一个旨在共享内容的Web服务服务器.我想通过包含附件的SOAP响应来提供内容.现在,我正在使用Spring WS处理请求并提供响应.

我的服务类似于以下内容:

@Endpoint
public class Service{

    @PayloadRoot(namespace = "http://foo.com/coffee", localPart = "order")
    @ResponsePayload
    public Coffee getCoffee(@RequestPayload Order order){
        return new Coffee("Hot Joe");
    }

}
Run Code Online (Sandbox Code Playgroud)

但是假设我想在回复中附上一杯咖啡的图片,我在哪里以及如何做到这一点?

编辑:另外,Spring-WS附带的示例显示了如何使用客户端发送附件,而不是服务器应该如何响应(这是我在这里问的问题).

java spring soap spring-ws

5
推荐指数
1
解决办法
9484
查看次数

JBoss:JaxB DataHandler兼容性

我正在使用JBoss 5.1(EAP).我正在使用Spring webservices(3.0.5).对于编组我使用的是JaxB.

我正在使用maven.jaxb2.plugin从架构(xsd)生成pojo.

当我在JBoss上部署EAR时,我收到以下错误:

    19:05:52,524 ERROR [[eventmanager-ws]] Allocate exception for servlet eventmanager-ws
    com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
    javax.activation.DataHandler does not have a no-arg default constructor.
            this problem is related to the following location:
                    at javax.activation.DataHandler
                    at protected javax.activation.DataHandler
                    uk.co.aol.shipmanager.ws.schema.ReportResponse.data
                    at uk.co.aol.shipmanager.ws.schema.ReportResponse
                    at public uk.co.aol.shipmanager.ws.schema.ReportResponse
                    uk.co.aol.shipmanager.ws.schema.ObjectFactory.createReportResponse()
                    at uk.co.aol.shipmanager.ws.schema.ObjectFactory

            at com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.j>ava:102)
            at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:472)
            at com.sun.xml.bind.v2.runtime.JAXBContextImpl.(JAXBContextImpl.java:302)
            at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1136)
            at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:154)
            at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:121)
            at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:202)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:128)
            at javax.xml.bind.ContextFinder.find(ContextFinder.java:277)
            at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:372)
            at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:337) …

jboss spring-ws jaxb

5
推荐指数
1
解决办法
1419
查看次数

HTTP标头中缺少Spring WebServiceTemplate SOAPAction

我很难通过Spring-ws WebServiceTemplate调用SOAP 1.2 WebService.正在进行的请求缺少Http Header中的SOAPAction,并且服务器抛出错误"无法处理没有有效操作参数的请求.请提供有效的soap操作." 通过wireshark监控,我能够发现SOAP Action丢失了.我也不支持任何代理.

通过TCP Mon(像SOAP UI这样的工具)运行请求,我确保我尝试发送的SOAP 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:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans  
                        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                        http://www.springframework.org/schema/util
                        http://www.springframework.org/schema/util/spring-util-3.0.xsd">

<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
    <property name="soapVersion">
    <util:constant static-field="org.springframework.ws.soap.SoapVersion.SOAP_12" />
    </property>
</bean>

<bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
 <constructor-arg ref="messageFactory" />
<property name="defaultUri" value="https://ecomapi.networksolutions.com/soapservice.asmx" />
<property name="messageSender">
    <bean class="org.springframework.ws.transport.http.CommonsHttpMessageSender" />     </property>
</bean>
Run Code Online (Sandbox Code Playgroud)

这是我的java代码:

            public void simpleSendAndReceive() {
            try{
            StreamSource source = new StreamSource(new StringReader(MESSAGE));
            StreamResult result = new StreamResult(System.out);
            SoapActionCallback actionCallBack = new SoapActionCallback("https://ecomapi.networksolutions.com/soapservice.asmx") {
                public void doWithMessage(WebServiceMessage msg) {
                    SoapMessage …
Run Code Online (Sandbox Code Playgroud)

java spring soap spring-ws

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

JDOM 2和xpath

以下是从Spring-ws手册中摘录的代码:

public class HolidayEndpoint {

  private static final String NAMESPACE_URI = "http://mycompany.com/hr/schemas";

  private XPath startDateExpression;

  private XPath endDateExpression;

  private XPath nameExpression;

  private HumanResourceService humanResourceService;

  @Autowired
  public HolidayEndpoint(HumanResourceService humanResourceService)                      (2)
      throws JDOMException {
    this.humanResourceService = humanResourceService;

    Namespace namespace = Namespace.getNamespace("hr", NAMESPACE_URI);

    startDateExpression = XPath.newInstance("//hr:StartDate");
    startDateExpression.addNamespace(namespace);

    endDateExpression = XPath.newInstance("//hr:EndDate");
    endDateExpression.addNamespace(namespace);

    nameExpression = XPath.newInstance("concat(//hr:FirstName,' ',//hr:LastName)");
    nameExpression.addNamespace(namespace);
  }
Run Code Online (Sandbox Code Playgroud)

我的问题是,这似乎是使用JDOM 1.0,我想使用JDOM 2.0.

如何将此代码从JDOM 1.0转换为JDOM 2.0?为什么Spring没有更新他们的示例代码?

谢谢!

java spring-ws jdom jdom-2

5
推荐指数
1
解决办法
6663
查看次数

Apache HttpClient 4.3和x509客户端证书进行身份验证

现在我正在寻找有关如何通过HttpComponentsMessageSender(不相关)重写客户端x509证书身份验证的弃用解决方案的任务的解决方案.

例如,弃用的解决方案是:

    SSLSocketFactory lSchemeSocketFactory = new SSLSocketFactory(this.keyStore, this.keyStorePassword);
    Scheme sch = new Scheme("https", 443, lSchemeSocketFactory);

    DefaultHttpClient httpClient = (DefaultHttpClient)getHttpClient();
    httpClient.getConnectionManager().getSchemeRegistry().register(sch);
Run Code Online (Sandbox Code Playgroud)

作为我使用的CloseableHttpClient的新解决方案:

    SSLContextBuilder sslContextBuilder = SSLContexts.custom()
            // this key store must contain the key/cert of the client
            .loadKeyMaterial(keyStore, keyStorePassword.toCharArray());

    if (trustStore != null) {
        // this key store must contain the certs needed and trusted to verify the servers cert
        sslContextBuilder.loadTrustMaterial(trustStore);
    }

    SSLContext sslContext = sslContextBuilder.build();

    LayeredConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext);

    // Create a registry of custom connection socket factories for …
Run Code Online (Sandbox Code Playgroud)

java ssl spring-ws httpclient x509certificate

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

如何使用注释配置PayloadValidatingInterceptor

我正在尝试开发Spring Web服务并遵循本教程https://spring.io/guides/gs/production-web-service/

项目结构(和配置类名称)与本教程中提到的相同。我正在尝试使用注释进行所有可能的配置,并希望避免所有基于xml的配置。到目前为止,我什至通过使用Java配置避免了applicationContext.xml和web.xml。但是,现在,我想介绍本教程中所示的XSD验证:http : //stack-over-flow.blogspot.com/2012/03/spring-ws-schema-validation-using.html,即通过扩展PayloadValidatingInterceptor类如本教程所示,此自定义验证器拦截器随后需要使用以下xml配置进行注册:

<bean class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping">
 <property name="interceptors">
  <list>
    <ref bean="validatingInterceptor"/>   
  </list>
 </property>
</bean>

<bean id="validatingInterceptor" class="com.test.ValidationInterceptor ">
     <property name="schema" value="/jaxb/test.xsd"/>
</bean>
Run Code Online (Sandbox Code Playgroud)

但是,我不起诉如何使用注释进行上述配置。即将XSD文件设置为拦截器。我尝试覆盖WsConfigurerAdaptor类的“ addInterceptor”以注册拦截器。请让我知道是否需要这样做,或者使用批注完成整件事的正确方法是什么。

spring spring-ws spring-boot

5
推荐指数
2
解决办法
3493
查看次数

SpringBoot SOAP Web服务动态WSDL生成不起作用如果从RequestPayload元素中删除Request后缀

我正在使用Spring Boot SOAP Webservice Sample项目创建SOAP Web服务.如果我使用以下代码动态生成WSDL显示操作.

@PayloadRoot(namespace = NAMESPACE_URI, localPart = "AvailNotifRequest")
@ResponsePayload
public OTAHotelAvailNotifRS getAvailNotif(@RequestPayload AvailNotifRequest request) {
Run Code Online (Sandbox Code Playgroud)

但我需要这样的变更请求元素.

@PayloadRoot(namespace = NAMESPACE_URI, localPart = "OTAHotelAvailNotifRQ")
@ResponsePayload
public OTAHotelAvailNotifRS getOTAHotelAvailNotifRQ(@RequestPayload OTAHotelAvailNotifRQ request) {
Run Code Online (Sandbox Code Playgroud)

我在这个链接上发现了一个类似的问题Spring Web服务动态wsdl没有生成架构元素的消息答案说我们需要在请求元素之后添加后缀Request,如 AvailNotifRequest,但我想使用OTAHotelAvailNotifRQ作为我的请求输入.我如何使用它,因为当我更改这样的请求输入时,我没有在wsdl中获取操作.

soap wsdl web-services spring-ws spring-boot

5
推荐指数
1
解决办法
1387
查看次数

Spring WS WSDL自动公开:不遵循xsd导入

我正在尝试基于多个xml模式为Spring WS Web服务动态生成WSDL。我有多个xsd文件,所有文件都使用xsd:import元素“连接”。

Spring WS参考说:

如果要使用包含或导入的多个模式,则需要将Commons XMLSchema放在类路径上。如果Commons XMLSchema位于类路径上,则上述元素将跟随所有XSD导入和包含,并将它们作为单个XSD内联到WSDL中。这极大地简化了架构的部署,仍然使分别编辑它们成为可能。

所以我添加了这个Maven依赖项:

    <dependency>
        <groupId>org.apache.ws.xmlschema</groupId>
        <artifactId>xmlschema-core</artifactId>
        <version>2.2.1</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

并以这种方式配置WSDL构建器:

@Bean(name="updateContactService")
public DefaultWsdl11Definition defaultWsdl11Definition() throws Exception {
    DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
    wsdl11Definition.setPortTypeName("updateContactPort");
    wsdl11Definition.setLocationUri("/ws/updateContact");
    wsdl11Definition.setTargetNamespace("http://spring.io/guides/gs-producing-web-service");
    wsdl11Definition.setSchema(updateContactXsd());
    return wsdl11Definition;
}   

@Bean
public XsdSchemaCollection updateContactXsd() throws Exception {
    return new SimpleXsdSchema(new ClassPathResource("xsds/contact/outboundMessage.xsd"));
}
Run Code Online (Sandbox Code Playgroud)

但是生成的WSDL仅包含一个架构元素(并以错误的位置显示了导入)。

<xs:import namespace="http://xmlns.oracle.com/apps/cdm/foundation/parties/personService/" schemaLocation="personService.xsd"/>
Run Code Online (Sandbox Code Playgroud)

有小费吗?Spring WS版本是2.3.1

<?xml version="1.0" encoding="UTF-8" standalone="no"?><wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:sch="http://xmlns.oracle.com/apps/crmCommon/content/outboundMessage/types/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://spring.io/guides/gs-producing-web-service" targetNamespace="http://spring.io/guides/gs-producing-web-service">
  <wsdl:types>
    <xs:schema xmlns="http://xmlns.oracle.com/apps/crmCommon/content/outboundMessage/types/" xmlns:ns2="http://xmlns.oracle.com/apps/cdm/foundation/parties/personService/" xmlns:tns0="http://xmlns.oracle.com/apps/crmCommon/content/outboundMessage/types/" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://xmlns.oracle.com/apps/crmCommon/content/outboundMessage/types/">
    <xs:import namespace="http://xmlns.oracle.com/apps/cdm/foundation/parties/personService/" schemaLocation="personService.xsd"/>
    <xs:element name="process" type="tns0:processType"/>
    <xs:complexType name="processType">
        <xs:sequence>
            <xs:element maxOccurs="unbounded" …
Run Code Online (Sandbox Code Playgroud)

java spring xsd wsdl spring-ws

5
推荐指数
1
解决办法
4299
查看次数

正确测试Spring服务

以下测试失败,NullPointerException并在线上显示usersRepo.save(user);。我相信这是因为当测试进入performProvision()功能时,usersRepo对象就是null

但是,当Web服务实际上正在运行并且控制器的端点被命中时,一切正常,并且数据库已更新。

知道为什么测试失败了吗?我的想法是PAutoProvision引用真实的数据库,而它应该处理内存数据库,所以也许存在某种冲突?我还看到了很多不同的示例,它们的注释设置不同,所以我想这可能也是一个问题。

UsersRepo扩展了JpaRepository,其中PAutoProvision是一个SQL表实体。

如果没有足够的信息,我可以提供的UsersRepoPAutoProvision以及ProvisionController如果必要的类。

服务:

@Service
public class ProvisionService {

    @Autowired
    private UsersRepo usersRepo;


    public String performProvision(UserData userData) {
        try {
            PAutoProvision user = new PAutoProvision(userData);
            usersRepo.save(user);  // OOTB CRUD repository functionality of springData to update/insert record data
            return String.format("Success: User %s has been added to the database", userData.getUserId());
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(e.toString());
            System.out.println("\n\n Cannot perform the provisioning …
Run Code Online (Sandbox Code Playgroud)

java junit spring hibernate spring-ws

5
推荐指数
1
解决办法
8755
查看次数