Package org.apache.synapse

Examples of org.apache.synapse.SynapseLog


     */
    public boolean mediate(MessageContext synCtx) {

        try {

            SynapseLog synLog = getLog(synCtx);

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

                if (synLog.isTraceTraceEnabled()) {
                    synLog.traceTrace("Message : " + synCtx.getEnvelope());
                }
                synLog.traceOrDebug("Performing XQuery using query resource with key : " +
                        queryKey);
            }

            // perform the xquery
            performQuery(synCtx, synLog);

            synLog.traceOrDebug("End : XQuery mediator");

            return true;

        } catch (Exception e) {
            handleException("Unable to execute the query ", e);
View Full Code Here


     * @param synCtx the current message to be sent
     * @return false always as this is a leaf mediator
     */
    public boolean mediate(MessageContext synCtx) {

        SynapseLog synLog = getLog(synCtx);

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

        if (receivingSequence != null) {
            if (synLog.isTraceOrDebugEnabled()) {
                synLog.traceOrDebug("Receiving sequence is set to: " + receivingSequence);
            }
            synCtx.setProperty(SynapseConstants.RECEIVING_SEQUENCE,
                    receivingSequence.evaluateValue(synCtx));
        }

        // if no endpoints are defined, send where implicitly stated
        if (endpoint == null) {

            if (synLog.isTraceOrDebugEnabled()) {
                StringBuffer sb = new StringBuffer();
                sb.append("Sending ").append(synCtx.isResponse() ? "response" : "request")
                        .append(" message using implicit message properties..");
                sb.append("\nSending To: ").append(synCtx.getTo() != null ?
                        synCtx.getTo().getAddress() : "null");
                sb.append("\nSOAPAction: ").append(synCtx.getWSAAction() != null ?
                        synCtx.getWSAAction() : "null");
                synLog.traceOrDebug(sb.toString());
            }

            if (synLog.isTraceTraceEnabled()) {
                synLog.traceTrace("Envelope : " + synCtx.getEnvelope());
            }
            synCtx.getEnvironment().send(null, synCtx);

        } else {
            endpoint.send(synCtx);
        }

        synLog.traceOrDebug("End : Send mediator");

        return true;
    }
View Full Code Here

     * @param synCtx - MessageContext to be mediated
     * @return boolean false if need to stop processing of the parent message
     */
    public boolean mediate(MessageContext synCtx) {

        SynapseLog synLog = getLog(synCtx);

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

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

        try {
            // get a copy of the message for the processing, if the continueParent is set to true
            // this original message can go in further mediations and hence we should not change
            // the original message context
            SOAPEnvelope envelope = MessageHelper.cloneSOAPEnvelope(synCtx.getEnvelope());

            // get the iteration elements and iterate through the list,
            // this call will also detach all the iteration elements
            List splitElements = EIPUtils.getDetachedMatchingElements(envelope, synCtx, expression);

            if (synLog.isTraceOrDebugEnabled()) {
                synLog.traceOrDebug("Splitting with XPath : " + expression + " resulted in " +
                    splitElements.size() + " elements");
            }

            // if not preservePayload remove all the child elements
            if (!preservePayload && envelope.getBody() != null) {
                for (Iterator itr = envelope.getBody().getChildren(); itr.hasNext();) {
                    itr.next();
                    itr.remove();
                }
            }

            int msgCount = splitElements.size();
            int msgNumber = 0;

            // iterate through the list
            for (Object o : splitElements) {

                // for the moment iterator will look for an OMNode as the iteration element
                if (!(o instanceof OMNode)) {
                    handleException("Error splitting message with XPath : "
                        + expression + " - result not an OMNode", synCtx);
                }

                if (synLog.isTraceOrDebugEnabled()) {
                    synLog.traceOrDebug("Submitting " + (msgNumber+1) + " of " + msgNumber +
                        " messages for processing in parallel");
                }

                target.mediate(
                    getIteratedMessage(synCtx, msgNumber++, msgCount, envelope, (OMNode) o));
            }

        } catch (JaxenException e) {
            handleException("Error evaluating split XPath expression : " + expression, e, synCtx);
        } catch (AxisFault af) {
            handleException("Error creating an iterated copy of the message", af, synCtx);
        }

        // if the continuation of the parent message is stopped from here set the RESPONSE_WRITTEN
        // property to SKIP to skip the blank http response
        OperationContext opCtx
            = ((Axis2MessageContext) synCtx).getAxis2MessageContext().getOperationContext();
        if (!continueParent && opCtx != null) {
            opCtx.setProperty(Constants.RESPONSE_WRITTEN,"SKIP");
        }

        synLog.traceOrDebug("End : Iterate mediator");

        // whether to continue mediation on the original message
        return continueParent;
    }
View Full Code Here

        }
    }

    public boolean mediate(MessageContext synCtx) {

        SynapseLog synLog = getLog(synCtx);
        boolean isResponse = synCtx.isResponse();
        ConfigurationContext cc;
        org.apache.axis2.context.MessageContext axisMC;

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

            if (synLog.isTraceTraceEnabled()) {
                synLog.traceTrace("Message : " + synCtx.getEnvelope());
            }
        }
        // To ensure the creation of throttle is thread safe – It is possible create same throttle
        // object multiple times  by multiple threads.

        synchronized (throttleLock) {

            // get Axis2 MessageContext and ConfigurationContext
            axisMC = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
            cc = axisMC.getConfigurationContext();

            //To ensure check for clustering environment only happens one time
            if ((throttle == null && !isResponse) || (isResponse
                    && concurrentAccessController == null)) {
                ClusteringAgent clusteringAgent = cc.getAxisConfiguration().getClusteringAgent();
                if (clusteringAgent != null &&
                        clusteringAgent.getStateManager() != null) {
                    isClusteringEnable = true;
                }
            }

            // Throttle only will be created ,if the massage flow is IN
            if (!isResponse) {
                //check the availability of the ConcurrentAccessControler
                //if this is a clustered environment
                if (isClusteringEnable) {
                    concurrentAccessController =
                            (ConcurrentAccessController) cc.getProperty(key);
                }
                // for request messages, read the policy for throttling and initialize
                if (inLinePolicy != null) {
                    // this uses a static policy
                    if (throttle == null) {  // only one time creation

                        if (synLog.isTraceTraceEnabled()) {
                            synLog.traceTrace("Initializing using static throttling policy : "
                                    + inLinePolicy);
                        }
                        try {
                            // process the policy
                            throttle = ThrottleFactory.createMediatorThrottle(inLinePolicy);

                            //At this point concurrent access controller definitely 'null'
                            // f the clustering is disable.
                            //For a clustered environment,it is 'null' ,
                            //if this is the first instance on the cluster ,
                            // that message mediation has occurred through this mediator.
                            if (throttle != null && concurrentAccessController == null) {
                                concurrentAccessController =
                                        throttle.getConcurrentAccessController();
                                if (concurrentAccessController != null) {
                                    cc.setProperty(key, concurrentAccessController);
                                }
                            }
                        } catch (ThrottleException e) {
                            handleException("Error processing the throttling policy", e, synCtx);
                        }
                    }

                } else if (policyKey != null) {

                    // If the policy has specified as a registry key.
                    // load or re-load policy from registry or local entry if not already available

                    Entry entry = synCtx.getConfiguration().getEntryDefinition(policyKey);
                    if (entry == null) {
                        handleException("Cannot find throttling policy using key : "
                                + policyKey, synCtx);

                    } else {
                        boolean reCreate = false;
                        // if the key refers to a dynamic resource
                        if (entry.isDynamic()) {
                            if ((!entry.isCached() || entry.isExpired()) &&
                                    version != entry.getVersion()) {
                                reCreate = true;
                                version = entry.getVersion();
                            }
                        }
                        if (reCreate || throttle == null) {
                            Object entryValue = synCtx.getEntry(policyKey);
                            if (entryValue == null) {
                                handleException(
                                        "Null throttling policy returned by Entry : "
                                                + policyKey, synCtx);

                            } else {
                                if (!(entryValue instanceof OMElement)) {
                                    handleException("Policy returned from key : " + policyKey +
                                            " is not an OMElement", synCtx);

                                } else {
                                    //Check for reload in a cluster environment –
                                    // For clustered environment ,if the concurrent access controller
                                    // is not null and throttle is not null , then must reload.
                                    if (isClusteringEnable && concurrentAccessController != null
                                            && throttle != null) {
                                        concurrentAccessController = null; // set null ,
                                        // because need reload
                                    }

                                    try {
                                        // Creates the throttle from the policy
                                        throttle = ThrottleFactory.createMediatorThrottle((OMElement) entryValue);

                                        //For non-clustered  environment , must re-initiates
                                        //For  clustered  environment,
                                        //concurrent access controller is null ,
                                        //then must re-initiates
                                        if (throttle != null && (concurrentAccessController == null
                                                || !isClusteringEnable)) {
                                            concurrentAccessController =
                                                    throttle.getConcurrentAccessController();
                                            if (concurrentAccessController != null) {
                                                cc.setProperty(key, concurrentAccessController);
                                            } else {
                                                cc.removeProperty(key);
                                            }
                                        }
                                    } catch (ThrottleException e) {
                                        handleException("Error processing the throttling policy",
                                                e, synCtx);
                                    }
                                }
                            }
                        }
                    }
                }
            } else {
                // if the message flow path is OUT , then must lookp from ConfigurationContext -
                // never create ,just get the existing one
                concurrentAccessController =
                        (ConcurrentAccessController) cc.getProperty(key);
            }
        }
        //perform concurrency throttling
        boolean canAccess = doThrottleByConcurrency(isResponse, synLog);

        //if the access is success through concurrency throttle and if this is a request message
        //then do access rate based throttling
        if (throttle != null && !isResponse && canAccess) {
            canAccess = throttleByAccessRate(synCtx, axisMC, cc, synLog);
        }
        // all the replication functionality of the access rate based throttling handles by itself
        // Just replicate the current state of ConcurrentAccessController
        if (isClusteringEnable && concurrentAccessController != null) {
            if (cc != null) {
                try {
                    if (synLog.isTraceOrDebugEnabled()) {
                        synLog.traceOrDebug("Going to replicates the  " +
                                "states of the ConcurrentAccessController with key : " + key);
                    }
                    Replicator.replicate(cc);
                } catch (ClusteringFault clusteringFault) {
                    handleException("Error during the replicating  states ",
                            clusteringFault, synCtx);
                }
            }
        }
        if (canAccess) {
            if (onAcceptSeqKey != null) {
                Mediator mediator = synCtx.getSequence(onAcceptSeqKey);
                if (mediator != null) {
                    return mediator.mediate(synCtx);
                } else {
                    handleException("Unable to find onAccept sequence with key : "
                            + onAcceptSeqKey, synCtx);
                }
            } else if (onAcceptMediator != null) {
                return onAcceptMediator.mediate(synCtx);
            } else {
                return true;
            }

        } else {
            if (onRejectSeqKey != null) {
                Mediator mediator = synCtx.getSequence(onRejectSeqKey);
                if (mediator != null) {
                    return mediator.mediate(synCtx);
                } else {
                    handleException("Unable to find onReject sequence with key : "
                            + onRejectSeqKey, synCtx);
                }
            } else if (onRejectMediator != null) {
                return onRejectMediator.mediate(synCtx);
            } else {
                return false;
            }
        }

        synLog.traceOrDebug("End : Throttle mediator");
        return canAccess;
    }
