标签: spring-ws

Spring:记录传出的 HTTP 请求

我正在尝试在基于 Spring 的 Web 应用程序中记录所有传出的 Http 请求。是否有用于此目的的拦截器?我想在离开应用程序之前记录所有传出的内容和标题。我正在使用spring-ws发送 SOAP 请求。所以基本上,我不仅要记录 SOAP 请求 xml(如这里提到的如何使 Spring WebServices 记录所有 SOAP 请求?),还要记录整个 http 请求。

java spring spring-ws

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

Spring-WS:如何提取 Soap 消息体

我正在尝试从 spring-ws 应用程序中的肥皂请求中提取肥皂主体。我的肥皂请求是

 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org  /soap/envelope/" xmlns:sch="http://www.manager.cts.com/schema">
 <soapenv:Header/>
   <soapenv:Body>
     <sch:addManagerRequest>
         <sch:name>shivani</sch:name>
         <sch:salary>1231231</sch:salary>
         <sch:developer>
            <sch:firstName>asd</sch:firstName>
            <sch:lastName>asdasd</sch:lastName>
            <sch:salary>123123</sch:salary>
         </sch:developer>
     </sch:addManagerRequest>
  </soapenv:Body>
</soapenv:Envelope>
Run Code Online (Sandbox Code Playgroud)

我尝试使用以下代码提取肥皂体:

@Override
public boolean handleRequest(MessageContext messageContext, Object endpoint) throws Exception {
    SoapMessage message = (SoapMessage) messageContext.getRequest();
    SoapBody soapBody = message.getSoapBody();

    Source bodySource = soapBody.getSource();
    DOMSource bodyDomSource = (DOMSource) bodySource;

    Node bodyNode = bodyDomSource.getNode();
    System.out.println(bodyNode.getNodeValue());
    System.out.println(bodyNode.getChildNodes());
 }
Run Code Online (Sandbox Code Playgroud)

输出是:

 null
 [soapenv:Body: null]
Run Code Online (Sandbox Code Playgroud)

请帮我解决这个问题。我是 spring-ws 的新手

spring spring-ws

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

在 Spring 项目中启用 jetty 调试日志记录

在 Jetty 9 服务器的源代码中有很多有用的调试输出。我使用 Spring 4.3.3(包括 Jetty 作为依赖项)并且愿意启用 Jetty 的调试输出(websocket 部分最重要)我该怎么做?

spring spring-ws jetty spring-boot jetty-9

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

使用 Spring-ws 和 4.5.x Http 客户端忽略 DNS 循环以获得可靠的超时

我们将 Http Client 4.5.x 与 Spring-Ws 结合使用,并使用该webServiceTemplate.marshalSendAndReceive(requestObject)方法发出请求。我们希望有一个可靠的连接超时值,但目前遇到了第 8 节(DNS 循环)中描述的问题,其中尝试了多个 IP 地址,因此超时是不可预测的。是否有简单的方法可以仅使用 Spring-ws 和 Http Client 库在一定时间后设置硬超时,或者是否需要设置某种自定义超时?


案例:连接超时设置为 1 秒(方法的实际超时为 4 秒——是否可以使用 Spring/Http 客户端库将方法超时设置为 1 秒?)

应用程序日志(Http 客户端日志设置为DEBUG):

16:45:02 (org.apache.http.impl.execchain.MainClientExec) Opening connection {}->http://salesforce.com:448 
16:45:02 (org.apache.http.impl.conn.DefaultHttpClientConnectionOperator) Connecting to salesforce.com/96.43.149.26:448 
16:45:03 (org.apache.http.impl.conn.DefaultHttpClientConnectionOperator) Connect to salesforce.com/96.43.149.26:448 timed out. Connection will be retried using another IP address 
16:45:03 (org.apache.http.impl.conn.DefaultHttpClientConnectionOperator) Connecting to salesforce.com/96.43.145.26:448 
16:45:04 (org.apache.http.impl.conn.DefaultHttpClientConnectionOperator) Connect to salesforce.com/96.43.145.26:448 timed out. Connection will be retried using another IP address 
16:45:04 …
Run Code Online (Sandbox Code Playgroud)

java spring-ws apache-httpclient-4.x

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

是否可以在Spring WS Web服务中重命名响应命名空间前缀?

