KickJava   Java API By Example, From Geeks To Geeks.

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


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.jbi.serviceengine.bridge;
24 import com.sun.ejb.Container;
25 import com.sun.enterprise.jbi.serviceengine.ServiceEngineException;
26 import com.sun.enterprise.jbi.serviceengine.util.soap.MessageExchangeHelper;
27 import com.sun.enterprise.jbi.serviceengine.comm.MessageProcessor;
28 import com.sun.logging.LogDomains;
29 import com.sun.enterprise.security.jauth.ServerAuthConfig;
30 import com.sun.enterprise.security.jauth.ServerAuthContext;
31 import com.sun.enterprise.security.wss.WebServiceSecurity;
32 import com.sun.enterprise.webservice.Ejb2RuntimeEndpointInfo;
33 import com.sun.enterprise.webservice.EjbRuntimeEndpointInfo;
34 import com.sun.xml.rpc.spi.JaxRpcObjectFactory;
35 import com.sun.xml.rpc.spi.runtime.SOAPMessageContext;
36 import com.sun.xml.rpc.spi.runtime.Handler;
37 import com.sun.xml.rpc.spi.runtime.SOAPConstants;
38 import com.sun.xml.rpc.spi.runtime.StreamingHandler;
39
40
41 import java.util.logging.Level JavaDoc;
42 import java.util.logging.Logger JavaDoc;
43 import javax.jbi.messaging.MessageExchange;
44 import javax.xml.namespace.QName JavaDoc;
45 import javax.xml.soap.SOAPMessage JavaDoc;
46
47 /**
48  * Process a MEP for a new incoming message from NMR.
49  * Processing always happen in a new thread.
50  *
51  * @authod Binod PG.
52  */

53 public class JAXRPCMessageProcessor extends MessageProcessor {
54     protected static Logger JavaDoc logger =
55             LogDomains.getLogger(LogDomains.EJB_LOGGER);
56     JaxRpcObjectFactory rpcFactory = JaxRpcObjectFactory.newInstance();
57     // @@@ This should be added to jaxrpc spi, probably within
58
// SOAPConstants.
59
private static final QName JavaDoc FAULT_CODE_CLIENT =
60             new QName JavaDoc(SOAPConstants.URI_ENVELOPE, "Client");
61     
62     /**
63      * MessageAcceptor uses this method to start processing the MEP.
64      */

65     public void process() {
66         execute();
67     }
68     
69     /**
70      * Actual code that starts processing the MEP.
71      */

72     public void doWork() {
73         try {
74             // Add code here to process the received message.
75
MessageExchange me = getMessageExchange();
76             String JavaDoc endpoint = me.getEndpoint().getEndpointName();
77             QName JavaDoc service = me.getEndpoint().getServiceName();
78             SOAPMessage JavaDoc response = null;
79             MessageExchangeHelper meHelper = new MessageExchangeHelper();
80             meHelper.setMessageExchange(me);
81             try {
82                 debug(Level.FINEST,"serviceengine.process_incoming_request",
83                         new Object JavaDoc[]{service.getLocalPart(), endpoint});
84                         
85                  
86                  EjbRuntimeEndpointInfo runtimeEndpointInfo =
87                     (EjbRuntimeEndpointInfo)RuntimeEndpointInfoRegistryImpl.getInstance().
88                     getRuntimeEndpointInfo(service, endpoint);
89                  
90                  response = processEJBRequest(
91                          meHelper.denormalizeMessage(true), runtimeEndpointInfo);
92             } catch(Throwable JavaDoc e) {
93                 logger.log(Level.SEVERE, "serviceengine.error_incoming_request", e);
94                 ServiceEngineException seException = new ServiceEngineException(e);
95                 meHelper.handleException(seException);
96             }
97             meHelper.handleResponse(response, false);
98         } catch(Exception JavaDoc e) {
99             logger.log(Level.SEVERE, "JavaEEServiceEngine : Error processing request" + e , e);
100         }
101     }
102     
103     private void debug(Level JavaDoc logLevel, String JavaDoc msgID, Object JavaDoc[] params) {
104         logger.log(logLevel, msgID, params);
105     }
106     
107     private SOAPMessage JavaDoc processEJBRequest(SOAPMessage JavaDoc message,
108             EjbRuntimeEndpointInfo endpointInfo) {
109         ServerAuthContext sAC = null;
110         SOAPMessageContext msgContext = null;
111         boolean wssSucceded = true;
112         
113         if (message != null) {
114             Container container = endpointInfo.getContainer();
115             msgContext = rpcFactory.createSOAPMessageContext();
116             // Set context class loader to application class loader
117
container.externalPreInvoke();
118             msgContext.setMessage(message);
119             
120             Handler implementor = null;
121             try {
122                 // Do ejb container pre-invocation and pre-handler
123
// logic
124
implementor = ((Ejb2RuntimeEndpointInfo) endpointInfo).getHandlerImplementor(msgContext);
125                 ServerAuthConfig authConfig = endpointInfo.getServerAuthConfig();
126                 if (authConfig != null) {
127                     sAC = authConfig.getAuthContext
128                             ((StreamingHandler)implementor,message);
129                     if (sAC != null) {
130                         wssSucceded =
131                                 WebServiceSecurity.validateRequest(msgContext,sAC);
132                     }
133                 }
134                 
135                 // Pass control back to jaxrpc runtime to invoke
136
// any handlers and call the webservice method itself,
137
// which will be flow back into the ejb container.
138
if (wssSucceded) {
139                     implementor.handle(msgContext);
140                 }
141                
142                 SOAPMessage JavaDoc reply = msgContext.getMessage();
143                 
144                 if (sAC != null && wssSucceded) {
145                     WebServiceSecurity.secureResponse(msgContext,sAC);
146                 }
147                 
148                 if (reply.saveRequired()) {
149                     reply.saveChanges();
150                 }
151                 return reply;
152                 
153             } catch(Exception JavaDoc e) {
154                 logger.fine(e.getMessage());
155             } finally {
156                 
157                 // Always call release, even if an error happened
158
// during getImplementor(), since some of the
159
// preInvoke steps might have occurred. It's ok
160
// if implementor is null.
161
endpointInfo.releaseImplementor();
162                 // Restore context class loader
163
container.externalPostInvoke();
164             }
165         } else {
166             String JavaDoc errorMsg = "null message POSTed to ejb endpoint " +
167                     endpointInfo.getEndpoint().getEndpointName() +
168                     " at " + endpointInfo.getEndpointAddressUri();
169             logger.fine(errorMsg);
170             msgContext.writeSimpleErrorResponse
171                     (FAULT_CODE_CLIENT, errorMsg);
172         }
173         
174         return null;
175     }
176 }
177
178
Popular Tags