KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > wsmgmt > agent > GlobalMessageListenerImpl


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.admin.wsmgmt.agent;
24
25 import com.sun.enterprise.webservice.monitoring.GlobalMessageListener;
26 import com.sun.enterprise.webservice.monitoring.Endpoint;
27 import com.sun.enterprise.webservice.monitoring.TransportInfo;
28 import com.sun.xml.rpc.spi.runtime.*;
29 import com.sun.enterprise.deployment.WebServiceEndpoint;
30 import com.sun.enterprise.deployment.BundleDescriptor;
31 import com.sun.enterprise.deployment.Application;
32
33 import com.sun.enterprise.admin.wsmgmt.filter.spi.FilterRegistry;
34 import com.sun.enterprise.admin.wsmgmt.filter.spi.FilterRouter;
35 import com.sun.enterprise.admin.wsmgmt.filter.spi.FilterContext;
36 import com.sun.enterprise.admin.wsmgmt.filter.spi.Filter;
37
38 import java.util.HashMap JavaDoc;
39
40 import com.sun.enterprise.admin.wsmgmt.stats.spi.StatsProviderManager;
41 import com.sun.enterprise.admin.wsmgmt.stats.impl.WebServiceEndpointStatsProviderImpl;
42 import com.sun.enterprise.admin.wsmgmt.WebServiceMgrBackEnd;
43 import com.sun.enterprise.admin.monitor.callflow.Agent;
44 import com.sun.enterprise.admin.monitor.callflow.ThreadLocalData;
45 import com.sun.enterprise.Switch;
46
47
48 /**
49  * This singleton class receives all the callbacks for web service endpoints
50  */

