KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > webservice > Ejb2RuntimeEndpointInfo


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.webservice;
24
25 import java.io.ByteArrayOutputStream JavaDoc;
26 import java.io.ByteArrayInputStream JavaDoc;
27 import java.io.OutputStreamWriter JavaDoc;
28 import java.io.OutputStream JavaDoc;
29 import java.io.InputStream JavaDoc;
30 import java.io.File JavaDoc;
31
32 import java.rmi.Remote JavaDoc;
33
34 import com.sun.enterprise.deployment.WebServiceEndpoint;
35 import com.sun.enterprise.deployment.WebService;
36 import com.sun.enterprise.deployment.archivist.Archivist;
37 import com.sun.enterprise.Switch;
38 import com.sun.ejb.Container;
39 import com.sun.ejb.containers.StatelessSessionContainer;
40 import com.sun.ejb.Invocation;
41 import com.sun.enterprise.InvocationManager;
42
43 import com.sun.enterprise.security.jauth.ServerAuthConfig;
44 import com.sun.enterprise.webservice.WSSCallbackHandler;
45
46 import javax.xml.rpc.handler.MessageContext JavaDoc;
47 import com.sun.xml.rpc.spi.runtime.Handler;
48 import com.sun.xml.rpc.spi.runtime.Tie;
49
50 import java.util.logging.Logger JavaDoc;
51 import java.util.logging.Level JavaDoc;
52 import com.sun.logging.LogDomains;
53
54
55 /**
56  * Runtime dispatch information about one ejb web service
57  * endpoint. This class must support concurrent access,
58  * since a single instance will be used for all web
59  * service invocations through the same ejb endpoint.
60  *
61  * @author Kenneth Saks
62  */

63 public class Ejb2RuntimeEndpointInfo extends EjbRuntimeEndpointInfo {
64
65
66     private Class JavaDoc tieClass;
67
68     // Lazily instantiated and cached due to overhead
69
// of initialization.
70
private Tie tieInstance;
71
72
73     public Ejb2RuntimeEndpointInfo(WebServiceEndpoint webServiceEndpoint,
74                                   StatelessSessionContainer ejbContainer,
75                                   Object JavaDoc servant, Class JavaDoc tie) {
76                                   
77         super(webServiceEndpoint, ejbContainer, servant);
78         tieClass = tie;
79     }
80
81     public Handler getHandlerImplementor(MessageContext JavaDoc msgContext)
82         throws Exception JavaDoc {
83
84         // We need to split the preInvoke tasks into stages since handlers
85
// need access to java:comp/env and method authorization must take
86
// place before handlers are run. Note that the application
87
// classloader was set much earlier when the invocation first arrived
88
// so we don't need to set it here.
89
Invocation inv = new Invocation();
90
91         // Do the portions of preInvoke that don't need a Method object.
92
inv.isWebService = true;
93         inv.container = container;
94         inv.messageContext = msgContext;
95         inv.transactionAttribute = Container.TX_NOT_INITIALIZED;
96
97         // If the endpoint has at least one handler, method
98
// authorization will be performed by a container-provided handler
99
// before any application handler handleRequest methods are called.
100
// Otherwise, the ejb container will do the authorization.
101
inv.securityPermissions = Container.SEC_NOT_INITIALIZED;
102
103         invManager.preInvoke(inv);
104
105         // In all cases, the WebServiceInvocationHandler will do the
106
// remaining preInvoke tasks : getContext, preInvokeTx, etc.
107

108         // Create the tie and servant to pass to jaxrpc runtime system.
109
// The servant is a dynamic proxy implementing the Service Endpoint
110
// Interface. Use endpoint address uri to disambiguate case where
111
// an ejb implements more than one endpoint.
112
//
113
// NOTE : Tie instance MUST be created after InvManager.preInvoke,
114
// since tie initialization could result in handler instance creation.
115
// This also means ejb container handler cannot expect to access
116
// Invocation object from Handler.init()
117

118         // Both tie and ejb container servant support concurrent access,
119
// so lazily create tie and use the same instance for all invocations
120
// through this ejb endpoint. Tie instance is a heavyweight resource
121
// so it would be prohibitive to create one per thread.
122
synchronized(this) {
123             if( tieInstance == null ) {
124                 tieInstance = (Tie) tieClass.newInstance();
125                 tieInstance.setTarget((Remote JavaDoc) webServiceEndpointServant);
126             }
127         }
128
129         inv.setWebServiceTie(tieInstance);
130
131         return (Handler) tieInstance;
132     }
133
134     /**
135      * Called after attempt to handle message. This is coded defensively
136      * so we attempt to clean up no matter how much progress we made in
137      * getImplementor. One important thing is to complete the invocation
138      * manager preInvoke().
139      */

140     public void releaseImplementor(Handler handler) {
141         try {
142             Invocation inv = (Invocation) invManager.getCurrentInvocation();
143
144             // Only use container version of postInvoke if we got past
145
// assigning an ejb instance to this invocation. This is
146
// because the web service invocation does an InvocationManager
147
// preInvoke *before* assigning an ejb instance. So, we need
148
// to ensure that InvocationManager.postInvoke is always
149
// called. It was cleaner to keep this logic in this class
150
// and WebServiceInvocationHandler rather than change the
151
// behavior of BaseContainer.preInvoke and
152
// BaseContainer.postInvoke.
153

154             if( inv != null ) {
155                 if( inv.ejb != null ) {
156                     container.postInvoke(inv);
157                 } else {
158                     invManager.postInvoke(inv);
159                 }
160             }
161         } catch(Throwable JavaDoc t) {
162             logger.log(Level.FINE, "", t);
163         }
164
165     }
166
167     public EjbMessageDispatcher getMessageDispatcher() {
168         // message dispatcher is stateless, no need to synchronize, worse
169
// case, we'll create too many.
170
if (messageDispatcher==null) {
171             messageDispatcher = new EjbWebServiceDispatcher();
172         }
173         return messageDispatcher;
174     }
175 }
176
Popular Tags