org.apache.axis2.context.MessageContext msgContext = mc.getAxisMessageContext();
// Get the ServiceDescription and injectionDesc which contain
// cached information
ServiceDescription serviceDesc = mc.getEndpointDescription().getServiceDescription();
ResourceInjectionServiceRuntimeDescription injectionDesc = null;
if (serviceDesc != null) {
injectionDesc =
ResourceInjectionServiceRuntimeDescriptionFactory
.get(serviceDesc, serviceImplClass);
}
// See if there is an existing service object
ServiceContext serviceContext = msgContext.getServiceContext();
Object serviceimpl = serviceContext.getProperty(ServiceContext.SERVICE_OBJECT);
if (serviceimpl != null) {
this.instance = serviceimpl;
if (log.isDebugEnabled()) {
log.debug("Service Instance found in the service context, reusing the instance");
}
// If resource injection is needed, create the SOAPMessageContext and update the WebServiceContext
// Create MessageContext for current invocation.
if (injectionDesc != null && injectionDesc.hasResourceAnnotation()) {
javax.xml.ws.handler.MessageContext soapMessageContext =
createSOAPMessageContext(mc);
//Get WebServiceContext from ServiceContext
WebServiceContext ws =
(WebServiceContext)serviceContext.getProperty(WEBSERVICE_MESSAGE_CONTEXT);
//Add the MessageContext for current invocation
if (ws != null) {
updateWebServiceContext(ws, soapMessageContext);
}
}
//since service impl is there in service context , take that from there
return serviceimpl;
} else {
// create a new service impl class for that service
serviceimpl = createServiceInstance(msgContext.getAxisService(), serviceImplClass);
this.instance = serviceimpl;
if (log.isDebugEnabled()) {
log.debug("New Service Instance created");
}
// If resource injection is needed, create the SOAPMessageContext and build the WebServiceContext
// Create MessageContext for current invocation.
if (injectionDesc != null && injectionDesc.hasResourceAnnotation()) {
javax.xml.ws.handler.MessageContext soapMessageContext =
createSOAPMessageContext(mc);
// Create WebServiceContext
WebServiceContextImpl wsContext = new WebServiceContextImpl();
//Add MessageContext for this request.
wsContext.setSoapMessageContext(soapMessageContext);
// Inject WebServiceContext
injectWebServiceContext(mc, wsContext, serviceimpl);
serviceContext.setProperty(WEBSERVICE_MESSAGE_CONTEXT, wsContext);
}
//Invoke PostConstruct
if (injectionDesc != null && injectionDesc.getPostConstructMethod() != null) {
invokePostConstruct(injectionDesc.getPostConstructMethod());
}
serviceContext.setProperty(ServiceContext.SERVICE_OBJECT, serviceimpl);
return serviceimpl;
}
}