KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.lang.reflect.Method JavaDoc;
31 import javax.xml.namespace.QName JavaDoc;
32
33 import javax.xml.rpc.JAXRPCException JavaDoc;
34 import javax.xml.rpc.handler.Handler JavaDoc;
35 import javax.xml.rpc.handler.GenericHandler JavaDoc;
36 import javax.xml.rpc.handler.HandlerInfo JavaDoc;
37 import javax.xml.rpc.handler.MessageContext JavaDoc;
38
39 import com.sun.enterprise.Switch;
40 import com.sun.enterprise.ComponentInvocation;
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  * servlet web service endpoint.
50  *
51  * @author Kenneth Saks
52  */

53 public class ServletPreHandler extends GenericHandler JavaDoc {
54
55     private static Logger JavaDoc logger =
56         LogDomains.getLogger(LogDomains.WEB_LOGGER);
57     private WsUtil wsUtil = new WsUtil();
58
59     public ServletPreHandler() {}
60
61     public QName JavaDoc[] getHeaders() {
62         return new QName JavaDoc[0];
63     }
64
65     public boolean handleRequest(MessageContext JavaDoc context) {
66         ComponentInvocation inv = null;
67
68         try {
69             Switch theSwitch = Switch.getSwitch();
70             InvocationManager invManager = theSwitch.getInvocationManager();
71             inv = invManager.getCurrentInvocation();
72
73             Method JavaDoc method = wsUtil.getInvMethod(inv.getWebServiceTie(),
74                                                 context);
75
76             // Result can be null for some error cases. This will be
77
// handled by jaxrpc runtime so we don't treat it as an exception.
78
if( method != null ) {
79                 inv.setWebServiceMethod(method);
80             } else {
81                 inv.setWebServiceMethod(null);
82             }
83
84         } catch(Exception JavaDoc e) {
85             logger.log(Level.WARNING, "preWebHandlerError", e);
86             wsUtil.throwSOAPFaultException(e.getMessage(), context);
87         }
88
89         return true;
90     }
91
92 }
93
Popular Tags