View Full Code Here

     * @param synCtx - MessageContext which is subjected to the cloning
     * @return boolean true if this needs to be further mediated (continueParent=true)
     */
    public boolean mediate(MessageContext synCtx) {

        SynapseLog synLog = getLog(synCtx);

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

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

        // get the targets list, clone the message for the number of targets and then
        // mediate the cloned messages using the targets
        Iterator<Target> iter = targets.iterator();
        int i = 0;
        while (iter.hasNext()) {
            if (synLog.isTraceOrDebugEnabled()) {
                synLog.traceOrDebug("Submitting " + (i+1) + " of " + targets.size() +
                    " messages for processing in parallel");
            }

            iter.next().mediate(getClonedMessageContext(synCtx, i++, targets.size()));
        }

        // if the continuation of the parent message is stopped from here set the RESPONSE_WRITTEN
        // property to SKIP to skip the blank http response
        OperationContext opCtx
            = ((Axis2MessageContext) synCtx).getAxis2MessageContext().getOperationContext();
        if (!continueParent && opCtx != null) {
            opCtx.setProperty(Constants.RESPONSE_WRITTEN, "SKIP");
        }

        // finalize tracing and debugging
        synLog.traceOrDebug("End : Clone mediator");

        // if continue parent is true mediators after the clone will be called for the further
        // mediation of the message which is subjected for clonning (parent message)
        return continueParent;
    }
