Search in sources :

Example 61 with InputStream

use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project ballerina by ballerina-lang.

the class MimeUtilityFunctionTest method testLargePayload.

@Test(description = "When the payload exceeds 2MB check whether the response received back matches  " + "the original content length")
public void testLargePayload() {
    String path = "/test/largepayload";
    try {
        ByteChannel byteChannel = TestUtil.openForReading("datafiles/io/text/fileThatExceeds2MB.txt");
        Channel channel = new MockByteChannel(byteChannel, 10);
        CharacterChannel characterChannel = new CharacterChannel(channel, StandardCharsets.UTF_8.name());
        String responseValue = characterChannel.readAll();
        characterChannel.close();
        HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "POST", responseValue);
        HTTPCarbonMessage response = Services.invokeNew(serviceResult, "mockEP", cMsg);
        Assert.assertNotNull(response, "Response message not found");
        InputStream inputStream = new HttpMessageDataStreamer(response).getInputStream();
        Assert.assertNotNull(inputStream, "Inputstream is null");
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        MimeUtil.writeInputToOutputStream(inputStream, outputStream);
        Assert.assertEquals(outputStream.size(), 2323779);
    } catch (IOException | URISyntaxException e) {
        log.error("Error occurred in testLargePayload", e.getMessage());
    }
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) InputStream(java.io.InputStream) Channel(org.ballerinalang.nativeimpl.io.channels.base.Channel) MockByteChannel(org.ballerinalang.test.nativeimpl.functions.io.MockByteChannel) ByteChannel(java.nio.channels.ByteChannel) CharacterChannel(org.ballerinalang.nativeimpl.io.channels.base.CharacterChannel) BString(org.ballerinalang.model.values.BString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) MockByteChannel(org.ballerinalang.test.nativeimpl.functions.io.MockByteChannel) MockByteChannel(org.ballerinalang.test.nativeimpl.functions.io.MockByteChannel) ByteChannel(java.nio.channels.ByteChannel) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) CharacterChannel(org.ballerinalang.nativeimpl.io.channels.base.CharacterChannel) Test(org.testng.annotations.Test)

Example 62 with InputStream

use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project ballerina by ballerina-lang.

the class MultipartEncoderTest method testNestedPartsInOutResponse.

@Test(description = "Retrieve body parts from the Request and send it across Response")
public void testNestedPartsInOutResponse() {
    String path = "/multipart/nested_parts_in_outresponse";
    HTTPTestRequest inRequestMsg = Util.createNestedPartRequest(path);
    HTTPCarbonMessage response = Services.invokeNew(serviceResult, MOCK_ENDPOINT_NAME, inRequestMsg);
    Assert.assertNotNull(response, "Response message not found");
    InputStream inputStream = new HttpMessageDataStreamer(response).getInputStream();
    try {
        List<MIMEPart> mimeParts = MultipartDecoder.decodeBodyParts(inRequestMsg.getHeader(HttpHeaderNames.CONTENT_TYPE.toString()), inputStream);
        Assert.assertEquals(mimeParts.size(), 2);
        List<MIMEPart> childParts = MultipartDecoder.decodeBodyParts(mimeParts.get(1).getContentType(), mimeParts.get(1).readOnce());
        Assert.assertEquals(childParts.size(), 2);
    } catch (MimeTypeParseException e) {
        log.error("Error occurred while testing mulitpart/mixed encoding", e.getMessage());
    }
}
Also used : MimeTypeParseException(javax.activation.MimeTypeParseException) HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) MIMEPart(org.jvnet.mimepull.MIMEPart) Test(org.testng.annotations.Test)

Example 63 with InputStream

use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project ballerina by ballerina-lang.

the class MultipartEncoderTest method testMultipartsInOutResponse.

@Test(description = "Test whether the encoded body parts can be sent through Response, with a given boundary")
public void testMultipartsInOutResponse() {
    String path = "/multipart/encode_out_response";
    HTTPTestRequest inRequestMsg = MessageUtils.generateHTTPMessage(path, HttpConstants.HTTP_METHOD_GET);
    HTTPCarbonMessage response = Services.invokeNew(serviceResult, MOCK_ENDPOINT_NAME, inRequestMsg);
    Assert.assertNotNull(response, "Response message not found");
    InputStream inputStream = new HttpMessageDataStreamer(response).getInputStream();
    try {
        List<MIMEPart> mimeParts = MultipartDecoder.decodeBodyParts("multipart/mixed; boundary=" + "e3a0b9ad7b4e7cdb", inputStream);
        Assert.assertEquals(mimeParts.size(), 4);
        BStruct bodyPart = Util.getEntityStruct(result);
        validateBodyPartContent(mimeParts, bodyPart);
    } catch (MimeTypeParseException e) {
        log.error("Error occurred while testing mulitpart/mixed encoding", e.getMessage());
    } catch (IOException e) {
        log.error("Error occurred while decoding binary part", e.getMessage());
    }
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) MimeTypeParseException(javax.activation.MimeTypeParseException) HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) IOException(java.io.IOException) MIMEPart(org.jvnet.mimepull.MIMEPart) Test(org.testng.annotations.Test)

