在code-first开发模式中,从SEI实现类或SEI开始,handler chains是通过 @HandlerChain注释进行配置的。实例:
@WebService(……) @HandlerChain(file="handler-chain.xml") public class CreditCardServiceImpl { ... }
对应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>com.javaeye.jaxws.cardhandler.common.ServiceAuthenticationSOAPHandler </javaee:handler-class> </javaee:handler> </javaee:handler-chain> </javaee:handler-chains>
当以contract-first为开发模式时,JAX-WS 2.0 没有定义一种标准的方法去hander chains。然而通过引用实现,我们通过一个额外的声明去定义WSDL,并且通过wsimport工具去产生annotated service class和SEI。例如:通过下面的额外绑定声明文件service-config-single.xml,在描述文件中只要把上面代码潜入到jaxws:bindings元素中。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <bindings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" wsdlLocation="CreditCardService.wsdl" xmlns="http://java.sun.com/xml/ns/jaxws"> <bindings node="wsdl:definitions"> <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>com.javaeye.jaxws.cardhandler.common.ServiceAuthenticationSOAPHandler </javaee:handler-class> </javaee:handler> </javaee:handler-chain> </javaee:handler-chains> </bindings> </bindings>
有先采用声明在实现类上的handler chains
基于services, ports, 和 protocol bindings配置服务端的handler chains
在client我们通过编码配置,不同handler chains 使用不同message exchanges基于services, ports, and protocol bindings。
在描述文件中有四种子元素帮我们完成这样的任务:javaee:handler-chain, javaee:service-name-pattern,
javaee:port-name-pattern, or javaee:protocol-binding。如果handler chains没有对应的配置,将使用所有的元素。
下面是一个演示实例:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <bindings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" wsdlLocation="CreditCardService.wsdl" xmlns="http://java.sun.com/xml/ns/jaxws"> <bindings node="wsdl:definitions"> <javaee:handler-chains xmlns:javaee="http://java.sun.com/xml/ns/javaee"> <javaee:handler-chain> <javaee:service-name-pattern xmlns:ns1="http://cardservice.handler.jaxws. company.com/service">ns1:CardService</javaee:service-name-pattern> <javaee:handler> <javaee:handler-class>com.company.jaxws.handler.cardservice.common. EnvelopeLoggingSOAPHandler</javaee:handler-class> </javaee:handler> <javaee:handler> <javaee:handler-class>com.company.jaxws.handler.cardservice.common. JAXBPayloadLoggingLogicalHandler</javaee:handler-class> </javaee:handler> </javaee:handler-chain> <javaee:handler-chain> <javaee:port-name-pattern xmlns:ns2="http://cardservice.handler.jaxws. company.com/service">*</javaee:port-name-pattern> <javaee:handler> <javaee:handler-class>com.company.jaxws.handler.cardservice.common. ServiceAuthenticationSOAPHandler</javaee:handler-class> </javaee:handler> <javaee:handler> <javaee:handler-class>com.company.jaxws.handler.cardservice.common. ServicePerformanceMonitorLogicalHandler</javaee:handler-class> </javaee:handler> </javaee:handler-chain> <javaee:handler-chain> <javaee:protocol-bindings>##SOAP11_HTTP</javaee:protocol-bindings> <javaee:handler> <javaee:handler-class>com.company.jaxws.handler.cardservice.common. HTTPHeaderLoggingLogicalHandler</javaee:handler-class> </javaee:handler> </javaee:handler-chain> </javaee:handler-chains> </bindings> </bindings>
javaee:protocol-bindings子元素可选的值为。
URI | Alias |
http://schemas.xmlsoap.org/wsdl/soap/http | ##SOAP11_HTTP |
http://schemas.xmlsoap.org/wsdl/soap/http?mtom=true | ##SOAP11_HTTP_MTOM |
http://www.w3.org/2003/05/soap/bindings/HTTP/ | ##SOAP12_HTTP |
http://www.w3.org/2003/05/soap/bindings/HTTP/?mtom=true | ##SOAP12_HTTP_MTOM |
http://www.w3.org/2004/08/wsdl/http | ##XML_HTTP |