View Full Code Here

     * @return Always true , to continue mediation
     * @see org.apache.synapse.Mediator#mediate(org.apache.synapse.MessageContext)
     */
    public boolean mediate(MessageContext synCtx) {

        SynapseLog synLog = getLog(synCtx);

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

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

        SessionDescription sessionDescription = ruleMediatorDescription.getSessionDescription();

        if (registryKey != null) {
            ReturnValue returnValue = interceptor.extract(registryKey, synCtx, null);
            if (returnValue.getValue() == null) {
                handleException("RuleSet cannot be found for the registry key : " + registryKey,
                        synCtx);
            }
            if (returnValue.isFresh()) {
                synchronized (resourceLock) {
                    addRuleSet(returnValue.getValue(), sessionDescription);
                }
            }
            if (!added) {
                synchronized (resourceLock) {
                    if (!added) {
                        addRuleSet(returnValue.getValue(), sessionDescription);
                    }
                }
            }
        }

        boolean reCreateSession = true;
        if (session != null) {     //todo synchronize as needed
            if (session instanceof Expirable && ((Expirable) session).isExpired()) {
                session.release();
            } else {
                reCreateSession = false;
            }
        }

        if (reCreateSession) {
            session = ruleEngine.createSession(sessionDescription);
        }

        List<Object> facts = inputManager.processInputs(synCtx);
        if (facts.isEmpty()) {
            if (log.isDebugEnabled()) {
                log.debug("There is no facts to be injected into the rule engine");
            }
            return true;
        }
        List results = session.execute(facts);
        outputManager.processOutputs(results, synCtx);

        //execute the rules
        String executeChildren = (String) synCtx.getProperty(EXECUTE_CHILDREN);
        if (executeChildren != null) {
            synCtx.getPropertyKeySet().remove(EXECUTE_CHILDREN);
            if ("true".equals(executeChildren)) {
                return super.mediate(synCtx);
            }
        }
        if (synLog.isTraceOrDebugEnabled()) {
            synLog.traceOrDebug("End : Rule mediator");
        }
        return true;
    }
