KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > handlers > SOAPMonitorHandler


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.axis.handlers;
18
19 import org.apache.axis.AxisFault;
20 import org.apache.axis.Message;
21 import org.apache.axis.MessageContext;
22 import org.apache.axis.SOAPPart;
23 import org.apache.axis.monitor.SOAPMonitorConstants;
24 import org.apache.axis.monitor.SOAPMonitorService;
25
26 /**
27  * This handler is used to route SOAP messages to the
28  * SOAP monitor service.
29  *
30  * @author Brian Price (pricebe@us.ibm.com)
31  */

32
33 public class SOAPMonitorHandler extends BasicHandler {
34
35   private static long next_message_id = 1;
36
37   /**
38    * Constructor
39    */

40   public SOAPMonitorHandler() {
41     super();
42   }
43
44   /**
45    * Process and SOAP message
46    */

47   public void invoke(MessageContext messageContext) throws AxisFault {
48     String JavaDoc target = messageContext.getTargetService();
49     // Check for null target
50
if (target == null) {
51         target = "";
52     }
53     // Get id, type and content
54
Long JavaDoc id;
55     Integer JavaDoc type;
56     Message message;
57     if (!messageContext.getPastPivot()) {
58       id = assignMessageId(messageContext);
59       type = new Integer JavaDoc(SOAPMonitorConstants.SOAP_MONITOR_REQUEST);
60       message = messageContext.getRequestMessage();
61     } else {
62       id = getMessageId(messageContext);
63       type = new Integer JavaDoc(SOAPMonitorConstants.SOAP_MONITOR_RESPONSE);
64       message = messageContext.getResponseMessage();
65     }
66     // Get the SOAP portion of the message
67
String JavaDoc soap = null;
68     if (message != null) {
69       soap = ((SOAPPart)message.getSOAPPart()).getAsString();
70     }
71     // If we have an id and a SOAP portion, then send the
72
// message to the SOAP monitor service
73
if ((id != null) && (soap != null)) {
74       SOAPMonitorService.publishMessage(id,type,target,soap);
75     }
76   }
77
78   /**
79    * Assign a new message id
80    */

81   private Long JavaDoc assignMessageId(MessageContext messageContext) {
82     Long JavaDoc id = null;
83     synchronized(SOAPMonitorConstants.SOAP_MONITOR_ID) {
84       id = new Long JavaDoc(next_message_id);
85       next_message_id++;
86     }
87     messageContext.setProperty(SOAPMonitorConstants.SOAP_MONITOR_ID, id);
88     return id;
89   }
90
91   /**
92    * Get the already assigned message id
93    */

94   private Long JavaDoc getMessageId(MessageContext messageContext) {
95     Long JavaDoc id = null;
96     id = (Long JavaDoc) messageContext.getProperty(SOAPMonitorConstants.SOAP_MONITOR_ID);
97     return id;
98   }
99 }
100
Popular Tags