gpt4 book ai didi

java - 执行 WS 操作后未调用 SoapHandler

转载 作者:行者123 更新时间:2023-11-30 09:50:44 27 4
gpt4 key购买 nike

我有一个也使用 SOAP WS(在 doGet 中)的 servlet。我想查看 SOAP 信封(或 soap 消息中的任何其他内容)。我将此代码添加到我的 servlet 类中:

class ClientHandlerResolver implements HandlerResolver {
public List<Handler> getHandlerChain(PortInfo port_info) {
List<Handler> hchain = new ArrayList<Handler>();
hchain.add(new TestHandler()); // soap handler defined in TestHandler.java dumps messages to stdout
return hchain;
}
}

我是一个单独的类(class),我有我的 TestHandler:

public class TestHandler implements SOAPHandler<SOAPMessageContext> {
private static final String LoggerName = "ClientSideLogger";
private Logger logger;
private final boolean log_p = true; // set to false to turn off

public TestHandler() {
logger = Logger.getLogger(LoggerName);
}

public boolean handleMessage(SOAPMessageContext ctx) {
if (log_p)
logger.info("Test::handleMessage");

// Is this an outbound message, i.e., a request?
Boolean request_p = (Boolean)
ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

// Manipulate the SOAP only if it's a request
if (request_p) {
try {
SOAPMessage msg = ctx.getMessage();
msg.writeTo(System.out);

}
catch(SOAPException e)
{ System.err.println(e);
}
catch(IOException e)
{ System.err.println(e);
}
}
return true; // continue down the chain

public boolean handleFault(SOAPMessageContext ctx) {
return true;

public Set<QName> getHeaders() { 
if (log_p)
logger.info("getHeaders");
return null;

}

public void close(MessageContext messageContext) { 
if (log_p)
logger.info("close");
}

当我发出 WS 请求时,什么也没有打印出来。我什至不知道是否调用了处理程序。

如何查看Handler中定义的打印输出?

最佳答案

我不确定 Eclipse 为您生成了什么,但这是一种方法。假设 MyService 是从 WSDL 生成的接口(interface):

URL wsdlURL = new URL("...");
QName serviceName = new QName("...", "...");
Service service = Service.create(wsdlURL, serviceName);
HandlerResolver handlerResolver = new ClientHandlerResolver();
service.setHandlerResolver(handlerResolver);
MyService myService = service.getPort(MyService.class);
// invoke methods (operations) on myService

关于java - 执行 WS 操作后未调用 SoapHandler,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5019039/

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