KickJava   Java API By Example, From Geeks To Geeks.

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


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.lang.reflect.Method JavaDoc;
28
29 import java.rmi.RemoteException JavaDoc;
30 import java.rmi.UnmarshalException JavaDoc;
31
32 import javax.xml.namespace.QName JavaDoc;
33
34 import javax.xml.rpc.JAXRPCException JavaDoc;
35 import javax.xml.rpc.handler.Handler JavaDoc;
36 import javax.xml.rpc.handler.GenericHandler JavaDoc;
37 import javax.xml.rpc.handler.HandlerInfo JavaDoc;
38 import javax.xml.rpc.handler.MessageContext JavaDoc;
39
40 import com.sun.enterprise.Switch;
41 import com.sun.enterprise.ComponentInvocation;
42 import com.sun.enterprise.InvocationManager;
43
44 import java.util.logging.Logger JavaDoc;
45 import java.util.logging.Level JavaDoc;
46 import com.sun.logging.LogDomains;
47
48 /**
49  * This handler is inserted last in the handler chain for an
50  * servlet web service endpoint.
51  *
52  * @author Kenneth Saks
53  */

54 public class ServletPostHandler extends GenericHandler JavaDoc {
55
56     private static Logger JavaDoc logger =
57         LogDomains.getLogger(LogDomains.WEB_LOGGER);
58     private WsUtil wsUtil = new WsUtil();
59
60     public ServletPostHandler() {}
61
62     public QName JavaDoc[] getHeaders() {
63         return new QName JavaDoc[0];
64     }
65
66     public boolean handleRequest(MessageContext JavaDoc context) {
67         ComponentInvocation inv = null;
68
69         try {
70             Switch theSwitch = Switch.getSwitch();
71             InvocationManager invManager = theSwitch.getInvocationManager();
72             inv = invManager.getCurrentInvocation();
73
74             Method JavaDoc webServiceMethodInPreHandler = inv.getWebServiceMethod();
75             if( webServiceMethodInPreHandler != null ) {
76                 Method JavaDoc postHandlerMethod =
77                     wsUtil.getInvMethod(inv.getWebServiceTie(), context);
78             
79                 if( !webServiceMethodInPreHandler.equals(postHandlerMethod) ) {
80                     throw new UnmarshalException JavaDoc
81                         ("Original method " + webServiceMethodInPreHandler
82                          + " does not match post-handler method " +
83                          postHandlerMethod);
84                 }
85             }
86         } catch(Exception JavaDoc e) {
87             logger.log(Level.WARNING, "postWebHandlerError", e);
88             wsUtil.throwSOAPFaultException(e.getMessage(), context);
89         }
90
91         return true;
92     }
93
94 }
95
Popular Tags