Search in sources :

Example 31 with SynapseException

use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.

the class SimpleQuartzSerializer method serializeStartup.

public OMElement serializeStartup(OMElement parent, Startup s) {
    if (!(s instanceof StartUpController)) {
        throw new SynapseException("called TaskSerializer on some other " + "kind of startup" + s.getClass().getName());
    }
    StartUpController sq = (StartUpController) s;
    TaskDescription taskDescription = sq.getTaskDescription();
    if (taskDescription != null) {
        OMElement task = TaskDescriptionSerializer.serializeTaskDescription(SynapseConstants.SYNAPSE_OMNAMESPACE, taskDescription);
        if (task == null) {
            throw new SynapseException("Task Element can not be null.");
        }
        if (parent != null) {
            parent.addChild(task);
        }
        return task;
    } else {
        throw new SynapseException("Task Description is null");
    }
}
Also used : SynapseException(org.apache.synapse.SynapseException) TaskDescription(org.apache.synapse.task.TaskDescription) OMElement(org.apache.axiom.om.OMElement)

Example 32 with SynapseException

use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.

the class StartUpController method init.

public void init(SynapseEnvironment synapseEnvironment) {
    this.synapseEnvironment = synapseEnvironment;
    if (taskDescription == null) {
        handleException("Error while initializing the startup. TaskDescription is null.");
    }
    initSynapseTaskManager(synapseEnvironment);
    TaskDescriptionRepository repository = synapseTaskManager.getTaskDescriptionRepository();
    if (repository == null) {
        handleException("Task Description Repository cannot be found");
        return;
    }
    repository.addTaskDescription(taskDescription);
    if (!processPinnedServers(taskDescription, synapseEnvironment)) {
        return;
    }
    resolveTaskImpl(taskDescription, synapseEnvironment);
    loadTaskProperties();
    initializeTask(synapseEnvironment);
    if (taskDescription.getResource(TaskDescription.INSTANCE) == null || taskDescription.getResource(TaskDescription.CLASSNAME) == null) {
        taskDescription.addResource(TaskDescription.INSTANCE, task);
        taskDescription.addResource(TaskDescription.CLASSNAME, task.getClass().getName());
    }
    try {
        Map<String, Object> map = new HashMap<>();
        map.put(TaskConstants.SYNAPSE_ENV, synapseEnvironment);
        TaskScheduler taskScheduler = synapseTaskManager.getTaskScheduler();
        TaskManager taskManager = synapseTaskManager.getTaskManagerImpl();
        if (taskManager == null) {
            logger.error("Could not initialize Start up controller. TaskManager not found.");
            return;
        }
        taskManager.setProperties(map);
        taskScheduler.init(synapseEnvironment.getSynapseConfiguration().getProperties(), taskManager);
        submitTask(taskScheduler, taskDescription);
        logger.debug("Submitted task [" + taskDescription.getName() + "] to Synapse task scheduler.");
    } catch (Exception e) {
        String msg = "Error starting up Scheduler : " + e.getLocalizedMessage();
        logger.fatal(msg, e);
        throw new SynapseException(msg, e);
    }
}
Also used : TaskManager(org.apache.synapse.task.TaskManager) SynapseTaskManager(org.apache.synapse.task.SynapseTaskManager) SynapseException(org.apache.synapse.SynapseException) TaskDescriptionRepository(org.apache.synapse.task.TaskDescriptionRepository) HashMap(java.util.HashMap) TaskScheduler(org.apache.synapse.task.TaskScheduler) SynapseException(org.apache.synapse.SynapseException) UnknownHostException(java.net.UnknownHostException)

Example 33 with SynapseException

use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.

the class Resource method process.

