Using the Dispatch API can be tricky. I haven't tried it with SOAPMessage, so I'm not sure if WS-Security works there or not. I've added two examples though to show how to use the Dispatch API with Signature using payload:
https://github.com/apache/cxf/blob/5d67785208334062a950dc7f85ffcb7d52af3db5/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/action/ActionTest.java#L492 and message: https://github.com/apache/cxf/blob/5d67785208334062a950dc7f85ffcb7d52af3db5/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/action/ActionTest.java#L534 Colm. On Tue, Feb 6, 2018 at 8:13 PM, George S. <geor...@mhsoftware.com> wrote: > Would you mind giving me a few pointers? I'm trying things out. I'm told > (I can't run it myself) that the message is not getting signed. I'm > probably doing something really dumb, but if you could help I would > appreciate it. Here's my code: > > try { > MessageFactory mf = MessageFactory.newInstance(); > SOAPMessage reqMesg = mf.createMessage(); > SOAPMessage response;// = mf.createMessage(); > toSOAPElement(notifyDocketingCompleteRequest, reqMesg); > > String namespace = cfgProps.getProperty("efm.namespace",""); > String serviceName = cfgProps.getProperty("efm.serviceName",""); > String portName = cfgProps.getProperty("efm.portName",""); > String methodName = cfgProps.getProperty("efm.methodName.nDC",""); > String endpointAddress = cfgProps.getProperty("efm.stag > eEndpointAddress",""); > String WS_URL = cfgProps.getProperty("efm.stageWS_URL",""); > > URL wsdlLocation =new URL(WS_URL); > QName serviceQName =new QName(namespace, serviceName); > QName portQName =new QName(namespace, portName); > > Service service = Service.create(wsdlLocation, serviceQName); > PortType port=service.getPort(portQName,PortType.class); > > Map<String,Object> interceptorProperties=new HashMap<>(); > interceptorProperties.put(WSHandlerConstants.ACTION,"Signature"); > interceptorProperties.put(WSHandlerConstants.SIG_PROP_FILE," > client_sign.properties"); > > WSS4JOutInterceptor interceptor=new WSS4JOutInterceptor(intercepto > rProperties); > > Client cxfClient=ClientProxy.getClient(port); > cxfClient.getOutInterceptors().add(interceptor); > > Dispatch<SOAPMessage> dispatch = service.createDispatch(portQName, > SOAPMessage.class, Service.Mode.MESSAGE); > > BindingProvider bp = (BindingProvider) dispatch; > SOAPBinding binding = (SOAPBinding) bp.getBinding(); > bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, > endpointAddress); > binding.setMTOMEnabled(true); > > List<Handler> handlerChain =new ArrayList<Handler>(); > p.ClientLogicalHandler cAuth =new p.ClientLogicalHandler(); > p.EnvelopeLoggingSOAPHandler logging =new > p.EnvelopeLoggingSOAPHandler(); > handlerChain.add(cAuth); > handlerChain.add(logging); > binding.setHandlerChain(handlerChain); > // Put it all in the context object > Map<String,Object> myContext = bp.getRequestContext(); > > response = dispatch.invoke(reqMesg); > ElementNSImpl myResponseElement = (ElementNSImpl) > response.getSOAPBody(); > > return myResponseElement; > > } catch (SOAPException e1){ > e1.printStackTrace(); > } catch (SOAPFaultException e1){ > SOAPFault fault = e1.getFault(); > e1.printStackTrace(); > return fault; > } catch (Exception wse){ > String errResponse = wse.getMessage(); > wse.printStackTrace(); > System.out.println(wse); > Object response = errResponse; > return response; > } > > > On 2/2/2018 2:55 AM, Colm O hEigeartaigh wrote: > >> If you want to add an interceptor on the client side, you can do something >> like: >> >> Service service = Service.create(wsdlLocation, serviceQName); >> PortType port = service.getPort(portQName, PortType.class); >> Client cxfClient = ClientProxy.getClient(port); >> cxfClient.getOutInterceptors().add(...) >> >> Here's an example: >> >> https://github.com/apache/cxf/blob/dcae47fac2c0e22994572e674 >> 4852070737223e5/systests/ws-security/src/test/java/org/apach >> e/cxf/systest/ws/ut/UsernameTokenTest.java#L439 >> >> Colm. >> >> On Thu, Feb 1, 2018 at 9:07 PM, George S. <geor...@mhsoftware.com> wrote: >> >> I apologize for the really basic level of my question. I've looked at the >>> docs and I'm really not figuring out how to do this. I'm adapting some >>> code: >>> >>> import javax.xml.ws.Service; >>> >>> URL wsdlLocation =new URL(WS_URL); >>> QName serviceQName =new QName(namespace, serviceName); >>> QName portQName =new QName(namespace, portName); >>> Service service = Service.create(wsdlLocation, serviceQName); >>> >>> and I'm desperately trying to figure out how to get an Endpoint so I can >>> add an Interceptor. If I have the service ( which from looking at the >>> code >>> for javax.xml.ws.Service is created by a Provider()), how can I get to >>> the >>> endpoint? >>> >>> I've looked at: >>> >>> http://cxf.apache.org/docs/ws-security.html >>> >>> and in the section labelled "Adding the interceptors via the API", the >>> example shows passing in a "myServiceImpl". >>> >>> What are the steps to go through for creation of a "myServiceImpl"? What >>> are class is "myServiceImpl", and how is one obtained? >>> >>> Again, I apologize if these questions for the basic nature of my >>> questions. >>> >>> >>> >>> -- >>> George S. >>> *MH Software, Inc.* >>> Voice: 303 438 9585 >>> http://www.mhsoftware.com >>> >>> >> >> > -- > George S. > *MH Software, Inc.* > Voice: 303 438 9585 > http://www.mhsoftware.com > -- Colm O hEigeartaigh Talend Community Coder http://coders.talend.com