コード例 #1
0
  /** @param synCtx */
  public void evaluate(MessageContext synCtx) {
    String result;
    if (value != null) {
      result = value;
    } else if (expression != null) {
      result = expression.stringValueOf(synCtx);
    } else {
      throw new SynapseException("A value or expression must be specified");
    }

    if (scope == null || XMLConfigConstants.SCOPE_DEFAULT.equals(scope)) {
      synCtx.setProperty(name, result);
    } else if (XMLConfigConstants.SCOPE_AXIS2.equals(scope)) {
      // Setting property into the  Axis2 Message Context
      Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx;
      org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext();
      axis2MessageCtx.setProperty(name, result);
    } else if (XMLConfigConstants.SCOPE_CLIENT.equals(scope)) {
      // Setting property into the  Axis2 Message Context client options
      Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx;
      org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext();
      axis2MessageCtx.getOptions().setProperty(name, result);
    } else if (XMLConfigConstants.SCOPE_TRANSPORT.equals(scope)) {
      // Setting Transport Headers
      Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx;
      org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext();
      Object headers =
          axis2MessageCtx.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);

      if (headers != null && headers instanceof Map) {
        Map headersMap = (Map) headers;
        headersMap.put(name, result);
      }
      if (headers == null) {
        Map headersMap = new HashMap();
        headersMap.put(name, result);
        axis2MessageCtx.setProperty(
            org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS, headersMap);
      }
    }
  }
コード例 #2
0
  /**
   * Extract transport headers from the synapse message context.
   *
   * @param synCtx synapse message context
   * @return transport headers map
   */
  public static Map<String, Object> extractTransportProperties(MessageContext synCtx) {
    Map<String, Object> transportPropertyMap = new TreeMap<>();

    Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx;
    org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext();
    Object headers =
        axis2MessageCtx.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);

    if (headers != null && headers instanceof Map) {
      Map headersMap = (Map) headers;
      Set<String> axis2PropertySet = headersMap.keySet();
      for (String entry : axis2PropertySet) {
        transportPropertyMap.put(entry, headersMap.get(entry));
      }
    }

    // Adding important transport related properties
    if (axis2MessageCtx.getTo() != null) {
      transportPropertyMap.put(SynapseConstants.HEADER_TO, axis2MessageCtx.getTo().getAddress());
    }

    if (axis2MessageCtx.getFrom() != null) {
      transportPropertyMap.put(
          SynapseConstants.HEADER_FROM, axis2MessageCtx.getFrom().getAddress());
    }

    if (axis2MessageCtx.getWSAAction() != null) {
      transportPropertyMap.put("WSAction", axis2MessageCtx.getWSAAction());
    }

    if (axis2MessageCtx.getSoapAction() != null) {
      transportPropertyMap.put("SOAPAction", axis2MessageCtx.getSoapAction());
    }

    if (axis2MessageCtx.getReplyTo() != null) {
      transportPropertyMap.put(
          SynapseConstants.HEADER_REPLY_TO, axis2MessageCtx.getReplyTo().getAddress());
    }

    if (axis2MessageCtx.getMessageID() != null) {
      transportPropertyMap.put(SynapseConstants.HEADER_MESSAGE_ID, axis2MessageCtx.getMessageID());
    }

    // Remove unnecessary properties
    if (transportPropertyMap.get("Cookie") != null) {
      transportPropertyMap.remove("Cookie");
    }

    return transportPropertyMap;
  }
コード例 #3
0
  public boolean processSecurity(String credentials, MessageContext messageContext) {
    String decodedCredentials = new String(new Base64().decode(credentials.getBytes()));
    String userName = decodedCredentials.split(":")[0];
    String password = decodedCredentials.split(":")[1];
    Axis2MessageContext axis2Msgcontext = null;
    org.apache.axis2.context.MessageContext msgContext;
    axis2Msgcontext = (Axis2MessageContext) messageContext;
    msgContext = axis2Msgcontext.getAxis2MessageContext();
    msgContext.setProperty("username", userName);

    return true;

    /*if ("admin".equals(userName) && "admin".equals(password)) {
        return true;
    } else {
        return false;
    }*/

  }
