KickJava   Java API By Example, From Geeks To Geeks.

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


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.lang.reflect.Method JavaDoc;
26
27 import java.rmi.UnmarshalException JavaDoc;
28
29 import javax.xml.namespace.QName JavaDoc;
30 import javax.xml.rpc.JAXRPCException JavaDoc;
31 import javax.xml.rpc.handler.Handler JavaDoc;
32 import javax.xml.rpc.handler.GenericHandler JavaDoc;
33 import javax.xml.rpc.handler.HandlerInfo JavaDoc;
34 import javax.xml.rpc.handler.MessageContext JavaDoc;
35
36
37 import com.sun.enterprise.Switch;
38 import com.sun.ejb.Container;
39 import com.sun.ejb.Invocation;
40 import com.sun.enterprise.InvocationManager;
41
42 import java.util.logging.Logger JavaDoc;
43 import java.util.logging.Level JavaDoc;
44 import com.sun.logging.LogDomains;
45
46 /**
47  * This handler is inserted last in the handler chain for an
48  * ejb web service endpoint. It ensures that the application handlers
49  * did not change anything in the soap message that would change the
50  * dispatch method.
51  *
52  * @author Kenneth Saks
53  */

54 public class EjbContainerPostHandler extends GenericHandler JavaDoc {
55
56     private static Logger JavaDoc logger =
57         LogDomains.getLogger(LogDomains.EJB_LOGGER);
58     private WsUtil wsUtil = new WsUtil();
59
60     public EjbContainerPostHandler() {}
61
62     public QName JavaDoc[] getHeaders() {
63         return new QName JavaDoc[0];
64     }
65
66     public boolean handleRequest(MessageContext JavaDoc context) {
67         Invocation inv = null;
68         boolean continueProcessing = true;
69
70         try {
71             Switch theSwitch = Switch.getSwitch();
72             InvocationManager invManager = theSwitch.getInvocationManager();
73             inv = (Invocation) invManager.getCurrentInvocation();
74             Container container = (Container) inv.container;
75
76             Method JavaDoc webServiceMethodInPreHandler = inv.getWebServiceMethod();
77
78             if( webServiceMethodInPreHandler != null ) {
79                 // Now that application handlers have run, do another method
80
// lookup and compare the results with the original one. This
81
// ensures that the application handlers have not changed
82
// the message context in any way that would impact which
83
// method is invoked.
84
Method JavaDoc postHandlerMethod =
85                     wsUtil.getInvMethod(inv.getWebServiceTie(), context);
86                 if( !webServiceMethodInPreHandler.equals(postHandlerMethod) ) {
87                     inv.exception = new UnmarshalException JavaDoc
88                         ("Original method " + webServiceMethodInPreHandler +
89                          " does not match post-handler method " +
90                          postHandlerMethod);
91                 }
92             }
93         } catch(Exception JavaDoc e) {
94             String JavaDoc errorMsg = "Exception while getting method for " +
95                 ((inv != null ) ?
96                  ((Container) inv.container).getEjbDescriptor().getName() : "");
97             inv.exception = new UnmarshalException JavaDoc(errorMsg);
98             inv.exception.initCause(e);
99         }
100         
101         if( inv.exception != null ) {
102             logger.log(Level.WARNING, "postEjbHandlerError", inv.exception);
103             wsUtil.throwSOAPFaultException(inv.exception.getMessage(),
104                                            context);
105         }
106
107         return true;
108     }
109
110 }
111
Popular Tags