View Full Code Here

     * @return whether to continue further mediaiton or not as a boolean value
     * @see org.apache.synapse.Mediator#mediate(org.apache.synapse.MessageContext)
     */
    public boolean mediate(MessageContext synCtx) {

        SynapseLog synLog = getLog(synCtx);

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

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

        if (synLog.isTraceOrDebugEnabled()) {
            synLog.traceOrDebug("Start dispatching operation: "
                                + operation.getName());
        }

        Object result = null;
        //delegate salesforce operation for this mediator
        try {
            result = requestHandler.handle(operation, synCtx);
        } catch (SynapseException e) {
            synLog.logSynapseException("Error Executing Salesforce Mediator.Exiting further processing..", e);
            return false;
        }

        if (synLog.isTraceTraceEnabled()) {
            synLog.traceTrace("Response payload received : " + result);
        }

        if (result != null) {
            try {
                new ResponseHandler().handle(operation, synCtx, result);
                if (log.isDebugEnabled()) {
                    log.debug("Salesforce Response : " + result);
                }
            } catch (SynapseException e) {
                synLog.logSynapseException("Error Executing Salesforce Mediator Response processing.", e);
                return true;
            }
        } else {
            synLog.traceOrDebug("Service returned a null response");
        }

        if (synLog.isTraceOrDebugEnabled()) {
            synLog.traceOrDebug("End dispatching operation: "
                                + operation.getName());
        }

        if (synLog.isTraceOrDebugEnabled()) {

            synLog.traceOrDebug("End : Salesforce mediator");
        }

        return true;
    }
View Full Code Here

   *
   * @see org.apache.synapse.Mediator#mediate(org.apache.synapse.MessageContext)
   */
  public boolean mediate(MessageContext synCtx) {

    SynapseLog synLog = getLog(synCtx);

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

      if (synLog.isTraceTraceEnabled()) {
        synLog.traceTrace("Message : " + synCtx.getEnvelope());
      }
    }
    dispatch(synCtx);
    if (synLog.isTraceOrDebugEnabled()) {
      synLog.traceOrDebug("End : PayPal mediator");
    }

    return true;
  }
