@Override
  protected void startListeningForService(AxisService service) throws AxisFault {
    E endpoint = createEndpoint(service);
    endpoint.setListener(this);
    endpoint.setService(service);
    endpoint.setContentType(
        ParamUtils.getRequiredParam(service, "transport." + getTransportName() + ".contentType"));
    endpoint.setMetrics(metrics);

    try {
      dispatcher.addEndpoint(endpoint);
    } catch (IOException ex) {
      throw new AxisFault(
          "Unable to listen on endpoint " + endpoint.getEndpointReference(defaultIp), ex);
    }
    if (log.isDebugEnabled()) {
      log.debug(
          "Started listening on endpoint "
              + endpoint.getEndpointReference(defaultIp)
              + " [contentType="
              + endpoint.getContentType()
              + "; service="
              + service.getName()
              + "]");
    }
    endpoints.put(service.getName(), endpoint);
  }
 @Override
 protected void stopListeningForService(AxisService service) {
   try {
     dispatcher.removeEndpoint(endpoints.get(service.getName()));
   } catch (IOException ex) {
     log.error("I/O exception while stopping listener for service " + service.getName(), ex);
   }
   endpoints.remove(service.getName());
 }
  /**
   * Loads a web service from a web service wrapper
   *
   * @param wrapper Web service wrapper
   * @throws Exception
   */
  protected void loadService(IServiceConfig wsDef) throws Exception {

    // first create the service
    String serviceId = wsDef.getId();
    AxisService axisService = AxisUtil.createService(wsDef, getAxisConfiguration());

    // add any additional transports
    addTransports(axisService);

    // add any end points
    addServiceEndPoints(axisService);

    // create the WSDL for the service
    AxisUtil.createServiceWsdl(axisService, wsDef, getAxisConfiguration());

    // add the wrapper to the service list
    services.put(serviceId, wsDef);

    // start the service
    axisConfig.addService(axisService);
    axisConfig.startService(axisService.getName());

    // enable or disable the service as the wrapper dictates
    axisService.setActive(wsDef.isEnabled());
  }
예제 #4
0
  /** {@inheritDoc} */
  public InvocationResponse invoke(MessageContext messageContext) throws AxisFault {
    if (log.isDebugEnabled()) {
      log.debug(
          "Starting Activation Handler invocation. Incoming Message: "
              + messageContext.getEnvelope().toString());
    }

    AxisService service = messageContext.getAxisService();
    int tenantId = getTenantId(messageContext);
    if (service != null && "ActivationService".equals(service.getName())) {
      log.debug("Granted access to the Activation Service");
      if (tenantId > 0) {
        TenantAxisUtils.getTenantAxisConfiguration(
            getTenantDomain(), messageContext.getConfigurationContext());
        log.debug("Loaded Tenant Configuration");
      }
      return InvocationResponse.CONTINUE;
    }
    if (tenantId == MultitenantConstants.SUPER_TENANT_ID) {
      log.debug("Granted access for super tenant");
      return InvocationResponse.CONTINUE;
    }
    if (ActivationManager.activationRecorded(tenantId)) {
      if (ActivationManager.getActivation(tenantId)) {
        TenantAxisUtils.getTenantAxisConfiguration(
            getTenantDomain(), messageContext.getConfigurationContext());
        log.debug("Loaded Tenant Configuration");
        return InvocationResponse.CONTINUE;
      } else {
        if (log.isWarnEnabled()) {
          String serviceName = Util.getServiceName();
          log.warn("Failed attempt to access " + serviceName + " by tenant " + tenantId);
        }
        return InvocationResponse.ABORT;
      }
    }
    String serviceName = Util.getServiceName();
    try {
      if (CloudServicesUtil.isCloudServiceActive(serviceName, tenantId)) {
        log.debug("Successful attempt to access " + serviceName + " by tenant " + tenantId);
        ActivationManager.setActivation(tenantId, true);
        TenantAxisUtils.getTenantAxisConfiguration(
            getTenantDomain(), messageContext.getConfigurationContext());
        log.debug("Loaded Tenant Configuration");
        return InvocationResponse.CONTINUE;
      }
    } catch (Exception e) {
      throw new AxisFault("Failed to determine Activation status.", e);
    }
    log.warn("Failed attempt to access " + serviceName + " by tenant " + tenantId);
    ActivationManager.setActivation(tenantId, false);
    return InvocationResponse.ABORT;
  }
