/**
   * Invokes the bussiness logic invocation on the service implementation class
   *
   * @param msgContext the incoming message context
   * @param newmsgContext the response message context
   * @throws AxisFault on invalid method (wrong signature) or behaviour (return null)
   */
  public void invokeBusinessLogic(MessageContext msgContext, MessageContext newmsgContext)
      throws AxisFault {
    try {

      // get the implementation class for the Web Service
      Object obj = getTheImplementationObject(msgContext);

      // find the WebService method
      Class implClass = obj.getClass();

      AxisOperation opDesc = msgContext.getAxisOperation();
      Method method = findOperation(opDesc, implClass);

      if (method == null) {
        throw new AxisFault(
            Messages.getMessage("methodDoesNotExistInOut", opDesc.getName().toString()));
      }

      OMElement result =
          (OMElement)
              method.invoke(
                  obj, new Object[] {msgContext.getEnvelope().getBody().getFirstElement()});
      SOAPFactory fac = getSOAPFactory(msgContext);
      SOAPEnvelope envelope = fac.getDefaultEnvelope();

      if (result != null) {
        envelope.getBody().addChild(result);
      }

      newmsgContext.setEnvelope(envelope);
    } catch (Exception e) {
      throw AxisFault.makeFault(e);
    }
  }
  /**
   * Invokes the bussiness logic invocation on the service implementation class
   *
   * @param msgContext the incoming message context
   * @param newmsgContext the response message context
   * @throws AxisFault on invalid method (wrong signature) or behaviour (return null)
   */
  public void invokeBusinessLogic(MessageContext msgContext) throws AxisFault {

    Object obj = null;
    try {

      String in_action = msgContext.getWSAAction();

      if (logger.isDebugEnabled()) {
        logger.debug("In MEP: in_action = " + in_action);
      }

      validate_action(msgContext);

      // get the implementation class for the Web Service

      obj = getTheImplementationObject(msgContext);

      // make return message context available to service
      if (obj instanceof AppendixV) {
        AppendixV xo = (AppendixV) obj;
      }

    } catch (Exception e) {

      logger.error(
          "Error in XDSRawXMLIn:\n"
              + ExceptionUtil.exception_details(e)
              + "\ngetSoapAction = "
              + msgContext.getSoapAction());

      throw AxisFault.makeFault(e);
    }

    // find the WebService method

    Class implClass = obj.getClass();

    AxisOperation opDesc = msgContext.getAxisOperation();

    Method method = findOperation(opDesc, implClass);

    Method methodDisplay;
    try {
      methodDisplay =
          implClass.getMethod("setMessageContextIn", new Class[] {MessageContext.class});
    } catch (SecurityException e) {
      logger.error(
          "Error in XDSRawXMLIn:\n"
              + "class is "
              + implClass.getName()
              + " method is setMessageContextIn"
              + ExceptionUtil.exception_details(e)
              + "\ngetSoapAction = "
              + msgContext.getSoapAction());

      throw AxisFault.makeFault(e);
    } catch (NoSuchMethodException e) {
      logger.error(
          "Error in XDSRawXMLIn:\n"
              + "class is "
              + implClass.getName()
              + " method is setMessageContextIn"
              + ExceptionUtil.exception_details(e)
              + "\ngetSoapAction = "
              + msgContext.getSoapAction());

      throw AxisFault.makeFault(e);
    }

    try {
      methodDisplay.invoke(obj, new Object[] {msgContext});
    } catch (Exception e) {
      logger.error(
          "Error in XDSRawXMLIn:\n"
              + "class is "
              + implClass.getName()
              + " method is setMessageContextIn"
              + ExceptionUtil.exception_details(e)
              + "\ngetSoapAction = "
              + msgContext.getSoapAction());

      throw AxisFault.makeFault(e);
    }

    if (method == null) {
      throw new AxisFault(Messages.getMessage("methodDoesNotExistIn", opDesc.getName().toString()));
    }

    try {
      method.invoke(obj, new Object[] {msgContext.getEnvelope().getBody().getFirstElement()});

    } catch (Exception e) {
      logger.error(
          "Error in XDSRawXMLIn:\n"
              + "class is "
              + implClass.getName()
              + " method is setMessageContextIn"
              + ExceptionUtil.exception_details(e)
              + "\ngetSoapAction = "
              + msgContext.getSoapAction());

      throw AxisFault.makeFault(e);
    }
  }