View Full Code Here

   */
  private void dispatch(MessageContext synCtx) {

    try {

      SynapseLog synLog = getLog(synCtx);
      if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Start dispatching operation: "
            + operation.getName());
      }
            //create service client options for paypal ws API calls
      Options options = getOptions(synCtx);
      sc.setOptions(options);

            //generate headers and payload based on paypal config
      OMElement requestHeader = handleHeader(synCtx);
      OMElement requestPayload = handlePayload(synCtx);
      System.out.println("Printing RequestHeader:");
      System.out.println(requestHeader);

            if (synLog.isTraceOrDebugEnabled()) {
                final String caption = operation
        .getAction() != null ? " with action : " + operation.getAction() : "";
                synLog.traceOrDebug(String.format(
            "About to invoke service : %s", serviceURL, caption ));
                if (synLog.isTraceTraceEnabled()) {
                    synLog.traceTrace("Request message header  : "
              + requestHeader);
                    synLog.traceTrace("Request message payload : "
              + requestPayload);
                }
            }

            sc.addHeader(requestHeader);
            System.out.println("Printing RequestPayload :" + requestPayload);

            OMElement result = sc.sendReceive(requestPayload);
            //OMElement result = sendRecieve();

            System.out.println("Printing the result:");
            System.out.println(result);
            if (synLog.isTraceTraceEnabled()) {
                synLog.traceTrace("Response payload received : " + result);
            }

            if (result != null) {
                handleResponse(result, synCtx);
            } else {
                synLog.traceOrDebug("Service returned a null response");
            }

      if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("End dispatching operation: "
            + operation.getName());
      }
    } catch (JaxenException e) {
      handleException("Error handling service response", e, synCtx);
    } catch (AxisFault e) {
View Full Code Here

     * @return whether to continue further mediaiton or not as a boolean value
     * @see org.apache.synapse.Mediator#mediate(org.apache.synapse.MessageContext)
     * @see Route#doRoute(org.apache.synapse.MessageContext, SynapseLog)
     */
    public boolean mediate(MessageContext synCtx) {
        SynapseLog synLog = getLog(synCtx);

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

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

        for (Route route : routes) {

            int routeState = route.doRoute(synCtx, synLog);

            // if the message does not match the route conditions
            if (Route.ROUTE_NOT_MACHING_STATE == routeState && synLog.isTraceOrDebugEnabled()) {
                synLog.traceOrDebug("The message does not matches the routing conditions : " +
                        "Expression = '" + route.getExpression() + "'" + (route.getMatch() != null ?
                        " Pattern = '" + route.getMatch().toString() + "'" : ""));
            } else {

                // get the route target for logging purposes
                Target routeTarget = route.getTarget();
                String targetString = null;

                if (routeTarget != null) {

                    // prepare a target string for loggin purposes
                    if (routeTarget.getSequenceRef() != null) {
                        targetString = "Sequence <" + routeTarget.getSequenceRef() + ">";
                    } else if (routeTarget.getSequence() != null) {
                        targetString = "Sequence <annonymous>";
                    } else if (routeTarget.getEndpointRef() != null) {
                        targetString = "Endpoint <" + routeTarget.getEndpointRef() + ">";
                    } else if (routeTarget.getEndpoint() != null) {
                        targetString = "Endpoint <annonymous>";
                    } else {
                        targetString = "without an endpoint or a sequence";
                    }
                }

                // if routed and the message may route furhter using the existing routes
                if (Route.ROUTED_WITH_CONTINUE_STATE == routeState && synLog.isTraceOrDebugEnabled()) {

                    synLog.traceOrDebug("The message has been routed to the target : "
                            + targetString + ", but further routings are allowed");

                    // if routed and the message should not be routed with other remaining routes
                } else if (Route.ROUTED_WITH_BREAK_STATE == routeState) {

                    synLog.traceOrDebug("The message has been routed to the target : "
                            + targetString + ", and no further routes are allowed");

                    // break this router permitting further routings
                    break;
                } else if (Route.ROUTED_AND_DROPPED_STATE == routeState) {

                    synLog.traceOrDebug("The message has been routed to the target : "
                            + targetString + ", and the message is droped on the route");

                    return false;
                }
            }
        }

        if (synLog.isTraceOrDebugEnabled()) {
            synLog.traceOrDebug("End : Router mediator");
        }

        // normally message routing is redirecting the message, so this permits further mediation
        // in this path where as the message is mediated using the roted path(s) by default, but it
        // can be configured by the continueAfter attribute if required
View Full Code Here

TOP

Related Classes of org.apache.synapse.SynapseLog

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.