Skip to content

Instantly share code, notes, and snippets.

@nipunthathsara
Created July 13, 2018 12:50
Show Gist options
  • Save nipunthathsara/28e6349b311b256f6d402d15e0585e4f to your computer and use it in GitHub Desktop.
Save nipunthathsara/28e6349b311b256f6d402d15e0585e4f to your computer and use it in GitHub Desktop.
Axis2 SOAP client sample
package org.wso2.sample;
import org.apache.axiom.om.*;
import org.apache.axiom.soap.*;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.OperationClient;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.synapse.MessageContext;
import org.apache.synapse.mediators.AbstractMediator;
public class CustomMediator extends AbstractMediator{
public boolean mediate(MessageContext messageContext) {
try{
ServiceClient serviceClient = new ServiceClient();
Options options = new Options();
options.setTo(new EndpointReference("https://"));
serviceClient.setOptions(options);
OperationClient operationClient = serviceClient.createClient(ServiceClient.ANON_OUT_IN_OP);
operationClient.addMessageContext(createMessage());
operationClient.execute(true);
}catch (AxisFault e){
System.out.println(e);
}
return true;
}
private org.apache.axis2.context.MessageContext createMessage() throws AxisFault {
org.apache.axis2.context.MessageContext messageContext1 = new org.apache.axis2.context.MessageContext();
SOAPFactory soapFactory = OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope soapEnvelope = soapFactory.createSOAPEnvelope();
SOAPBody soapBody = soapFactory.createSOAPBody();
soapEnvelope.addChild(soapBody);
messageContext1.setEnvelope(soapEnvelope);
return messageContext1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment