Search in sources :

Example 46 with Endpoint

use of org.apache.synapse.endpoints.Endpoint in project wso2-synapse by wso2.

the class FailoverEndpointSerializer method serializeEndpoint.

protected OMElement serializeEndpoint(Endpoint endpoint) {
    if (!(endpoint instanceof FailoverEndpoint)) {
        handleException("Invalid endpoint type.");
    }
    FailoverEndpoint failoverEndpoint = (FailoverEndpoint) endpoint;
    fac = OMAbstractFactory.getOMFactory();
    OMElement endpointElement = fac.createOMElement("endpoint", SynapseConstants.SYNAPSE_OMNAMESPACE);
    OMElement failoverElement = fac.createOMElement("failover", SynapseConstants.SYNAPSE_OMNAMESPACE);
    endpointElement.addChild(failoverElement);
    serializeCommonAttributes(endpoint, endpointElement);
    if (failoverEndpoint.isBuildMessageAtt()) {
        failoverElement.addAttribute(XMLConfigConstants.BUILD_MESSAGE, Boolean.toString(failoverEndpoint.isBuildMessageAtt()), null);
    }
    for (Endpoint childEndpoint : failoverEndpoint.getChildren()) {
        failoverElement.addChild(EndpointSerializer.getElementFromEndpoint(childEndpoint));
    }
    if (!failoverEndpoint.isDynamic()) {
        failoverElement.addAttribute("dynamic", "false", null);
    }
    // serialize the parameters
    serializeProperties(failoverEndpoint, endpointElement);
    return endpointElement;
}
Also used : Endpoint(org.apache.synapse.endpoints.Endpoint) FailoverEndpoint(org.apache.synapse.endpoints.FailoverEndpoint) OMElement(org.apache.axiom.om.OMElement) FailoverEndpoint(org.apache.synapse.endpoints.FailoverEndpoint)

Example 47 with Endpoint

use of org.apache.synapse.endpoints.Endpoint in project wso2-synapse by wso2.

the class TestMessageContext method getEndpoint.

public Endpoint getEndpoint(String key) {
    Object o = localEntries.get(key);
    if (o != null && o instanceof Endpoint) {
        return (Endpoint) o;
    } else {
        Endpoint e = getConfiguration().getEndpoint(key);
        synchronized (e) {
            if (!e.isInitialized()) {
                e.init(synEnv);
            }
        }
        localEntries.put(key, e);
        return e;
    }
}
Also used : Endpoint(org.apache.synapse.endpoints.Endpoint)

Example 48 with Endpoint

use of org.apache.synapse.endpoints.Endpoint in project wso2-synapse by wso2.

the class ProxyServiceMessageReceiver method receive.