Ejemplo n.º 3
0
  /**
   * Loads a throttle metadata for a particular throttle type
   *
   * @param messageContext - The messageContext
   * @param throttleType - The type of throttle
   * @return IPBaseThrottleConfiguration - The IPBaseThrottleConfiguration - load from
   *     AxisConfiguration
   * @throws ThrottleException Throws if the throttle type is unsupported
   */
  public Throttle loadThrottle(MessageContext messageContext, int throttleType)
      throws ThrottleException {

    Throttle throttle = null;
    ConfigurationContext configContext = messageContext.getConfigurationContext();
    // the Parameter which hold throttle ipbase object
    // to get throttles map from the configuration context

    Map throttles = (Map) configContext.getPropertyNonReplicable(ThrottleConstants.THROTTLES_MAP);
    if (throttles == null) {
      if (debugOn) {
        log.debug("Couldn't find throttles object map .. thottlling will not be occurred ");
      }
      return null;
    }
    switch (throttleType) {
      case ThrottleConstants.GLOBAL_THROTTLE:
        {
          throttle = (Throttle) throttles.get(ThrottleConstants.GLOBAL_THROTTLE_KEY);
          break;
        }
      case ThrottleConstants.OPERATION_BASED_THROTTLE:
        {
          AxisOperation axisOperation = messageContext.getAxisOperation();
          if (axisOperation != null) {
            QName opName = axisOperation.getName();
            if (opName != null) {
              AxisService service = (AxisService) axisOperation.getParent();
              if (service != null) {
                String currentServiceName = service.getName();
                if (currentServiceName != null) {
                  throttle = (Throttle) throttles.get(currentServiceName + opName.getLocalPart());
                }
              }
            }
          } else {
            if (debugOn) {
              log.debug("Couldn't find axis operation ");
            }
            return null;
          }
          break;
        }
      case ThrottleConstants.SERVICE_BASED_THROTTLE:
        {
          AxisService axisService = messageContext.getAxisService();
          if (axisService != null) {
            throttle = (Throttle) throttles.get(axisService.getName());
          } else {
            if (debugOn) {
              log.debug("Couldn't find axis service ");
            }
            return null;
          }
          break;
        }
      default:
        {
          throw new ThrottleException("Unsupported Throttle type");
        }
    }
    return throttle;
  }
  /**
   * Handle the response or error (during a failed send) message received for an outgoing request
   *
   * @param messageID Request message ID
   * @param response the Axis2 MessageContext that has been received and has to be handled
   * @param synapseOutMsgCtx the corresponding (outgoing) Synapse MessageContext for the above Axis2
   *     MC, that holds Synapse specific information such as the error handler stack and local
   *     properties etc.
   * @throws AxisFault if the message cannot be processed
   */
  private void handleMessage(
      String messageID,
      MessageContext response,
      org.apache.synapse.MessageContext synapseOutMsgCtx,
      AsyncCallback callback)
      throws AxisFault {
    // apply the tenant information to the out message context
    TenantInfoConfigurator configurator =
        synapseOutMsgCtx.getEnvironment().getTenantInfoConfigurator();
    if (configurator != null) {
      configurator.applyTenantInfo(synapseOutMsgCtx);
    }
    Object o = response.getProperty(SynapseConstants.SENDING_FAULT);
    if (o != null && Boolean.TRUE.equals(o)) {

      StatisticsReporter.reportFaultForAll(
          synapseOutMsgCtx, ErrorLogFactory.createErrorLog(response));
      // there is a sending fault. propagate the fault to fault handlers.

      Stack faultStack = synapseOutMsgCtx.getFaultStack();
      if (faultStack != null && !faultStack.isEmpty()) {

        // if we have access to the full synapseOutMsgCtx.getEnvelope(), then let
        // it flow with the error details. Else, replace its envelope with the
        // fault envelope
        try {
          synapseOutMsgCtx.getEnvelope().build();
        } catch (OMException x) {
          synapseOutMsgCtx.setEnvelope(response.getEnvelope());
        }

        Exception e = (Exception) response.getProperty(SynapseConstants.ERROR_EXCEPTION);

        synapseOutMsgCtx.setProperty(SynapseConstants.SENDING_FAULT, Boolean.TRUE);
        synapseOutMsgCtx.setProperty(
            SynapseConstants.ERROR_CODE, response.getProperty(SynapseConstants.ERROR_CODE));
        synapseOutMsgCtx.setProperty(
            SynapseConstants.ERROR_MESSAGE, response.getProperty(SynapseConstants.ERROR_MESSAGE));
        synapseOutMsgCtx.setProperty(
            SynapseConstants.ERROR_DETAIL, response.getProperty(SynapseConstants.ERROR_DETAIL));
        synapseOutMsgCtx.setProperty(SynapseConstants.ERROR_EXCEPTION, e);

        if (log.isDebugEnabled()) {
          log.debug(
              "[Failed Request Message ID : "
                  + messageID
                  + "]"
                  + " [New to be Retried Request Message ID : "
                  + synapseOutMsgCtx.getMessageID()
                  + "]");
        }

        int errorCode = (Integer) response.getProperty(SynapseConstants.ERROR_CODE);

        // If a timeout has occured and the timeout action of the callback is to discard the message
        if (errorCode == SynapseConstants.NHTTP_CONNECTION_TIMEOUT
            && callback.getTimeOutAction() == SynapseConstants.DISCARD) {
          // Do not execute any fault sequences. Discard message
          if (log.isWarnEnabled()) {
            log.warn(
                "Synapse timed out for the request with Message ID : "
                    + messageID
                    + ". Ignoring fault handlers since the timeout action is DISCARD");
          }
          faultStack.removeAllElements();
        } else {
          ((FaultHandler) faultStack.pop()).handleFault(synapseOutMsgCtx, null);
        }
      }

    } else {

      // there can always be only one instance of an Endpoint in the faultStack of a message
      // if the send was successful, so remove it before we proceed any further
      Stack faultStack = synapseOutMsgCtx.getFaultStack();

      Endpoint successfulEndpoint = null;
      if (faultStack != null && !faultStack.isEmpty() && faultStack.peek() instanceof Endpoint) {
        successfulEndpoint = (Endpoint) faultStack.pop();
      }

      if (log.isDebugEnabled()) {
        log.debug("Synapse received an asynchronous response message");
        log.debug(
            "Received To: " + (response.getTo() != null ? response.getTo().getAddress() : "null"));
        log.debug(
            "SOAPAction: "
                + (response.getSoapAction() != null ? response.getSoapAction() : "null"));
        log.debug(
            "WSA-Action: " + (response.getWSAAction() != null ? response.getWSAAction() : "null"));
        String[] cids = response.getAttachmentMap().getAllContentIDs();
        if (cids != null && cids.length > 0) {
          for (String cid : cids) {
            log.debug("Attachment : " + cid);
          }
        }
        log.debug("Body : \n" + response.getEnvelope());
      }
      MessageContext axisOutMsgCtx =
          ((Axis2MessageContext) synapseOutMsgCtx).getAxis2MessageContext();

      // Processes 'Accept-Encoding'
      ResponseAcceptEncodingProcessor.process(response, axisOutMsgCtx);

      response.setServiceContext(null);
      response.setOperationContext(axisOutMsgCtx.getOperationContext());
      response.setAxisMessage(
          axisOutMsgCtx.getAxisOperation().getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE));

      // set properties on response
      response.setServerSide(true);
      response.setProperty(SynapseConstants.ISRESPONSE_PROPERTY, Boolean.TRUE);
      response.setProperty(
          MessageContext.TRANSPORT_OUT, axisOutMsgCtx.getProperty(MessageContext.TRANSPORT_OUT));
      response.setProperty(
          org.apache.axis2.Constants.OUT_TRANSPORT_INFO,
          axisOutMsgCtx.getProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO));
      response.setTransportIn(axisOutMsgCtx.getTransportIn());
      response.setTransportOut(axisOutMsgCtx.getTransportOut());

      // If request is REST assume that the response is REST too
      response.setDoingREST(axisOutMsgCtx.isDoingREST());
      if (axisOutMsgCtx.isDoingMTOM()) {
        response.setDoingMTOM(true);
        response.setProperty(
            org.apache.axis2.Constants.Configuration.ENABLE_MTOM,
            org.apache.axis2.Constants.VALUE_TRUE);
      }
      if (axisOutMsgCtx.isDoingSwA()) {
        response.setDoingSwA(true);
        response.setProperty(
            org.apache.axis2.Constants.Configuration.ENABLE_SWA,
            org.apache.axis2.Constants.VALUE_TRUE);
      }

      // when axis2 receives a soap message without addressing headers it users
      // DISABLE_ADDRESSING_FOR_OUT_MESSAGES property to keep it and hence avoid addressing
      // headers on the response. this causes a problem for synapse if the original message
      // it receivs (from client) has addressing and the synaspse service invocation has not
      // engage addressing. in this case when synapse receives the response from the server
      // addessing In handler dissable addressing since that response does not have addressing
      // headers. synapse sends the response to its orignal client using the same message
      // context. Then this response does not have addressing headers since it already
      // disable. to avoid this we need to set the DISABLE_ADDRESSING_FOR_OUT_MESSAGES
      // property state to original state.
      if (axisOutMsgCtx.getProperty(AddressingConstants.DISABLE_ADDRESSING_FOR_OUT_MESSAGES)
          != null) {

        response.setProperty(
            AddressingConstants.DISABLE_ADDRESSING_FOR_OUT_MESSAGES,
            axisOutMsgCtx.getProperty(AddressingConstants.DISABLE_ADDRESSING_FOR_OUT_MESSAGES));
      } else {
        response.removeProperty(AddressingConstants.DISABLE_ADDRESSING_FOR_OUT_MESSAGES);
      }

      Object messageType =
          axisOutMsgCtx.getProperty(org.apache.axis2.Constants.Configuration.MESSAGE_TYPE);
      if (!HTTPConstants.MEDIA_TYPE_X_WWW_FORM.equals(messageType)) {
        // copy the message type property that's used by the out message to the
        // response message
        response.setProperty(org.apache.axis2.Constants.Configuration.MESSAGE_TYPE, messageType);
      }

      // compare original received message (axisOutMsgCtx) soap version with the response
      // if they are different change to original version
      if (axisOutMsgCtx.isSOAP11() != response.isSOAP11()) {
        if (axisOutMsgCtx.isSOAP11()) {
          SOAPUtils.convertSOAP12toSOAP11(response);
        } else {
          SOAPUtils.convertSOAP11toSOAP12(response);
        }
      }

      if (axisOutMsgCtx.getMessageID() != null) {
        response.setRelationships(new RelatesTo[] {new RelatesTo(axisOutMsgCtx.getMessageID())});
      }

      response.setReplyTo(axisOutMsgCtx.getReplyTo());
      response.setFaultTo(axisOutMsgCtx.getFaultTo());

      if (axisOutMsgCtx.isPropertyTrue(NhttpConstants.IGNORE_SC_ACCEPTED)) {
        response.setProperty(NhttpConstants.FORCE_SC_ACCEPTED, Constants.VALUE_TRUE);
      }

      // create the synapse message context for the response
      Axis2MessageContext synapseInMessageContext =
          new Axis2MessageContext(
              response, synapseOutMsgCtx.getConfiguration(), synapseOutMsgCtx.getEnvironment());
      synapseInMessageContext.setResponse(true);

      Object obj = synapseOutMsgCtx.getProperty(SynapseConstants.FORCE_ERROR_PROPERTY);
      String errorOnSOAPFault = (String) obj;

      if (Constants.VALUE_TRUE.equals(errorOnSOAPFault) && successfulEndpoint != null) {

        if (log.isDebugEnabled()) {
          log.debug("FORCE_ERROR_ON_SOAP_FAULT is true, checking for SOAPFault");
        }

        try {
          RelayUtils.buildMessage(
              ((Axis2MessageContext) synapseInMessageContext).getAxis2MessageContext(), true);
        } catch (Exception e) {
          // handleException("Error while building message", e, synapseInMessageContext);
        }

        if ((synapseInMessageContext.getEnvelope() != null)
            && synapseInMessageContext.getEnvelope().hasFault()) {

          if (log.isDebugEnabled()) {
            log.debug(
                "SOAPFault found in response message, forcing endpoint "
                    + successfulEndpoint.getName()
                    + " to fail");
          }

          // setup new pipe configuration..if failure happens (this will be setup as the source
          // writer and during the TargetContext
          // clean up operation the writer will be reset and pull to the buffer
          MessageContext axis2OUTMC =
              ((Axis2MessageContext) synapseOutMsgCtx).getAxis2MessageContext();
          NHttpServerConnection conn =
              (NHttpServerConnection) axis2OUTMC.getProperty("pass-through.Source-Connection");
          if (conn != null) {
            SourceConfiguration sourceConfiguration =
                (SourceConfiguration) axis2OUTMC.getProperty("PASS_THROUGH_SOURCE_CONFIGURATION");
            Pipe pipe =
                new Pipe(
                    conn,
                    sourceConfiguration.getBufferFactory().getBuffer(),
                    "source",
                    sourceConfiguration);
            axis2OUTMC.setProperty(PassThroughConstants.PASS_THROUGH_PIPE, pipe);
          }

          StatisticsReporter.reportFaultForAll(
              synapseOutMsgCtx, ErrorLogFactory.createErrorLog(response));
          synapseOutMsgCtx.setProperty(SynapseConstants.SENDING_FAULT, Boolean.TRUE);
          synapseOutMsgCtx.setProperty(
              SynapseConstants.ERROR_CODE, SynapseConstants.ENDPOINT_CUSTOM_ERROR);
          ((FaultHandler) successfulEndpoint).handleFault(synapseOutMsgCtx, null);
          return;
        } else {
          successfulEndpoint.onSuccess();
        }

      } else if (successfulEndpoint != null) {
        successfulEndpoint.onSuccess();
      }

      synapseInMessageContext.setTo(
          new EndpointReference(AddressingConstants.Final.WSA_ANONYMOUS_URL));
      synapseInMessageContext.setTracingState(synapseOutMsgCtx.getTracingState());

      // set the properties of the original MC to the new MC

      for (Object key : synapseOutMsgCtx.getPropertyKeySet()) {
        synapseInMessageContext.setProperty(
            (String) key, synapseOutMsgCtx.getProperty((String) key));
      }

      // Copy SequenceCallStack from original MC to the new MC
      if (synapseOutMsgCtx.isContinuationEnabled()) {

        // Set the message direction
        if (!synapseOutMsgCtx.isResponse()) {
          synapseInMessageContext.setResponse(false);
        }

        Stack<ContinuationState> seqContinuationStates =
            synapseOutMsgCtx.getContinuationStateStack();
        for (int i = 0; i < seqContinuationStates.size(); i++) {
          synapseInMessageContext.pushContinuationState(seqContinuationStates.get(i));
        }
      }

      // If this response is related to session affinity endpoints -Server initiated session
      Dispatcher dispatcher =
          (Dispatcher)
              synapseOutMsgCtx.getProperty(SynapseConstants.PROP_SAL_ENDPOINT_CURRENT_DISPATCHER);
      if (dispatcher != null && dispatcher.isServerInitiatedSession()) {
        dispatcher.updateSession(synapseInMessageContext);
      }

      StatisticsReporter.reportForAllOnResponseReceived(synapseInMessageContext);

      // send the response message through the synapse mediation flow
      try {
        synapseOutMsgCtx.getEnvironment().injectMessage(synapseInMessageContext);
      } catch (SynapseException syne) {
        Stack stack = synapseInMessageContext.getFaultStack();
        if (stack != null && !stack.isEmpty()) {
          ((FaultHandler) stack.pop()).handleFault(synapseInMessageContext, syne);
        } else {
          log.error(
              "Synapse encountered an exception, "
                  + "No error handlers found - [Message Dropped]\n"
                  + syne.getMessage());
        }
      }
    }
  }