我基于http://spring.io/guides/gs/producing-web-service/上的示例构建了一个Spring WS Web服务.响应包含带有前缀"ns2"的命名空间.

xmlns:ns2="http://www.mycompany.com/somewhere"
Run Code Online (Sandbox Code Playgroud)

皂响应

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header/>
   <SOAP-ENV:Body>
      <ns2:mitteilungResponse xmlns:ns2="http://www.mycompany.com/somewhere">
         <ns2:responseContent>
            <ns2:message>Hello World!</ns2:message>
         </ns2:responseContent>
      </ns2:mitteilungResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Run Code Online (Sandbox Code Playgroud)

是否可以将该前缀重命名为"myprefix"?怎么样?任何人?

spring web-services spring-ws jaxb xml-namespaces

0
推荐指数
1
解决办法
2960
查看次数

使用Spring WS获取SOAP Header的内容

我正在尝试构建一个端点,该端点将从客户端接收SOAP消息。我收到的消息在soap标头中包含用户名和密码...

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://www.company.com/Application">
    <soapenv:Header  xmlns:wsse="http://__________.xsd">
        <wsse:Security >
            <wsse:UsernameToken>
                <wsse:Username>username</wsse:Username>
                <wsse:Password>password</wsse:Password>
            </wsse:UsernameToken>
        </wsse:Security>

   </soapenv:Header>
   <soapenv:Body>
Run Code Online (Sandbox Code Playgroud)

我使用的是Spring WS-显而易见的解决方案是在内部创建一个过滤器web.xml,该过滤器将完全绕过Spring WS,解析SOAP消息,提取用户名和密码,然后继续到Spring WS,它将再次解析SOAP。

有没有一种方法可以在不绕过Spring WS的情况下获取标头的内容?

我尝试在其中添加一个bean sws:interceptors

<sws:interceptors>

    <!-- extract Security details from Header -->
    <bean class="com.company.application.service.SecurityInterceptorService" />

    <!-- log full Body of request -->
    <bean class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor"/>

    <!-- validate Request against XSD to make sure it's a valid request -->
    <bean id="CompanyApplication" class="com.company.application.interceptor.ValidatingInterceptor">
        <property name="schema" value="/WEB-INF/_______________.xsd" />
        <property name="validateRequest" value="true" />
        <property name="validateResponse" value="true" />
    </bean>

</sws:interceptors>
Run Code Online (Sandbox Code Playgroud)

然后实现该类:

public class SecurityInterceptorService …
Run Code Online (Sandbox Code Playgroud)

java spring soap web-services spring-ws

0
推荐指数
1
解决办法
7809
查看次数

java.lang.ClassNotFoundException:com.sun.xml.wss.XWSSecurityException

我有一个现有的基于SOAP的Web服务,我正在尝试使用'XwsSecurityInterceptor'和'SpringDigestPasswordValidationCallbackHandler'在其中实现Spring Web服务安全性.这就是我的弹簧配置的样子. 在此输入图像描述

我在JBoss7.1 AS中部署了这个应用程序.当应用程序启动时,抛出异常.它抱怨找不到'com.sun.xml.wss.XWSSecurityException'.

org.springframework.beans.factory.BeanCreationException:创建名为'org.springframework.ws.soap.addressing.server.AnnotationActionEndpointMapping#0'的bean时出错:init方法的调用失败; 嵌套异常是java.lang.NoClassDefFoundError:com/sun/xml/wss/XWSSecurityException引起:java.lang.ClassNotFoundException:com.sun.xml.wss.XWSSecurityException

现在我试图了解该问题的根本原因.所以我开始使用POM文件.

以下依赖关系是pom.