void process(MessageContext synCtx) {
    Integer statisticReportingIndex = null;
    boolean isStatisticsEnabled = RuntimeStatisticCollector.isStatisticsEnabled();
    if (!synCtx.isResponse()) {
        if (getDispatcherHelper() != null) {
            synCtx.setProperty(RESTConstants.REST_URL_PATTERN, getDispatcherHelper().getString());
        }
    }
    if (isStatisticsEnabled) {
        statisticReportingIndex = OpenEventCollector.reportChildEntryEvent(synCtx, getResourceName(synCtx, name), ComponentType.RESOURCE, getAspectConfiguration(), true);
    }
    if (log.isDebugEnabled()) {
        log.debug("Processing message with ID: " + synCtx.getMessageID() + " through the " + "resource: " + name);
    }
    if (!synCtx.isResponse()) {
        String method = (String) synCtx.getProperty(RESTConstants.REST_METHOD);
        if (RESTConstants.METHOD_OPTIONS.equals(method) && sendOptions(synCtx)) {
            if (isStatisticsEnabled) {
                CloseEventCollector.closeEntryEvent(synCtx, getResourceName(synCtx, name), ComponentType.RESOURCE, statisticReportingIndex, true);
            }
            return;
        }
        synCtx.setProperty(RESTConstants.SYNAPSE_RESOURCE, name);
        String path = RESTUtils.getFullRequestPath(synCtx);
        int queryIndex = path.indexOf('?');
        if (queryIndex != -1) {
            String query = path.substring(queryIndex + 1);
            String[] entries = query.split(RESTConstants.QUERY_PARAM_DELIMITER);
            String name = null, value;
            for (String entry : entries) {
                int index = entry.indexOf('=');
                if (index != -1) {
                    try {
                        name = entry.substring(0, index);
                        value = URLDecoder.decode(entry.substring(index + 1), RESTConstants.DEFAULT_ENCODING);
                        synCtx.setProperty(RESTConstants.REST_QUERY_PARAM_PREFIX + name, value);
                    } catch (UnsupportedEncodingException ignored) {
                    }
                } else {
                    // If '=' sign isn't presnet in the entry means that the '&' character is part of
                    // the query parameter value. If so query parameter value should be updated appending
                    // the remaining characters.
                    String existingValue = (String) synCtx.getProperty(RESTConstants.REST_QUERY_PARAM_PREFIX + name);
                    value = RESTConstants.QUERY_PARAM_DELIMITER + entry;
                    synCtx.setProperty(RESTConstants.REST_QUERY_PARAM_PREFIX + name, existingValue + value);
                }
            }
        }
    }
    SequenceMediator sequence = synCtx.isResponse() ? outSequence : inSequence;
    if (sequence != null) {
        registerFaultHandler(synCtx);
        sequence.mediate(synCtx);
        if (isStatisticsEnabled) {
            CloseEventCollector.closeEntryEvent(synCtx, getResourceName(synCtx, name), ComponentType.RESOURCE, statisticReportingIndex, true);
        }
        return;
    }
    String sequenceKey = synCtx.isResponse() ? outSequenceKey : inSequenceKey;
    if (sequenceKey != null) {
        registerFaultHandler(synCtx);
        Mediator referredSequence = synCtx.getSequence(sequenceKey);
        if (referredSequence != null) {
            referredSequence.mediate(synCtx);
        } else {
            throw new SynapseException("Specified sequence: " + sequenceKey + " cannot " + "be found");
        }
        if (isStatisticsEnabled) {
            CloseEventCollector.closeEntryEvent(synCtx, getResourceName(synCtx, name), ComponentType.RESOURCE, statisticReportingIndex, true);
        }
        return;
    }
    // response, simply send it back to the client.
    if (synCtx.isResponse()) {
        if (log.isDebugEnabled()) {
            log.debug("No out-sequence configured. Sending the response back.");
        }
        registerFaultHandler(synCtx);
        Axis2Sender.sendBack(synCtx);
    } else if (log.isDebugEnabled()) {
        log.debug("No in-sequence configured. Dropping the request.");
    }
    if (isStatisticsEnabled) {
        CloseEventCollector.closeEntryEvent(synCtx, getResourceName(synCtx, name), ComponentType.RESOURCE, statisticReportingIndex, true);
    }
}
Also used : SynapseException(org.apache.synapse.SynapseException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Mediator(org.apache.synapse.Mediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator)

Example 34 with SynapseException

use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.

the class LibDeployerUtils method populateDependencies.

/**
 * populate Dependencies using main root artifacts.xml.. Schema for artifacts.xml is follwing
 *
 *<artifacts>
 *         <artifact name="SampleLib" package="synapse.sample" >
 *                <dependency artifact="templates1" /> +
 *                <description>sample synapse library</description> ?
 *         </artifact>
 *    </artifacts>
 *
 * @param libXmlPath
 * @return
 */
private static SynapseLibrary populateDependencies(String libXmlPath) {
    File f = new File(libXmlPath);
    if (!f.exists()) {
        throw new SynapseException("artifacts.xml file not found at : " + libXmlPath);
    }
    InputStream xmlInputStream = null;
    try {
        xmlInputStream = new FileInputStream(f);
        OMElement documentElement = new StAXOMBuilder(xmlInputStream).getDocumentElement();
        if (documentElement == null) {
            throw new SynapseArtifactDeploymentException("Document element for artifacts.xml is " + "null. Can't build " + "the synapse library configuration");
        }
        Iterator artifactItr = documentElement.getChildrenWithLocalName(LibDeployerConstants.ARTIFACT);
        SynapseLibrary mainSynLibArtifact = null;
        mainSynLibArtifact = createSynapseLibraryWithDeps(((OMElement) artifactItr.next()));
        if (mainSynLibArtifact == null) {
            throw new SynapseArtifactDeploymentException("artifacts.xml is invalid. <artifact> element" + " Not Found ");
        }
        return mainSynLibArtifact;
    } catch (FileNotFoundException e) {
        throw new SynapseArtifactDeploymentException("artifacts.xml File cannot be loaded from " + libXmlPath, e);
    } catch (XMLStreamException e) {
        throw new SynapseArtifactDeploymentException("Error while parsing the artifacts.xml file ", e);
    } finally {
        if (xmlInputStream != null) {
            try {
                xmlInputStream.close();
            } catch (IOException e) {
                log.error("Error while closing input stream.", e);
            }
        }
    }
}
Also used : SynapseException(org.apache.synapse.SynapseException) XMLStreamException(javax.xml.stream.XMLStreamException) SynapseArtifactDeploymentException(org.apache.synapse.deployers.SynapseArtifactDeploymentException) SynapseLibrary(org.apache.synapse.libraries.model.SynapseLibrary) OMElement(org.apache.axiom.om.OMElement) StAXOMBuilder(org.apache.axiom.om.impl.builder.StAXOMBuilder) ZipFile(java.util.zip.ZipFile)

Example 35 with SynapseException

use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.

the class ServiceDynamicLoadbalanceEndpoint method sendMessage.

private void sendMessage(MessageContext synCtx) {
    logSetter();
    setCookieHeader(synCtx);
    // TODO: Refactor Session Aware LB dispatching code
    // Check whether a valid session for session aware dispatching is available
    Member currentMember = null;
    SessionInformation sessionInformation = null;
    if (isSessionAffinityBasedLB()) {
        // first check if this session is associated with a session. if so, get the endpoint
        // associated for that session.
        sessionInformation = (SessionInformation) synCtx.getProperty(SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION);
        currentMember = (Member) synCtx.getProperty(SynapseConstants.PROP_SAL_ENDPOINT_CURRENT_MEMBER);
        if (sessionInformation == null && currentMember == null) {
            sessionInformation = dispatcher.getSession(synCtx);
            if (sessionInformation != null) {
                if (log.isDebugEnabled()) {
                    log.debug("Current session id : " + sessionInformation.getId());
                }
                currentMember = sessionInformation.getMember();
                synCtx.setProperty(SynapseConstants.PROP_SAL_ENDPOINT_CURRENT_MEMBER, currentMember);
                // This is for reliably recovery any session information if while response is getting ,
                // session information has been removed by cleaner.
                // This will not be a cost as  session information a not heavy data structure
                synCtx.setProperty(SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION, sessionInformation);
            }
        }
    }
    // Dispatch request the relevant member
    String targetHost = getTargetHost(synCtx);
    ConfigurationContext configCtx = ((Axis2MessageContext) synCtx).getAxis2MessageContext().getConfigurationContext();
    if (slbMembershipHandler.getConfigurationContext() == null) {
        slbMembershipHandler.setConfigurationContext(configCtx);
    }
    ServiceDynamicLoadbalanceFaultHandlerImpl faultHandler = new ServiceDynamicLoadbalanceFaultHandlerImpl();
    faultHandler.setHost(targetHost);
    setupTransportHeaders(synCtx);
    if (sessionInformation != null && currentMember != null) {
        // send message on current session
        sessionInformation.updateExpiryTime();
        sendToApplicationMember(synCtx, currentMember, faultHandler, false);
    } else {
        // prepare for a new session
        currentMember = slbMembershipHandler.getNextApplicationMember(targetHost);
        if (currentMember == null) {
            String msg = "No application members available";
            log.error(msg);
            throw new SynapseException(msg);
        }
        sendToApplicationMember(synCtx, currentMember, faultHandler, true);
    }
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) SessionInformation(org.apache.synapse.endpoints.dispatch.SessionInformation) SynapseException(org.apache.synapse.SynapseException) Member(org.apache.axis2.clustering.Member)

Aggregations

SynapseException (org.apache.synapse.SynapseException)136 OMElement (org.apache.axiom.om.OMElement)31 OMAttribute (org.apache.axiom.om.OMAttribute)23 MessageContext (org.apache.synapse.MessageContext)20 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)16 QName (javax.xml.namespace.QName)15 Iterator (java.util.Iterator)14 JaxenException (org.jaxen.JaxenException)14 XMLStreamException (javax.xml.stream.XMLStreamException)13 AxisFault (org.apache.axis2.AxisFault)13 Map (java.util.Map)12 Endpoint (org.apache.synapse.endpoints.Endpoint)12 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)10 IOException (java.io.IOException)8 MalformedURLException (java.net.MalformedURLException)8 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)8 OMNode (org.apache.axiom.om.OMNode)7 Mediator (org.apache.synapse.Mediator)7 MediatorProperty (org.apache.synapse.mediators.MediatorProperty)7