gpt4 book ai didi

Tracing XML request/responses with JAX-WS when error occurs(发生错误时使用JAX-WS跟踪XML请求/响应)

转载 作者:bug小助手 更新时间:2023-10-22 17:34:43 34 4
gpt4 key购买 nike



I want to log raw soap post requests if there are any errors , I am using JAX-WS. Any help will be appreciated.

如果有任何错误,我想记录原始soap post请求,我使用的是JAX-WS。任何帮助都将不胜感激。



Is there an easy way (aka: not using a proxy) to get access to the raw request/response XML for a webservice published with JAX-WS reference implementation (the one included in JDK 1.5 and better) only when exception occurs in response? I want to log raw SOAP reuest so that I can test it thorugh any webservice client at a later stage

有没有一种简单的方法(也就是说:不使用代理)可以访问使用JAX-WS参考实现发布的Web服务的原始请求/响应XML(JDK 1.5及更好版本中包含的那个),只有在响应中发生异常时才能访问?我想记录原始SOAP重用,以便在稍后阶段通过任何Web服务客户端对其进行测试


更多回答
优秀答案推荐

Use

使用



com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.dump=true

com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.dump=true



and



com.sun.xml.internal.ws.transport.http.HttpAdapter.dump=true

com.sun.xml.internal.ws.transport.httpHttpAdapter.dump=true



instead (note the "internal" in the package name), this did the trick for me.

相反(注意包名称中的“internal”),这对我来说很有用。



Cheers,
Torsten

干杯,托尔斯滕



Just thought I would mention this:

我只是想提一下:



The question when to use the property name with the internal in it and when not ?



If you read the Metro Guide it will tell you to use:

如果您阅读《地铁指南》,它会告诉您使用:



on client:

在客户端上:



com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump=true


on server:

在服务器上:



com.sun.xml.ws.transport.http.HttpAdapter.dump=true


However: It seems to me that when JAX-WS RI library got included as standard with the JDK (this was with Java 6) then Sun had to rename the property name to include 'internal'. So if you are using JAX-WS RI as it comes bundled with the JDK, then you must be sure to add the internal to the property name. Otherwise it will not work. In other words you need to use:

然而:在我看来,当JAX-WSRI库作为JDK的标准包含时(这是Java6),Sun不得不将属性名称重命名为包含“internal”。因此,如果您使用的是与JDK捆绑在一起的JAX-WSRI,那么您必须确保将内部添加到属性名称中。否则它将不起作用。换句话说,您需要使用:



on client:

在客户端上:



com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.dump=true


on server:

在服务器上:



com.sun.xml.internal.ws.transport.http.HttpAdapter.dump=true


On the other hand if you are using a standalone version of JAX-WS RI (or of Metro as a whole) then I would guess you should use the property name without the internal.

另一方面,如果您使用的是JAX-WSRI(或整个Metro)的独立版本,那么我想您应该使用不带内部的属性名称。



I'll be glad if someone has inside knowledge on this and can say if this is true or not.

如果有人对此有内幕消息,并能说出这是真是假,我会很高兴。



It is OK to go with system properties (here is Gradle DSL for test task):

可以使用系统属性(这里是测试任务的Gradle DSL):


systemProperty "com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump", "true"
systemProperty "com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.dump", "true"
systemProperty "com.sun.xml.ws.transport.http.HttpAdapter.dump", "true"
systemProperty "com.sun.xml.internal.ws.transport.http.HttpAdapter.dump", "true"
systemProperty "com.sun.xml.ws.transport.http.HttpAdapter.dumpTreshold", "99999"
systemProperty "com.sun.xml.internal.ws.transport.http.HttpAdapter.dumpTreshold", "99999"

but those settings are global and may have high volume to enable them on PROD... It is not fun to add filters to your logging framework bound to business logic if you want to reduce volume of XML logging.

但是这些设置是全局的,并且可能有很高的容量来在PROD上启用它们…如果你想减少XML日志记录的容量,那么在绑定到业务逻辑的日志记录框架中添加过滤器并不有趣。


Details on capturing req/rsp bodies in WS handlers are in my answer How can I pass data back from a SOAP handler to a webservice client?

关于在WS处理程序中捕获req/rsp主体的详细信息,请参阅我的答案。如何将数据从SOAP处理程序传递回Web服务客户端?


Here is an important part:

以下是一个重要部分:


public class MsgLogger implements SOAPHandler<SOAPMessageContext> {

public static String REQEST_BODY = "com.evil.request";
public static String RESPONSE_BODY = "com.evil.response";

@Override
public Set<QName> getHeaders() {
return null;
}

@Override
public boolean handleMessage(SOAPMessageContext context) {
SOAPMessage msg = context.getMessage();
Boolean beforeRequest = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream(32_000);
context.getMessage().writeTo(baos);
String key = beforeRequest ? REQEST_BODY : RESPONSE_BODY;
context.put(key, baos.toString("UTF-8"));
context.setScope(key, MessageContext.Scope.APPLICATION);
} catch (SOAPException | IOException e) { }
return true;
}

@Override
public boolean handleFault(SOAPMessageContext context) {
return handleMessage(context);
}

