KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > wsmgmt > filter > impl > AggregateStatsFilter


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.filter.impl;
24
25 import com.sun.enterprise.admin.wsmgmt.config.spi.Constants;
26 import com.sun.enterprise.admin.wsmgmt.filter.spi.Filter;
27 import com.sun.enterprise.admin.wsmgmt.filter.spi.FilterContext;
28 import com.sun.enterprise.admin.wsmgmt.stats.spi.StatsProviderManager;
29 import com.sun.enterprise.admin.wsmgmt.stats.impl.WebServiceEndpointStatsProviderImpl;
30
31 import javax.xml.soap.SOAPMessage JavaDoc;
32 import javax.xml.soap.SOAPBody JavaDoc;
33 import javax.xml.soap.SOAPFault JavaDoc;
34 import com.sun.enterprise.admin.wsmgmt.SOAPMessageContext;
35
36
37 /**
38  * Filter that can implement or collect web services management information
39  */

40 public class AggregateStatsFilter implements Filter {
41
42     /**
43      * Public Constructor.
44      *
45      * @param epName End point name for which stats are collected
46      */

47     public AggregateStatsFilter() {
48     }
49
50     /**
51      * Returns the unique name for this filter
52      */

53     public String JavaDoc getName() {
54         return Constants.AGGREGATE_STATS_FILTER;
55     }
56
57     /**
58      * Invoke the filter.
59      */

60     public void process(String JavaDoc stage, String JavaDoc endpoint, FilterContext context) {
61
62         WebServiceEndpointStatsProviderImpl impl = (
63             WebServiceEndpointStatsProviderImpl) StatsProviderManager.
64             getInstance().getEndpointStatsProvider(endpoint);
65
66         if ( stage.equals(Filter.PRE_PROCESS_REQUEST) ) {
67             impl.setRequestTimeStamp( System.currentTimeMillis(),null, null, 0);
68         } else {
69             if ( stage.equals(Filter.POST_PROCESS_RESPONSE) ) {
70
71                SOAPMessageContext smc = context.getMessageContext();
72                SOAPMessage JavaDoc sm = null;
73                SOAPFault JavaDoc fault = null;
74                try {
75                    if (smc != null)
76                        sm = smc.getMessage();
77                     if (sm != null) {
78                         SOAPBody JavaDoc sb = sm.getSOAPBody();
79                         if (sb != null) {
80                             fault = sb.getFault();
81                         }
82                     }
83                 } catch ( Exception JavaDoc e) {
84                     // if body can not be obtained, consider this as failure
85
// (fault) case, however fault information is not available
86
impl.setFault(0,
87                     System.currentTimeMillis(), context.getExecutionTime(), null,null, null);
88                     return;
89                 }
90  
91                 if ( fault == null) {
92                     impl.setSuccess(0, System.currentTimeMillis(),
93                     context.getExecutionTime());
94                 } else {
95                     impl.setFault(0,
96                     System.currentTimeMillis(),context.getExecutionTime(),
97                     fault.getFaultCode(), fault.getFaultString(),
98                     fault.getFaultString() );
99                 }
100             } else {
101                 throw new RuntimeException JavaDoc(" Should not be called for this stage of execution of web service end point " + endpoint);
102             }
103         }
104
105     }
106
107 }
108
Popular Tags