use of org.apache.synapse.core.axis2.Axis2SynapseEnvironment in project wso2-synapse by wso2.
the class HessianMessageBuilderTest method testProcessDocumentWithSynEnv.
public void testProcessDocumentWithSynEnv() throws IOException {
SynapseEnvironment synEnv = new Axis2SynapseEnvironment(new ConfigurationContext(new AxisConfiguration()), new SynapseConfiguration());
testProcessDocument(synEnv);
}
use of org.apache.synapse.core.axis2.Axis2SynapseEnvironment in project wso2-synapse by wso2.
the class HessianMessageBuilderTest method testProcessDocumentFaultWithSynEnv.
public void testProcessDocumentFaultWithSynEnv() throws IOException {
SynapseEnvironment synEnv = new Axis2SynapseEnvironment(new ConfigurationContext(new AxisConfiguration()), new SynapseConfiguration());
testProcessDocumentFault(synEnv);
}
use of org.apache.synapse.core.axis2.Axis2SynapseEnvironment in project wso2-synapse by wso2.
the class SynapseConfiguration method initCarbonTenantConfigurator.
/**
* @param se
*/
private void initCarbonTenantConfigurator(SynapseEnvironment se) {
Axis2SynapseEnvironment axis2SynapseEnvironment = (Axis2SynapseEnvironment) se;
// Tenant info configurator
TenantInfoConfigurator configurator = TenantInfoConfigProvider.getConfigurator();
axis2SynapseEnvironment.setTenantInfoConfigurator(configurator);
TenantInfoInitiator tenantInfoInitiator = TenantInfoInitiatorProvider.getTenantInfoInitiator();
axis2SynapseEnvironment.setTenantInfoInitiator(tenantInfoInitiator);
}
use of org.apache.synapse.core.axis2.Axis2SynapseEnvironment in project wso2-synapse by wso2.
the class MessageInjector method execute.
/**
* This will be invoked by the scheduler to inject the message
* in to the SynapseEnvironment
*/
public void execute() {
if (log.isDebugEnabled()) {
log.debug("execute");
}
if (synapseEnvironment == null) {
handleError("Synapse Environment not set");
return;
}
if (synapseEnvironment.getTaskManager() != null && !synapseEnvironment.getTaskManager().isInitialized()) {
log.warn("Task Manager not initialized. Not executing the cycle");
return;
}
if (message == null && registryKey == null) {
handleError("message or registry-key not set");
return;
}
if (INJECT_TO_PROXY.equalsIgnoreCase(injectTo)) {
if (proxyName == null || proxyName.equals("")) {
handleError("Proxy service name not specified");
}
// Prepare axis2 message context
org.apache.axis2.context.MessageContext axis2MsgCtx = new org.apache.axis2.context.MessageContext();
ConfigurationContext configurationContext = ((Axis2SynapseEnvironment) synapseEnvironment).getAxis2ConfigurationContext();
axis2MsgCtx.setConfigurationContext(configurationContext);
axis2MsgCtx.setIncomingTransportName(Constants.TRANSPORT_LOCAL);
axis2MsgCtx.setServerSide(true);
axis2MsgCtx.setMessageID(UIDGenerator.generateURNString());
try {
AxisService axisService = configurationContext.getAxisConfiguration().getService(proxyName);
if (axisService == null) {
handleError("Proxy Service: " + proxyName + " not found");
}
axis2MsgCtx.setAxisService(axisService);
} catch (AxisFault axisFault) {
handleError("Error occurred while attempting to find the Proxy Service");
}
if (to != null) {
axis2MsgCtx.setTo(new EndpointReference(to));
}
SOAPEnvelope envelope = null;
if (format == null) {
envelope = OMAbstractFactory.getSOAP12Factory().createSOAPEnvelope();
} else if (SOAP11_FORMAT.equalsIgnoreCase(format)) {
envelope = OMAbstractFactory.getSOAP11Factory().createSOAPEnvelope();
} else if (SOAP12_FORMAT.equalsIgnoreCase(format)) {
envelope = OMAbstractFactory.getSOAP12Factory().createSOAPEnvelope();
} else if (POX_FORMAT.equalsIgnoreCase(format)) {
envelope = OMAbstractFactory.getSOAP12Factory().createSOAPEnvelope();
axis2MsgCtx.setDoingREST(true);
} else if (GET_FORMAT.equalsIgnoreCase(format)) {
envelope = OMAbstractFactory.getSOAP12Factory().createSOAPEnvelope();
axis2MsgCtx.setDoingREST(true);
axis2MsgCtx.setProperty(Constants.Configuration.HTTP_METHOD, Constants.Configuration.HTTP_METHOD_GET);
} else {
handleError("incorrect format specified");
}
try {
PayloadHelper.setXMLPayload(envelope, message.cloneOMElement());
axis2MsgCtx.setEnvelope(envelope);
} catch (AxisFault axisFault) {
handleError("Error in setting the message payload : " + message);
}
if (soapAction != null) {
axis2MsgCtx.setSoapAction(soapAction);
}
try {
if (log.isDebugEnabled()) {
log.debug("injecting message to proxy service : " + proxyName);
}
AxisEngine.receive(axis2MsgCtx);
} catch (AxisFault axisFault) {
handleError("Error occurred while invoking proxy service : " + proxyName);
}
} else {
MessageContext mc = synapseEnvironment.createMessageContext();
mc.setMessageID(UIDGenerator.generateURNString());
mc.pushFaultHandler(new MediatorFaultHandler(mc.getFaultSequence()));
if (to != null) {
mc.setTo(new EndpointReference(to));
}
if (registryKey == null) {
if (format == null) {
PayloadHelper.setXMLPayload(mc, message.cloneOMElement());
} else {
try {
if (SOAP11_FORMAT.equalsIgnoreCase(format)) {
mc.setEnvelope(OMAbstractFactory.getSOAP11Factory().createSOAPEnvelope());
} else if (SOAP12_FORMAT.equalsIgnoreCase(format)) {
mc.setEnvelope(OMAbstractFactory.getSOAP12Factory().createSOAPEnvelope());
} else if (POX_FORMAT.equalsIgnoreCase(format)) {
mc.setDoingPOX(true);
} else if (GET_FORMAT.equalsIgnoreCase(format)) {
mc.setDoingGET(true);
}
PayloadHelper.setXMLPayload(mc, message.cloneOMElement());
} catch (AxisFault axisFault) {
handleError("Error in setting the message payload : " + message);
}
}
} else {
Object entry = mc.getEntry(registryKey);
if (entry == null) {
handleError("Key " + registryKey + " not found ");
}
String text = "";
if (entry instanceof OMElement) {
OMElement e = (OMElement) entry;
removeIndentations(e);
text = e.toString();
} else if (entry instanceof OMText) {
text = ((OMText) entry).getText();
} else if (entry instanceof String) {
text = (String) entry;
}
OMElement omXML = null;
try {
omXML = AXIOMUtil.stringToOM(text);
if (format == null) {
PayloadHelper.setXMLPayload(mc, omXML);
} else {
if (SOAP11_FORMAT.equalsIgnoreCase(format)) {
mc.setEnvelope(OMAbstractFactory.getSOAP11Factory().createSOAPEnvelope());
} else if (SOAP12_FORMAT.equalsIgnoreCase(format)) {
mc.setEnvelope(OMAbstractFactory.getSOAP12Factory().createSOAPEnvelope());
} else if (POX_FORMAT.equalsIgnoreCase(format)) {
mc.setDoingPOX(true);
} else if (GET_FORMAT.equalsIgnoreCase(format)) {
mc.setDoingGET(true);
}
PayloadHelper.setXMLPayload(mc, omXML);
}
} catch (XMLStreamException e) {
handleError("Error parsing XML for JSON conversion, please check your property values return valid XML");
} catch (AxisFault axisFault) {
handleError("Error in setting the message payload : " + omXML);
}
}
if (soapAction != null) {
mc.setSoapAction(soapAction);
}
// Adding runtime properties to SynapseMessageContext, if exists
if (runtimeProperties != null && runtimeProperties.size() > 0) {
for (Map.Entry<String, Object> entry : runtimeProperties.entrySet()) {
mc.setProperty(entry.getKey(), entry.getValue());
}
}
if (INJECT_TO_SEQUENCE.equalsIgnoreCase(injectTo)) {
if (sequenceName == null || sequenceName.equals("")) {
handleError("Sequence name not specified");
}
SequenceMediator seq = (SequenceMediator) synapseEnvironment.getSynapseConfiguration().getSequence(sequenceName);
if (seq != null) {
if (log.isDebugEnabled()) {
log.debug("injecting message to sequence : " + sequenceName);
}
mc.pushFaultHandler(new MediatorFaultHandler(mc.getFaultSequence()));
synapseEnvironment.injectAsync(mc, seq);
} else {
handleError("Sequence: " + sequenceName + " not found");
}
} else {
if (log.isDebugEnabled()) {
log.debug("injecting message to main sequence");
}
synapseEnvironment.injectMessage(mc);
}
}
}
use of org.apache.synapse.core.axis2.Axis2SynapseEnvironment in project wso2-synapse by wso2.
the class ResourceTest method testFaultSequence.
public void testFaultSequence() throws Exception {
API api = new API("TestAPI", "/test");
Resource resource = new Resource();
resource.setDispatcherHelper(new URITemplateHelper("/~{user}"));
SequenceMediator inSequence = getTestSequence("seq.in", "seq.in.value");
((PropertyMediator) inSequence.getChild(0)).setScope("axis2");
XSLTMediator xsltMediator = new XSLTMediator();
xsltMediator.setXsltKey(new Value("/bogus/key"));
inSequence.addChild(xsltMediator);
resource.setInSequence(inSequence);
SequenceMediator faultSequence = getTestSequence("seq.fault", "seq.fault.value");
((PropertyMediator) faultSequence.getChild(0)).setScope("axis2");
resource.setFaultSequence(faultSequence);
api.addResource(resource);
SynapseConfiguration synapseConfig = new SynapseConfiguration();
synapseConfig.addAPI(api.getName(), api);
synapseConfig.addSequence("main", getTestSequence("main.in", "main.value"));
MessageContext synCtx = getMessageContext(synapseConfig, false, "/test/~foo", "GET");
MessageContextCreatorForAxis2.setSynConfig(synapseConfig);
MessageContextCreatorForAxis2.setSynEnv(synCtx.getEnvironment());
org.apache.axis2.context.MessageContext mc = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
mc.setConfigurationContext(((Axis2SynapseEnvironment) synCtx.getEnvironment()).getAxis2ConfigurationContext());
new SynapseMessageReceiver().receive(mc);
assertEquals("seq.in.value", mc.getProperty("seq.in"));
assertEquals("seq.fault.value", mc.getProperty("seq.fault"));
}
Aggregations