@Override
public void close(MessageContext context) { }
}

To register handler and use preserved properties:

要注册处理程序并使用保留的属性,请执行以下操作:


BindingProvider provider = (BindingProvider) port;
List<Handler> handlerChain = provider.getBinding().getHandlerChain();
handlerChain.add(new MsgLogger());
provider.getBinding().setHandlerChain(handlerChain);

Req req = ...;
Rsp rsp = port.serviceCall(req); // call WS Port

// Access saved message bodies:
Map<String, Object> responseContext = provider.getResponseContext();
String reqBody = (String) responseContext.get(MsgLogger.REQEST_BODY);
String rspBody = (String) responseContext.get(MsgLogger.RESPONSE_BODY);

With this solution (it is only the skeleton, proper error handling / edge cases is up to you) you decide to log later when you've got response.

有了这个解决方案(它只是框架,正确的错误处理/边缘情况由您决定),您可以在收到响应后决定登录。



In addition to Torsten's answer

除了Torsten的回答




com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.dump=true




Make sure that you set this before instantiating the WebServiceClient object (the one that extends Service)

请确保在实例化WebServiceClient对象(扩展Service的对象)之前设置了此项



The first thing you might want to try is using one, or both, of the following system properties:

您可能想尝试的第一件事是使用以下系统属性中的一个或两个:



Client:

客户:



com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump=true


Server:

服务器:



com.sun.xml.ws.transport.http.HttpAdapter.dump=true


If you working with Jboss 6.1 and you want to print the logs for the JAX-WS generated classes request to the SOAP web service,
open the file /home/oracle/jboss-eap-6.1/bin/standalone.sh
note: please go where you have installed jboss

如果您使用Jboss 6.1,并且希望将JAX-WS生成的类请求的日志打印到SOAP web服务,请打开文件/home/orace/Jboss-eap-6.1/bin/standalone.sh注意:请转到安装Jboss的位置



You will find something like this

你会发现这样的东西



JAVA_OPTS="$JAVA_OPTS -agentlib:jdwp=transport=dt_socket,address=$DEBUG_PORT,server=y,suspend=n"


Change it to the one shown below

将其更改为如下所示



JAVA_OPTS="$JAVA_OPTS -Dcom.sun.xml.ws.transport.http.client.HttpTransportPipe.dump=true -agentlib:jdwp=transport=dt_socket,address=$DEBUG_PORT,server=y,suspend=n"


Also make sure you enable debug

还要确保启用调试



DEBUG_MODE=true


I think that what you need is an handler, see:
http://jax-ws.java.net/articles/handlers_introduction.html


With handler you can intercept web service call, and have access to all the SOAP message.

我认为您需要的是一个处理程序,请参阅:http://jax-ws.java.net/articles/handlers_introduction.html使用处理程序,您可以拦截web服务调用,并可以访问所有SOAP消息。



This worked for me:

这对我很有效:



-Dcom.sun.xml.ws.transport.http.client.HttpTransportPipe.dump=true

更多回答

changed catalina.sh file , included 'internal' but still cant see any changes in logs/catalina.yyyy-MM-dd.log files

更改了catalina.sh文件,包括“内部”,但在logs/catalina.yyyy-MM-dd.log文件中仍然看不到任何更改

.internal. is required when you are using the JAX WS version contained in the JRE, whereas the non ".internal." version is used, when you are explicitly using a JAX WS library

当您使用JRE中包含的JAX WS版本时,需要.internal.,而当您显式使用JAX WS库时,则使用非“.internal..”版本

how to add timestamp, at what time a particular request reached to server and at what time server responded back ?

如何添加时间戳,特定请求何时到达服务器,服务器何时响应?

This answer is based on The Java API for XML-Based Web Services (JAX-WS) 2.3 spec so should work for any JAX WS implementation.

这个答案基于Java API for XML-based Web Services(JAX-WS)2.3规范,因此应该适用于任何JAX-WS实现。

I added above properties in my catalina.properties file in my tomcat server, but cant see any logs updated, please advise

我在tomcat服务器的catalina.properties文件中添加了以上属性,但看不到任何更新的日志,请告知

added to my catalina.sh on JAVA_OPTS but cant see any changes

已在JAVA_OPTS上添加到我的catalina.sh,但看不到任何更改

Don't change catalina.properties. How are you setting JAVA_OPTS? The logging should be output via System.out.

不要更改catalina.properties。如何设置JAVA_OPTS?日志记录应通过System.out输出。

Following is the JAVA_OPTS line in my catalina.sh file JAVA_OPTS="-Dcom.sun.xml.ws.fault.SOAPFaultBuilder.disableCaptureStackTrace = false -Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms512m -Xmx1024m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m -XX:MaxPermSize=256m -XX:+DisableExplicitGC -Dcom.sun.xml.ws.transport.http.client.HttpTransportPipe.dump = true -Dcom.sun.xml.ws.transport.http.HttpAdapter.dump = true"

...and nothing's showing up in logs/catalina.out? I suppose it would be good to know what JDK and Tomcat versions you're using...

…日志/catalina中没有显示任何内容。是吗?我想最好知道您使用的JDK和Tomcat版本是什么。。。

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com