1 18 package org.apache.axis2.clientapi; 19 20 import org.apache.axis2.addressing.EndpointReference; 21 import org.apache.axis2.context.MessageContext; 22 import org.apache.axis2.context.ServiceContext; 23 import org.apache.axis2.description.OperationDescription; 24 import org.apache.axis2.description.TransportOutDescription; 25 import org.apache.axis2.engine.AxisFault; 26 import org.apache.axis2.om.OMAbstractFactory; 27 import org.apache.axis2.om.OMElement; 28 import org.apache.axis2.soap.SOAPEnvelope; 29 import org.apache.axis2.soap.SOAPFactory; 30 import org.apache.axis2.soap.impl.llom.soap11.SOAP11Constants; 31 import org.apache.axis2.soap.impl.llom.soap12.SOAP12Constants; 32 33 import javax.xml.namespace.QName ; 34 35 38 public abstract class MEPClient { 39 protected ServiceContext serviceContext; 40 protected final String mep; 41 protected String soapVersionURI = SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI; 42 protected String soapAction = ""; 43 protected boolean doREST = false; 44 protected String wsaAction; 45 46 public void setDoREST(boolean b) { 47 doREST = b; 48 } 49 50 51 public String getSoapAction() { 52 return soapAction; 53 } 54 55 public MEPClient(ServiceContext service, String mep) { 56 this.serviceContext = service; 57 this.mep = mep; 58 } 59 60 protected void verifyInvocation(OperationDescription axisop,MessageContext msgCtx) throws AxisFault { 61 if (axisop == null) { 62 throw new AxisFault("OperationDescription can not be null"); 63 } 64 65 if (mep.equals(axisop.getMessageExchangePattern())) { 66 throw new AxisFault("This mepClient supports only " 67 + mep 68 + " And the Axis Operations suppiled supports " 69 + axisop.getMessageExchangePattern()); 70 } 71 72 if (serviceContext.getServiceConfig().getOperation(axisop.getName()) == null) { 73 serviceContext.getServiceConfig().addOperation(axisop); 74 } 75 msgCtx.setDoingREST(doREST); 76 if(wsaAction != null){ 77 msgCtx.setWSAAction(wsaAction); 78 } 79 } 80 81 protected MessageContext prepareTheSystem(OMElement toSend) throws AxisFault { 82 MessageContext msgctx = new MessageContext(serviceContext.getEngineContext()); 83 84 SOAPEnvelope envelope = createDefaultSOAPEnvelope(); 85 envelope.getBody().addChild(toSend); 86 msgctx.setEnvelope(envelope); 87 return msgctx; 88 } 89 90 public TransportOutDescription inferTransport(EndpointReference epr) throws AxisFault { 91 String transport = null; 92 if (epr != null) { 93 String toURL = epr.getAddress(); 94 int index = toURL.indexOf(':'); 95 if (index > 0) { 96 transport = toURL.substring(0, index); 97 } 98 } 99 100 if (transport != null) { 101 return serviceContext.getEngineContext().getAxisConfiguration().getTransportOut(new QName (transport)); 102 103 } else { 104 throw new AxisFault("Cannot Infer transport from the URL"); 105 } 106 107 } 108 109 public SOAPEnvelope createDefaultSOAPEnvelope() throws AxisFault{ 110 SOAPFactory fac = null; 111 if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(soapVersionURI)) { 112 fac = OMAbstractFactory.getSOAP12Factory(); 113 } else if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(soapVersionURI)) { 114 fac = OMAbstractFactory.getSOAP11Factory(); 115 } else { 116 throw new AxisFault("Invalid SOAP URI. Axis2 only supports SOAP 1.1 and 1.2"); 117 } 118 return fac.getDefaultEnvelope(); 119 } 120 121 124 public void setSoapVersionURI(String string) { 125 soapVersionURI = string; 126 } 127 128 131 public void setSoapAction(String string) { 132 soapAction = string; 133 } 134 135 138 public void setWsaAction(String string) { 139 wsaAction = string; 140 } 141 142 } 143 | Popular Tags |