Source Code Cross Referenced for EndpointLifecycleManagerImpl.java in  » Web-Services-AXIS2 » jax-ws » org » apache » axis2 » jaxws » server » endpoint » lifecycle » impl » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Services AXIS2 » jax ws » org.apache.axis2.jaxws.server.endpoint.lifecycle.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements. See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership. The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License. You may obtain a copy of the License at
009:         *
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied. See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         */
019:        package org.apache.axis2.jaxws.server.endpoint.lifecycle.impl;
020:
021:        import java.lang.reflect.Method;
022:
023:        import javax.xml.ws.WebServiceContext;
024:
025:        import org.apache.axis2.Constants;
026:        import org.apache.axis2.context.ServiceContext;
027:        import org.apache.axis2.description.AxisService;
028:        import org.apache.axis2.description.Parameter;
029:        import org.apache.axis2.jaxws.ExceptionFactory;
030:        import org.apache.axis2.jaxws.context.WebServiceContextImpl;
031:        import org.apache.axis2.jaxws.context.factory.MessageContextFactory;
032:        import org.apache.axis2.jaxws.context.utils.ContextUtils;
033:        import org.apache.axis2.jaxws.core.MessageContext;
034:        import org.apache.axis2.jaxws.description.ServiceDescription;
035:        import org.apache.axis2.jaxws.handler.SoapMessageContext;
036:        import org.apache.axis2.jaxws.i18n.Messages;
037:        import org.apache.axis2.jaxws.lifecycle.BaseLifecycleManager;
038:        import org.apache.axis2.jaxws.lifecycle.LifecycleException;
039:        import org.apache.axis2.jaxws.runtime.description.injection.ResourceInjectionServiceRuntimeDescription;
040:        import org.apache.axis2.jaxws.runtime.description.injection.ResourceInjectionServiceRuntimeDescriptionFactory;
041:        import org.apache.axis2.jaxws.server.endpoint.injection.ResourceInjector;
042:        import org.apache.axis2.jaxws.server.endpoint.injection.WebServiceContextInjector;
043:        import org.apache.axis2.jaxws.server.endpoint.injection.factory.ResourceInjectionFactory;
044:        import org.apache.axis2.jaxws.server.endpoint.lifecycle.EndpointLifecycleManager;
045:        import org.apache.axis2.jaxws.injection.ResourceInjectionException;
046:        import org.apache.axis2.util.Loader;
047:        import org.apache.commons.logging.Log;
048:        import org.apache.commons.logging.LogFactory;
049:
050:        public class EndpointLifecycleManagerImpl extends BaseLifecycleManager
051:                implements  EndpointLifecycleManager {
052:            public static final String WEBSERVICE_MESSAGE_CONTEXT = "javax.xml.ws.WebServiceContext";
053:            private static final Log log = LogFactory
054:                    .getLog(EndpointLifecycleManagerImpl.class);
055:
056:            public EndpointLifecycleManagerImpl(Object endpointInstance) {
057:                this .instance = endpointInstance;
058:            }
059:
060:            public EndpointLifecycleManagerImpl() {
061:            }
062:
063:            /* (non-Javadoc)
064:             * @see org.apache.axis2.jaxws.server.endpoint.lifecycle.EndpointLifecycleManager#createServiceInstance(org.apache.axis2.jaxws.core.MessageContext, java.lang.Class)
065:             */
066:            public Object createServiceInstance(MessageContext mc,
067:                    Class serviceImplClass) throws LifecycleException,
068:                    ResourceInjectionException {
069:                org.apache.axis2.context.MessageContext msgContext = mc
070:                        .getAxisMessageContext();
071:
072:                // Get the ServiceDescription and injectionDesc which contain
073:                // cached information
074:                ServiceDescription serviceDesc = mc.getEndpointDescription()
075:                        .getServiceDescription();
076:                ResourceInjectionServiceRuntimeDescription injectionDesc = null;
077:                if (serviceDesc != null) {
078:                    injectionDesc = ResourceInjectionServiceRuntimeDescriptionFactory
079:                            .get(serviceDesc, serviceImplClass);
080:                }
081:
082:                // See if there is an existing service object
083:                ServiceContext serviceContext = msgContext.getServiceContext();
084:                Object serviceimpl = serviceContext
085:                        .getProperty(ServiceContext.SERVICE_OBJECT);
086:                if (serviceimpl != null) {
087:                    this .instance = serviceimpl;
088:
089:                    if (log.isDebugEnabled()) {
090:                        log
091:                                .debug("Service Instance found in the service context, reusing the instance");
092:                    }
093:
094:                    // If resource injection is needed, create the SOAPMessageContext and update the WebServiceContext
095:                    // Create MessageContext for current invocation.
096:                    if (injectionDesc != null
097:                            && injectionDesc.hasResourceAnnotation()) {
098:                        javax.xml.ws.handler.MessageContext soapMessageContext = createSOAPMessageContext(mc);
099:                        //Get WebServiceContext from ServiceContext
100:                        WebServiceContext ws = (WebServiceContext) serviceContext
101:                                .getProperty(WEBSERVICE_MESSAGE_CONTEXT);
102:                        //Add the MessageContext for current invocation
103:                        if (ws != null) {
104:                            updateWebServiceContext(ws, soapMessageContext);
105:                        }
106:                    }
107:
108:                    //since service impl is there in service context , take that from there
109:                    return serviceimpl;
110:                } else {
111:                    // create a new service impl class for that service
112:                    serviceimpl = createServiceInstance(msgContext
113:                            .getAxisService(), serviceImplClass);
114:                    this .instance = serviceimpl;
115:
116:                    if (log.isDebugEnabled()) {
117:                        log.debug("New Service Instance created");
118:                    }
119:
120:                    // If resource injection is needed, create the SOAPMessageContext and build the WebServiceContext
121:                    // Create MessageContext for current invocation.
122:                    if (injectionDesc != null
123:                            && injectionDesc.hasResourceAnnotation()) {
124:                        javax.xml.ws.handler.MessageContext soapMessageContext = createSOAPMessageContext(mc);
125:                        // Create WebServiceContext
126:                        WebServiceContextImpl wsContext = new WebServiceContextImpl();
127:                        //Add MessageContext for this request.
128:                        wsContext.setSoapMessageContext(soapMessageContext);
129:                        // Inject WebServiceContext
130:                        injectWebServiceContext(mc, wsContext, serviceimpl);
131:                        serviceContext.setProperty(WEBSERVICE_MESSAGE_CONTEXT,
132:                                wsContext);
133:                    }
134:
135:                    //Invoke PostConstruct
136:                    if (injectionDesc != null
137:                            && injectionDesc.getPostConstructMethod() != null) {
138:                        invokePostConstruct(injectionDesc
139:                                .getPostConstructMethod());
140:                    }
141:                    serviceContext.setProperty(ServiceContext.SERVICE_OBJECT,
142:                            serviceimpl);
143:                    return serviceimpl;
144:                }
145:            }
146:
147:            private Object createServiceInstance(AxisService service,
148:                    Class serviceImplClass) {
149:                if (log.isDebugEnabled()) {
150:                    log.debug("Creating new instance of service endpoint");
151:                }
152:
153:                if (serviceImplClass == null) {
154:                    throw ExceptionFactory.makeWebServiceException(Messages
155:                            .getMessage("EndpointControllerErr5"));
156:                }
157:
158:                Object instance = null;
159:                try {
160:                    // allow alternative definition of makeNewServiceObject
161:                    if (service != null
162:                            && service
163:                                    .getParameter(Constants.SERVICE_OBJECT_SUPPLIER) != null) {
164:                        ClassLoader classLoader = service.getClassLoader();
165:
166:                        Parameter serviceObjectParam = service
167:                                .getParameter(Constants.SERVICE_OBJECT_SUPPLIER);
168:                        Class serviceObjectMaker = Loader.loadClass(
169:                                classLoader, ((String) serviceObjectParam
170:                                        .getValue()).trim());
171:
172:                        // Find static getServiceObject() method, call it if there
173:                        Method method = serviceObjectMaker.getMethod(
174:                                "getServiceObject",
175:                                new Class[] { AxisService.class });
176:                        if (method != null) {
177:                            return method.invoke(serviceObjectMaker
178:                                    .newInstance(), new Object[] { service });
179:                        }
180:                    }
181:                    instance = serviceImplClass.newInstance();
182:                } catch (IllegalAccessException e) {
183:                    throw ExceptionFactory.makeWebServiceException(Messages
184:                            .getMessage("EndpointControllerErr6",
185:                                    serviceImplClass.getName()));
186:                } catch (InstantiationException e) {
187:                    throw ExceptionFactory.makeWebServiceException(Messages
188:                            .getMessage("EndpointControllerErr6",
189:                                    serviceImplClass.getName()));
190:                } catch (Exception e) {
191:                    throw ExceptionFactory.makeWebServiceException(Messages
192:                            .getMessage("EndpointControllerErr6",
193:                                    serviceImplClass.getName()));
194:                }
195:
196:                return instance;
197:            }
198:
199:            private javax.xml.ws.handler.MessageContext createSOAPMessageContext(
200:                    MessageContext mc) {
201:                SoapMessageContext soapMessageContext = (SoapMessageContext) MessageContextFactory
202:                        .createSoapMessageContext(mc);
203:                ContextUtils.addProperties(soapMessageContext, mc);
204:                return soapMessageContext;
205:            }
206:
207:            private void injectWebServiceContext(MessageContext mc,
208:                    WebServiceContext wsContext, Object serviceInstance)
209:                    throws ResourceInjectionException {
210:                ResourceInjector ri = ResourceInjectionFactory
211:                        .createResourceInjector(WebServiceContext.class);
212:                ri.inject(wsContext, serviceInstance);
213:            }
214:
215:            private void updateWebServiceContext(WebServiceContext wsContext,
216:                    javax.xml.ws.handler.MessageContext soapMessageContext)
217:                    throws ResourceInjectionException {
218:                WebServiceContextInjector wci = (WebServiceContextInjector) ResourceInjectionFactory
219:                        .createResourceInjector(WebServiceContext.class);
220:                wci.addMessageContext(wsContext, soapMessageContext);
221:
222:            }
223:
224:        }
w_w___w___._j_av___a___2_s__.__c___o_m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.