Created
July 13, 2018 12:50
-
-
Save nipunthathsara/28e6349b311b256f6d402d15e0585e4f to your computer and use it in GitHub Desktop.
Axis2 SOAP client sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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