/** Configures SOAP interceptors for the given client. */ protected void configureInterceptors(Client client) { client.getInInterceptors().add(new Cxf3791WorkaroundInterceptor()); // WS-Addressing-related interceptors if (wsTransactionConfiguration.isAddressing()) { MustUnderstandDecoratorInterceptor interceptor = new MustUnderstandDecoratorInterceptor(); for (String nsUri : SoapUtils.WS_ADDRESSING_NS_URIS) { interceptor.addHeader(new QName(nsUri, "Action")); } client.getOutInterceptors().add(interceptor); MAPCodec mapCodec = new MAPCodec(); MAPAggregator mapAggregator = new MAPAggregator(); client.getInInterceptors().add(mapCodec); client.getInInterceptors().add(mapAggregator); client.getInFaultInterceptors().add(mapCodec); client.getInFaultInterceptors().add(mapAggregator); client.getOutInterceptors().add(mapCodec); client.getOutInterceptors().add(mapAggregator); client.getOutFaultInterceptors().add(mapCodec); client.getOutFaultInterceptors().add(mapAggregator); } if (wsTransactionConfiguration.isSwaOutSupport()) { client.getOutInterceptors().add(new ProvidedAttachmentOutInterceptor()); client.getOutInterceptors().add(new FixContentTypeOutInterceptor()); } InterceptorUtils.copyInterceptorsFromProvider(customInterceptors, client); }
/** * Returns a client stub for the web-service. * * <p>This method reuses the last stub created by the current thread. * * @return the client stub. */ public synchronized Object getClient() { if (threadLocalPort.get() == null) { URL wsdlURL = getClass().getClassLoader().getResource(wsTransactionConfiguration.getWsdlLocation()); Service service = Service.create(wsdlURL, wsTransactionConfiguration.getServiceName()); Object port = service.getPort(wsTransactionConfiguration.getSei()); Client client = ClientProxy.getClient(port); configureBinding(port); configureInterceptors(client); threadLocalPort.set(port); LOG.debug("Created client adapter for: {}", wsTransactionConfiguration.getServiceName()); } return threadLocalPort.get(); }
/** Configures SOAP binding of the given SOAP port. */ private void configureBinding(Object port) { BindingProvider bindingProvider = (BindingProvider) port; Map<String, Object> reqContext = bindingProvider.getRequestContext(); reqContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, serviceUrl); Binding binding = bindingProvider.getBinding(); SOAPBinding soapBinding = (SOAPBinding) binding; soapBinding.setMTOMEnabled(wsTransactionConfiguration.isMtom()); }