You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fx-dev@ws.apache.org by Mark Badorrek <mb...@avoga.com.au> on 2007/02/25 22:05:29 UTC

Invoking Axis2

Dear All,
 
I have a requirement to invoke a webservice on a soap message I already have (i.e. no transport). IN Axis 1.4 we used to do the following:
 
|   String text = "<this is my soap message etc etc etc>"; 
|   String service = "my_service_name";
|
|   // Setup Axis
|   org.apache.axis.Message axisSoapMessage = new org.apache.axis.Message(text);
|   MessageContext axisMsgCtxt = new org.apache.axis.MessageContext(axisEngine);
|   axisMsgCtxt.setRequestMessage(axisSoapMessage);
|   axisMsgCtxt.setTargetService(service);
|
|   // Invoke axis
|   axisEngine.invoke(axisMsgCtxt);
|   String response = axisMsgCtxt.getResponseMessage().getSOAPPartAsString();
 
And that work quite well.
 
Now I've moved to Axis2 and I'm not quite sure what to do.
 
I've made a directory 'repo', with a sub-directory 'services'.
In 'services' I've placed my 'aar' file.
 
My code looks like this:
 
|   File repository = new File("repo");
|   String repositoryPath = repository.getAbsolutePath();
|   
|   ConfigurationContext myConfigContext =  
|       |ConfigurationContextFactory.createConfigurationContextFromFileSystem(repositoryPath, null);
|   
|   
|   MessageContext axisMsgCtxt = new MessageContext();
|   axisMsgCtxt.setConfigurationContext(myConfigContext);
|   axisMsgCtxt.setServerSide(true);
|   // Setup the request message
|   // AxisMessage message = new AxisMessage();
|   // axisMsgCtxt.setAxisMessage(message);
|
|   String soapNamespaceURI = "";
|   if (text.indexOf(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI) > -1) {
|                soapNamespaceURI = SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI;
|   } else if (text.indexOf(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI) > -1) {
|                soapNamespaceURI = SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI;
|   }
|    
|   ByteArrayInputStream bais = new ByteArrayInputStream(text.getBytes());
|   XMLStreamReader reader = StAXUtils.createXMLStreamReader(bais);
|   StAXBuilder builder = new StAXSOAPModelBuilder(reader, soapNamespaceURI);
|   SOAPEnvelope envelope = (SOAPEnvelope) builder.getDocumentElement();
|   axisMsgCtxt.setEnvelope(envelope);
|
|   // Tell axis which service we want
|   AxisService service = new AxisService(serviceName);
|   axisMsgCtxt.setAxisService(service)
|
|  //.. that's about all so far...
 
 
I believe that I'm doing the right thing with the repository/configuration, but I'm afraid I have no confidence in my code. Just to re-iterate, I'm trying to achieve the same thing in Axis2 and I have in Axis1.4.
 
Can anyone advise.
 
Cheers,
 
Mark B