CXF添加Header

Posted by Vincent on Sunday, May 10, 2015

CXF的header处理了半天。。。

添加拦截器

    
public class HotelHeaderInterceptor extends AbstractSoapInterceptor {
public void handleMessage(SoapMessage message) throws Fault {
		    
		    List<Header> headers = message.getHeaders(); 
		 
		    AuthenticationHeader aheader = new AuthenticationHeader();
		    aheader.setCulture(com.tourico.schemas.webservices.authentication.Culture.EN_US);
		    aheader.setLoginName(username);
		    aheader.setPassword(password);
		    aheader.setVersion(new JAXBElement<String>(new QName("", "version"), String.class, version));
		    
		    JAXBElement<AuthenticationHeader> authHeaders = new ObjectFactory().createAuthenticationHeader(aheader);
		    
		    Header header;
			try {
				header = new Header(authHeaders.getName(), aheader,new JAXBDataBinding(AuthenticationHeader.class));
				headers.add(header);
			    message.put(Header.HEADER_LIST, headers);
			} catch (JAXBException e) {
				
				e.printStackTrace();
			}
	}

调用服务之前处理

    IDestinationContracts  port = service.getIISDestinationHosting() ;
			Client cxfClient = ClientProxy.getClient(port);
			
			cxfClient.getOutInterceptors().add(new HeaderInterceptor(Phase.WRITE));

「真诚赞赏,手留余香」

我的乐与怒

真诚赞赏,手留余香

使用微信扫描二维码完成支付