public void receive(org.apache.axis2.context.MessageContext mc) throws AxisFault {
    boolean traceOn = proxy.getAspectConfiguration().isTracingEnabled();
    boolean traceOrDebugOn = traceOn || log.isDebugEnabled();
    CustomLogSetter.getInstance().setLogAppender(proxy.getArtifactContainerName());
    String remoteAddr = (String) mc.getProperty(org.apache.axis2.context.MessageContext.REMOTE_ADDR);
    if (traceOrDebugOn) {
        traceOrDebug(traceOn, "Proxy Service " + name + " received a new message" + (remoteAddr != null ? " from : " + remoteAddr : "..."));
        traceOrDebug(traceOn, ("Message To: " + (mc.getTo() != null ? mc.getTo().getAddress() : "null")));
        traceOrDebug(traceOn, ("SOAPAction: " + (mc.getSoapAction() != null ? mc.getSoapAction() : "null")));
        traceOrDebug(traceOn, ("WSA-Action: " + (mc.getWSAAction() != null ? mc.getWSAAction() : "null")));
        if (traceOn && trace.isTraceEnabled()) {
            String[] cids = null;
            try {
                cids = mc.getAttachmentMap().getAllContentIDs();
            } catch (Exception ex) {
                // partially read stream could lead to corrupted attachment map and hence this exception
                // corrupted attachment map leads to inconsistent runtime exceptions and behavior
                // discard the attachment map for the fault handler invocation
                // ensure the successful completion for fault handler flow
                mc.setAttachmentMap(null);
                log.error("Synapse encountered an exception when reading attachments from bytes stream. " + "Hence Attachments map is dropped from the message context.", ex);
            }
            if (cids != null && cids.length > 0) {
                for (String cid : cids) {
                    trace.trace("With attachment content ID : " + cid);
                }
            }
            trace.trace("Envelope : " + mc.getEnvelope());
        }
    }
    MessageContext synCtx = MessageContextCreatorForAxis2.getSynapseMessageContext(mc);
    Integer statisticReportingIndex = null;
    // Statistic reporting
    boolean isStatisticsEnabled = RuntimeStatisticCollector.isStatisticsEnabled();
    if (isStatisticsEnabled) {
        statisticReportingIndex = OpenEventCollector.reportEntryEvent(synCtx, this.name, proxy.getAspectConfiguration(), ComponentType.PROXYSERVICE);
    }
    Object inboundServiceParam = proxy.getParameterMap().get(SynapseConstants.INBOUND_PROXY_SERVICE_PARAM);
    Object inboundMsgCtxParam = mc.getProperty(SynapseConstants.IS_INBOUND);
    // check whether the message is from Inbound EP
    if (inboundMsgCtxParam == null || !(boolean) inboundMsgCtxParam) {
        // check whether service parameter is set to true or null, then block this request
        if (inboundServiceParam != null && (Boolean.valueOf((String) inboundServiceParam))) {
            /*
                return because same proxy is exposed via InboundEP and service parameter(inbound.only) is set to
                true, which disable normal http transport proxy
                */
            if (!synCtx.getFaultStack().isEmpty()) {
                if (log.isDebugEnabled()) {
                    log.debug("Executing fault handler - message discarded due to the proxy is allowed only via InboundEP");
                }
                (synCtx.getFaultStack().pop()).handleFault(synCtx, new Exception("Proxy Service " + name + " message discarded due to the proxy is allowed only via InboundEP"));
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("Proxy Service " + name + " message discarded due to the proxy is " + "allowed only via InboundEP");
                }
            }
            return;
        }
    }
    TenantInfoConfigurator configurator = synCtx.getEnvironment().getTenantInfoConfigurator();
    if (configurator != null) {
        configurator.extractTenantInfo(synCtx);
    }
    TransportInDescription trpInDesc = mc.getTransportIn();
    if (trpInDesc != null) {
        synCtx.setProperty(SynapseConstants.TRANSPORT_IN_NAME, trpInDesc.getName());
    }
    // get service log for this message and attach to the message context also set proxy name
    Log serviceLog = LogFactory.getLog(SynapseConstants.SERVICE_LOGGER_PREFIX + name);
    ((Axis2MessageContext) synCtx).setServiceLog(serviceLog);
    synCtx.setProperty(SynapseConstants.PROXY_SERVICE, name);
    // synCtx.setTracingState(proxy.getTraceState());
    synCtx.setProperty(SynapseConstants.IS_CLIENT_DOING_REST, mc.isDoingREST());
    synCtx.setProperty(SynapseConstants.IS_CLIENT_DOING_SOAP11, mc.isSOAP11());
    try {
        if (synCtx.getEnvironment().isDebuggerEnabled()) {
            SynapseDebugManager debugManager = synCtx.getEnvironment().getSynapseDebugManager();
            debugManager.acquireMediationFlowLock();
            debugManager.advertiseMediationFlowStartPoint(synCtx);
            if (!synCtx.isResponse()) {
                SynapseWireLogHolder wireLogHolder = (SynapseWireLogHolder) ((Axis2MessageContext) synCtx).getAxis2MessageContext().getProperty(SynapseDebugInfoHolder.SYNAPSE_WIRE_LOG_HOLDER_PROPERTY);
                if (wireLogHolder == null) {
                    wireLogHolder = new SynapseWireLogHolder();
                }
                if (synCtx.getProperty(SynapseConstants.PROXY_SERVICE) != null && !synCtx.getProperty(SynapseConstants.PROXY_SERVICE).toString().isEmpty()) {
                    wireLogHolder.setProxyName(synCtx.getProperty(SynapseConstants.PROXY_SERVICE).toString());
                }
                ((Axis2MessageContext) synCtx).getAxis2MessageContext().setProperty(SynapseDebugInfoHolder.SYNAPSE_WIRE_LOG_HOLDER_PROPERTY, wireLogHolder);
            }
        }
        synCtx.setProperty(SynapseConstants.RESPONSE_STATE, new ResponseState());
        List handlers = synCtx.getEnvironment().getSynapseHandlers();
        Iterator<SynapseHandler> iterator = handlers.iterator();
        while (iterator.hasNext()) {
            SynapseHandler handler = iterator.next();
            if (!handler.handleRequestInFlow(synCtx)) {
                return;
            }
        }
        Mediator mandatorySeq = synCtx.getConfiguration().getMandatorySequence();
        if (mandatorySeq != null) {
            if (log.isDebugEnabled()) {
                log.debug("Start mediating the message in the " + "pre-mediate state using the mandatory sequence");
            }
            if (!mandatorySeq.mediate(synCtx)) {
                if (log.isDebugEnabled()) {
                    log.debug("Request message for the proxy service " + name + " dropped in " + "the pre-mediation state by the mandatory sequence : \n" + synCtx);
                }
                return;
            }
        }
        // setup fault sequence - i.e. what happens when something goes wrong with this message
        proxy.registerFaultHandler(synCtx);
        boolean inSequenceResult = true;
        // Using inSequence for the incoming message mediation
        if (proxy.getTargetInSequence() != null) {
            Mediator inSequence = synCtx.getSequence(proxy.getTargetInSequence());
            if (inSequence != null) {
                traceOrDebug(traceOn, "Using sequence named : " + proxy.getTargetInSequence() + " for incoming message mediation");
                inSequenceResult = inSequence.mediate(synCtx);
            } else {
                handleException("Unable to find in-sequence : " + proxy.getTargetInSequence(), synCtx);
            }
        } else if (proxy.getTargetInLineInSequence() != null) {
            traceOrDebug(traceOn, "Using the anonymous " + "in-sequence of the proxy service for mediation");
            inSequenceResult = proxy.getTargetInLineInSequence().mediate(synCtx);
        }
        // if inSequence returns true, forward message to endpoint
        if (inSequenceResult) {
            if (proxy.getTargetEndpoint() != null) {
                Endpoint endpoint = synCtx.getEndpoint(proxy.getTargetEndpoint());
                if (endpoint != null) {
                    traceOrDebug(traceOn, "Forwarding message to the endpoint : " + proxy.getTargetEndpoint());
                    endpoint.send(synCtx);
                } else {
                    handleException("Unable to find the endpoint specified : " + proxy.getTargetEndpoint(), synCtx);
                }
            } else if (proxy.getTargetInLineEndpoint() != null) {
                traceOrDebug(traceOn, "Forwarding the message to the anonymous " + "endpoint of the proxy service");
                proxy.getTargetInLineEndpoint().send(synCtx);
            }
        }
    } catch (SynapseException syne) {
        if (!synCtx.getFaultStack().isEmpty()) {
            warn(traceOn, "Executing fault handler due to exception encountered", synCtx);
            ((FaultHandler) synCtx.getFaultStack().pop()).handleFault(synCtx, syne);
        } else {
            warn(traceOn, "Exception encountered but no fault handler found - " + "message dropped", synCtx);
        }
    } finally {
        // Statistic reporting
        if (isStatisticsEnabled) {
            CloseEventCollector.tryEndFlow(synCtx, this.name, ComponentType.PROXYSERVICE, statisticReportingIndex, true);
        }
        if (synCtx.getEnvironment().isDebuggerEnabled()) {
            SynapseDebugManager debugManager = synCtx.getEnvironment().getSynapseDebugManager();
            debugManager.advertiseMediationFlowTerminatePoint(synCtx);
            debugManager.releaseMediationFlowLock();
        }
        doPostInjectUpdates(synCtx);
    }
}
Also used : SynapseException(org.apache.synapse.SynapseException) Log(org.apache.commons.logging.Log) SynapseWireLogHolder(org.apache.synapse.transport.http.conn.SynapseWireLogHolder) TransportInDescription(org.apache.axis2.description.TransportInDescription) SynapseHandler(org.apache.synapse.SynapseHandler) SynapseDebugManager(org.apache.synapse.debug.SynapseDebugManager) SynapseException(org.apache.synapse.SynapseException) TenantInfoConfigurator(org.apache.synapse.carbonext.TenantInfoConfigurator) Endpoint(org.apache.synapse.endpoints.Endpoint) List(java.util.List) Mediator(org.apache.synapse.Mediator) MessageContext(org.apache.synapse.MessageContext)

