View Javadoc
1   /**
2    * This Source Code Form is subject to the terms of the Mozilla Public
3    * License, v. 2.0. If a copy of the MPL was not distributed with this
4    * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5    *
6    * If it is not possible or desirable to put the notice in a particular
7    * file, then You may include the notice in a location (such as a LICENSE
8    * file in a relevant directory) where a recipient would be likely to look
9    * for such a notice.
10  
11   * 
12   */
13   
14  /*  ---------------------------------------------------------------------------
15   *  U.S. Government, Department of the Army
16   *  Army Materiel Command
17   *  Research Development Engineering Command
18   *  Communications Electronics Research Development and Engineering Center
19   *  ---------------------------------------------------------------------------
20   */
21  
22  package org.miloss.fgsms.agents;
23  
24  import org.miloss.fgsms.common.Constants;
25  import java.util.Collections;
26  import java.util.Set;
27  import javax.xml.namespace.QName;
28  import javax.xml.soap.SOAPException;
29  import javax.xml.ws.handler.MessageContext;
30  import javax.xml.ws.handler.soap.SOAPHandler;
31  import javax.xml.ws.handler.soap.SOAPMessageContext;
32  import org.apache.log4j.Level;
33  import org.miloss.fgsms.common.Logger;;
34  
35  /**
36   *
37   * @author AO
38   */
39  public class JbossWSMonitor implements SOAPHandler<SOAPMessageContext> {
40  
41      private Logger log;
42  
43      public JbossWSMonitor() {
44          log = Logger.getLogger(org.miloss.fgsms.common.Constants.LoggerName);
45      }
46  
47      public boolean handleMessage(SOAPMessageContext messageContext) {
48          long start = System.currentTimeMillis();
49          // MessageProcessor obj = MessageProcessor.getSingletonObject();
50          Boolean isRequest = !(Boolean) messageContext.get(SOAPMessageContext.MESSAGE_OUTBOUND_PROPERTY);
51  
52          if (isRequest) {
53  
54              try {
55                  ProcessInboundMessage(messageContext);
56              } catch (SOAPException ex) {
57                  log.log(Level.WARN, "fgsms Error processing inbound message", ex);
58                  return true;
59              }
60          } else {
61              try {
62  
63                  ProcessOutboundMessage(messageContext, false);
64              } catch (SOAPException ex) {
65                  log.log(Level.WARN, "fgsms Error processing outbound message", ex);
66              }
67  
68          }
69  
70  
71          // log.log(Level.WARNING, "fgsms Timer, handleMessage " + (System.currentTimeMillis() - start));
72          return true;
73      }
74  
75      public Set<QName> getHeaders() {
76          return Collections.EMPTY_SET;
77      }
78  
79      public boolean handleFault(SOAPMessageContext messageContext) {
80          //long start = System.currentTimeMillis();
81          Boolean isRequest = !(Boolean) messageContext.get(SOAPMessageContext.MESSAGE_OUTBOUND_PROPERTY);
82  
83          if (isRequest) {
84  
85              try {
86                  ProcessInboundMessage(messageContext);
87              } catch (SOAPException ex) {
88                  log.log(Level.WARN, "fgsms Error processing inbound message", ex);
89                  return true;
90              }
91          } else {
92              try {
93  
94                  ProcessOutboundMessage(messageContext, true);
95              } catch (SOAPException ex) {
96                  log.log(Level.WARN, "fgsms Error processing outbound message", ex);
97              }
98  
99          }
100         //log.log(Level.WARNING, "fgsms Timer, handleFault " + (System.currentTimeMillis() - start));
101         return true;
102     }
103 
104     public void close(MessageContext context) {
105     }
106 
107     private void ProcessInboundMessage(SOAPMessageContext messageContext) throws SOAPException {
108 
109         JbossWSCommonMessageHandler.ProcessRequest(messageContext, false, this.getClass().getCanonicalName());
110     }
111 
112     private void ProcessOutboundMessage(SOAPMessageContext messageContext, boolean fault) throws SOAPException {
113 
114         JbossWSCommonMessageHandler.ProcessResponse(messageContext, fault, false, this.getClass().getCanonicalName());
115     }
116 }