1 16 17 package org.apache.axis2.receivers; 18 19 import org.apache.axis2.Constants; 20 import org.apache.axis2.context.MessageContext; 21 import org.apache.axis2.context.SessionContext; 22 import org.apache.axis2.description.Parameter; 23 import org.apache.axis2.description.ServiceDescription; 24 import org.apache.axis2.engine.AxisFault; 25 import org.apache.axis2.engine.MessageReceiver; 26 import org.apache.axis2.om.OMAbstractFactory; 27 import org.apache.axis2.soap.SOAPFactory; 28 import org.apache.axis2.soap.impl.llom.soap11.SOAP11Constants; 29 import org.apache.axis2.soap.impl.llom.soap12.SOAP12Constants; 30 31 import javax.xml.namespace.QName ; 32 33 public abstract class AbstractMessageReceiver implements MessageReceiver { 34 public static final String SERVICE_CLASS = "ServiceClass"; 35 public static final String SCOPE = "scope"; 36 37 protected SOAPFactory fac; 38 39 40 47 protected Object makeNewServiceObject(MessageContext msgContext) throws AxisFault { 48 try { 49 50 String nsURI = msgContext.getEnvelope().getNamespace().getName(); 51 if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(nsURI)) { 52 fac = OMAbstractFactory.getSOAP12Factory(); 53 } else if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(nsURI)) { 54 fac = OMAbstractFactory.getSOAP11Factory(); 55 }else { 56 throw new AxisFault("Unknown SOAP Version. Current Axis handles only SOAP 1.1 and SOAP 1.2 messages"); 57 } 58 59 ServiceDescription service = 60 msgContext.getOperationContext().getServiceContext().getServiceConfig(); 61 ClassLoader classLoader = service.getClassLoader(); 62 Parameter implInfoParam = service.getParameter(SERVICE_CLASS); 63 if (implInfoParam != null) { 64 Class implClass = 65 Class.forName((String ) implInfoParam.getValue(), true, classLoader); 66 return implClass.newInstance(); 67 } else { 68 throw new AxisFault("SERVICE_CLASS parameter is not specified"); 69 } 70 71 } catch (Exception e) { 72 throw AxisFault.makeFault(e); 73 } 74 } 75 76 83 protected Object getTheImplementationObject(MessageContext msgContext) throws AxisFault { 84 ServiceDescription service = 85 msgContext.getOperationContext().getServiceContext().getServiceConfig(); 86 87 Parameter scopeParam = service.getParameter(SCOPE); 88 QName serviceName = service.getName(); 89 if (scopeParam != null && Constants.SESSION_SCOPE.equals(scopeParam.getValue())) { 90 SessionContext sessionContext = msgContext.getSessionContext(); 91 synchronized(sessionContext){ 92 Object obj = sessionContext.getProperty(serviceName.getLocalPart()); 93 if (obj == null) { 94 obj = makeNewServiceObject(msgContext); 95 sessionContext.setProperty(serviceName.getLocalPart(), obj); 96 } 97 return obj; 98 } 99 } else if (scopeParam != null && Constants.APPLICATION_SCOPE.equals(scopeParam.getValue())) { 100 SessionContext globalContext = msgContext.getSessionContext(); 101 synchronized(globalContext){ 102 Object obj = globalContext.getProperty(serviceName.getLocalPart()); 103 if (obj == null) { 104 obj = makeNewServiceObject(msgContext); 105 globalContext.setProperty(serviceName.getLocalPart(), obj); 106 } 107 return obj; 108 } 109 } else { 110 return makeNewServiceObject(msgContext); 111 } 112 } 113 114 public SOAPFactory getSOAPFactory(){ 115 return fac; 116 } 117 } 118 | Popular Tags |