Example 49 with Endpoint

use of org.apache.synapse.endpoints.Endpoint in project wso2-synapse by wso2.

the class EndpointDeployer method deploySynapseArtifact.

@Override
public String deploySynapseArtifact(OMElement artifactConfig, String fileName, Properties properties) {
    if (log.isDebugEnabled()) {
        log.debug("Endpoint Deployment from file : " + fileName + " : Started");
    }
    CustomLogSetter.getInstance().setLogAppender(customLogContent);
    try {
        Endpoint ep = EndpointFactory.getEndpointFromElement(artifactConfig, false, properties);
        // Set the car name
        ep.setArtifactContainerName(customLogContent);
        if (ep != null) {
            ep.setFileName((new File(fileName)).getName());
            if (log.isDebugEnabled()) {
                log.debug("Endpoint named '" + ep.getName() + "' has been built from the file " + fileName);
            }
            ep.init(getSynapseEnvironment());
            if (log.isDebugEnabled()) {
                log.debug("Initialized the endpoint : " + ep.getName());
            }
            getSynapseConfiguration().addEndpoint(ep.getName(), ep);
            if (log.isDebugEnabled()) {
                log.debug("Endpoint Deployment from file : " + fileName + " : Completed");
            }
            log.info("Endpoint named '" + ep.getName() + "' has been deployed from file : " + fileName);
            return ep.getName();
        } else {
            handleSynapseArtifactDeploymentError("Endpoint Deployment Failed. The artifact " + "described in the file " + fileName + " is not an Endpoint");
        }
    } catch (Exception e) {
        handleSynapseArtifactDeploymentError("Endpoint Deployment from the file : " + fileName + " : Failed.", e);
    }
    return null;
}
Also used : Endpoint(org.apache.synapse.endpoints.Endpoint) File(java.io.File) DeploymentException(org.apache.axis2.deployment.DeploymentException)

