1 16 17 package org.apache.axis2.clientapi; 18 19 import org.apache.axis2.addressing.EndpointReference; 20 import org.apache.axis2.context.ConfigurationContext; 21 import org.apache.axis2.context.MessageContext; 22 import org.apache.axis2.context.ServiceContext; 23 import org.apache.axis2.deployment.DeploymentException; 24 import org.apache.axis2.description.ServiceDescription; 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.om.OMFactory; 29 import org.apache.axis2.om.OMNamespace; 30 import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder; 31 import org.apache.axis2.om.impl.llom.factory.OMXMLBuilderFactory; 32 import org.apache.axis2.soap.SOAPBody; 33 import org.apache.axis2.soap.SOAPEnvelope; 34 import org.apache.axis2.soap.SOAPFactory; 35 import org.apache.axis2.soap.impl.llom.SOAPProcessingException; 36 import org.apache.wsdl.WSDLService; 37 38 import javax.xml.stream.XMLStreamReader; 39 40 41 42 46 public abstract class Stub { 47 48 protected ConfigurationContext _configurationContext; 49 protected static ServiceDescription _service; 50 protected ServiceContext _serviceContext; 51 protected EndpointReference toEPR ; 52 53 54 55 60 protected boolean _maintainSession = false; 61 protected String _currentSessionId = null; 62 63 64 protected Stub()throws DeploymentException, AxisFault{ 65 66 } 67 68 72 public void _setSessionInfo(String key, Object value)throws java.lang.Exception { 73 if(!_maintainSession){ 74 throw new java.lang.Exception ("Client is running the session OFF mode: Start session before saving to a session "); 76 } 77 _configurationContext.getServiceContext(_currentSessionId).setProperty(key, value); 78 } 79 80 81 public Object _getSessionInfo(String key) throws java.lang.Exception { 82 if(!_maintainSession){ 83 throw new java.lang.Exception ("Client is running the session OFF mode: Start session before saving to a session "); 85 } 86 return _configurationContext.getServiceContext(_currentSessionId).getProperty(key); 87 } 88 89 public void _startSession(){ 90 _maintainSession = true; 91 _currentSessionId = getID() ; 92 } 93 94 public void _endSession(){ 95 _maintainSession = false; 96 } 97 98 protected String _getServiceContextID(){ 99 if(_maintainSession) 100 return _currentSessionId; 101 else 102 return getID(); 103 } 104 105 private String getID(){ 106 return Long.toString(System.currentTimeMillis()); 108 } 109 110 protected SOAPEnvelope createEnvelope() throws SOAPProcessingException { 112 SOAPEnvelope env = getFactory().getDefaultEnvelope(); 113 return env; 114 } 115 116 protected void setValueRPC(SOAPEnvelope env,String methodNamespaceURI,String methodName,String [] paramNames,Object [] values){ 117 SOAPBody body = env.getBody(); 118 OMFactory fac = this.getFactory(); 119 120 OMNamespace methodNamespace = fac.createOMNamespace(methodNamespaceURI,"ns1"); 121 OMElement elt = fac.createOMElement(methodName,methodNamespace); 122 if (paramNames!=null){ 123 for (int i = 0; i < paramNames.length; i++) { 125 String paramName = paramNames[i]; 126 Object value = values[i]; 127 elt.addChild(StubSupporter.createRPCMappedElement(paramName, 128 fac.createOMNamespace("",null), value, 130 fac)); 131 } 132 } 133 body.addChild(elt); 134 } 135 136 137 protected OMElement getElementFromReader(XMLStreamReader reader) { 138 StAXOMBuilder builder = OMXMLBuilderFactory.createStAXOMBuilder(OMAbstractFactory.getOMFactory(),reader) ; 139 return builder.getDocumentElement(); 140 } 141 142 protected void setValueDoc(SOAPEnvelope env,OMElement value){ 143 if (value!=null){ 144 SOAPBody body = env.getBody(); 145 body.addChild(value); 146 } 147 } 148 149 protected OMElement getElement(SOAPEnvelope env,String type){ 150 SOAPBody body = env.getBody(); 151 OMElement element = body.getFirstElement(); 152 153 if (WSDLService.STYLE_RPC.equals(type)){ 154 return element.getFirstElement(); }else if (WSDLService.STYLE_DOC.equals(type)){ 156 return element; 157 }else { 158 throw new UnsupportedOperationException ("Unsupported type"); 159 } 160 161 } 162 163 179 protected MessageContext getMessageContext() throws AxisFault { 180 return new MessageContext(_configurationContext); 181 } 182 183 184 private SOAPFactory getFactory(){ 185 return OMAbstractFactory.getSOAP11Factory(); 186 } 187 } 188 189 | Popular Tags |