コード例 #4
0
ファイル: PropertyMediator.java プロジェクト: rcamus/platform
  /**
   * Sets a property into the current (local) Synapse Context or into the Axis Message Context or
   * into Transports Header and removes above properties from the corresponding locations.
   *
   * @param synCtx the message context
   * @return true always
   */
  public boolean mediate(MessageContext synCtx) {

    SynapseLog synLog = getLog(synCtx);

    if (synLog.isTraceOrDebugEnabled()) {
      synLog.traceOrDebug("Start : Property mediator");

      if (synLog.isTraceTraceEnabled()) {
        synLog.traceTrace("Message : " + synCtx.getEnvelope());
      }
    }

    if (action == ACTION_SET) {

      Object resultValue = getResultValue(synCtx);

      // if the result value is a String we can apply a reguar expression to
      // choose part of it
      if (resultValue instanceof String && pattern != null) {
        resultValue = getMatchedValue((String) resultValue, synLog);
      }

      if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug(
            "Setting property : "
                + name
                + " at scope : "
                + (scope == null ? "default" : scope)
                + " to : "
                + resultValue
                + " (i.e. "
                + (value != null ? "constant : " + value : "result of expression : " + expression)
                + ")");
      }

      if (scope == null || XMLConfigConstants.SCOPE_DEFAULT.equals(scope)) {
        // Setting property into the  Synapse Context
        synCtx.setProperty(name, resultValue);

      } else if (XMLConfigConstants.SCOPE_AXIS2.equals(scope)
          && synCtx instanceof Axis2MessageContext) {
        // Setting property into the  Axis2 Message Context
        Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx;
        org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext();
        axis2MessageCtx.setProperty(name, resultValue);

      } else if (XMLConfigConstants.SCOPE_CLIENT.equals(scope)
          && synCtx instanceof Axis2MessageContext) {
        // Setting property into the  Axis2 Message Context client options
        Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx;
        org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext();
        axis2MessageCtx.getOptions().setProperty(name, resultValue);

      } else if (XMLConfigConstants.SCOPE_TRANSPORT.equals(scope)
          && synCtx instanceof Axis2MessageContext) {
        // Setting Transport Headers
        Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx;
        org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext();
        Object headers =
            axis2MessageCtx.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);

        if (headers != null && headers instanceof Map) {
          Map headersMap = (Map) headers;
          headersMap.put(name, resultValue);
        }
        if (headers == null) {
          Map headersMap = new HashMap();
          headersMap.put(name, resultValue);
          axis2MessageCtx.setProperty(
              org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS, headersMap);
        }
      } else if (XMLConfigConstants.SCOPE_OPERATION.equals(scope)
          && synCtx instanceof Axis2MessageContext) {
        // Setting Transport Headers
        Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx;
        org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext();
        axis2smc.getAxis2MessageContext().getOperationContext().setProperty(name, resultValue);
      }

    } else {
      if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug(
            "Removing property : " + name + " (scope:" + (scope == null ? "default" : scope) + ")");
      }

      if (scope == null || XMLConfigConstants.SCOPE_DEFAULT.equals(scope)) {
        // Removing property from the  Synapse Context
        Set pros = synCtx.getPropertyKeySet();
        if (pros != null) {
          pros.remove(name);
        }

      } else if ((XMLConfigConstants.SCOPE_AXIS2.equals(scope)
              || XMLConfigConstants.SCOPE_CLIENT.equals(scope))
          && synCtx instanceof Axis2MessageContext) {

        // Removing property from the Axis2 Message Context
        Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx;
        org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext();
        axis2MessageCtx.removeProperty(name);

      } else if (XMLConfigConstants.SCOPE_TRANSPORT.equals(scope)
          && synCtx instanceof Axis2MessageContext) {
        // Removing transport headers
        Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx;
        org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext();
        Object headers =
            axis2MessageCtx.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
        if (headers != null && headers instanceof Map) {
          Map headersMap = (Map) headers;
          headersMap.remove(name);
        } else {
          synLog.traceOrDebug("No transport headers found for the message");
        }
      }
    }
    synLog.traceOrDebug("End : Property mediator");
    return true;
  }