Search in sources :

Example 16 with Builder

use of org.apache.axis2.builder.Builder in project wso2-synapse by wso2.

the class BinaryRelayBuilderTest method testProcessDocument.

/**
 * This method tests whether it is possible to create OMElement from the input stream
 * @throws Exception
 */
@Test
public void testProcessDocument() throws Exception {
    InputStream in = new ByteArrayInputStream("testString".getBytes());
    String contentType = "application/xml";
    MessageContext messageContext = new MessageContext();
    BinaryRelayBuilder builder = new BinaryRelayBuilder();
    OMElement response = builder.processDocument(in, contentType, messageContext);
    String expected = "<?xml version='1.0' encoding='utf-8'?>" + "<soapenv:Envelope xmlns:soapenv=\"http://www.w3.org/2003/05/soap-envelope\">" + "<soapenv:Body><ns:binary xmlns:ns=\"http://ws.apache.org/commons/ns/payload\">dGVzdFN0cmluZw==</ns:binary>" + "</soapenv:Body></soapenv:Envelope>";
    Assert.assertEquals("Couldn't create OMElement!", expected, response.toString());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OMElement(org.apache.axiom.om.OMElement) MessageContext(org.apache.axis2.context.MessageContext) Test(org.junit.Test)

Example 17 with Builder

use of org.apache.axis2.builder.Builder in project wso2-synapse by wso2.

the class RelayUtilsTest method testShouldOverwriteContentType.

@Test
public void testShouldOverwriteContentType() {
    MessageContext msgContext1 = Mockito.mock(MessageContext.class);
    TargetRequest tgtRequest1 = Mockito.mock(TargetRequest.class);
    Mockito.when(msgContext1.getProperty(PassThroughConstants.MESSAGE_BUILDER_INVOKED)).thenReturn(Boolean.FALSE);
    Mockito.when(msgContext1.getProperty(PassThroughConstants.NO_ENTITY_BODY)).thenReturn(Boolean.TRUE);
    boolean result = RelayUtils.shouldOverwriteContentType(msgContext1, tgtRequest1);
    Assert.assertFalse("Content type has been chosen to overwrite when builder is not invoked and " + "no incoming content type is present", result);
    Mockito.when(msgContext1.getProperty(PassThroughConstants.MESSAGE_BUILDER_INVOKED)).thenReturn(Boolean.TRUE);
    Mockito.when(msgContext1.getProperty(PassThroughConstants.NO_ENTITY_BODY)).thenReturn(Boolean.FALSE);
    result = RelayUtils.shouldOverwriteContentType(msgContext1, tgtRequest1);
    Assert.assertTrue("Content type has not been chosen to overwrite when there's a body " + "and builder is invoked", result);
    Map<String, LinkedHashSet<String>> headers = new HashMap<>();
    LinkedHashSet<String> contentTypeHeaderSet = new LinkedHashSet<>();
    contentTypeHeaderSet.add("application/json");
    headers.put("Content-Type", contentTypeHeaderSet);
    Mockito.when(tgtRequest1.getHeaders()).thenReturn(headers);
    result = RelayUtils.shouldOverwriteContentType(msgContext1, tgtRequest1);
    Assert.assertTrue("Content type has not been chosen to overwrite when there's a content type header", result);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) MessageContext(org.apache.axis2.context.MessageContext) TargetRequest(org.apache.synapse.transport.passthru.TargetRequest) Test(org.junit.Test)

Example 18 with Builder

use of org.apache.axis2.builder.Builder in project wso2-synapse by wso2.

the class VFSTransportTest method suite.

public static TestSuite suite() throws Exception {
    // TODO: the VFS listener doesn't like reuseResources == true...
    ManagedTestSuite suite = new ManagedTestSuite(VFSTransportTest.class, false);
    // Since VFS has no Content-Type header, SwA is not supported.
    suite.addExclude("(test=AsyncSwA)");
    TransportTestSuiteBuilder builder = new TransportTestSuiteBuilder(suite);
    ContentTypeServiceConfigurator cfgtr = new ContentTypeServiceConfigurator("transport.vfs.ContentType");
    builder.addEnvironment(new VFSTestEnvironment(new File("target/vfs3")), new VFSTransportDescriptionFactory());
    builder.addAsyncChannel(new VFSAsyncFileChannel("req/in"));
    builder.addAxisAsyncTestClient(new AxisAsyncTestClient());
    builder.addByteArrayAsyncTestClient(new VFSAsyncClient());
    builder.addAxisAsyncEndpoint(new AxisAsyncEndpoint(), cfgtr);
    builder.addByteArrayAsyncEndpoint(new VFSMockAsyncEndpoint());
    builder.addRequestResponseChannel(new VFSRequestResponseFileChannel("req/in", "req/out"));
    builder.addByteArrayRequestResponseTestClient(new VFSRequestResponseClient());
    builder.addEchoEndpoint(new AxisEchoEndpoint(), cfgtr);
    builder.build();
    // suite.addTest(new MinConcurrencyTest(server, new AsyncChannel[] { new VFSFileChannel("req/in1"), new VFSFileChannel("req/in2") }, 1, true, env, tdf));
    return suite;
}
Also used : AxisAsyncEndpoint(org.apache.axis2.transport.testkit.axis2.endpoint.AxisAsyncEndpoint) ManagedTestSuite(org.apache.axis2.transport.testkit.ManagedTestSuite) AxisAsyncTestClient(org.apache.axis2.transport.testkit.axis2.client.AxisAsyncTestClient) AxisEchoEndpoint(org.apache.axis2.transport.testkit.axis2.endpoint.AxisEchoEndpoint) ContentTypeServiceConfigurator(org.apache.axis2.transport.testkit.axis2.endpoint.ContentTypeServiceConfigurator) File(java.io.File) TransportTestSuiteBuilder(org.apache.axis2.transport.testkit.TransportTestSuiteBuilder)

Example 19 with Builder

use of org.apache.axis2.builder.Builder in project pentaho-platform by pentaho.

the class AbstractAxisConfigurator method getAxisConfiguration.

/**
 * Creates the AxisConfiguration object using an XML document. Subclasses of this class must provide the XML via an
 * input stream. The concrete implementation can store the XML file wherever it wants as we only need an InputStream
 */
public AxisConfiguration getAxisConfiguration() throws AxisFault {
    if (axisConfig != null) {
        // we have already initialized
        return axisConfig;
    }
    try {
        // create a new AxisConfiguration
        axisConfig = new AxisConfiguration();
        // get the config XML input stream
        InputStream in = getConfigXml();
        // build the configuration
        AxisConfigBuilder builder = new AxisConfigBuilder(in, axisConfig, null);
        builder.populateConfig();
    } catch (Exception e) {
        e.printStackTrace();
        throw AxisFault.makeFault(e);
    }
    // set this object as the Axis configurator. Axis will call loadServices().
    axisConfig.setConfigurator(this);
    return axisConfig;
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) InputStream(java.io.InputStream) AxisConfigBuilder(org.apache.axis2.deployment.AxisConfigBuilder)

Example 20 with Builder

use of org.apache.axis2.builder.Builder in project wso2-synapse by wso2.

the class MultiSSLProfileReloader method reloadSSLProfileConfig.

public String reloadSSLProfileConfig() throws AxisFault {
    Parameter oldParameter = transportInDescription.getParameter("SSLProfiles");
    Parameter profilePathParam = transportInDescription.getParameter("SSLProfilesConfigPath");
    if (oldParameter != null && profilePathParam != null) {
        transportInDescription.removeParameter(oldParameter);
        ServerConnFactoryBuilder builder = new ServerConnFactoryBuilder(transportInDescription, null);
        TransportInDescription loadedTransportIn = builder.loadMultiProfileSSLConfig();
        if (loadedTransportIn != null) {
            transportInDescription = loadedTransportIn;
            httpCoreNIOMultiSSLListener.reload(transportInDescription);
            return "SSLProfiles reloaded Successfully";
        }
        // add old value back
        transportInDescription.addParameter(oldParameter);
    }
    return "Failed to reload SSLProfiles";
}
Also used : Parameter(org.apache.axis2.description.Parameter) TransportInDescription(org.apache.axis2.description.TransportInDescription) ServerConnFactoryBuilder(org.apache.synapse.transport.nhttp.config.ServerConnFactoryBuilder)

Aggregations

OMElement (org.apache.axiom.om.OMElement)24 MessageContext (org.apache.axis2.context.MessageContext)15 Builder (org.apache.axis2.builder.Builder)13 AxisFault (org.apache.axis2.AxisFault)11 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 SOAPBuilder (org.apache.axis2.builder.SOAPBuilder)8 InputStream (java.io.InputStream)7 HashMap (java.util.HashMap)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 EndpointReference (org.apache.axis2.addressing.EndpointReference)5 ContentType (javax.mail.internet.ContentType)4 ParseException (javax.mail.internet.ParseException)4 XMLStreamException (javax.xml.stream.XMLStreamException)4 Parameter (org.apache.axis2.description.Parameter)4 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)4 MessageFormatter (org.apache.axis2.transport.MessageFormatter)4 ManagedTestSuite (org.apache.axis2.transport.testkit.ManagedTestSuite)4 TransportTestSuiteBuilder (org.apache.axis2.transport.testkit.TransportTestSuiteBuilder)4 AxisAsyncTestClient (org.apache.axis2.transport.testkit.axis2.client.AxisAsyncTestClient)4