Spring boot 将XML SOAP请求从Spring引导客户端应用程序打印到控制台
正如标题所说,我需要请求的字符串表示,这是我向SOAPWeb服务发起的 如何将请求发送到web服务: 首先,我从Swagger向我的控制器发出请求:Spring boot 将XML SOAP请求从Spring引导客户端应用程序打印到控制台,spring-boot,web-services,soap,soap-client,Spring Boot,Web Services,Soap,Soap Client,正如标题所说,我需要请求的字符串表示,这是我向SOAPWeb服务发起的 如何将请求发送到web服务: 首先,我从Swagger向我的控制器发出请求: @RequestMapping(value = "/helloworld", method = RequestMethod.POST) @ResponseBody public HelloWorldResponse helloworldRequest(@RequestParam(value = "request&quo
@RequestMapping(value = "/helloworld", method = RequestMethod.POST)
@ResponseBody
public HelloWorldResponse helloworldRequest(@RequestParam(value = "request") String request) {
HelloWorldResponse response = helloWorldClient.getValue(request);
return response;
}
然后在我的服务
层中,我有:
@Service
public class HelloWorldClient extends WebServiceGatewaySupport {
public HelloWorldResponse getValue(String myValue) {
ObjectFactory objectFactory = new ObjectFactory();
HelloWorld request = objectFactory.createHelloWorld();
JAXBElement<String> value = objectFactory.createHelloWorldMyValue(myValue);
request.setMyValue(value);
HelloWorldResponse response = (HelloWorldResponse) getWebServiceTemplate()
.marshalSendAndReceive("https://clienttesthorizon.horizonafs.com/AFSServices/AFSService.svc/basicHttpBinding",
request, new SoapActionCallback("http://tempuri.org/IAFSService/HelloWorld"));
return response;
}
}
HelloWorld
和HelloWorldResponse
是由生成的类。这项服务正在发挥作用。基本上,我传递字符串:John
,我从那个web服务得到一个响应:`helloworld John
我的目标是打印出请求发送前的实际字符串
到目前为止,我已经尝试了两种方法:
方法1
在application.properties
中,我设置了以下行:
log4j.rootCategory=INFO, stdout
log4j.logger.org.springframework.ws.client.MessageTracing.sent=TRACE
log4j.logger.org.springframework.ws.client.MessageTracing.received=TRACE
控制台上没有打印任何内容
方法2
在我的控制器(来自上面)所在的同一个包中,我有以下类:
@Component
public class MyFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
ContentCachingRequestWrapper requestWrapper = new ContentCachingRequestWrapper(request);
ContentCachingResponseWrapper responseWrapper = new ContentCachingResponseWrapper(response);
filterChain.doFilter(requestWrapper, responseWrapper);
byte[] resquestArray = requestWrapper.getContentAsByteArray();
String resquestStr = new String(resquestArray, requestWrapper.getCharacterEncoding());
System.out.println(resquestStr);
if(resquestStr.isEmpty()) System.out.println("this get printed");
}
}
你能找到解决办法吗?
@Component
public class MyFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
ContentCachingRequestWrapper requestWrapper = new ContentCachingRequestWrapper(request);
ContentCachingResponseWrapper responseWrapper = new ContentCachingResponseWrapper(response);
filterChain.doFilter(requestWrapper, responseWrapper);
byte[] resquestArray = requestWrapper.getContentAsByteArray();
String resquestStr = new String(resquestArray, requestWrapper.getCharacterEncoding());
System.out.println(resquestStr);
if(resquestStr.isEmpty()) System.out.println("this get printed");
}
}