KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > jbi > serviceengine > bridge > JAXWSRuntimeEndpointHelper


1 /*
2  * JAXWSRuntimeEndpointHelper.java
3  *
4  * Created on February 2, 2006, 3:08 PM
5  *
6  * To change this template, choose Tools | Options and locate the template under
7  * the Source Creation and Management node. Right-click the template and choose
8  * Open. You can then make changes to the template in the Source Editor.
9  */

10
11 package com.sun.enterprise.jbi.serviceengine.bridge;
12
13 import com.sun.enterprise.jbi.serviceengine.ServiceEngineException;
14 import com.sun.enterprise.jbi.serviceengine.core.ServiceEngineEndpoint;
15 import com.sun.enterprise.webservice.EjbRuntimeEndpointInfo;
16 import com.sun.enterprise.webservice.JAXWSRuntimeEpiRegistry;
17 import com.sun.enterprise.webservice.WebServiceEjbEndpointRegistry;
18 import com.sun.xml.ws.spi.runtime.RuntimeEndpointInfo;
19 import com.sun.xml.ws.spi.runtime.WSRtObjectFactory;
20 import com.sun.xml.ws.spi.runtime.WebServiceContext;
21 import javax.xml.ws.handler.MessageContext.Scope;
22
23 /**
24  *
25  * @author mu125243
26  */

27 public class JAXWSRuntimeEndpointHelper {
28
29     /** Creates a new instance of JAXWSRuntimeEndpointHelper */
30     public JAXWSRuntimeEndpointHelper() {
31     }
32     
33     public static void releaseEjbEndpoint(ServiceEngineEndpoint endpt) {
34         WebServiceEjbEndpointRegistry registry =
35                 WebServiceEjbEndpointRegistry.getRegistry();
36         EjbRuntimeEndpointInfo ejbRtEndptInfo =
37                 registry.getEjbWebServiceEndpoint(endpt.getURI(), "POST", null);
38         ejbRtEndptInfo.releaseImplementor();
39     }
40     
41     public static Object JavaDoc populateRuntimeInfo(ServiceEngineEndpoint endpt)
42     throws ServiceEngineException {
43         RuntimeEndpointInfo runtimeInfo = null;
44         if(endpt.isImplementedByEJB()) {
45             runtimeInfo = populateEjbRuntimeInfo(endpt);
46         } else {
47             runtimeInfo = populateWebRuntimeInfo(endpt);
48         }
49         setMessageContext(runtimeInfo);
50         return runtimeInfo;
51     }
52     
53     static void setMessageContext(RuntimeEndpointInfo runtimeInfo) {
54         if(runtimeInfo != null) {
55             // Set the message context
56
WebServiceContext wsCtxt = runtimeInfo.getWebServiceContext();
57             javax.xml.ws.handler.MessageContext msgCtxt =
58                     (javax.xml.ws.handler.MessageContext )WSRtObjectFactory.newInstance().createMessageContext();
59             msgCtxt.put(javax.xml.ws.handler.MessageContext.MESSAGE_OUTBOUND_PROPERTY,Boolean.FALSE);
60             msgCtxt.setScope(javax.xml.ws.handler.MessageContext.MESSAGE_OUTBOUND_PROPERTY, Scope.APPLICATION);
61             wsCtxt.setMessageContext(msgCtxt);
62         }
63     }
64     
65     private static RuntimeEndpointInfo populateEjbRuntimeInfo(
66             ServiceEngineEndpoint endpt) throws ServiceEngineException {
67         try {
68             WebServiceEjbEndpointRegistry registry =
69                     WebServiceEjbEndpointRegistry.getRegistry();
70             
71             EjbRuntimeEndpointInfo ejbRtEndptInfo =
72                     registry.getEjbWebServiceEndpoint(endpt.getURI(), "POST", null);
73             
74             RuntimeEndpointInfo rtEndptInfo = ejbRtEndptInfo.prepareInvocation(true);
75             return rtEndptInfo;
76         } catch(Exception JavaDoc e) {
77             throw new ServiceEngineException(e.getMessage());
78         }
79     }
80     
81     private static RuntimeEndpointInfo populateWebRuntimeInfo(
82             ServiceEngineEndpoint endpt) throws ServiceEngineException {
83         try {
84             String JavaDoc url = endpt.getURI();
85             String JavaDoc contextRoot = endpt.getContextRoot();
86             
87             RuntimeEndpointInfo endpointInfo =
88                     JAXWSRuntimeEpiRegistry.getInstance().
89                     getRuntimeEndpointInfo(contextRoot, url, url);
90             ClassLoader JavaDoc prevClassLoader = Thread.currentThread().getContextClassLoader();
91             Thread.currentThread().setContextClassLoader(endpt.getClassLoader());
92             endpointInfo.init();
93             
94             Thread.currentThread().setContextClassLoader(prevClassLoader);
95             return endpointInfo;
96         } catch(Exception JavaDoc e) {
97             throw new ServiceEngineException(e);
98         }
99     }
100 }
101
Popular Tags