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");
}
}
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);
}
}
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);
}
}
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);
}
}
}
}
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);
}
}
Aggregations