<dependency>
    <groupId>org.springframework.ws</groupId>
    <artifactId>spring-ws-core</artifactId>
    <version>${org.springframework.ws.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework.ws</groupId>
    <artifactId>spring-ws-security</artifactId>
    <version>${org.springframework.ws.version}</version>
</dependency>

<dependency>
    <groupId>com.sun.xml.wss</groupId>
    <artifactId>xws-security</artifactId>
    <version>3.0</version>
</dependency>

<dependency>
    <groupId>javax.activation</groupId>
    <artifactId>activation</artifactId>
    <version>1.1.1</version>
</dependency>

<dependency>
    <groupId>javax.xml</groupId>
    <artifactId>xmldsig</artifactId>
    <version>1.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

作为我研发的一部分,我选择了'spring-ws-core'和'spring-ws-security'的旧版本(2.1.2)以及'sjsxp'的'1.0.2'版本.应用程序启动后,当我提供无效密码时,我收到了身份验证错误.如果我提供正确的凭据,应用程序响应正常.这是我想用这些罐子的最新版本实现的.

现在我想知道为什么缺少2.3.0/2.4.0.

所以我尝试了'mvn依赖:tree -Dverbose',发现2.1.2版本带来了'xws-security'.

在此输入图像描述

所以我想添加那个依赖.

    <dependency>
        <groupId>com.sun.xml.wss</groupId>
        <artifactId>xws-security</artifactId>
        <version>3.0</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

现在这迫使我再添加两个依赖项.我也加了.

    <dependency>
        <groupId>javax.activation</groupId>
        <artifactId>activation</artifactId>
        <version>1.1.1</version>
    </dependency>

    <dependency>
        <groupId>javax.xml</groupId>
        <artifactId>xmldsig</artifactId>
        <version>1.0</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

但是maven存储库中缺少第二个'xmldsig'.我可以下载并手动将其添加到我当地的m2 repo.但我想以适当的方式解决它.在搜索时我遇到了这个帖子. http://maven.40175.n5.nabble.com/where-to-get-xmldsig-1-0-jar-td92435.html

有人在谈论另一种选择.

在此输入图像描述

我可以看到这是在'spring-ws-security:jar'的2.3.0版本中可用的.

在此输入图像描述

现在我的问题是,需要避免/添加什么,以便应用程序启动最新版本的jar?手指交叉.....

java spring spring-ws spring-security maven

0
推荐指数
1
解决办法
2727
查看次数

如何使用 Spring 的 PayloadValidatingInterceptor 验证多个 XSD 模式

我有一个带有多个 XSD 模式的 Spring Boot 项目(我使用的是 Spring-WS)。

如果我使用 Spring 的 PayloadValidatingInterceptor 来验证请求和响应,它只适用于最新的设置模式。

例如:

public void addInterceptors(List<EndpointInterceptor> interceptors) {
    PayloadValidatingInterceptor validatingInterceptor = new PayloadValidatingInterceptor();
    validatingInterceptor.setValidateRequest(true);
    validatingInterceptor.setValidateResponse(true);
    validatingInterceptor.setXsdSchema(getFirstSchema());
    validatingInterceptor.setXsdSchema(getSecondSchema());
    interceptors.add(validatingInterceptor);
    super.addInterceptors(interceptors);
}
Run Code Online (Sandbox Code Playgroud)

此代码段将使 Spring 仅验证第二个模式,而不是第一个。我尝试创建多个 PayloadValidatingInterceptors 以使用 super.addInterceptors(interceptors); 添加它们,但它也不起作用。我能找到的唯一响应(使用 Java 而不是 XML)来自 2009 年:

https://jira.spring.io/browse/SWS-481

有谁知道基于 Java 的解决方案来验证来自同一项目中多个 XSD 的请求和响应?

java xsd wsdl spring-ws spring-boot

0
推荐指数
1
解决办法
3796
查看次数

@Autowired 在 EndpointInterceptor 中不起作用

我有一个自定义EndpointInterceptor实现;

@Component
public class MyEndpointInterceptor implements EndpointInterceptor {

@Autowired
private Jaxb2Marshaller marshaller;

@Override
public boolean handleRequest(MessageContext messageContext, Object o) throws Exception {
    return true;
}

@Override
public boolean handleResponse(MessageContext messageContext, Object o) throws Exception {
    return true;
}

@Override
public boolean handleFault(MessageContext messageContext, Object o) throws Exception {
    return true;
}

@Override
public void afterCompletion(MessageContext messageContext, Object o, Exception e) throws Exception {
    // ... do stuff with marshaller
}
}
Run Code Online (Sandbox Code Playgroud)

拦截器添加在扩展的配置类中WsConfigurerAdapter

@Configuration
@EnableWs
public class …
Run Code Online (Sandbox Code Playgroud)

java spring-ws

0
推荐指数
1
解决办法
1255
查看次数