Example 64 with InputStream

use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project charon by wso2.

the class SCIMUserSchemaExtensionBuilder method readConfiguration.

/*
     * This method reads configuration file and stores in the memory as an
     * configuration map
     *
     * @param configFilePath
     * @throws CharonException
     */
private void readConfiguration(String configFilePath) throws CharonException {
    File provisioningConfig = new File(configFilePath);
    try {
        InputStream inputStream = new FileInputStream(provisioningConfig);
        // Scanner scanner = new Scanner(new FileInputStream(provisioningConfig));
        Scanner scanner = new Scanner(inputStream, "utf-8").useDelimiter("\\A");
        String jsonString = scanner.hasNext() ? scanner.next() : "";
        JSONArray attributeConfigArray = new JSONArray(jsonString);
        for (int index = 0; index < attributeConfigArray.length(); ++index) {
            JSONObject attributeConfig = attributeConfigArray.getJSONObject(index);
            ExtensionAttributeSchemaConfig attrubteConfig = new ExtensionAttributeSchemaConfig(attributeConfig);
            extensionConfig.put(attrubteConfig.getName(), attrubteConfig);
            /**
             * NOTE: Assume last config is the root config
             */
            if (index == attributeConfigArray.length() - 1) {
                extensionRootAttributeName = attrubteConfig.getName();
            }
        }
        inputStream.close();
    } catch (FileNotFoundException e) {
        throw new CharonException(SCIMConfigConstants.SCIM_SCHEMA_EXTENSION_CONFIG + " file not found!", e);
    } catch (JSONException e) {
        throw new CharonException("Error while parsing " + SCIMConfigConstants.SCIM_SCHEMA_EXTENSION_CONFIG + " file!", e);
    } catch (IOException e) {
        throw new CharonException("Error while closing " + SCIMConfigConstants.SCIM_SCHEMA_EXTENSION_CONFIG + " file!", e);
    }
}
Also used : Scanner(java.util.Scanner) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) JSONArray(org.json.JSONArray) FileNotFoundException(java.io.FileNotFoundException) JSONException(org.json.JSONException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) JSONObject(org.json.JSONObject) CharonException(org.wso2.charon3.core.exceptions.CharonException) File(java.io.File)

Example 65 with InputStream

use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-business-process by wso2.

the class BPELAppDeployerDSComponent method activate.

protected void activate(ComponentContext ctxt) {
    try {
        // register bpel deployer as an OSGi Service
        BPELAppDeployer bpelDeployer = new BPELAppDeployer();
        appHandlerRegistration = ctxt.getBundleContext().registerService(AppDeploymentHandler.class.getName(), bpelDeployer, null);
        // read required-features.xml
        URL reqFeaturesResource = ctxt.getBundleContext().getBundle().getResource(AppDeployerConstants.REQ_FEATURES_XML);
        if (reqFeaturesResource != null) {
            InputStream xmlStream = reqFeaturesResource.openStream();
            requiredFeatures = AppDeployerUtils.readRequiredFeaturs(new StAXOMBuilder(xmlStream).getDocumentElement());
        }
    } catch (Throwable e) {
        log.error("Failed to activate BPEL Application Deployer", e);
    }
}
Also used : InputStream(java.io.InputStream) StAXOMBuilder(org.apache.axiom.om.impl.builder.StAXOMBuilder) BPELAppDeployer(org.wso2.carbon.application.deployer.bpel.BPELAppDeployer) URL(java.net.URL)

Aggregations

Test (org.testng.annotations.Test)80 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)67 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)58 InputStream (java.io.InputStream)54 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)54 Event (org.wso2.siddhi.core.event.Event)48 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)47 IOException (java.io.IOException)32 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)24 ByteArrayInputStream (java.io.ByteArrayInputStream)20 API (org.wso2.carbon.apimgt.core.models.API)18 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)17 FileInputStream (java.io.FileInputStream)15 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)13 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)12 Response (javax.ws.rs.core.Response)11 HashMap (java.util.HashMap)9 APIMgtWSDLException (org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException)8 File (java.io.File)7 Connection (java.sql.Connection)7