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   *  U.S. Government, Department of the Army
15   *  Army Materiel Command
16   *  Research Development Engineering Command
17   *  Communications Electronics Research Development and Engineering Center
18   *  ---------------------------------------------------------------------------
19   */
20  package org.miloss.fgsms.agents;
21  
22  import java.util.Collections;
23  import java.util.Set;
24  
25  import javax.xml.namespace.QName;
26  import javax.xml.soap.SOAPException;
27  import javax.xml.ws.handler.MessageContext;
28  import javax.xml.ws.handler.soap.SOAPHandler;
29  import javax.xml.ws.handler.soap.SOAPMessageContext;
30  import org.miloss.fgsms.common.Constants;
31  import org.apache.log4j.Level;
32  import org.miloss.fgsms.common.Logger;;
33  
34  /**
35   * FGSMS agent for services
36   *
37   * @author AO
38   */
39  public class JAXWSGenericAgent implements SOAPHandler<SOAPMessageContext> {
40  
41      private Logger log;
42  
43      public JAXWSGenericAgent() {
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              }
59          } else {
60              try {
61  
62                  ProcessOutboundMessage(messageContext, false);
63              } catch (SOAPException ex) {
64                  log.log(Level.WARN, "fgsms Error processing outbound message", ex);
65              }
66  
67          }
68          return true;
69      }
70  
71      public Set<QName> getHeaders() {
72          return Collections.EMPTY_SET;
73      }
74  
75      public boolean handleFault(SOAPMessageContext messageContext) {
76          try {
77              ProcessOutboundMessage(messageContext, true);
78          } catch (SOAPException ex) {
79              log.log(Level.WARN, "fgsms error processing fault message", ex);
80          }
81          return true;
82      }
83  
84      public void close(MessageContext context) {
85      }
86  
87      private void ProcessInboundMessage(SOAPMessageContext messageContext) throws SOAPException {
88  
89          JAXWSGenericCommonMessageHandler.processRequest(messageContext, false, this.getClass().getCanonicalName());
90  
91      }
92  
93      private void ProcessOutboundMessage(SOAPMessageContext messageContext, boolean fault) throws SOAPException {
94          JAXWSGenericCommonMessageHandler.processResponse(messageContext, fault, false, this.getClass().getCanonicalName());
95  
96      }
97  }