KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > webservice > monitoring > JAXWSEndpointImpl


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
24 package com.sun.enterprise.webservice.monitoring;
25
26 import javax.servlet.http.HttpServletRequest JavaDoc;
27
28 import com.sun.xml.ws.spi.runtime.MessageContext;
29 import com.sun.xml.ws.spi.runtime.SOAPMessageContext;
30 import com.sun.xml.ws.spi.runtime.SystemHandlerDelegate;
31
32 /**
33  * Implementation of the JAXWS endpoint interface and JAXWs System Handler Delegate
34  *
35  * @author Jerome Dochez
36  */

37 public class JAXWSEndpointImpl extends EndpointImpl implements SystemHandlerDelegate {
38     
39     SystemHandlerDelegate parent = null;
40     
41     /** Creates a new instance of EndpointImpl */
42     JAXWSEndpointImpl(String JavaDoc endpointSelector, EndpointType type) {
43         super(endpointSelector, type);
44     }
45     
46     public boolean processRequest(MessageContext ctxt) throws Exception JavaDoc {
47
48     boolean status = true;
49
50         if(!(ctxt instanceof SOAPMessageContext)) {
51             return status;
52         }
53         SOAPMessageContext messageContext = (SOAPMessageContext)ctxt;
54         // let's get our thread local context
55
WebServiceEngineImpl wsEngine = WebServiceEngineImpl.getInstance();
56         try {
57             if (parent!=null) {
58                 status = parent.processRequest(ctxt);
59             }
60             
61             if (!listeners.isEmpty() || wsEngine.hasGlobalMessageListener()) {
62
63                 String JavaDoc messageID = (String JavaDoc) messageContext.get(EndpointImpl.MESSAGE_ID);
64                 
65                 // someone is listening ?
66
if (messageID!=null) {
67                     HttpServletRequest JavaDoc httpReq = (HttpServletRequest JavaDoc) messageContext.get(MessageContext.SERVLET_REQUEST);
68                     HttpRequestInfoImpl info = new HttpRequestInfoImpl(httpReq);
69                     wsEngine.processRequest(messageID, messageContext, info);
70                 }
71                 
72                 // any local listeners ?
73
if (!listeners.isEmpty()) {
74                     // create the message trace and save it to our message context
75
MessageTraceImpl request = new MessageTraceImpl();
76                     request.setEndpoint(this);
77                     request.setMessageContext(messageContext);
78                     HttpServletRequest JavaDoc httpReq = (HttpServletRequest JavaDoc) messageContext.get(MessageContext.SERVLET_REQUEST);
79                     request.setTransportInfo(new HttpRequestInfoImpl(httpReq));
80                     messageContext.put(EndpointImpl.REQUEST_TRACE, request);
81                 }
82             }
83         } catch(Exception JavaDoc e) {
84             wsEngine.sLogger.warning("Exception while tracing request : " + e.getMessage());
85         throw e;
86         }
87         return status;
88     }
89
90     public void processResponse(MessageContext ctxt) throws Exception JavaDoc {
91         
92         if(!(ctxt instanceof SOAPMessageContext)) {
93             return;
94         }
95         SOAPMessageContext messageContext = (SOAPMessageContext)ctxt;
96         // let's get our thread local context
97
WebServiceEngineImpl wsEngine = WebServiceEngineImpl.getInstance();
98         try {
99             
100             if (wsEngine.hasGlobalMessageListener() || !listeners.isEmpty()) {
101                 
102                 String JavaDoc messageID = (String JavaDoc) messageContext.get(EndpointImpl.MESSAGE_ID);
103                 // do we have a global listener ?
104
if (messageID!=null) {
105                     wsEngine.processResponse(messageID, messageContext);
106                 }
107                 
108                 // local listeners
109
if (!listeners.isEmpty()) {
110                     MessageTraceImpl response = new MessageTraceImpl();
111                     response.setEndpoint(this);
112                     response.setMessageContext(messageContext);
113                     for (MessageListener listener : listeners) {
114                         listener.invocationProcessed((MessageTrace) messageContext.get(REQUEST_TRACE), response);
115                     }
116                 }
117             }
118
119         // do security after tracing
120
if (parent!=null) {
121                 parent.processResponse(ctxt);
122             }
123
124         } catch(Exception JavaDoc e) {
125             wsEngine.sLogger.warning("Exception while tracing response : " + e.getMessage());
126         throw e;
127         }
128     }
129
130     public void preInvokeEndpointHook(MessageContext messageContext) {
131     if (parent!=null) {
132         parent.preInvokeEndpointHook(messageContext);
133     }
134     }
135     
136     public void setParent(SystemHandlerDelegate parent) {
137         this.parent = parent;
138     }
139 }
140
Popular Tags