我想使用MTOM和Spring WS将大文件从服务器发送到客户端.我意识到这不是这类事情的最佳方法,但这是一项要求.我有MTOM设置,它适用于50mb左右的小文件.我遇到较大文件的内存不足错误,并通过更改不同的堆空间大小,我可以发送稍大的文件,但没有接近1GB.1GB是我的测试用例.如何将MTOM服务从服务器流式传输或分块到客户端?我使用Java 6更新17,Tomcat 6和Spring WS 1.5.7与SaajSoapMessageFactory.
我找到了使用jax-ws进行流式传输的示例,但我不确定如何将其合并到Spring WS端点中.
我正在尝试为Web服务编写一个拦截器,它将在发送到端点之前修改Soap消息的内容.如果客户端发送了一个消息,其中某个元素的值为1,我希望能够将该元素更改为2,这样,当消息到达端点时,它看起来好像客户端提交了2而不是我不确定这是一项困扰我的艰巨任务,还是一项我正在努力实现的艰巨任务.
我已经介入了一些Spring拦截器; 但是验证和日志记录拦截器并不是每个都会改变传输中的消息.Wss4jSecurityInterceptor确实为MessageContext添加了一些属性; 但我无法利用它正在做的任何事情.我有一个拦截器的外壳; 但没有任何东西可以做任何有价值的事情.
public boolean handleRequest(MessageContext messageContext, Object endpoint)
throws Exception {
SaajSoapMessage saajSoapMessage = (SaajSoapMessage) messageContext
.getRequest();
SOAPMessage soapMessage = saajSoapMessage.getSaajMessage();
SOAPBody soapBody = soapMessage.getSOAPBody();
return true;
}
Run Code Online (Sandbox Code Playgroud)
我希望其他人可能已经解决了这个特殊问题.任何见解将不胜感激.谢谢.
我正在使用Objects作为从客户端到服务服务器的消息.如何配置端点以便找到服务?@PayloadRoot似乎不合适,因为我不使用xml架构,而是使用@XmlRootElement注释的对象(即Street)
我的代码:
spring-ws-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: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">
<context:component-scan base-package="com.coral.project.endpoints"/>
<sws:annotation-driven />
<sws:dynamic-wsdl id="test" portTypeName="TestCase" locationUri="/testService/"
targetNamespace="http://www.example.org/schemasDef/test/definitions">
<sws:xsd location="/WEB-INF/schemasDef/test.xsd"/>
</sws:dynamic-wsdl>
<bean id="springWSClient" class="com.coral.project.endpoints.SpringWSClient">
<property name="defaultUri" value="http://localhost:8080/parking/springServices/testService/"/>
<property name="marshaller" ref="marshaller" />
<property name="unmarshaller" ref="marshaller" />
</bean>
<oxm:jaxb2-marshaller id="marshaller">
<oxm:class-to-be-bound name="com.coral.project.entity.Street"/>
</oxm:jaxb2-marshaller>
</beans>
Run Code Online (Sandbox Code Playgroud)
客户端:
public class SpringWSClient extends WebServiceGatewaySupport {
public void getSum() throws SOAPException, IOException, TransformerException {
StreetDao streetDao = SpringUtils.getBean(StreetDao.class);
Street street = streetDao.findById(1);
getWebServiceTemplate().marshalSendAndReceive(street);
}
}
Run Code Online (Sandbox Code Playgroud)
终点: …
我正在使用spring-ws 2.0.2和spring-ws-test来运行我的SOAP服务器的集成测试.我使用的方法与http://static.springsource.org/spring-ws/site/apidocs/org/springframework/ws/test/server/MockWebServiceClient.html中的方法完全相同
这是我运行的代码,为了简洁而省略了预期的响应XML,因为它与问题无关.
我希望能够在响应有效负载中看到xml,但无法弄清楚如何访问它.如果我在设置响应后设置断点并检查它,我可以看到它有一个类型为SaajSoapMessage的私有messageContext.response,但我无法弄清楚如何访问它,或者是否有更好的方法来查看响应XML.
package com.example.integration;
import static org.springframework.ws.test.server.RequestCreators.*;
import static org.springframework.ws.test.server.ResponseMatchers.*;
import static org.testng.AssertJUnit.*;
import javax.xml.transform.Source;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.ws.test.server.MockWebServiceClient;
import org.springframework.ws.test.server.ResponseActions;
import org.springframework.xml.transform.StringSource;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@ContextConfiguration(locations={"/transaction-test-context.xml", "/spring-web-services-servlet.xml"})
public class BaseWebServiceIntegrationTest {
@Autowired
private ApplicationContext applicationContext;
private MockWebServiceClient mockClient;
@BeforeClass(groups="integration")
public void createClient() {
assertNotNull("expected applicationContext to be non-null", applicationContext);
mockClient = MockWebServiceClient.createClient(applicationContext);
}
@Test(groups="integration")
public void proofOfConcept() {
assertNotNull("expected mockClient to be non-null", mockClient);
Source requestPayload = new StringSource(
"<s0:ListDevicesRequest " + …
Run Code Online (Sandbox Code Playgroud) 我编写了一个与UPS Web服务一起使用的Web服务客户端(使用Java Spring和JAXB Marshaller).当我发送有效请求时,一切正常.当我发送无效请求(重量> 150磅)时,UPS Web服务会响应SOAP Fault.客户端应用程序失败了
org.springframework.oxm.UnmarshallingFailureException: JAXB unmarshalling
exception; nested exception is javax.xml.bind.UnmarshalException:
unexpected element (uri:"http://schemas.xmlsoap.org/soap/envelope/", local:"Fault").
Run Code Online (Sandbox Code Playgroud)
显然我的程序无法破译Web服务返回的SOAP错误.我写了一个自定义的FaultMessageResolver,但它没有被调用.这是代码:
public class UpsRateClient extends WebServiceGatewaySupport {
public UpsRateClient(WebServiceMessageFactory messageFactory) {
super(messageFactory);
getWebServiceTemplate().setFaultMessageResolver(new UpsFaultMessageResolver());
}
public RateResponse getRate(RateRequest rateRequest) {
return (RateResponse) getWebServiceTemplate().marshalSendAndReceive(rateRequest, new UpsRequestWSMC());
}
private class UpsFaultMessageResolver implements FaultMessageResolver {
public void resolveFault(WebServiceMessage message) throws IOException{
System.out.println("Inside UpsFaultMessageResolver");
}
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的时间!
我想知道是否可以使用Spring Web Services从WSDL文件创建Web服务客户端.
我的意思是从WSDL开始,我暂时没有任何XSD.
但我已经阅读了Josh Long的"Spring Recipes A Problem-Solution Approach",Hamidreza Sattari的"Spring Web Services 2 Cookbook"和教程本身(6.在客户端使用Spring Web Services),并没有提及此功能.
我还读过其他帖子,比如Webservice-Client:Spring WS,JAXB和一个WSDL文件的常用方法?或来自WSDL的Spring-ws客户端(此处为stackoverflow)但没有任何进一步的结果.
我甚至在Spring论坛上提出了这个问题,但是在超过60次读取之后没有回复:是否可以使用SWS从WSDL文件创建WS-client?(似乎没有)
也许这是不可能的.
谢谢.
我正在尝试使用soap标头发送SOAP请求,如下所示:
<SOAP-ENV:Header>
<Security xmlns="http://www.xxx.org/xxx/2003/05">
<UsernameToken><Username>yyyy</Username><Password>xxx</Password>
</UsernameToken></Security></SOAP-ENV:Header>
Run Code Online (Sandbox Code Playgroud)
为了做到这一点,我正在使用添加标题元素 SoapActionCallback
SoapActionCallback actionCallBack = new SoapActionCallback("https://aaa.com/bbb.asmx") {
public void doWithMessage(WebServiceMessage msg) {
SoapMessage smsg = (SoapMessage) msg;
smsg.setSoapAction("http://www.xxx.org/yyy/2003/05/SessionCreate");
SoapHeaderElement security = smsg.getSoapHeader().addHeaderElement(new QName("http://www.xxx.org/yyy", "Security"));
security.setText("<UsernameToken><Username>yyyy</Username><Password>xxx</Password></UsernameToken>");
}
};
Run Code Online (Sandbox Code Playgroud)
我的问题是soap标题看起来像这样
<SOAP-ENV:Header><Security xmlns="http://www.xxx.org/yyy/2003/05"><UsernameToken><Username>yyyyy</Username><Password>xxxx</Password></UsernameToken></Security></SOAP-ENV:Header>
Run Code Online (Sandbox Code Playgroud)
结果我的请求失败了:
如何正确添加此消息?
我们已经注意到,在运行时,SOAP Web服务似乎运行得更快
spring-boot:run
Run Code Online (Sandbox Code Playgroud)
而不是像我们为部署和运行那样打包JAR
java -jar mySpringApp.jar
Run Code Online (Sandbox Code Playgroud)
加速大约是2-3倍,所以很明显我们希望这对我们的现场环境来说.
为了验证这不是我们的应用程序中的东西,我已经尝试使用弹簧指南中的示例应用程序
git source https://github.com/spring-guides/gs-soap-service.git
使用JMeter进行测试显示了同样的加速速度.我已经在Windows 7 Java 1.8.0_31和Ubuntu 14.04平台上使用1.8.0_45-b14测试了这个.
这似乎只是肥皂服务的情况,简单的html并没有表现出任何显着的性能差异.知道是什么原因引起的吗?
我们使用WSSpringServlet(Spring 4.10)发布自动生成的WSDL,但它似乎在每次启动时生成不同的WSDL.有没有办法强制进行任何严格的排序?即使是字母也足够好.
我们正在使用旧技术来测试我们的Web服务(javascumbs).是否有一些教程如何将其迁移到springframework-ws-test?
现在我的测试看起来像:
@Test
public void testWs() throws Exception {
MessageContext message = helper.receiveMessage("xml/file.xml");
WebServiceMessage response = message.getResponse();
MessageValidator validator = helper.createMessageValidator(response);
validator.assertNotSoapFault();
validator.assertSoapMessage();
validator.validate("xsd/xsd1.xsd", "xsd/xsd2.xsd");
validator.compare("xml/response.ftl");
}
Run Code Online (Sandbox Code Playgroud)
我在这里找到了一些教程.但它看起来完全不同.我从文件加载xml,它也包含envelop和header,在这个例子中只有请求