use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class DynamicLoadbalanceEndpointFactory method createEndpoint.
protected Endpoint createEndpoint(OMElement epConfig, boolean anonymousEndpoint, Properties properties) {
OMElement loadbalanceElement = epConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "dynamicLoadbalance"));
if (loadbalanceElement != null) {
DynamicLoadbalanceEndpoint loadbalanceEndpoint = new DynamicLoadbalanceEndpoint();
// set endpoint name
OMAttribute name = epConfig.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "name"));
if (name != null) {
loadbalanceEndpoint.setName(name.getAttributeValue());
}
// get the session for this endpoint
OMElement sessionElement = epConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "session"));
if (sessionElement != null) {
OMElement sessionTimeout = sessionElement.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "sessionTimeout"));
if (sessionTimeout != null) {
try {
loadbalanceEndpoint.setSessionTimeout(Long.parseLong(sessionTimeout.getText().trim()));
} catch (NumberFormatException nfe) {
handleException("Invalid session timeout value : " + sessionTimeout.getText());
}
}
String type = sessionElement.getAttributeValue(new QName("type"));
if (type.equalsIgnoreCase("soap")) {
Dispatcher soapDispatcher = new SoapSessionDispatcher();
loadbalanceEndpoint.setDispatcher(soapDispatcher);
} else if (type.equalsIgnoreCase("http")) {
Dispatcher httpDispatcher = new HttpSessionDispatcher();
loadbalanceEndpoint.setDispatcher(httpDispatcher);
}
loadbalanceEndpoint.setSessionAffinity(true);
}
// set if failover is turned off
String failover = loadbalanceElement.getAttributeValue(new QName("failover"));
if (failover != null && failover.equalsIgnoreCase("false")) {
loadbalanceEndpoint.setFailover(false);
} else {
loadbalanceEndpoint.setFailover(true);
}
OMElement eventHandler = loadbalanceElement.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "membershipHandler"));
if (eventHandler != null) {
String clazz = eventHandler.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE, "class")).trim();
try {
LoadBalanceMembershipHandler lbMembershipHandler = (LoadBalanceMembershipHandler) Class.forName(clazz).newInstance();
Properties lbProperties = new Properties();
for (Iterator props = eventHandler.getChildrenWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "property")); props.hasNext(); ) {
OMElement prop = (OMElement) props.next();
String propName = prop.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE, "name")).trim();
String propValue = prop.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE, "value")).trim();
lbProperties.put(propName, propValue);
}
// Set load balance algorithm
LoadbalanceAlgorithm algorithm = LoadbalanceAlgorithmFactory.createLoadbalanceAlgorithm(loadbalanceElement, null);
lbMembershipHandler.init(lbProperties, algorithm);
loadbalanceEndpoint.setLoadBalanceMembershipHandler(lbMembershipHandler);
} catch (Exception e) {
String msg = "Could not instantiate " + "LoadBalanceMembershipHandler implementation " + clazz;
log.error(msg, e);
throw new SynapseException(msg, e);
}
}
processProperties(loadbalanceEndpoint, epConfig);
return loadbalanceEndpoint;
}
return null;
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class SequenceMediatorFactory method createSpecificMediator.
public Mediator createSpecificMediator(OMElement elem, Properties properties) {
SequenceMediator seqMediator = new SequenceMediator();
OMAttribute n = elem.getAttribute(ATT_NAME);
OMAttribute e = elem.getAttribute(ATT_ONERROR);
if (n != null) {
seqMediator.setName(n.getAttributeValue());
if (e != null) {
seqMediator.setErrorHandler(e.getAttributeValue());
}
processAuditStatus(seqMediator, elem);
addChildren(elem, seqMediator, properties);
} else {
n = elem.getAttribute(ATT_KEY);
if (n != null) {
// ValueFactory for creating dynamic or static Value
ValueFactory keyFac = new ValueFactory();
// create dynamic or static key based on OMElement
Value generatedKey = keyFac.createValue(XMLConfigConstants.KEY, elem);
// setKey
seqMediator.setKey(generatedKey);
if (e != null) {
String msg = "A sequence mediator with a reference to another " + "sequence can not have 'ErrorHandler'";
log.error(msg);
throw new SynapseException(msg);
}
} else {
String msg = "A sequence mediator should be a named sequence or a reference " + "to another sequence (i.e. a name attribute or key attribute is required)";
log.error(msg);
throw new SynapseException(msg);
}
}
return seqMediator;
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class StartupFinder method serializeStartup.
/**
* This method will serialize the config using the supplied QName (looking
* up the right class to do it)
*
* @param parent -
* Parent OMElement to which the created element will be added if
* not null
* @param startup -
* Startup to be serialized
* @return OMElement startup
*/
public OMElement serializeStartup(OMElement parent, Startup startup) {
Class<? extends StartupSerializer> cls = serializerMap.get(startup.getTagQName());
if (cls == null) {
String msg = "Unknown startup type referenced by startup element : " + startup.getTagQName();
log.error(msg);
throw new SynapseException(msg);
}
try {
StartupSerializer ss = cls.newInstance();
return ss.serializeStartup(parent, startup);
} catch (InstantiationException e) {
String msg = "Error initializing startup serializer: " + cls;
log.error(msg);
throw new SynapseException(msg, e);
} catch (IllegalAccessException e) {
String msg = "Error initializing startup ser: " + cls;
log.error(msg);
throw new SynapseException(msg, e);
}
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class Axis2Sender method sendBack.
/**
* Send a response back to a client of Synapse
*
* @param smc the Synapse message context sent as the response
*/
public static void sendBack(org.apache.synapse.MessageContext smc) {
if (preventMultipleResponses(smc)) {
return;
}
MessageContext messageContext = ((Axis2MessageContext) smc).getAxis2MessageContext();
// prevent it from going into any other transport sender
if (messageContext.isPropertyTrue(NhttpConstants.SC_ACCEPTED) && messageContext.getTransportOut() != null && !messageContext.getTransportOut().getName().startsWith(Constants.TRANSPORT_HTTP)) {
return;
}
// fault processing code
if (messageContext.isDoingREST() && messageContext.isFault() && isMessagePayloadHasASOAPFault(messageContext)) {
POXUtils.convertSOAPFaultToPOX(messageContext);
}
try {
messageContext.setProperty(SynapseConstants.ISRESPONSE_PROPERTY, Boolean.TRUE);
if (AddressingHelper.isReplyRedirected(messageContext) && !messageContext.getReplyTo().hasNoneAddress()) {
messageContext.setTo(messageContext.getReplyTo());
messageContext.setReplyTo(null);
messageContext.setWSAAction("");
messageContext.setSoapAction("");
messageContext.setProperty(NhttpConstants.IGNORE_SC_ACCEPTED, Constants.VALUE_TRUE);
messageContext.setProperty(AddressingConstants.DISABLE_ADDRESSING_FOR_OUT_MESSAGES, Boolean.FALSE);
}
if (messageContext.getEnvelope().hasFault() && AddressingHelper.isFaultRedirected(messageContext) && (messageContext.getFaultTo() == null || !messageContext.getFaultTo().hasNoneAddress())) {
messageContext.setTo(messageContext.getFaultTo());
messageContext.setFaultTo(null);
messageContext.setWSAAction("");
messageContext.setSoapAction("");
messageContext.setProperty(NhttpConstants.IGNORE_SC_ACCEPTED, Constants.VALUE_TRUE);
messageContext.setProperty(AddressingConstants.DISABLE_ADDRESSING_FOR_OUT_MESSAGES, Boolean.FALSE);
}
String preserveAddressingProperty = (String) smc.getProperty(SynapseConstants.PRESERVE_WS_ADDRESSING);
if (preserveAddressingProperty != null && Boolean.parseBoolean(preserveAddressingProperty)) {
/*Avoiding duplicate addressing headers*/
messageContext.setProperty(AddressingConstants.REPLACE_ADDRESSING_HEADERS, "true");
messageContext.setMessageID(smc.getMessageID());
} else {
MessageHelper.removeAddressingHeaders(messageContext);
messageContext.setMessageID(UIDGenerator.generateURNString());
}
// determine weather we need to preserve the processed headers
String preserveHeaderProperty = (String) smc.getProperty(SynapseConstants.PRESERVE_PROCESSED_HEADERS);
if (preserveHeaderProperty == null || !Boolean.parseBoolean(preserveHeaderProperty)) {
// remove the processed headers
MessageHelper.removeProcessedHeaders(messageContext, (preserveAddressingProperty != null && Boolean.parseBoolean(preserveAddressingProperty)));
}
// temporary workaround for https://issues.apache.org/jira/browse/WSCOMMONS-197
if (messageContext.isEngaged(SynapseConstants.SECURITY_MODULE_NAME) && messageContext.getEnvelope().getHeader() == null) {
SOAPFactory fac = messageContext.isSOAP11() ? OMAbstractFactory.getSOAP11Factory() : OMAbstractFactory.getSOAP12Factory();
fac.createSOAPHeader(messageContext.getEnvelope());
}
Axis2FlexibleMEPClient.clearSecurtityProperties(messageContext.getOptions());
// Invoke Synapse Handlers
Iterator<SynapseHandler> iterator = smc.getEnvironment().getSynapseHandlers().iterator();
while (iterator.hasNext()) {
SynapseHandler handler = iterator.next();
if (!handler.handleResponseOutFlow(smc)) {
return;
}
}
doSOAPFormatConversion(smc);
// handles concurrent throttling based on the messagecontext.
handleConcurrentThrottleCount(smc);
// If the request arrives through an inbound endpoint
if (smc.getProperty(SynapseConstants.IS_INBOUND) != null && (Boolean) smc.getProperty(SynapseConstants.IS_INBOUND)) {
if (smc.getProperty(InboundEndpointConstants.INBOUND_ENDPOINT_RESPONSE_WORKER) != null) {
InboundResponseSender inboundResponseSender = (InboundResponseSender) smc.getProperty(InboundEndpointConstants.INBOUND_ENDPOINT_RESPONSE_WORKER);
inboundResponseSender.sendBack(smc);
} else {
String msg = "Inbound Response Sender not found -" + " Inbound Endpoint may not support sending a response back";
log.error(msg);
throw new SynapseException(msg);
}
} else {
// If the request arrives through a conventional transport listener
AxisEngine.send(messageContext);
}
} catch (AxisFault e) {
handleException(getResponseMessage(messageContext), e);
}
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class MessageContextCreatorForAxis2 method getSynapseMessageContext.
public static MessageContext getSynapseMessageContext(org.apache.axis2.context.MessageContext axisMsgCtx) throws AxisFault {
if (synCfg == null || synEnv == null) {
String msg = "Synapse environment has not initialized properly..";
log.fatal(msg);
throw new SynapseException(msg);
}
// we should try to get the synapse configuration and environment from
// the axis2 configuration.
SynapseEnvironment synapseEnvironment = getSynapseEnvironment(axisMsgCtx);
SynapseConfiguration synapseConfiguration = getSynapseConfiguration(axisMsgCtx);
if (synapseConfiguration != null && synapseEnvironment != null) {
return new Axis2MessageContext(axisMsgCtx, synapseConfiguration, synapseEnvironment);
} else {
return new Axis2MessageContext(axisMsgCtx, synCfg, synEnv);
}
}
Aggregations