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.MessageContext; 23 import org.apache.axis2.context.ServiceContext; 24 import org.apache.axis2.description.OperationDescription; 25 import org.apache.axis2.description.ServiceDescription; 26 import org.apache.axis2.engine.AxisFault; 27 import org.apache.axis2.om.OMElement; 28 import org.apache.axis2.soap.SOAPEnvelope; 29 30 import javax.xml.namespace.QName ; 31 import java.util.HashMap ; 32 33 36 public class Call extends InOutMEPClient { 37 38 private HashMap properties; 39 protected static OperationDescription operationTemplate; 40 private MessageContext lastResponseMessage; 41 45 46 public Call() throws AxisFault { 47 super(assumeServiceContext(null)); 48 } 49 50 56 public Call(String clientHome) throws AxisFault { 57 super(assumeServiceContext(clientHome)); 58 } 59 60 64 public Call(ServiceContext service) { 65 super(service); 66 } 67 68 75 76 public OMElement invokeBlocking(String axisop, OMElement toSend) throws AxisFault { 77 78 OperationDescription axisConfig = 79 serviceContext.getServiceConfig().getOperation(new QName (axisop)); 80 if (axisConfig == null) { 81 axisConfig = new OperationDescription(new QName (axisop)); 82 axisConfig.setRemainingPhasesInFlow(operationTemplate.getRemainingPhasesInFlow()); 83 axisConfig.setPhasesOutFlow(operationTemplate.getPhasesOutFlow()); 84 axisConfig.setPhasesInFaultFlow(operationTemplate.getPhasesInFaultFlow()); 85 axisConfig.setPhasesOutFaultFlow(operationTemplate.getPhasesOutFaultFlow()); 86 serviceContext.getServiceConfig().addOperation(axisConfig); 87 } 88 89 MessageContext msgctx = prepareTheSystem(toSend); 94 95 this.lastResponseMessage = super.invokeBlocking(axisConfig, msgctx); 96 SOAPEnvelope resEnvelope = lastResponseMessage.getEnvelope(); 97 return resEnvelope.getBody().getFirstElement(); 98 } 99 107 108 public void invokeNonBlocking(String axisop, OMElement toSend, Callback callback) 109 throws AxisFault { 110 OperationDescription axisConfig = 111 serviceContext.getServiceConfig().getOperation(new QName (axisop)); 112 if (axisConfig == null) { 113 axisConfig = new OperationDescription(new QName (axisop)); 114 axisConfig.setRemainingPhasesInFlow(operationTemplate.getRemainingPhasesInFlow()); 115 axisConfig.setPhasesOutFlow(operationTemplate.getPhasesOutFlow()); 116 axisConfig.setPhasesInFaultFlow(operationTemplate.getPhasesInFaultFlow()); 117 axisConfig.setPhasesOutFaultFlow(operationTemplate.getPhasesOutFaultFlow()); 118 serviceContext.getServiceConfig().addOperation(axisConfig); 119 } 120 MessageContext msgctx = prepareTheSystem(toSend); 121 122 super.invokeNonBlocking(axisConfig, msgctx, callback); 123 } 124 125 130 protected static ServiceContext assumeServiceContext(String clinetHome) throws AxisFault { 131 ConfigurationContext sysContext = null; 132 if (ListenerManager.configurationContext == null) { 133 ConfigurationContextFactory efac = new ConfigurationContextFactory(); 134 sysContext = efac.buildClientConfigurationContext(clinetHome); 135 }else{ 136 sysContext = ListenerManager.configurationContext; 137 } 138 139 QName assumedServiceName = new QName ("AnonnoymousService"); 141 ServiceDescription axisService = new ServiceDescription(assumedServiceName); 142 operationTemplate = new OperationDescription(new QName ("TemplateOperatin")); 143 axisService.addOperation(operationTemplate); 144 sysContext.getAxisConfiguration().addService(axisService); 145 ServiceContext service = sysContext.createServiceContext(assumedServiceName); 146 return service; 147 } 148 149 153 public Object get(String key) { 154 return serviceContext.getProperty(key); 155 } 156 157 162 public void set(String key, Object value) { 163 serviceContext.getEngineContext().setProperty(key, value); 164 } 165 168 public MessageContext getLastResponseMessage() { 169 return lastResponseMessage; 170 } 171 172 } 173 | Popular Tags |