KickJava   Java API By Example, From Geeks To Geeks.

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


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  * InvocationTrace.java
26  *
27  * Created on November 22, 2004, 4:35 PM
28  */

29
30 package com.sun.enterprise.webservice.monitoring;
31
32 import java.util.Date JavaDoc;
33 import java.util.logging.Level JavaDoc;
34 import java.io.ByteArrayOutputStream JavaDoc;
35
36 import java.util.regex.Matcher JavaDoc;
37 import java.util.regex.Pattern JavaDoc;
38
39 /**
40  * An invocation trace contains the timestamp os a particular
41  * message invocation, the stringified SOAP request and
42  * response or the SOAP Faults if the invocation resulted in one.
43  *
44  * @author Jerome Dochez
45  */

46 public class MessageTraceImpl implements MessageTrace {
47         
48     private Endpoint source;
49     private String JavaDoc soapMessage=null;
50     private TransportInfo transportInfo=null;
51     private int hashcode=0;
52     
53     
54     /** Creates a new instance of InvocationTrace */
55     public MessageTraceImpl() {
56         
57     }
58     
59     /**
60      * Return the SOAPMessage as a string including the SOAPHeaders or not
61      * @param include the soap headers.
62      * @return the soap message
63      */

64     public String JavaDoc getMessage(boolean includeHeaders) {
65
66         if (soapMessage!=null) {
67             if (includeHeaders) {
68                 return soapMessage;
69             }
70         
71             StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
72             Pattern JavaDoc p = Pattern.compile("<env:Body>.*</env:Body>");
73             Matcher JavaDoc m = p.matcher(soapMessage);
74             if (m.find()) {
75                 return soapMessage.substring(m.start(),m.end());
76             } else {
77                 return soapMessage;
78             }
79         }
80         return null;
81     }
82     
83     /**
84      * Return the endpoint where this message originated from
85      */

86     public Endpoint getEndpoint() {
87         return source;
88     }
89     
90     public void setMessageContext(com.sun.xml.rpc.spi.runtime.SOAPMessageContext soapMessageCtx) {
91         
92         hashcode = soapMessageCtx.hashCode();
93         
94         ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
95         try {
96             soapMessageCtx.getMessage().writeTo(baos);
97         } catch(Exception JavaDoc e) {
98             WebServiceEngineImpl.sLogger.log(Level.WARNING, "Cannot log SOAP Message " + e.getMessage());
99         }
100
101         soapMessage = baos.toString();
102     }
103     
104     public void setMessageContext(com.sun.xml.ws.spi.runtime.SOAPMessageContext soapMessageCtx) {
105         
106         hashcode = soapMessageCtx.hashCode();
107         
108         ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
109         try {
110             soapMessageCtx.getMessage().writeTo(baos);
111         } catch(Exception JavaDoc e) {
112             WebServiceEngineImpl.sLogger.log(Level.WARNING, "Cannot log SOAP Message " + e.getMessage());
113         }
114
115         soapMessage = baos.toString();
116     }
117     
118     public String JavaDoc getMessageID() {
119         return String.valueOf(hashcode);
120     }
121     
122     public void setEndpoint(Endpoint source) {
123         this.source = source;
124     }
125     
126     public TransportInfo getTransportInfo() {
127         return transportInfo;
128     }
129     
130     public void setTransportInfo(TransportInfo info) {
131         transportInfo = info;
132     }
133 }
134
Popular Tags