use of org.apache.axis2.engine.AxisConfiguration in project wso2-synapse by wso2.
the class DeferredMessageBuilder method getDocument.
public OMElement getDocument(MessageContext msgCtx, InputStream in) throws XMLStreamException, IOException {
/**
* HTTP Delete requests may contain entity body or not. Hence if the request is a HTTP DELETE, we have to verify
* that the payload stream is empty or not.
*/
if (HTTPConstants.HEADER_DELETE.equals(msgCtx.getProperty(Constants.Configuration.HTTP_METHOD)) && RelayUtils.isEmptyPayloadStream(in)) {
msgCtx.setProperty(PassThroughConstants.NO_ENTITY_BODY, Boolean.TRUE);
return TransportUtils.createSOAPEnvelope(null);
}
String contentType = (String) msgCtx.getProperty(Constants.Configuration.CONTENT_TYPE);
String _contentType = getContentType(contentType, msgCtx);
in = HTTPTransportUtils.handleGZip(msgCtx, in);
AxisConfiguration configuration = msgCtx.getConfigurationContext().getAxisConfiguration();
Parameter useFallbackParameter = configuration.getParameter(Constants.Configuration.USE_DEFAULT_FALLBACK_BUILDER);
boolean useFallbackBuilder = false;
if (useFallbackParameter != null) {
useFallbackBuilder = JavaUtils.isTrueExplicitly(useFallbackParameter.getValue(), useFallbackBuilder);
}
Map transportHeaders = (Map) msgCtx.getProperty(MessageContext.TRANSPORT_HEADERS);
String contentLength = null;
String trasferEncoded = null;
if (transportHeaders != null) {
contentLength = (String) transportHeaders.get(HTTP.CONTENT_LEN);
trasferEncoded = (String) transportHeaders.get(HTTP.TRANSFER_ENCODING);
if (contentType.equals(PassThroughConstants.DEFAULT_CONTENT_TYPE) && (contentLength == null || Integer.valueOf(contentLength) == 0) && trasferEncoded == null) {
msgCtx.setProperty(PassThroughConstants.NO_ENTITY_BODY, true);
msgCtx.setProperty(Constants.Configuration.CONTENT_TYPE, "");
msgCtx.setProperty(PassThroughConstants.RELAY_EARLY_BUILD, true);
return new SOAP11Factory().getDefaultEnvelope();
}
}
OMElement element = null;
Builder builder;
if (contentType != null) {
// loading builder from externally..
// builder = configuration.getMessageBuilder(_contentType,useFallbackBuilder);
builder = MessageProcessorSelector.getMessageBuilder(_contentType, msgCtx);
if (builder != null) {
try {
if (contentLength != null && "0".equals(contentLength) && !msgCtx.isDoingREST()) {
element = new org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory().getDefaultEnvelope();
// since we are setting an empty envelop to achieve the empty body, we have to set a different
// content-type other than text/xml, application/soap+xml or any other content-type which will
// invoke the soap builder, otherwise soap builder will get hit and an empty envelope
// will be send out
msgCtx.setProperty(Constants.Configuration.MESSAGE_TYPE, "application/xml");
} else {
element = builder.processDocument(in, contentType, msgCtx);
}
} catch (AxisFault axisFault) {
log.error("Error building message", axisFault);
throw axisFault;
}
}
}
if (element == null) {
if (msgCtx.isDoingREST()) {
try {
element = BuilderUtil.getPOXBuilder(in, null).getDocumentElement();
} catch (XMLStreamException e) {
log.error("Error building message using POX Builder", e);
throw e;
}
} else {
// switch to default
builder = new SOAPBuilder();
try {
if (contentLength != null && "0".equals(contentLength)) {
element = new SOAP11Factory().getDefaultEnvelope();
// since we are setting an empty envelop to achieve the empty body, we have to set a different
// content-type other than text/xml, application/soap+xml or any other content-type which will
// invoke the soap builder, otherwise soap builder will get hit and an empty envelope
// will be send out
msgCtx.setProperty(Constants.Configuration.MESSAGE_TYPE, "application/xml");
} else {
element = builder.processDocument(in, contentType, msgCtx);
}
} catch (AxisFault axisFault) {
log.error("Error building message using SOAP builder");
throw axisFault;
}
}
}
// build the soap headers and body
if (element instanceof SOAPEnvelope) {
SOAPEnvelope env = (SOAPEnvelope) element;
env.hasFault();
}
// setting up original contentType (resetting the content type)
if (contentType != null && !contentType.isEmpty()) {
msgCtx.setProperty(Constants.Configuration.CONTENT_TYPE, contentType);
}
return element;
}
use of org.apache.axis2.engine.AxisConfiguration in project pentaho-platform by pentaho.
the class AxisServiceExecutorTest method setUp.
@Before
public void setUp() throws Exception {
StandaloneSession session = new StandaloneSession("test");
StubServiceSetup serviceSetup = new StubServiceSetup();
serviceSetup.setSession(session);
AxisConfiguration axisCfg = serviceSetup.getAxisConfiguration();
ConfigurationContext configContext = new ConfigurationContext(axisCfg);
serviceSetup.loadServices();
TransportInDescription tIn = new TransportInDescription(DEAFULT_TRANSPOT_PROTOCOL);
StubTransportListener receiver = new StubTransportListener();
tIn.setReceiver(receiver);
axisCfg.addTransportIn(tIn);
TransportOutDescription tOut = new TransportOutDescription(DEAFULT_TRANSPOT_PROTOCOL);
StubTransportSender sender = new StubTransportSender();
tOut.setSender(sender);
axisCfg.addTransportOut(tOut);
AxisWebServiceManager.currentAxisConfiguration = axisCfg;
AxisWebServiceManager.currentAxisConfigContext = configContext;
out = new ByteArrayOutputStream();
IOutputHandler outputHandler = new SimpleOutputHandler(out, false);
outputHandler.setMimeTypeListener(new MimeTypeListener());
contentGenerator = new AxisServiceExecutor();
contentGenerator.setOutputHandler(outputHandler);
contentGenerator.setMessagesList(new ArrayList<String>());
contentGenerator.setSession(session);
contentGenerator.setUrlFactory(new SimpleUrlFactory(BASE_URL + "?"));
assertNotNull("contentGenerator is null", contentGenerator);
assertNotNull("Logger is null", contentGenerator.getLogger());
}
use of org.apache.axis2.engine.AxisConfiguration in project pentaho-platform by pentaho.
the class WsdlPageTest method setUp.
@Before
public void setUp() {
beforeTestCfg = AxisWebServiceManager.currentAxisConfiguration;
beforeTestCtx = AxisWebServiceManager.currentAxisConfigContext;
AxisConfiguration axisCfg = new AxisConfiguration();
AxisWebServiceManager.currentAxisConfiguration = axisCfg;
AxisWebServiceManager.currentAxisConfigContext = new ConfigurationContext(axisCfg);
out = new ByteArrayOutputStream();
IOutputHandler outputHandler = new SimpleOutputHandler(out, false);
outputHandler.setMimeTypeListener(new MimeTypeListener());
StandaloneSession session = new StandaloneSession("test");
StubServiceSetup serviceSetup = new StubServiceSetup();
serviceSetup.setSession(session);
contentGenerator = new AxisServiceWsdlGenerator();
contentGenerator.setOutputHandler(outputHandler);
contentGenerator.setMessagesList(new ArrayList<String>());
contentGenerator.setSession(session);
contentGenerator.setUrlFactory(new SimpleUrlFactory(BASE_URL + "?"));
}
use of org.apache.axis2.engine.AxisConfiguration in project wso2-synapse by wso2.
the class TargetResponseTest method testCompletingStateTransition.
@Test
public void testCompletingStateTransition() throws Exception {
PowerMockito.whenNew(DefaultConnectionReuseStrategy.class).withNoArguments().thenReturn(connStrategy);
PowerMockito.when(connStrategy.keepAlive(any(HttpResponse.class), any(HttpContext.class))).thenReturn(true);
ConfigurationContext configurationContext = new ConfigurationContext(new AxisConfiguration());
WorkerPool workerPool = new NativeWorkerPool(3, 4, 5, 5, "name", "id");
PassThroughTransportMetricsCollector metrics = new PassThroughTransportMetricsCollector(true, "testScheme");
TargetConfiguration targetConfiguration = new TargetConfiguration(configurationContext, null, workerPool, metrics, null);
HttpResponse response = PowerMockito.mock(HttpResponse.class, Mockito.RETURNS_DEEP_STUBS);
NHttpClientConnection conn = PowerMockito.mock(NHttpClientConnection.class, Mockito.RETURNS_DEEP_STUBS);
TargetConnections connections = PowerMockito.mock(TargetConnections.class);
targetConfiguration.setConnections(connections);
PowerMockito.mockStatic(TargetContext.class);
TargetResponse targetResponse = new TargetResponse(targetConfiguration, response, conn, false, false);
try {
targetResponse.start(conn);
// Verify that the following mock method was called exactly 1 time
PowerMockito.verifyStatic(Mockito.times(1));
TargetContext.updateState(conn, ProtocolState.RESPONSE_DONE);
} catch (Exception e) {
logger.error(e);
Assert.fail("Unable to start the target response!");
}
}
use of org.apache.axis2.engine.AxisConfiguration in project wso2-synapse by wso2.
the class TargetResponseTest method testRead.
/**
* Testing reading from a pipe
* @throws Exception
*/
@Test
public void testRead() throws Exception {
ConfigurationContext configurationContext = new ConfigurationContext(new AxisConfiguration());
WorkerPool workerPool = new NativeWorkerPool(3, 4, 5, 5, "name", "id");
PassThroughTransportMetricsCollector metrics = new PassThroughTransportMetricsCollector(true, "testScheme");
TargetConfiguration targetConfiguration = new TargetConfiguration(configurationContext, null, workerPool, metrics, null);
targetConfiguration.build();
HttpResponse response = PowerMockito.mock(HttpResponse.class, Mockito.RETURNS_DEEP_STUBS);
NHttpClientConnection conn = PowerMockito.mock(NHttpClientConnection.class, Mockito.RETURNS_DEEP_STUBS);
ContentDecoder decoder = PowerMockito.mock(ContentDecoder.class);
TargetConnections connections = PowerMockito.mock(TargetConnections.class);
targetConfiguration.setConnections(connections);
PowerMockito.mockStatic(TargetContext.class);
PowerMockito.mockStatic(HttpRequest.class);
HttpRequest httpRequest = new BasicHttpRequest("GET", "test.com");
PowerMockito.when(conn.getContext().getAttribute("http.request")).thenReturn(httpRequest);
TargetContext cntxt = new TargetContext(targetConfiguration);
PowerMockito.when(TargetContext.get(any(NHttpClientConnection.class))).thenReturn(cntxt);
PowerMockito.when(decoder.read(any(ByteBuffer.class))).thenReturn(12);
PowerMockito.when(decoder.isCompleted()).thenReturn(true);
TargetResponse targetResponse = new TargetResponse(targetConfiguration, response, conn, true, false);
targetResponse.start(conn);
int result = targetResponse.read(conn, decoder);
Assert.assertEquals(12, result);
}
Aggregations