KickJava   Java API By Example, From Geeks To Geeks.

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


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 /*
25  * JAXRPCEndpointImpl.java
26  */

27
28 package com.sun.enterprise.webservice.monitoring;
29
30 import com.sun.xml.rpc.spi.runtime.SOAPMessageContext;
31 import com.sun.xml.rpc.spi.runtime.SystemHandlerDelegate;
32
33 /**
34  * Implementation of the JAXRPC endpoint interface and JAXRPC System Handler Delegate
35  *
36  * @author Jerome Dochez
37  */

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