KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.Iterator JavaDoc;
26
27 import java.rmi.RemoteException JavaDoc;
28 import java.rmi.UnmarshalException JavaDoc;
29
30 import javax.xml.namespace.QName JavaDoc;
31
32 import javax.xml.rpc.JAXRPCException JavaDoc;
33 import javax.xml.rpc.handler.Handler JavaDoc;
34 import javax.xml.rpc.handler.GenericHandler JavaDoc;
35 import javax.xml.rpc.handler.HandlerInfo JavaDoc;
36 import javax.xml.rpc.handler.MessageContext JavaDoc;
37
38 import com.sun.enterprise.Switch;
39 import com.sun.ejb.Container;
40 import com.sun.ejb.Invocation;
41 import com.sun.enterprise.InvocationManager;
42
43 import java.util.logging.Logger JavaDoc;
44 import java.util.logging.Level JavaDoc;
45 import com.sun.logging.LogDomains;
46
47 /**
48  * This handler is inserted first in the handler chain for an
49  * ejb web service endpoint. It performs security authorization
50  * before any of the application handlers are invoked, as required
51  * by JSR 109.
52  *
53  * @author Kenneth Saks
54  */

55 public class EjbContainerPreHandler extends GenericHandler JavaDoc {
56
57     private static Logger JavaDoc logger = LogDomains.getLogger(LogDomains.EJB_LOGGER);
58     private WsUtil wsUtil = new WsUtil();
59
60     public EjbContainerPreHandler() {}
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         Container container = null;
69
70         try {
71
72             Switch theSwitch = Switch.getSwitch();
73             InvocationManager invManager = theSwitch.getInvocationManager();
74             inv = (Invocation) invManager.getCurrentInvocation();
75             container = (Container) inv.container;
76
77             inv.method = wsUtil.getInvMethod(inv.getWebServiceTie(), context);
78
79             // Result can be null for some error cases. This will be
80
// handled by jaxrpc runtime so we don't treat it as an exception.
81
if( inv.method != null ) {
82                 inv.setWebServiceMethod(inv.method);
83                
84                 if ( !container.authorize(inv) ) {
85                     inv.exception = new Exception JavaDoc
86                         ("Client not authorized for invocation of "
87                          + inv.method);
88                 }
89             } else {
90                 inv.setWebServiceMethod(null);
91             }
92         } catch(Exception JavaDoc e) {
93             String JavaDoc errorMsg = "Error unmarshalling method " +
94                 ( (container != null ) ?
95                   "for ejb " + container.getEjbDescriptor().getName() :
96                   "" );
97             inv.exception = new UnmarshalException JavaDoc(errorMsg);
98             inv.exception.initCause(e);
99         }
100         
101         if( inv.exception != null ) {
102             logger.log(Level.WARNING, "preEjbHandlerError", inv.exception);
103             wsUtil.throwSOAPFaultException(inv.exception.getMessage(),
104                                            context);
105         }
106
107         return true;
108     }
109
110 }
111
Popular Tags