use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class ClassMediator method mediate.
/**
* Don't use a new instance... do one instance of the object per instance of
* this mediator
*
* @param synCtx
* the message context
* @return as per standard semantics
*/
public boolean mediate(MessageContext synCtx) {
if (synCtx.getEnvironment().isDebuggerEnabled()) {
if (super.divertMediationRoute(synCtx)) {
return true;
}
}
SynapseLog synLog = getLog(synCtx);
if (synLog.isTraceOrDebugEnabled()) {
synLog.traceOrDebug("Start : Class mediator");
if (synLog.isTraceTraceEnabled()) {
synLog.traceTrace("Message : " + synCtx.getEnvelope());
}
}
if (synLog.isTraceOrDebugEnabled()) {
synLog.traceOrDebug("invoking : " + mediator.getClass() + ".mediate()");
}
boolean result;
try {
for (MediatorProperty property : properties) {
String propertyValue = property.getValue() != null ? property.getValue() : property.getEvaluatedExpression(synCtx);
PropertyHelper.setInstanceProperty(property.getName(), propertyValue, mediator);
}
result = mediator.mediate(synCtx);
} catch (Exception e) {
// so that the fault handler will be invoked
throw new SynapseException("Error occured in the mediation of the class mediator", e);
}
synLog.traceOrDebug("End : Class mediator");
return result;
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class MessageConverter method toStorableMessage.
/**
* Converts a Synapse Message Context to a representation that can be stored in the
* Message store queue.
* @param synCtx Source Synapse message context.
* @return Storable representation of the provided message context.
*/
public static StorableMessage toStorableMessage(MessageContext synCtx) {
StorableMessage message = new StorableMessage();
Axis2Message axis2msg = new Axis2Message();
SynapseMessage synMsg = new SynapseMessage();
Axis2MessageContext axis2MessageContext;
if (synCtx instanceof Axis2MessageContext) {
axis2MessageContext = (Axis2MessageContext) synCtx;
org.apache.axis2.context.MessageContext msgCtx = axis2MessageContext.getAxis2MessageContext();
axis2msg.setMessageID(UUIDGenerator.getUUID());
if (msgCtx.getAxisOperation() != null) {
axis2msg.setOperationAction(msgCtx.getAxisOperation().getSoapAction());
axis2msg.setOperationName(msgCtx.getAxisOperation().getName());
}
if (JsonUtil.hasAJsonPayload(msgCtx)) {
axis2msg.setJsonStream(JsonUtil.jsonPayloadToByteArray(msgCtx));
}
axis2msg.setAction(msgCtx.getOptions().getAction());
if (msgCtx.getAxisService() != null) {
axis2msg.setService(msgCtx.getAxisService().getName());
}
if (msgCtx.getRelatesTo() != null) {
axis2msg.setRelatesToMessageId(msgCtx.getRelatesTo().getValue());
}
if (msgCtx.getReplyTo() != null) {
axis2msg.setReplyToAddress(msgCtx.getReplyTo().getAddress());
}
if (msgCtx.getFaultTo() != null) {
axis2msg.setFaultToAddress(msgCtx.getFaultTo().getAddress());
}
if (msgCtx.getTo() != null) {
axis2msg.setToAddress(msgCtx.getTo().getAddress());
}
axis2msg.setDoingPOX(msgCtx.isDoingREST());
axis2msg.setDoingMTOM(msgCtx.isDoingMTOM());
axis2msg.setDoingSWA(msgCtx.isDoingSwA());
String soapEnvelope = msgCtx.getEnvelope().toString();
axis2msg.setSoapEnvelope(soapEnvelope);
axis2msg.setFLOW(msgCtx.getFLOW());
if (msgCtx.getTransportIn() != null) {
axis2msg.setTransportInName(msgCtx.getTransportIn().getName());
}
if (msgCtx.getTransportOut() != null) {
axis2msg.setTransportOutName(msgCtx.getTransportOut().getName());
}
Iterator<String> abstractMCProperties = msgCtx.getPropertyNames();
Map<String, Object> copy = new HashMap<String, Object>(msgCtx.getProperties().size());
while (abstractMCProperties.hasNext()) {
String propertyName = abstractMCProperties.next();
Object propertyValue = msgCtx.getProperty(propertyName);
if (propertyValue instanceof String || propertyValue instanceof Boolean || propertyValue instanceof Integer || propertyValue instanceof Double || propertyValue instanceof Character) {
copy.put(propertyName, propertyValue);
}
if (JMS_PRIORITY.equals(propertyName)) {
if (propertyValue instanceof Integer) {
message.setPriority((Integer) propertyValue);
} else if (propertyValue instanceof String) {
try {
int value = Integer.parseInt((String) propertyValue);
message.setPriority(value);
} catch (NumberFormatException e) {
}
}
}
}
axis2msg.addProperty(ABSTRACT_MC_PROPERTIES, copy);
Map<String, String> transportHeaders = getTransportHeaders(msgCtx);
axis2msg.addProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS, transportHeaders);
Iterator<String> properties = msgCtx.getProperties().keySet().iterator();
while (properties.hasNext()) {
String key = properties.next();
Object value = msgCtx.getProperty(key);
if (value instanceof String) {
axis2msg.addProperty(key, value);
}
}
message.setAxis2message(axis2msg);
synMsg.setFaultResponse(synCtx.isFaultResponse());
synMsg.setTracingState(synCtx.getTracingState());
synMsg.setMessageFlowTracingState(synCtx.getMessageFlowTracingState());
synMsg.setResponse(synCtx.isResponse());
properties = synCtx.getPropertyKeySet().iterator();
while (properties.hasNext()) {
String key = properties.next();
Object value = synCtx.getProperty(key);
if (value instanceof String) {
synMsg.addProperty(key, (String) value);
}
if (value instanceof ArrayList && ((ArrayList) value).size() > 0 && ((ArrayList) value).get(0) instanceof OMElement) {
OMElement elem = ((OMElement) ((ArrayList) value).get(0));
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
elem.serialize(bos);
byte[] bytes = bos.toByteArray();
synMsg.addPropertyObject(OM_ELEMENT_PREFIX + key, bytes);
} catch (XMLStreamException e) {
logger.error("Error while converting OMElement to byte array", e);
}
}
}
message.setSynapseMessage(synMsg);
} else {
throw new SynapseException("Cannot store message to store.");
}
return message;
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class JDBCMessageStore method messageContentResultSet.
/**
*<p>
* Return the messages corresponding to the provided statement.
*</p>
*
* @param resultSet the result-set obtained from the statement.
* @param statement the SQL statement results are obtained for.
* @return the content of the messages.
* @throws SQLException during an error encountered when accessing the database.
*/
protected List<Map> messageContentResultSet(ResultSet resultSet, String statement) throws SQLException {
ArrayList<Map> elements = new ArrayList<>();
while (resultSet.next()) {
try {
HashMap<String, Object> rowData = new HashMap<>();
byte[] msgObj = resultSet.getBytes(MESSAGE_COLUMN_NAME);
MessageContext responseMessageContext = deserializeMessage(msgObj);
rowData.put(MESSAGE_COLUMN_NAME, responseMessageContext);
elements.add(rowData);
} catch (SQLException e) {
String message = "Error executing statement : " + statement + " against DataSource : " + jdbcConfiguration.getDSName();
throw new SynapseException(message, e);
}
}
return elements;
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class ResequenceMessageStore method getMessageWithMinimumId.
/**
* <p>
* Gets message with minimum sequence id.
* </p>
*
* @param resultSet the results returned from the query.
* @param statement statement which is executed to obtain the results.
* @return message which has the minimum sequence id.
* @throws SQLException if an error is returned from the db while obtaining the sequence id value.
*/
private List<Map> getMessageWithMinimumId(ResultSet resultSet, String statement) throws SQLException {
ArrayList<Map> elements = new ArrayList<>();
while (resultSet.next()) {
try {
HashMap<String, Object> rowData = new HashMap<>();
byte[] msgObj = resultSet.getBytes(MESSAGE_COLUMN_NAME);
MessageContext responseMessageContext = deserializeMessage(msgObj);
rowData.put(MESSAGE_COLUMN_NAME, responseMessageContext);
long sequenceId = resultSet.getLong(ResequenceMessageStoreConstants.SEQUENCE_ID_COLUMN);
rowData.put(ResequenceMessageStoreConstants.SEQUENCE_ID_COLUMN, sequenceId);
elements.add(rowData);
} catch (SQLException e) {
String message = "Error executing statement : " + statement + " against " + "DataSource : " + getJdbcConfiguration().getDSName();
throw new SynapseException(message, e);
}
}
return elements;
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class XSLTMediator method addFeature.
/**
* Add a feature to be set on the {@link TransformerFactory} used by this mediator instance.
* This method can also be used to enable some Synapse specific optimizations and
* enhancements as described in the documentation of this class.
*
* @param featureName The name of the feature
* @param isFeatureEnable the desired state of the feature
*
* @see TransformerFactory#setFeature(String, boolean)
* @see XSLTMediator
*/
public void addFeature(String featureName, boolean isFeatureEnable) {
MediatorProperty mp = new MediatorProperty();
mp.setName(featureName);
if (isFeatureEnable) {
mp.setValue("true");
} else {
mp.setValue("false");
}
transformerFactoryFeatures.add(mp);
if (USE_DOM_SOURCE_AND_RESULTS.equals(featureName)) {
if (isFeatureEnable) {
sourceBuilderFactory = new DOOMSourceBuilderFactory();
resultBuilderFactory = new DOOMResultBuilderFactory();
}
} else {
try {
transFact.setFeature(featureName, isFeatureEnable);
} catch (TransformerConfigurationException e) {
String msg = "Error occurred when setting features to the TransformerFactory";
log.error(msg, e);
throw new SynapseException(msg, e);
}
}
}
Aggregations