Ejemplo n.º 5
0
  public InvocationResponse invoke(MessageContext messageContext) throws AxisFault {

    int tenantID = PublisherUtil.getTenantId(messageContext);

    Map<Integer, EventingConfigData> tenantSpecificEventConfig =
        TenantEventConfigData.getTenantSpecificEventingConfigData();
    EventingConfigData eventingConfigData = tenantSpecificEventConfig.get(tenantID);

    if (eventingConfigData != null && eventingConfigData.isMessageTracingEnable()) {

      if (log.isDebugEnabled()) {
        log.debug("Message tracing enabled.");
      }

      AxisService service = messageContext.getAxisService();

      // Temporary fix for track API manager calls
      if (service == null
          || (SystemFilter.isFilteredOutService(service.getAxisServiceGroup())
              && !AgentUtil.allowedServices(service.getName()))
          || service.isClientSide()) {
        return InvocationResponse.CONTINUE;
      } else {

        String activityUUID = HandlerUtils.getUniqueId();
        Object transportHeaders = messageContext.getProperty(MessageContext.TRANSPORT_HEADERS);

        if (transportHeaders != null) {
          String aid = (String) ((Map) transportHeaders).get(MessageTracerConstants.ACTIVITY_ID);
          if (aid != null) {
            if (aid.equals(MessageTracerConstants.EMPTY_STRING)) {
              ((Map) messageContext.getProperty(MessageContext.TRANSPORT_HEADERS))
                  .put(MessageTracerConstants.ACTIVITY_ID, activityUUID);
              if (log.isDebugEnabled()) {
                log.debug("Propagated AID was empty, IN generating new AID");
              }
            } else {
              activityUUID = aid;
              if (log.isDebugEnabled()) {
                log.debug("IN using propagated AID");
              }
            }
          } else {
            ((Map) messageContext.getProperty(MessageContext.TRANSPORT_HEADERS))
                .put(MessageTracerConstants.ACTIVITY_ID, activityUUID);
            if (log.isDebugEnabled()) {
              log.debug("Propagated AID was null, IN generating new AID");
            }
          }
        } else {
          Map<String, String> headers = new TreeMap<String, String>();
          headers.put(MessageTracerConstants.ACTIVITY_ID, activityUUID);
          messageContext.setProperty(MessageContext.TRANSPORT_HEADERS, headers);
          if (log.isDebugEnabled()) {
            log.debug("Transport headers absent, IN generating new AID");
          }
        }

        messageContext.setProperty(MessageTracerConstants.TENANT_ID, tenantID);

        TracingInfo tracingInfo = new TracingInfo();
        tracingInfo.setActivityId(activityUUID);
        tracingInfo.setServer(AgentUtil.getServerName());
        tracingInfo.setMessageDirection(BAMDataPublisherConstants.IN_DIRECTION);
        tracingInfo.setHost(PublisherUtil.getHostAddress());
        tracingInfo.setServiceName(messageContext.getAxisService().getName());
        tracingInfo.setOperationName(messageContext.getAxisOperation().getName().getLocalPart());
        MessageContext inMessageContext =
            messageContext.getOperationContext().getMessageContext(WSDL2Constants.MESSAGE_LABEL_IN);
        if (inMessageContext != null) {
          Object requestProperty =
              inMessageContext.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);
          AgentUtil.extractInfoFromHttpHeaders(tracingInfo, requestProperty);
        }

        try {
          if (eventingConfigData.isDumpBodyEnable()) {
            try {
              Class cls =
                  Class.forName(
                      MessageTracerConstants
                          .ORG_APACHE_SYNAPSE_TRANSPORT_PASSTHRU_UTIL_RELAY_UTILS_CLASS_NAME);
              Class[] paramClasses = new Class[] {MessageContext.class, Boolean.TYPE};
              Method method =
                  cls.getMethod(MessageTracerConstants.BUILD_MESSAGE_METHOD_NAME, paramClasses);
              method.invoke(null, messageContext, false);
            } catch (ClassNotFoundException ignore) {
              // ignore
            } catch (Exception e) {
              throw new AxisFault("Error in building input message: " + e.getMessage(), e);
            }
            SOAPEnvelope soapEnvelope = messageContext.getEnvelope();
            SOAPBody body = soapEnvelope.getBody();
            if (body != null) {
              tracingInfo.setPayload(body.toString());
            }

            SOAPHeader header = soapEnvelope.getHeader();
            if (header != null) {
              tracingInfo.setHeader(header.toString());
            }
          }

          tracingInfo.setTimestamp(System.currentTimeMillis());

          if (MessageContext.IN_FLOW == messageContext.getFLOW()) {
            tracingInfo.setStatus(MessageTracerConstants.STATUS_SUCCESS);
          } else if (MessageContext.IN_FAULT_FLOW == messageContext.getFLOW()) {
            tracingInfo.setStatus(MessageTracerConstants.STATUS_FAULT);
          }

          publisher.publish(tenantID, tracingInfo);
        } catch (OMException e) {
          log.error("Unable to get SOAP details " + e.getMessage(), e);
        }
      }
    }
    return InvocationResponse.CONTINUE;
  }
  @Override
  public Handler.InvocationResponse invoke(MessageContext messageContext) throws AxisFault {

    SystemStatisticsUtil systemStatisticsUtil;
    SystemStatistics systemStatistics;

    try {
      int tenantID = PublisherUtil.getTenantId(messageContext);
      Map<Integer, EventConfigNStreamDef> tenantSpecificEventConfig =
          TenantEventConfigData.getTenantSpecificEventingConfigData();
      EventConfigNStreamDef eventingConfigData = tenantSpecificEventConfig.get(tenantID);

      // Check service stats enable -- if true -- go
      if (eventingConfigData != null && eventingConfigData.isServiceStatsEnable()) {

        systemStatisticsUtil = StatisticsServiceComponent.getSystemStatisticsUtil();
        systemStatistics = systemStatisticsUtil.getSystemStatistics(messageContext);
        AxisOperation axisOperation = messageContext.getAxisOperation();

        AxisService axisService = messageContext.getAxisService();
        if (axisService == null
            || SystemFilter.isFilteredOutService(axisService.getAxisServiceGroup())
            || axisService.isClientSide()) {
          return Handler.InvocationResponse.CONTINUE;
        }

        MessageContext inMessageContext = MessageContext.getCurrentMessageContext();

        // If already set in the activity handlers get it or create new publish data
        /*
                        PublishData publishData = (PublishData) messageContext.getProperty(
                                BAMDataPublisherConstants.PUBLISH_DATA);

                        EventData eventData;
                        if (publishData != null) {
                            eventData = publishData.getEventData();
                        } else {
                            publishData = new PublishData();
                            eventData = new EventData();
                            Date date = new Date();
                            Timestamp timestamp = new Timestamp(date.getTime());
                            eventData.setTimestamp(timestamp);
                            if (axisOperation != null) {
                                eventData.setOperationName(axisOperation.getName().getLocalPart());
                            } else {
                                eventData.setOperationName(null);
                            }

                            if (axisService != null) {
                                eventData.setServiceName(messageContext.getAxisService().getName());
                            } else {
                                eventData.setServiceName(null);
                            }

                            //This is a hack for setting message id when sending request to a non-existing operation.
                            if (eventingConfigData.isMsgDumpingEnable() && axisService != null &&
                                axisOperation == null) {
                                eventData.setOutMessageId(new ActivityOutHandler().getUniqueId());
                            }

                        }
        */

        PublishData publishData = new PublishData();
        EventData eventData = new EventData();
        /*                Date date = new Date();
        Timestamp timestamp = new Timestamp(date.getTime());
        eventData.setTimestamp(timestamp);*/
        if (axisOperation != null) {
          eventData.setOperationName(axisOperation.getName().getLocalPart());
        } else {
          eventData.setOperationName(null);
        }

        if (axisService != null) {
          eventData.setServiceName(messageContext.getAxisService().getName());
        } else {
          eventData.setServiceName(null);
        }

        // This is a hack for setting message id when sending request to a non-existing operation.
        /*                if (eventingConfigData.isMsgDumpingEnable() && axisService != null &&
            axisOperation == null) {
            eventData.setOutMessageId(new ActivityOutHandler().getUniqueId());
        }*/

        // Skip resetting same info if already set by activity in/out handlers
        /*                if (!eventingConfigData.isMsgDumpingEnable()) {

            Timestamp timestamp = null;
            if (inMessageContext != null) {
                timestamp = new Timestamp(Long.parseLong(inMessageContext.getProperty(
                        StatisticsConstants.REQUEST_RECEIVED_TIME).toString()));
                Object requestProperty = inMessageContext.getProperty(
                        HTTPConstants.MC_HTTP_SERVLETREQUEST);
                ServiceAgentUtil.extractInfoFromHttpHeaders(eventData, requestProperty);
            } else {
                Date date = new Date();
                timestamp = new Timestamp(date.getTime());
            }

            eventData.setTimestamp(timestamp);

        }*/

        Timestamp timestamp = null;
        if (inMessageContext != null) {
          timestamp =
              new Timestamp(
                  Long.parseLong(
                      inMessageContext
                          .getProperty(StatisticsConstants.REQUEST_RECEIVED_TIME)
                          .toString()));
          Object requestProperty =
              inMessageContext.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);
          ServiceAgentUtil.extractInfoFromHttpHeaders(eventData, requestProperty);
        } else {
          Date date = new Date();
          timestamp = new Timestamp(date.getTime());
        }

        eventData.setTimestamp(timestamp);

        eventData.setSystemStatistics(systemStatistics);

        publishData.setEventData(eventData);

        // Skip if bam server info already set at activity handlers
        if (!eventingConfigData.isMsgDumpingEnable()) {
          BAMServerInfo bamServerInfo = ServiceAgentUtil.addBAMServerInfo(eventingConfigData);
          publishData.setBamServerInfo(bamServerInfo);
        }

        Event event = ServiceAgentUtil.makeEventList(publishData, eventingConfigData);
        EventPublisher publisher = new EventPublisher();
        publisher.publish(event, eventingConfigData);
      }
    } catch (Throwable ignore) {
      log.error(
          "Error at SystemStatisticsOutHandler. "
              + "But continuing message processing for message id: "
              + messageContext.getMessageID(),
          ignore);
    }

    return Handler.InvocationResponse.CONTINUE;
  }