[英]how to imlement a SOAP handler in JAX-WS client
I'm triing to implement a SOAP Handler to a client. 我正在尝试为客户端实现SOAP Handler。 I'm using Wildfly8.2 java8 and JAX-WS and Maven
我正在使用Wildfly8.2 java8和JAX-WS以及Maven
I have generated the client interface class with eclipse from the endpoint WSDL 我已经从端点WSDL生成了带有eclipse的客户端接口类
The handler-chain.xml file is placed in the same package as the client interface. handler-chain.xml文件与客户端接口放在同一个包中。
When I call the web service it executes ok but the handler is not invoked. 当我调用Web服务时,它执行正常,但不调用处理程序。 If I put a brake point in the handler it is never invoked
如果我在处理程序中放置制动点,则永远不会调用它
the client interface is like this: 客户端界面是这样的:
@WebService(targetNamespace = "********************", name = "WorkflowEditor")
@XmlSeeAlso({ ObjectFactory.class })
@HandlerChain(file = "handler-chain.xml")
public interface WorkflowEditor {
I have tried also to put the xml in resources and call it in the annotation with the url I verified is working for example : 我还尝试将xml放在资源中并使用我验证过的url在注释中调用它,例如:
@WebService(targetNamespace = "**************", name = "WorkflowEditor")
@XmlSeeAlso({ ObjectFactory.class })
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
@HandlerChain(file = "http://cloudflow-backend-local.arctur.net:8080/resources/handler-chain.xml")
public interface WorkflowEditor {
the handler is like this: 处理程序是这样的:
package si.arctur.services.handlers;
import java.util.Set;
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.soap.SOAPMessageContext;
public class PrintEnvelopeHandler implements javax.xml.ws.handler.soap.SOAPHandler<SOAPMessageContext> {
@Override
public boolean handleMessage(SOAPMessageContext context) {
System.out.println("Client : handleMessage()......");
SOAPMessage soapMessage = context.getMessage();
return true;
}
@Override
public boolean handleFault(SOAPMessageContext context) {
System.out.println("Client : handleFault()......");
return true;
}
@Override
public void close(MessageContext context) {
System.out.println("Client : close()......");
}
@Override
public Set<QName> getHeaders() {
// TODO Auto-generated method stub
return null;
}
}
and the handler-chain.xml file is like this: 和handler-chain.xml文件是这样的:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<javaee:handler-chains
xmlns:javaee="http://java.sun.com/xml/ns/javaee"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<javaee:handler-chain>
<javaee:handler>
<javaee:handler-class>si.arctur.services.handlers.PrintEnvelopeHandler</javaee:handler-class>
</javaee:handler>
</javaee:handler-chain>
@HandlerChain
注释可以放在客户端类(使用@WebServiceClient
注释),如本教程中所述。
( NOTE : The guide specified by other answers here is flawed. It asks you to edit an automatically-generated file. This never ends well.) ( 注意 :此处其他答案指定的指南存在缺陷。它会要求您编辑自动生成的文件。这永远不会结束。)
There is (currently) no standard way to attach a handler chain to a Web Service client using annotations only. (目前)没有标准方法仅使用注释将处理程序链附加到Web Service客户端。 To add handlers, you'll need to use the JAX-WS API:
要添加处理程序,您需要使用JAX-WS API:
// 'sei' is assumed to be the service endpoint interface
BindingProvider bp = (BindingProvider) sei;
// Get the handler chain
List<Handler> handlerChain = bp.getBinding().getHandlerChain();
// Add your handler
handlerChain.add(myHandler);
// Re-set the handler chain (needed because getHandlerChain() returns
// a copy of the handlers' list.
bp.getBinding().setHandlerChain(handlerChain);
As I can understand, the client interface and the client class are located in 2 different packages. 据我所知,客户端接口和客户端类位于2个不同的包中。 Suspecting that handler-chain.xml can not be located.
怀疑无法找到handler-chain.xml 。
The most correct solution would be to place the handler-chain.xml file in the main/resources folder of your maven project. 最正确的解决方案是将handler-chain.xml文件放在maven项目的main / resources文件夹中。
Alternatively, try to give the full package path of the location of the file on the file attribute of the @HandlerChain
annotation. 或者,尝试在
@HandlerChain
注释的文件属性上提供文件位置的完整包路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.