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());
}
}
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());
}
}
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());
}
}
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);
}
}
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);
}
}
Aggregations