51 public class GlobalMessageListenerImpl implements GlobalMessageListener {
52
53     /**
54      * Callback when a web service response has finished being processed by the
55      * container and was sent back to the client
56      *
57      * @param messageID returned by the preProcessRequest call
58      */

59     public void postProcessResponse(String JavaDoc messageID, TransportInfo info) {
60         FilterContext fc = (FilterContext) msgId2fc.get(messageID);
61         long startTime = fc.getExecutionTime();
62         fc.setExecutionTime(System.currentTimeMillis() - startTime);
63         FilterRouter.getInstance().applyFilters(Filter.POST_PROCESS_RESPONSE,
64                 fc);
65         // Web service execution is ended, remove this message id information
66
msgId2fc.remove(messageID);
67     }
68
69     /**
70      * Callback when a web service request entered the web service container and
71      * before any system processing is done.
72      *
73      * @param endpoint is the endpoint the web service request is targeted to
74      */

75     public String JavaDoc preProcessRequest(Endpoint endpoint) {
76
77         String JavaDoc ep = null;
78         WebServiceEndpoint wse = endpoint.getDescriptor();
79         
80         if ( wse != null) {
81             ep = wse.getEndpointName();
82         }
83         //wse.resolveComponentLink();
84

85         BundleDescriptor bundle = wse.getBundleDescriptor();
86         Application app = bundle.getApplication();
87
88         String JavaDoc fqn =
89         WebServiceMgrBackEnd.getManager().getFullyQualifiedName(
90            app.getRegistrationName() ,
91            bundle.getModuleDescriptor().getArchiveUri(),
92            bundle.getModuleDescriptor().isStandalone(), ep);
93
94         if (FilterRegistry.getInstance().isManaged(fqn) == false) {
95             return null;
96         }
97         String JavaDoc mId = null;
98         String JavaDoc cfId = null;
99         boolean isCallFlowEnabled = false;
100
101         // call flow request id
102
Agent agent = Switch.getSwitch().getCallFlowAgent();
103         if (agent != null) {
104             if (agent.isEnabled()) {
105                 ThreadLocalData data = agent.getThreadLocalData();
106                 if (data != null) {
107                     cfId = data.getRequestId();
108                 }
109             }
110         }
111
112         if ( (cfId == null) || ("".equals(cfId)) ) {
113
114             // call flow id is not available; use own id
115
int newNumber = newSequenceNumber();
116             mId = new Integer JavaDoc(newNumber).toString();
117
118         } else {
119             // use id from call flow if it is not null
120
mId = cfId;
121             isCallFlowEnabled = true;
122         }
123         FilterContext fc = new FilterContext(endpoint, isCallFlowEnabled,
124             (TransportInfo)null,
125             (com.sun.enterprise.admin.wsmgmt.SOAPMessageContext)null, mId, fqn);
126
127         FilterRouter.getInstance().applyFilters(Filter.PRE_PROCESS_REQUEST,fc);
128
129         // update the endpoint 2 filter context mapping
130
msgId2fc.put(mId, fc);
131         
132         return mId;
133     }
134
135     /**
136      * Callback when a 1.X web service request is about the be delivered to the Web
137      * Service Implementation Bean.
138      *
139      * @param messageID - returned by preProcessRequest call
140      * @param context - the jaxrpc message trace, transport dependent.
141      */

142     public void processRequest(String JavaDoc messageID, com.sun.xml.rpc.spi.runtime.SOAPMessageContext context,
143         TransportInfo info) {
144         com.sun.enterprise.admin.wsmgmt.SOAPMessageContext smc =
145             new com.sun.enterprise.admin.wsmgmt.SOAPMessageContext_1_0(context);
146
147          FilterContext fc = (FilterContext) msgId2fc.get(messageID);
148         fc.setTransportInfo(info);
149         fc.setMessageContext(smc);
150         FilterRouter.getInstance().applyFilters(Filter.PROCESS_REQUEST,fc);
151     }
152
153     /**
154      * Callback when a 1.X web service response was returned by the Web Service
155      * Implementation Bean
156      *
157      * @param messageID - returned by preProcessRequest call
158      * @param context - the jaxrpc message trace, transport dependent.
159      */

160     public void processResponse(String JavaDoc messageID, com.sun.xml.rpc.spi.runtime.SOAPMessageContext context) {
161         String JavaDoc ep = null;
162         FilterContext fc = (FilterContext) msgId2fc.get(messageID);
163         FilterRouter.getInstance().applyFilters(Filter.PROCESS_RESPONSE,fc);
164     }
165
166     /**
167      * Callback when a 2.X web service request is about the be delivered to the Web
168      * Service Implementation Bean.
169      *
170      * @param messageID - returned by preProcessRequest call
171      * @param context - the jaxrpc message trace, transport dependent.
172      */

173     public void processRequest(String JavaDoc messageID, com.sun.xml.ws.spi.runtime.SOAPMessageContext context,
174         TransportInfo info) {
175         com.sun.enterprise.admin.wsmgmt.SOAPMessageContext smc =
176             new com.sun.enterprise.admin.wsmgmt.SOAPMessageContext_2_0(context);
177
178          FilterContext fc = (FilterContext) msgId2fc.get(messageID);
179         fc.setTransportInfo(info);
180         fc.setMessageContext(smc);
181         FilterRouter.getInstance().applyFilters(Filter.PROCESS_REQUEST,fc);
182     }
183
184     /**
185      * Callback when a 2.X web service response was returned by the Web Service
186      * Implementation Bean
187      *
188      * @param messageID - returned by preProcessRequest call
189      * @param context - the jaxrpc message trace, transport dependent.
190      */

191     public void processResponse(String JavaDoc messageID, com.sun.xml.ws.spi.runtime.SOAPMessageContext context) {
192         String JavaDoc ep = null;
193         FilterContext fc = (FilterContext) msgId2fc.get(messageID);
194         FilterRouter.getInstance().applyFilters(Filter.PROCESS_RESPONSE,fc);
195     }
196     
197     // XXX The following ID generation needs to be integrated with call flow
198
// ID generation
199

200     public static synchronized int newSequenceNumber() {
201         sequenceNumber++;
202         return sequenceNumber;
203     }
204
205     public static synchronized int getSequenceNumber() {
206         return sequenceNumber;
207     }
208
209     public static int sequenceNumber = 0;
210
211     // XXX need to optimized this lookup.
212

213     static HashMap JavaDoc msgId2fc = new HashMap JavaDoc();
214 }
215
Popular Tags