Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 将XML SOAP请求从Spring引导客户端应用程序打印到控制台_Spring Boot_Web Services_Soap_Soap Client - Fatal编程技术网

Spring boot 将XML SOAP请求从Spring引导客户端应用程序打印到控制台

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

正如标题所说,我需要请求的字符串表示,这是我向SOAPWeb服务发起的

如何将请求发送到web服务:

首先,我从Swagger向我的控制器发出请求:

@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");
        
    }
}