예제 #5
0
  /**
   * Populates service from corresponding OM.
   *
   * @param service_element an OMElement for the <service> tag
   * @return a filled-in AxisService, configured from the passed XML
   * @throws DeploymentException if there is a problem
   */
  public AxisService populateService(OMElement service_element) throws DeploymentException {
    try {
      // Determine whether service should be activated.
      String serviceActivate = service_element.getAttributeValue(new QName(ATTRIBUTE_ACTIVATE));
      if (serviceActivate != null) {
        if ("true".equals(serviceActivate)) {
          service.setActive(true);
        } else if ("false".equals(serviceActivate)) {
          service.setActive(false);
        }
      }

      // Processing service level parameters
      OMAttribute serviceNameatt = service_element.getAttribute(new QName(ATTRIBUTE_NAME));

      // If the service name is explicitly specified in the services.xml
      // then use that as the service name
      if (serviceNameatt != null) {
        if (!"".equals(serviceNameatt.getAttributeValue().trim())) {
          AxisService wsdlService = wsdlServiceMap.get(serviceNameatt.getAttributeValue());
          if (wsdlService != null) {
            wsdlService.setClassLoader(service.getClassLoader());
            wsdlService.setParent(service.getAxisServiceGroup());
            service = wsdlService;
            service.setWsdlFound(true);
            service.setCustomWsdl(true);
          }
          service.setName(serviceNameatt.getAttributeValue());
          // To be on the safe side
          if (service.getDocumentation() == null) {
            service.setDocumentation(serviceNameatt.getAttributeValue());
          }
        }
      }

      Iterator itr = service_element.getChildrenWithName(new QName(TAG_PARAMETER));
      processParameters(itr, service, service.getParent());

      Parameter childFirstClassLoading =
          service.getParameter(Constants.Configuration.ENABLE_CHILD_FIRST_CLASS_LOADING);
      if (childFirstClassLoading != null) {
        ClassLoader cl = service.getClassLoader();
        if (cl instanceof DeploymentClassLoader) {
          DeploymentClassLoader deploymentClassLoader = (DeploymentClassLoader) cl;
          if (JavaUtils.isTrueExplicitly(childFirstClassLoading.getValue())) {
            deploymentClassLoader.setChildFirstClassLoading(true);
          } else if (JavaUtils.isFalseExplicitly(childFirstClassLoading.getValue())) {
            deploymentClassLoader.setChildFirstClassLoading(false);
          }
        }
      }

      // If multiple services in one service group have different values
      // for the PARENT_FIRST
      // parameter then the final value become the value specified by the
      // last service in the group
      // Parameter parameter =
      // service.getParameter(DeploymentClassLoader.PARENT_FIRST);
      // if (parameter !=null && "false".equals(parameter.getValue())) {
      // ClassLoader serviceClassLoader = service.getClassLoader();
      // ((DeploymentClassLoader)serviceClassLoader).setParentFirst(false);
      // }
      // process service description
      OMElement descriptionElement =
          service_element.getFirstChildWithName(new QName(TAG_DESCRIPTION));
      if (descriptionElement != null) {
        OMElement descriptionValue = descriptionElement.getFirstElement();
        if (descriptionValue != null) {
          service.setDocumentation(descriptionValue);
        } else {
          service.setDocumentation(descriptionElement.getText());
        }
      } else {
        serviceNameatt = service_element.getAttribute(new QName(ATTRIBUTE_NAME));

        if (serviceNameatt != null) {
          if (!"".equals(serviceNameatt.getAttributeValue().trim())
              && service.getDocumentation() == null) {
            service.setDocumentation(serviceNameatt.getAttributeValue());
          }
        }
      }

      if (service.getParameter("ServiceClass") == null) {
        log.debug("The Service " + service.getName() + " does not specify a Service Class");
      }

      // Process WS-Addressing flag attribute
      OMAttribute addressingRequiredatt =
          service_element.getAttribute(new QName(ATTRIBUTE_WSADDRESSING));
      if (addressingRequiredatt != null) {
        String addressingRequiredString = addressingRequiredatt.getAttributeValue();
        AddressingHelper.setAddressingRequirementParemeterValue(service, addressingRequiredString);
      }

      // Setting service target namespace if any
      OMAttribute targetNameSpace = service_element.getAttribute(new QName(TARGET_NAME_SPACE));

      if (targetNameSpace != null) {
        String nameSpeceVale = targetNameSpace.getAttributeValue();
        if (nameSpeceVale != null && !"".equals(nameSpeceVale)) {
          service.setTargetNamespace(nameSpeceVale);
        }
      } else {
        if (service.getTargetNamespace() == null || "".equals(service.getTargetNamespace())) {
          service.setTargetNamespace(Java2WSDLConstants.DEFAULT_TARGET_NAMESPACE);
        }
      }

      // Processing service lifecycle attribute
      OMAttribute serviceLifeCycleClass = service_element.getAttribute(new QName(TAG_CLASS_NAME));
      if (serviceLifeCycleClass != null) {
        String className = serviceLifeCycleClass.getAttributeValue();
        loadServiceLifeCycleClass(className);
      }
      // Setting schema namespece if any
      OMElement schemaElement = service_element.getFirstChildWithName(new QName(SCHEMA));
      if (schemaElement != null) {
        OMAttribute schemaNameSpace = schemaElement.getAttribute(new QName(SCHEMA_NAME_SPACE));
        if (schemaNameSpace != null) {
          String nameSpeceVale = schemaNameSpace.getAttributeValue();
          if (nameSpeceVale != null && !"".equals(nameSpeceVale)) {
            service.setSchemaTargetNamespace(nameSpeceVale);
          }
        }
        OMAttribute elementFormDefault =
            schemaElement.getAttribute(new QName(SCHEMA_ELEMENT_QUALIFIED));
        if (elementFormDefault != null) {
          String value = elementFormDefault.getAttributeValue();
          if ("true".equals(value)) {
            service.setElementFormDefault(true);
          } else if ("false".equals(value)) {
            service.setElementFormDefault(false);
          }
        }

        // package to namespace mapping. This will be an element that
        // maps pkg names to a namespace
        // when this is doing AxisService.getSchemaTargetNamespace will
        // be overridden
        // This will be <mapping/> with @namespace and @package
        Iterator mappingIterator = schemaElement.getChildrenWithName(new QName(MAPPING));
        if (mappingIterator != null) {
          Map<String, String> pkg2nsMap = new Hashtable<String, String>();
          while (mappingIterator.hasNext()) {
            OMElement mappingElement = (OMElement) mappingIterator.next();
            OMAttribute namespaceAttribute =
                mappingElement.getAttribute(new QName(ATTRIBUTE_NAMESPACE));
            OMAttribute packageAttribute =
                mappingElement.getAttribute(new QName(ATTRIBUTE_PACKAGE));
            if (namespaceAttribute != null && packageAttribute != null) {
              String namespaceAttributeValue = namespaceAttribute.getAttributeValue();
              String packageAttributeValue = packageAttribute.getAttributeValue();
              if (namespaceAttributeValue != null && packageAttributeValue != null) {
                pkg2nsMap.put(packageAttributeValue.trim(), namespaceAttributeValue.trim());
              } else {
                log.warn(
                    "Either value of @namespce or @packagename not available. Thus, generated will be selected.");
              }
            } else {
              log.warn(
                  "Either @namespce or @packagename not available. Thus, generated will be selected.");
            }
          }
          service.setP2nMap(pkg2nsMap);
        }
      }

      // processing Default Message receivers
      OMElement messageReceiver =
          service_element.getFirstChildWithName(new QName(TAG_MESSAGE_RECEIVERS));
      if (messageReceiver != null) {
        HashMap<String, MessageReceiver> mrs =
            processMessageReceivers(service.getClassLoader(), messageReceiver);
        for (Map.Entry<String, MessageReceiver> entry : mrs.entrySet()) {
          service.addMessageReceiver(entry.getKey(), entry.getValue());
        }
      }

      // Removing exclude operations
      OMElement excludeOperations =
          service_element.getFirstChildWithName(new QName(TAG_EXCLUDE_OPERATIONS));
      ArrayList<String> excludeops = null;
      if (excludeOperations != null) {
        excludeops = processExcludeOperations(excludeOperations);
      }
      if (excludeops == null) {
        excludeops = new ArrayList<String>();
      }
      Utils.addExcludeMethods(excludeops);

      // <schema targetNamespace="http://x.y.z"/>
      // setting the PolicyInclude
      // processing <wsp:Policy> .. </..> elements
      Iterator policyElements =
          service_element.getChildrenWithName(new QName(POLICY_NS_URI, TAG_POLICY));

      if (policyElements != null && policyElements.hasNext()) {
        processPolicyElements(policyElements, service.getPolicySubject());
      }

      // processing <wsp:PolicyReference> .. </..> elements
      Iterator policyRefElements =
          service_element.getChildrenWithName(new QName(POLICY_NS_URI, TAG_POLICY_REF));

      if (policyRefElements != null && policyRefElements.hasNext()) {
        processPolicyRefElements(policyRefElements, service.getPolicySubject());
      }

      // processing service scope
      String sessionScope = service_element.getAttributeValue(new QName(ATTRIBUTE_SCOPE));
      if (sessionScope != null) {
        service.setScope(sessionScope);
      }

      // processing service-wide modules which required to engage globally
      Iterator moduleRefs = service_element.getChildrenWithName(new QName(TAG_MODULE));

      processModuleRefs(moduleRefs);

      // processing transports
      OMElement transports = service_element.getFirstChildWithName(new QName(TAG_TRANSPORTS));
      if (transports != null) {
        Iterator transport_itr = transports.getChildrenWithName(new QName(TAG_TRANSPORT));
        ArrayList<String> trs = new ArrayList<String>();
        while (transport_itr.hasNext()) {
          OMElement trsEle = (OMElement) transport_itr.next();
          String transportName = trsEle.getText().trim();
          if (axisConfig.getTransportIn(transportName) == null) {
            log.warn(
                "Service [ "
                    + service.getName()
                    + "] is trying to expose in a transport : "
                    + transportName
                    + " and which is not available in Axis2");
          } else {
            trs.add(transportName);
          }
        }

        if (trs.isEmpty()) {
          throw new AxisFault(
              "Service ["
                  + service.getName()
                  + "] is trying expose in tranpsorts: "
                  + transports
                  + " and which is/are not available in Axis2");
        }
        service.setExposedTransports(trs);
      }
      // processing operations
      Iterator operationsIterator = service_element.getChildrenWithName(new QName(TAG_OPERATION));
      ArrayList ops = processOperations(operationsIterator);

      for (int i = 0; i < ops.size(); i++) {
        AxisOperation operationDesc = (AxisOperation) ops.get(i);
        ArrayList wsamappings = operationDesc.getWSAMappingList();
        if (wsamappings == null) {
          continue;
        }
        if (service.getOperation(operationDesc.getName()) == null) {
          service.addOperation(operationDesc);
        }
        for (int j = 0; j < wsamappings.size(); j++) {
          String mapping = (String) wsamappings.get(j);
          if (mapping.length() > 0) {
            service.mapActionToOperation(mapping, operationDesc);
          }
        }
      }
      String objectSupplierValue = (String) service.getParameterValue(TAG_OBJECT_SUPPLIER);
      if (objectSupplierValue != null) {
        loadObjectSupplierClass(objectSupplierValue);
      }
      // Set the default message receiver for the operations that were
      // not listed in the services.xml
      setDefaultMessageReceivers();
      Utils.processBeanPropertyExclude(service);
      if (!service.isUseUserWSDL()) {
        // Generating schema for the service if the impl class is Java
        if (!service.isWsdlFound()) {
          // trying to generate WSDL for the service using JAM and
          // Java reflection
          try {
            if (generateWsdl(service)) {
              Utils.fillAxisService(service, axisConfig, excludeops, null);
            } else {
              ArrayList nonRpcOperations = getNonRPCMethods(service);
              Utils.fillAxisService(service, axisConfig, excludeops, nonRpcOperations);
            }
          } catch (Exception e) {
            throw new DeploymentException(
                Messages.getMessage("errorinschemagen", e.getMessage()), e);
          }
        }
      }
      if (service.isCustomWsdl()) {
        OMElement mappingElement =
            service_element.getFirstChildWithName(new QName(TAG_PACKAGE2QNAME));
        if (mappingElement != null) {
          processTypeMappings(mappingElement);
        }
      }

      for (String opName : excludeops) {
        service.removeOperation(new QName(opName));
      }

      // Need to call the same logic towice
      setDefaultMessageReceivers();
      Iterator moduleConfigs = service_element.getChildrenWithName(new QName(TAG_MODULE_CONFIG));
      processServiceModuleConfig(moduleConfigs, service, service);

      // Loading Data Locator(s) configured
      OMElement dataLocatorElement =
          service_element.getFirstChildWithName(new QName(DRConstants.DATA_LOCATOR_ELEMENT));
      if (dataLocatorElement != null) {
        processDataLocatorConfig(dataLocatorElement, service);
      }

      processEndpoints(service);
      processPolicyAttachments(service_element, service);

    } catch (AxisFault axisFault) {
      throw new DeploymentException(axisFault);
    }

    startupServiceLifecycle();
    return service;
  }
  /**
   * Create a ServiceTaskManager for the service passed in and its corresponding
   * JMSConnectionFactory
   *
   * @param jcf
   * @param service
   * @param workerPool
   * @return
   */
  public static ServiceTaskManager createTaskManagerForService(
      JMSConnectionFactory jcf, AxisService service, WorkerPool workerPool) {

    String name = service.getName();
    Map<String, String> svc = getServiceStringParameters(service.getParameters());
    Map<String, String> cf = jcf.getParameters();

    ServiceTaskManager stm = new ServiceTaskManager();

    stm.setServiceName(name);
    stm.addJmsProperties(cf);
    stm.addJmsProperties(svc);

    stm.setConnFactoryJNDIName(getRqdStringProperty(JMSConstants.PARAM_CONFAC_JNDI_NAME, svc, cf));
    String destName = getOptionalStringProperty(JMSConstants.PARAM_DESTINATION, svc, cf);
    if (destName == null) {
      destName = service.getName();
    }
    stm.setDestinationJNDIName(destName);
    stm.setDestinationType(getDestinationType(svc, cf));
    if (getOptionalBooleanProperty(JMSConstants.PARAM_SUB_DURABLE, svc, cf) != null
        && getOptionalBooleanProperty(JMSConstants.PARAM_SUB_DURABLE, svc, cf)) {
      stm.setDurableSubscriberClientId(
          getRqdStringProperty(JMSConstants.PARAM_DURABLE_SUB_CLIENT_ID, svc, cf));
    }

    stm.setJmsSpec11(getJMSSpecVersion(svc, cf));
    stm.setTransactionality(getTransactionality(svc, cf));
    stm.setCacheUserTransaction(
        getOptionalBooleanProperty(BaseConstants.PARAM_CACHE_USER_TXN, svc, cf));
    stm.setUserTransactionJNDIName(
        getOptionalStringProperty(BaseConstants.PARAM_USER_TXN_JNDI_NAME, svc, cf));
    stm.setSessionTransacted(
        getOptionalBooleanProperty(JMSConstants.PARAM_SESSION_TRANSACTED, svc, cf));
    stm.setSessionAckMode(getSessionAck(svc, cf));
    stm.setMessageSelector(getOptionalStringProperty(JMSConstants.PARAM_MSG_SELECTOR, svc, cf));
    stm.setSubscriptionDurable(getOptionalBooleanProperty(JMSConstants.PARAM_SUB_DURABLE, svc, cf));
    stm.setDurableSubscriberName(
        getOptionalStringProperty(JMSConstants.PARAM_DURABLE_SUB_NAME, svc, cf));

    stm.setCacheLevel(getCacheLevel(svc, cf));
    stm.setPubSubNoLocal(getOptionalBooleanProperty(JMSConstants.PARAM_PUBSUB_NO_LOCAL, svc, cf));

    Integer value = getOptionalIntProperty(JMSConstants.PARAM_RCV_TIMEOUT, svc, cf);
    if (value != null) {
      stm.setReceiveTimeout(value);
    }
    value = getOptionalIntProperty(JMSConstants.PARAM_CONCURRENT_CONSUMERS, svc, cf);
    if (value != null) {
      stm.setConcurrentConsumers(value);
    }
    value = getOptionalIntProperty(JMSConstants.PARAM_MAX_CONSUMERS, svc, cf);
    if (value != null) {
      stm.setMaxConcurrentConsumers(value);
    }
    value = getOptionalIntProperty(JMSConstants.PARAM_IDLE_TASK_LIMIT, svc, cf);
    if (value != null) {
      stm.setIdleTaskExecutionLimit(value);
    }
    value = getOptionalIntProperty(JMSConstants.PARAM_MAX_MSGS_PER_TASK, svc, cf);
    if (value != null) {
      stm.setMaxMessagesPerTask(value);
    }

    value = getOptionalIntProperty(JMSConstants.PARAM_RECON_INIT_DURATION, svc, cf);
    if (value != null) {
      stm.setInitialReconnectDuration(value);
    }
    value = getOptionalIntProperty(JMSConstants.PARAM_RECON_MAX_DURATION, svc, cf);
    if (value != null) {
      stm.setMaxReconnectDuration(value);
    }
    Double dValue = getOptionalDoubleProperty(JMSConstants.PARAM_RECON_FACTOR, svc, cf);
    if (dValue != null) {
      stm.setReconnectionProgressionFactor(dValue);
    }

    stm.setWorkerPool(workerPool);

    // remove processed properties from property bag
    stm.removeJmsProperties(JMSConstants.PARAM_CONFAC_JNDI_NAME);
    stm.removeJmsProperties(JMSConstants.PARAM_DESTINATION);
    stm.removeJmsProperties(JMSConstants.PARAM_JMS_SPEC_VER);
    stm.removeJmsProperties(BaseConstants.PARAM_TRANSACTIONALITY);
    stm.removeJmsProperties(BaseConstants.PARAM_CACHE_USER_TXN);
    stm.removeJmsProperties(BaseConstants.PARAM_USER_TXN_JNDI_NAME);
    stm.removeJmsProperties(JMSConstants.PARAM_SESSION_TRANSACTED);
    stm.removeJmsProperties(JMSConstants.PARAM_MSG_SELECTOR);
    stm.removeJmsProperties(JMSConstants.PARAM_SUB_DURABLE);
    stm.removeJmsProperties(JMSConstants.PARAM_DURABLE_SUB_NAME);
    stm.removeJmsProperties(JMSConstants.PARAM_CACHE_LEVEL);
    stm.removeJmsProperties(JMSConstants.PARAM_PUBSUB_NO_LOCAL);
    stm.removeJmsProperties(JMSConstants.PARAM_RCV_TIMEOUT);
    stm.removeJmsProperties(JMSConstants.PARAM_CONCURRENT_CONSUMERS);
    stm.removeJmsProperties(JMSConstants.PARAM_MAX_CONSUMERS);
    stm.removeJmsProperties(JMSConstants.PARAM_IDLE_TASK_LIMIT);
    stm.removeJmsProperties(JMSConstants.PARAM_MAX_MSGS_PER_TASK);
    stm.removeJmsProperties(JMSConstants.PARAM_RECON_INIT_DURATION);
    stm.removeJmsProperties(JMSConstants.PARAM_RECON_MAX_DURATION);
    stm.removeJmsProperties(JMSConstants.PARAM_RECON_FACTOR);
    stm.removeJmsProperties(JMSConstants.PARAM_DURABLE_SUB_CLIENT_ID);

    return stm;
  }
예제 #7
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;
  }
예제 #8
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;
  }