Thank you Andrei.

Regards,
Chandu.


On Thu, Jan 9, 2014 at 4:57 PM, Andrei Shakirin <[email protected]>wrote:

> Hi,
>
> I see two options:
> a) add necessary interceptors directly into client.
>       For example, for ws-addressing:
>         Client client = ((DispatchImpl)dispatch).getClient();
>
>                  MAPCodec mapCodec = new MAPCodec();
>                  MAPAggregatorImpl mapAggregator = new MAPAggregatorImpl();
>
>         client.getOutInterceptors().add(mapCodec);
>         client.getOutInterceptors().add(mapAggregator);
>         client.getInInterceptors().add(mapCodec);
>         client.getInInterceptors().add(mapAggregator);
>                ...
>
>       See AddressingFeatureApplier for exact interceptors list
>      The same way add interceptors for security. Necessary context
> properties can be set using dispatch.getRequestContext();
>
> b) Using dynamic policy approach:
>     implement custom interceptor invoking before PolicyOutInterceptor and
> PolicyInInterceptor, which:
>     a) interceptor parses ws-policy with necessary WSA and security
> assertions using Neethy;
>     b) applies this policy into PolicyConstants.POLICY_OVERRIDE message
> property
>
>  For details see the following blog
> http://ashakirin.blogspot.de/2012/02/using-ws-policy-in-cxf-projects.html.
>
> Regards,
> Andrei.
>
>
>
>
> > -----Original Message-----
> > From: Chandra Sekhar [mailto:[email protected]]
> > Sent: Mittwoch, 8. Januar 2014 13:18
> > To: [email protected]
> > Subject: Re: Query regarding CXF dynamic dispatch client
> >
> > Hi Andrei,
> >
> > Thanks for your reply.
> >
> > Basically, I am trying to use dispatch API to invoke a SOAP Service with
> WS-
> > Security & WS-Addressing enabled. So, how we will be able to use
> > interceptors concept in CXF, to add Security headers to SOAP request
> > envelope.
> >
> > Any references to such sample implementation for this, will be great
> helpful.
> >
> > Thanks,
> > Chandu.
> >
> >
> >
> > On Wed, Jan 8, 2014 at 2:41 PM, Andrei Shakirin
> > <[email protected]>wrote:
> >
> > > Hi,
> > >
> > > Could you explain your use case a bit more, what CXF functionality you
> > > need in conjunction with Dispatch?
> > >
> > > Regards,
> > > Andrei.
> > >
> > > > -----Original Message-----
> > > > From: Chandra Sekhar [mailto:[email protected]]
> > > > Sent: Dienstag, 7. Januar 2014 12:31
> > > > To: [email protected]
> > > > Subject: Re: Query regarding CXF dynamic dispatch client
> > > >
> > > > Andrei, Thanks again.
> > > >
> > > > Do you have any references to such implementation.
> > > >
> > > > Also, any more insights to it, please.
> > > >
> > > > Thanks,
> > > > Chandu.
> > > >
> > > >
> > > >
> > > > On Tue, Jan 7, 2014 at 4:12 PM, Andrei Shakirin
> > > > <[email protected]>wrote:
> > > >
> > > > >
> > > > > > -----Original Message-----
> > > > > > From: Chandra Sekhar [mailto:[email protected]]
> > > > > > Sent: Dienstag, 7. Januar 2014 11:24
> > > > > > To: [email protected]
> > > > > > Subject: Re: Query regarding CXF dynamic dispatch client
> > > > > >
> > > > > > Hi Andrei & All,
> > > > > >
> > > > > > Thanks for your reply.
> > > > > >
> > > > > > Actually I tried the same in my TYPE-2 approach. But, I am
> > > > > > concerned
> > > > > about
> > > > > > the fact that it uses plain JAX-WS API to dispatch the request.
> > > > > > With this approach, shall I be able to leverage the CXF's
> > > > > > advanced feature support
> > > > > (like
> > > > > > WS-*).
> > > > > >
> > > > >
> > > > > Yes, CXF features like security, ws-addressing, ws-policy are
> > > > > available also for Dispatch case.
> > > > > Under standard JAX-WS API call you will invoke CXF implementation
> > > > > with interceptors chain, etc.
> > > > >
> > > > > Regards,
> > > > > Andrei.
> > > > >
> > > > > > Any references to similar implementations are greatly
> appreciated.
> > > > > >
> > > > > > Thanks,
> > > > > > Chandu.
> > > > > >
> > > > > >
> > > > > >
> > > > > > On Tue, Jan 7, 2014 at 2:42 PM, Andrei Shakirin
> > > > > > <[email protected]>wrote:
> > > > > >
> > > > > > > Hi,
> > > > > > >
> > > > > > > I guess it is use case for the Dispatch interface. The code
> > > > > > > can look
> > > > > like:
> > > > > > >         ...
> > > > > > >         String serviceName = "myService";
> > > > > > >         Service service = Service.create(serviceName);
> > > > > > >         String actualSoapBinding = (soapBinding != null) ?
> > > > > > > soapBinding
> > > > > :
> > > > > > > SOAPBinding.SOAP11HTTP_BINDING;
> > > > > > >         service.addPort(portName, actualSoapBinding,
> > > targetEndpoint);
> > > > > > >         Dispatch<StreamSource> dispatcher =
> > > > > > > service.createDispatch(portName, StreamSource.class,
> > > > > > >                 Service.Mode.PAYLOAD);
> > > > > > >         ...
> > > > > > >        StreamSource request;
> > > > > > >        response = dispatcher.invoke(request);
> > > > > > >        ...
> > > > > > >
> > > > > > > You can look also in jaxws_dispatch_provider sample of CXF
> > > > > > > distribution for details.
> > > > > > >
> > > > > > > Regards,
> > > > > > > Andrei.
> > > > > > >
> > > > > > > > -----Original Message-----
> > > > > > > > From: Chandra Sekhar [mailto:[email protected]]
> > > > > > > > Sent: Montag, 6. Januar 2014 10:09
> > > > > > > > To: [email protected]
> > > > > > > > Subject: Query regarding CXF dynamic dispatch client
> > > > > > > >
> > > > > > > > Hi,
> > > > > > > >
> > > > > > > > I have a peculiar use-case where in I need to invoke a SOAP
> > > > > > > > Service
> > > > > > > without
> > > > > > > > refering the WSDL and without creating the stubs & JAXB
> classes.
> > > > > > > > Custom implementation of data mapping well suits to our
> > > > > > > > needs and infact we
> > > > > > > have it
> > > > > > > > in-place.
> > > > > > > >
> > > > > > > > I have the following information to invoke the Service :
> > > > > > > >
> > > > > > > > Style and Use
> > > > > > > > Operation Name
> > > > > > > > Namespace URI
> > > > > > > > SOAPAction
> > > > > > > > Endpoint URL
> > > > > > > > Binding SOAP version - 1.1/1.2
> > > > > > > >
> > > > > > > >
> > > > > > > > With the above information we are able to make a service
> > > > > > > > call using
> > > > > > > Axis2.
> > > > > > > >
> > > > > > > > I am trying to achieve the same using CXF. Basically I tried
> > > > > > > > the
> > > > > below.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > import java.io.FileInputStream; import java.io.InputStream;
> > > > > > > > import java.util.Iterator;
> > > > > > > >
> > > > > > > > import javax.xml.namespace.QName; import
> > > > > > > > javax.xml.soap.MessageFactory; import javax.xml.soap.Node;
> > > > > > > > import javax.xml.soap.SOAPBody; import
> > > > > > > > javax.xml.soap.SOAPEnvelope; import
> > > > > > > > javax.xml.soap.SOAPMessage; import javax.xml.soap.SOAPPart;
> > > > > > > > import javax.xml.ws.Dispatch; import javax.xml.ws.Service;
> > > > > > > > import javax.xml.ws.soap.SOAPBinding;
> > > > > > > >
> > > > > > > > import org.apache.cxf.endpoint.Client; import
> > > > > > > > org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFact
> > > > > > > > ory; import org.w3c.dom.NodeList;
> > > > > > > >
> > > > > > > >
> > > > > > > > public class CXFClient {
> > > > > > > >
> > > > > > > > /**
> > > > > > > >  * @param args
> > > > > > > >  */
> > > > > > > > public static void main(String[] args) { try {
> > > > > > > > //TYPE-1
> > > > > > > >  JaxWsDynamicClientFactory dcf =
> > > > > > > > JaxWsDynamicClientFactory.newInstance();
> > > > > > > > Client client = dcf.createClient("
> > > > > > > >
> > > > > >
> > > >
> > http://wsekhc1w7:8989/web/SOAPServlet/SOAP/TestService/Sample?WSDL
> > > > > > > > ");
> > > > > > > >  Object[] res = client.invoke("TestServiceSOAP1",
> "Hello...!");
> > > > > > > > System.out.println("Response :::    " + res[0]);
> > > > > > > >  //TYPE-2
> > > > > > > >      //QName serviceName = new
> > > > > > QName("urn:SOAP:TestService:Sample",
> > > > > > > > "SampleService");
> > > > > > > > //QName serviceName = new QName("Test", "Test"); QName
> > > > > > serviceName =
> > > > > > > > new QName("", "");
> > > > > > > >     Service service = Service.create(serviceName);
> > > > > > > >
> > > > > > > >     //QName portName = new
> > > > QName("urn:SOAP:TestService:Sample",
> > > > > > > > "SamplePortSOAP");
> > > > > > > >     //QName portName = new QName("Test", "Test");
> > > > > > > >     QName portName = new QName("", "");
> > > > > > > >
> > > > > > > >     service.addPort(portName,
> > SOAPBinding.SOAP11HTTP_BINDING, "
> > > > > > > >
> > > > http://wsekhc1w7:8989/web/SOAPServlet/SOAP/TestService/Sample";);
> > > > > > > >     Dispatch<SOAPMessage> dispatch =
> > > > > > > > service.createDispatch(portName, SOAPMessage.class,
> > > > > > > > Service.Mode.MESSAGE);
> > > > > > > >
> > > > > > > >         // Test request-response
> > > > > > > >         InputStream is = new
> > > > > > > >
> > > > FileInputStream("F:\\CXF_Demo\\src\\SampleRequestEnvelope.xml");
> > > > > > > >         SOAPMessage soapReqMsg =
> > > > > > > > MessageFactory.newInstance().createMessage(null, is);
> > > > > > > >
> > > > > > > >         SOAPMessage soapResMsg =
> > > > > > > > dispatch.invoke(soapReqMsg);
> > > > > > > >
> > > > > > > >     SOAPPart soapPart = soapResMsg.getSOAPPart();
> > > > > > > >     SOAPEnvelope envelope = soapPart.getEnvelope();
> > > > > > > >     SOAPBody body = envelope.getBody();
> > > > > > > >
> > > > > > > >     Iterator iter = body.getChildElements();
> > > > > > > >     while(iter.hasNext())
> > > > > > > >     {
> > > > > > > >      Node tempNode = (Node) iter.next();
> > > > > > > >      if(tempNode.getNodeType()==Node.ELEMENT_NODE)
> > > > > > > >      {
> > > > > > > >      NodeList list = tempNode.getChildNodes();
> > > > > > > >      for(int i=0; i<list.getLength(); i++)
> > > > > > > >      {
> > > > > > > >      if(list.item(i).getNodeType() == Node.ELEMENT_NODE)
> > > > > > > >      {
> > > > > > > >      NodeList list1 = tempNode.getChildNodes();
> > > > > > > >      for(int j=0; j<list.getLength(); j++)
> > > > > > > >      {
> > > > > > > >      //System.out.println(list1.item(j).getNodeName());
> > > > > > > >      if(list1.item(j).getNodeType() == Node.ELEMENT_NODE)
> > > > > > > >      {
> > > > > > > >      System.out.println("NodeName : " +
> > > > > > > > list1.item(j).getNodeName()
> > > > > > > > + "\n NodeValue : " +
> > > > > > > > + list1.item(j).getFirstChild().getNodeValue());
> > > > > > > >      }
> > > > > > > >      }
> > > > > > > >      }
> > > > > > > >      }
> > > > > > > >      }
> > > > > > > >      //System.out.println("TempNode : " +
> > > > tempNode.getNodeName());
> > > > > > > >     }
> > > > > > > > }
> > > > > > > > catch(Exception e)
> > > > > > > > {
> > > > > > > > e.printStackTrace();
> > > > > > > > }
> > > > > > > > }
> > > > > > > > }
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > In the above code snippet, TYPE-1 is using CXF's dynamic
> > > > > > > > client with
> > > > > > > which
> > > > > > > > found no way to decouple the WSDL dependency. Because all
> > > > > > > > the
> > > > > > > >  JaxWsDynamicClientFactory.createClient() overloaded methods
> > > > > > > > need WSDL URL.
> > > > > > > >
> > > > > > > > Though TYPE-2 does the same for us (without WSDL URL), but
> > > > > > > > the concern here is that it uses the JAX-WS API and can we
> > > > > > > > be able to embedd the CXF feature support (like WS-*).
> > > > > > > >
> > > > > > > > Suggestion to implement CXF dynamic client (without stubs &
> > > > > > > > classes
> > > > > > > > creation) greatly appreciated.
> > > > > > > >
> > > > > > > > Thanks in advance.
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Chandu
> > > > > > >
> > > > >
> > >
>

Reply via email to