Example 50 with Endpoint

use of org.apache.synapse.endpoints.Endpoint in project wso2-synapse by wso2.

the class EndpointDeployer method updateSynapseArtifact.

@Override
public String updateSynapseArtifact(OMElement artifactConfig, String fileName, String existingArtifactName, Properties properties) {
    Endpoint ep = EndpointFactory.getEndpointFromElement(artifactConfig, false, properties);
    CustomLogSetter.getInstance().setLogAppender((ep != null) ? ep.getArtifactContainerName() : "");
    if (log.isDebugEnabled()) {
        log.debug("Endpoint update from file : " + fileName + " has started");
    }
    try {
        if (ep == null) {
            handleSynapseArtifactDeploymentError("Endpoint update failed. The artifact " + "defined in the file: " + fileName + " is not a valid endpoint.");
            return null;
        }
        ep.setFileName(new File(fileName).getName());
        if (log.isDebugEnabled()) {
            log.debug("Endpoint: " + ep.getName() + " has been built from the file: " + fileName);
        }
        ep.init(getSynapseEnvironment());
        Endpoint existingEp = getSynapseConfiguration().getDefinedEndpoints().get(existingArtifactName);
        if (existingArtifactName.equals(ep.getName())) {
            getSynapseConfiguration().updateEndpoint(existingArtifactName, ep);
        } else {
            // The user has changed the name of the endpoint
            // We should add the updated endpoint as a new endpoint and remove the old one
            getSynapseConfiguration().addEndpoint(ep.getName(), ep);
            getSynapseConfiguration().removeEndpoint(existingArtifactName);
            log.info("Endpoint: " + existingArtifactName + " has been undeployed");
        }
        log.info("Endpoint: " + ep.getName() + " has been updated from the file: " + fileName);
        waitForCompletion();
        existingEp.destroy();
        if (existingArtifactName.equals(ep.getName())) {
            // If the endpoint name was same as the old one, above method call (destroy)
            // will unregister the endpoint MBean - So we should register it again.
            MBeanRegistrar.getInstance().registerMBean(ep.getMetricsMBean(), "Endpoint", ep.getName());
        }
        return ep.getName();
    } catch (DeploymentException e) {
        handleSynapseArtifactDeploymentError("Error while updating the endpoint from the " + "file: " + fileName);
    }
    return null;
}
Also used : Endpoint(org.apache.synapse.endpoints.Endpoint) DeploymentException(org.apache.axis2.deployment.DeploymentException) File(java.io.File)

Aggregations

Endpoint (org.apache.synapse.endpoints.Endpoint)64 OMElement (org.apache.axiom.om.OMElement)22 SynapseException (org.apache.synapse.SynapseException)13 AddressEndpoint (org.apache.synapse.endpoints.AddressEndpoint)13 SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)11 ArrayList (java.util.ArrayList)10 MessageContext (org.apache.synapse.MessageContext)9 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)8 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)8 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)8 IndirectEndpoint (org.apache.synapse.endpoints.IndirectEndpoint)8 SALoadbalanceEndpoint (org.apache.synapse.endpoints.SALoadbalanceEndpoint)8 InboundEndpoint (org.apache.synapse.inbound.InboundEndpoint)8 OMAttribute (org.apache.axiom.om.OMAttribute)7 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)7 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)7 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)7 QName (javax.xml.namespace.QName)6 AbstractEndpoint (org.apache.synapse.endpoints.AbstractEndpoint)6 DynamicLoadbalanceEndpoint (org.apache.synapse.endpoints.DynamicLoadbalanceEndpoint)6