1 18 package org.apache.axis2.clientapi; 19 20 import org.apache.axis2.context.ConfigurationContext; 21 import org.apache.axis2.context.ConfigurationContextFactory; 22 import org.apache.axis2.context.ServiceContext; 23 import org.apache.axis2.description.OperationDescription; 24 import org.apache.axis2.description.ServiceDescription; 25 import org.apache.axis2.engine.AxisFault; 26 import org.apache.axis2.om.OMElement; 27 28 import javax.xml.namespace.QName ; 29 30 36 public class MessageSender extends InOnlyMEPClient { 37 public MessageSender(ServiceContext service) { 38 super(service); 39 } 40 41 public MessageSender() throws AxisFault { 42 super(assumeServiceContext()); 43 } 44 public void send(String opName, OMElement toSend) throws AxisFault { 45 OperationDescription axisOp = serviceContext.getServiceConfig().getOperation(opName); 46 if(axisOp == null){ 47 axisOp = new OperationDescription(new QName (opName)); 48 serviceContext.getServiceConfig().addOperation(axisOp); 49 } 50 super.send(axisOp, prepareTheSystem(toSend)); 51 } 52 53 private static ServiceContext assumeServiceContext() throws AxisFault { 54 ConfigurationContext sysContext = null; 55 if (ListenerManager.configurationContext == null) { 56 ConfigurationContextFactory efac = new ConfigurationContextFactory(); 57 sysContext = efac.buildClientConfigurationContext(null); 58 } else { 59 sysContext = ListenerManager.configurationContext; 60 } 61 62 QName assumedServiceName = new QName ("AnonnoymousService"); 64 ServiceDescription axisService = new ServiceDescription(assumedServiceName); 65 sysContext.getAxisConfiguration().addService(axisService); 66 ServiceContext service = sysContext.createServiceContext(assumedServiceName); 67 return service; 68 } 69 } 70 | Popular Tags |