标签: spring-ws

Spring-ws -Problem从tomcat 6请求webservice

我已经实现了一个spring-ws服务,当我发送一个soap消息时,我收到了spring webapplication 1(在tomcat 6.0.32上运行):

请求:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:gen="http://www.foo.com/bar/webservice/generated">
   <soapenv:Header/>
   <soapenv:Body>
      <gen:GetAllPanelWSRequest/>
   </soapenv:Body>
</soapenv:Envelope>
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:GetAllPanelWSResponse xmlns:ns2="http://www.foo.com/bar/webservice/generated">
         <ns2:PanelWS ns2:Id="5">
            <ns2:name>all</ns2:name>
            <ns2:code>all</ns2:code>
         </ns2:PanelWS>
         <ns2:PanelWS ns2:Id="9">
            <ns2:name>test</ns2:name>
            <ns2:code>test1</ns2:code>
         </ns2:PanelWS>         
      </ns2:GetAllPanelWSResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Run Code Online (Sandbox Code Playgroud)

到目前为止没问题.从webappliction 2(不使用spring MVC等)我创建了一个函数,当我运行这个函数时它工作:

Main.java:

...
public class Main {
    public static void main(String[] args) {
        List<PanelWS> panelWSs = CallServices.getPanelWSs();
        for (PanelWS p : panelWSs) {
            System.out.println("\t" + makeString(p));
        }
    }
...
Run Code Online (Sandbox Code Playgroud)

CallServices.java

public static List<PanelWS> getPanelWSs() {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        PanelClient client = (PanelClient) …
Run Code Online (Sandbox Code Playgroud)

java spring jsp web-services spring-ws

10
推荐指数
2
解决办法
8172
查看次数

如何指定我在webServiceTemplate中使用哪种类型的soap?

我正在开发一个带有spring的soap web服务客户端.

我在用 webServiceTemplate

如何指定使用哪种类型的肥皂?

我可以看到它默认使用soap 1.1.

我想强迫它使用肥皂1.2

我怎样才能做到这一点?

spring soap web-services spring-ws

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

如何在Spring-ws端点中访问HTTP头?

如何在Spring-ws端点中访问HTTP头?

我的代码看起来像这样:

public class MyEndpoint extends AbstractMarshallingPayloadEndpoint {
  protected Object invokeInternal(Object arg) throws Exception {
      MyReq request = (MyReq) arg;
      // need to access some HTTP headers here
      return createMyResp();
  }
}
Run Code Online (Sandbox Code Playgroud)

invokeInternal()只获取未编组的JAXB对象作为参数.如何访问内部请求附带的HTTP标头invokeInternal()

一种可能有效的方法是创建一个Servlet过滤器,将头值存储到ThreadLocal变量中,然后在内部访问invokeInternal(),但是有更好的,更类似Spring的方法吗?

java spring spring-ws http-headers

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

在spring xml配置中连接字符串

我需要将spring bean的字符串值连接到现有字符串,然后将其设置为另一个bean的属性:

<bean id="inet" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="targetClass"><value>java.net.InetAddress</value></property>
    <property name="targetMethod"><value>getLocalHost</value></property>
</bean>
<bean id="host" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="targetObject"><ref local="inet"/></property>
    <property name="targetMethod"><value>getHostName</value></property>
</bean>
Run Code Online (Sandbox Code Playgroud)

此时,我在'host'bean中有主机名.我现在需要连接它并将它传递给publishedEndpointUrl属性.像这样的东西:

<jaxws:endpoint 
    id="foo"
    publishedEndpointUrl= "http://" + host + "/Foo" 
    implementor="com.example.v1.foo"
    address="/v1/Foo"/>
Run Code Online (Sandbox Code Playgroud)

如何使用spring xml配置完成?

java spring spring-ws cxf jax-ws

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

如何在FaultMessageResolver中解组SOAP Fault?

我是Spring-WS的新手,慢慢地把头缠在它上面.现在,我正在编写一个简单的客户端来与现有的WS进行通信.我正在使用WebServiceTemplate和marshalSendAndReceive方法.一切正常.

但是,当发生SOAP错误时,WST会抛出SoapFaultClientException.我注意到我可以创建自己的FaultMessageResolver来检查SOAP错误中包含的内容.但是,当我尝试在FaultMessageResolver中解组WebServiceMessage时,我收到以下错误消息:

JAXB unmarshalling exception; nested exception is javax.xml.bind.UnmarshalException: unexpected element (uri:"http://schemas.xmlsoap.org/soap/envelope/", local:"Fault"). Expected elements are ....
Run Code Online (Sandbox Code Playgroud)

显然,我的unmarshaller没有正确配置.我是否必须使用xjc自己生成JAXB故障模型,然后才能解组错误?我有点惊讶,这还不存在.

有没有更好的方法从我的soap:故障响应中添加我的自定义错误信息?我的错误看起来像以下,我试图提取/访问serviceErrors项.

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <soap:Fault>
         <faultcode>soap:Server</faultcode>
         <faultstring>Blaze Data Error</faultstring>
         <detail>
            <ns14:serviceErrors xmlns="http://www.nb.com/ClientServices/LendingSimulation/CalculateProfitabilityRequest" xmlns:ns13="http://www.nb.com/fw/errorMgmt" xmlns:ns14="http://www.nb.com/ClientServices/LendingSimulation/V1" >
               <ns13:faultstring>ServiceExecutionError</ns13:faultstring>
               <ns13:serviceError>
                  <ns13:errorCode>C10F1013</ns13:errorCode>
                  <ns13:errorType>B</ns13:errorType>
                  <ns13:errorMessage>Unable to retreive additional data</ns13:errorMessage>
                  <ns13:fieldName>Message error received from PHClient :  [An unexpected error code was received : system=PH context=[empty]]</ns13:fieldName>
                  <ns13:systemId>Calculator</ns13:systemId>
                  <ns13:time>2012-06-19 14:45:10.151-0400</ns13:time>
               </ns13:serviceError>
            </ns14:serviceErrors>
         </detail>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>
Run Code Online (Sandbox Code Playgroud)

谢谢!

埃里克

java web-services spring-ws jaxb

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

Spring WS和JAXB - 配置SOAPMessageDispatcher,DefaultMethodEndpointAdapter和MarshallingPayloadMethodProcessor

使用Spring-WS时,配置非常小,因为我一直在使用注释.最近我一直试图测试如何在SOAP响应中包含附件并使其工作我最终得到了以下配置.

<bean id="messageReceiver"
    class="org.springframework.ws.soap.server.SoapMessageDispatcher">
    <property name="endpointAdapters">
        <list>
            <ref bean="defaultMethodEndpointAdapter" />
        </list>
    </property>
</bean> 

<bean id="defaultMethodEndpointAdapter"
    class="org.springframework.ws.server.endpoint.adapter.DefaultMethodEndpointAdapter">
    <property name="methodArgumentResolvers">
        <list>
            <!-- Be careful here! You might need to add more processors if you do 
                more than webservices! -->
            <ref bean="marshallingPayloadMethodProcessor" />
        </list>
    </property>
    <property name="methodReturnValueHandlers">
        <list>
            <ref bean="marshallingPayloadMethodProcessor" />
        </list>
    </property>
</bean>     

<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    <property name="contextPath" value="com.mypackage.ws" />
    <property name="mtomEnabled" value="true" />
</bean>

<bean id="marshallingPayloadMethodProcessor"
    class="org.springframework.ws.server.endpoint.adapter.method.MarshallingPayloadMethodProcessor">
    <constructor-arg ref="marshaller" />
    <constructor-arg ref="marshaller" />
</bean> 
Run Code Online (Sandbox Code Playgroud)

通过上面的内容,我可以生成带附件的SOAP响应.问题是我真的不明白发生了什么.(即上述配置是做什么的,可以启用MTOM附件.

要启用附件:

  • 为什么我需要配置JAXB marshaller?没有此配置,所有不使用附件的Web服务都可以正常工作.我所要做的就是使用@EndPoint注释.非附件Web服务的请求/响应对象也是基于JAXB的,所以这表明我可能没有做到这一点(即使它有效).

  • 上面配置中显示的messageReceiver和defaultmethodEndpointAdapter bean的用途是什么?没有这些,非附件端点工作正常.

  • 最后是否可以注释上述任何配置而不是XML?我注意到JAX-WS有一个@MTOM注释但是找不到Spring-WS的等价物 …

java spring soap spring-ws java-ee

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

带有MVC的Spring Boot SOAP Web服务

我想结合Spring指南中的两个Spring(spring-boot)应用程序:

不幸的是,这些例子不能一起使用.servlet调度程序存在问题.添加dispatcherServlet bean后 - MVC servlet无法正常工作(错误404).

@Bean
public ServletRegistrationBean dispatcherServlet(ApplicationContext applicationContext) {
    MessageDispatcherServlet servlet = new MessageDispatcherServlet();
    servlet.setApplicationContext(applicationContext);
    servlet.setTransformWsdlLocations(true);
    return new ServletRegistrationBean(servlet, "/ws/*");
}
Run Code Online (Sandbox Code Playgroud)

如何配置servlet调度程序正常工作?

我想拥有:

  • localhost:8080/ws/* - 网络服务
  • localhost:8080/web/* - MVC组件

提前致谢!

java spring spring-ws spring-mvc spring-boot

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

如何更改Soap标头消息

我有肥皂请求发送到该服务.在发送之前我想编辑Soap标头

<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="1">
Run Code Online (Sandbox Code Playgroud)

这是我希望传递值为mustUnderstand0而不是1 的标题之一.因为我将值传递为1时会出现一个异常.我得到的值为1的异常是:

org.springframework.ws.soap.client.SoapFaultClientException: One or more mandatory SOAP header blocks not understood
Run Code Online (Sandbox Code Playgroud)

我已经通过将mustUnderstand值传递为0来检查Soap UI 并且它有效.现在我想从我的客户端发送同样的东西.

我试图在应用程序conext bean定义xml文件中添加参数,但没有按照下面的方法工作

<property name="securementmustUnderstand"><value>false</value></property>
Run Code Online (Sandbox Code Playgroud)

请让我知道如何mustUnderstand在我的客户端更改参数.

完整的bean定义如下:

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

    <bean id="reg" class="com.service.RegConsServiceImpl">
        <property name="regWebServiceTemplate" ref="regWebServiceTemplate"/>
    </bean>
    <bean id="regWebServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
        <constructor-arg ref="messageFactory"/>
        <property name="marshaller" ref="marshaller"/>
        <property name="unmarshaller" ref="unmarshaller"/>
        <property name="interceptors">          
            <list>
                <ref bean="wsRegClientSecurityInterceptor"/>
            </list>
        </property> 
    </bean>

    <bean id="wsRegClientSecurityInterceptor" class="org.springframework.ws.soap.security.wss4j.Wss4jSecurityInterceptor">
        <property name="securementmustUnderstand">
            <value>false</value>
        </property>
        <property name="securementActions" value="UsernameToken" />
        <property name="securementPasswordType" value="PasswordText"/>
        <property name="securementPassword">
            <value>${registration.ws.password}</value> …
Run Code Online (Sandbox Code Playgroud)

spring soap spring-ws soapui soap-client

9
推荐指数
0
解决办法
2544
查看次数

使用带有Soap v1.2的spring-w而不是默认的v1.1生成SOAP Web服务

我目前正在研究Spring soap服务器项目.我从Spring的http://spring.io/guides/gs/producing-web-service/开始使用Spring的入门指南来构建基本的SOAP服务.

默认的SOAP协议是SOAP v1.1.有没有办法可以通过注释将协议设置为v1.2?

@BindingType(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)@Endpoint课上尝试了注释,但似乎没有用.

我也尝试@Endpoint(value = SOAPBinding.SOAP12HTTP_BINDING)设置它,但是这在启动日志中看不到

INFO --- [nio-8080-exec-1] o.s.ws.soap.saaj.SaajSoapMessageFactory  :
 Creating SAAJ 1.3 MessageFactory with SOAP 1.1 Protocol
Run Code Online (Sandbox Code Playgroud)

当然,如果我向服务器发布SOAP请求,我会收到以下错误

2015-01-19 15:50:17.610 ERROR 20172 --- [nio-8080-exec-1] c.sun.xml.internal.messaging.saaj.soap : SAAJ0533: Cannot create message: incorrect content-type for SOAP version. Got application/soap+xml;
 charset=utf-8, but expected text/xml
2015-01-19 15:50:17.611 ERROR 20172 --- [nio-8080-exec-1] c.sun.xml.internal.messaging.saaj.soap   :
 SAAJ0535: Unable to internalize message
2015-01-19 15:50:17.617 ERROR 20172 --- [nio-8080-exec-1] a.c.c.C.[.[.[.[messageDispatcherServlet] :
 Servlet.service() for servlet [messageDispatcherServlet] in context …
Run Code Online (Sandbox Code Playgroud)

soap spring-ws soapserver

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

如何配置Spring REST服务来处理多个版本?

几乎所有API都处理不同的发行版本.通常你会看到这种版本:

但是我没有找到一个描述如何在Spring堆栈中组织它们的源代码.我想在每个控制器上都有一个/v1前缀@RequestMapping("/v1/questions")不是最好的方法.

想象一下@Service,只有当前版本的一层(在我们的例子中是V2).

我们的服务应该处理V1和V2的请求.唯一的变化是V2在问题实体上添加了一个新字段(这意味着V1问题可以很容易地转换为V2问题).

现在的问题是:

  • 如何组织不同于~.web.* @Controllerjava包的观点?
  • 如何注释~.web.* @Controller他们知道他们的版本的不同?以这种方式RequestMapping?或者是否可以使用上下文配置它们:在V1 java包中进行组件扫描?
  • 如何组织转换器?把它们放在哪里,如何命名它们?水木清华.像QuestionsV1ToV2控制器?
  • 是否有DTO图层重新征集?因为我们的域必须同时处理许多版本?

一个例子看起来像这样(我在各处添加了包):

// on V1 Question look like this:
public class project.domain.Question
{
    private String question;
}

// on v2 Question looks like this:
public class project.domain.Question
{
    private String question;
    private Date creationDate;
}


@Service
public class project.service.QuestionService
{
    public long create(Question q) {...};
    public Question read(long id) {...};
    public void remove(long id) …
Run Code Online (Sandbox Code Playgroud)

java rest spring spring-ws spring-mvc

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