use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.
the class AbstractHTTPAction method send.
/**
* Send outbound request through the client connector. If the Content-Type is multipart, check whether the boundary
* exist. If not get a new boundary string and add it as a parameter to Content-Type, just before sending header
* info through wire. If a boundary string exist at this point, serialize multipart entity body, else serialize
* entity body which can either be a message data source or a byte channel.
*
* @param dataContext holds the ballerina context and callback
* @param outboundRequestMsg Outbound request that needs to be sent across the wire
* @param async whether a handle should be return
* @return connector future for this particular request
* @throws Exception When an error occurs while sending the outbound request via client connector
*/
private void send(DataContext dataContext, HTTPCarbonMessage outboundRequestMsg, boolean async) throws Exception {
BStruct bConnector = (BStruct) dataContext.context.getRefArgument(0);
Struct httpClient = BLangConnectorSPIUtil.toStruct(bConnector);
HttpClientConnector clientConnector = (HttpClientConnector) httpClient.getNativeData(HttpConstants.HTTP_CLIENT);
String contentType = HttpUtil.getContentTypeFromTransportMessage(outboundRequestMsg);
String boundaryString = null;
if (HeaderUtil.isMultipart(contentType)) {
boundaryString = HttpUtil.addBoundaryIfNotExist(outboundRequestMsg, contentType);
}
HttpMessageDataStreamer outboundMsgDataStreamer = new HttpMessageDataStreamer(outboundRequestMsg);
OutputStream messageOutputStream = outboundMsgDataStreamer.getOutputStream();
RetryConfig retryConfig = getRetryConfiguration(httpClient);
HTTPClientConnectorListener httpClientConnectorLister = new HTTPClientConnectorListener(dataContext, retryConfig, outboundRequestMsg, outboundMsgDataStreamer);
HttpResponseFuture future = clientConnector.send(outboundRequestMsg);
if (async) {
future.setResponseHandleListener(httpClientConnectorLister);
} else {
future.setHttpConnectorListener(httpClientConnectorLister);
}
try {
if (boundaryString != null) {
serializeMultiparts(dataContext.context, messageOutputStream, boundaryString);
} else {
serializeDataSource(dataContext.context, messageOutputStream);
}
} catch (IOException | EncoderException serializerException) {
// We don't have to do anything here as the client connector will notify
// the error though the listener
logger.warn("couldn't serialize the message", serializerException);
}
}
use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.
the class GlobalVarServicePkgTest method testAssigningFuncInvFromDiffPkg.
@Test(description = "Test assigning function invocation from different package", enabled = false)
public void testAssigningFuncInvFromDiffPkg() {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/globalvar-pkg/func-inv-from-diff-pkg", "GET");
HTTPCarbonMessage response = Services.invokeNew(result, cMsg);
Assert.assertNotNull(response);
// Expected Json message : {"glbVarPkgFunc":8876}
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("glbVarPkgFunc").asText(), "8876");
}
use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.
the class GlobalVarServicePkgTest method testAssigningGlobalVarToServiceVarFromDiffPkg.
@Test(description = "Test assigning global variable to service variable from different package", enabled = false)
public void testAssigningGlobalVarToServiceVarFromDiffPkg() {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/globalvar-pkg/assign-to-service-var-from-diff-pkg", "GET");
HTTPCarbonMessage response = Services.invokeNew(result, cMsg);
Assert.assertNotNull(response);
// Expected Json message : {"serviceVarString":"stringval"}
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("serviceVarString").asText(), "stringval");
}
use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.
the class GlobalVarServicePkgTest method testAssigningFuncInvFromSamePkg.
@Test(description = "Test assigning function invocation from same package", enabled = false)
public void testAssigningFuncInvFromSamePkg() {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/globalvar-pkg/func-inv-from-same-pkg", "GET");
HTTPCarbonMessage response = Services.invokeNew(result, cMsg);
Assert.assertNotNull(response);
// Expected Json message : {"glbVarFunc":423277.72343}
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("glbVarFunc").asText(), "423277.72343");
}
use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.
the class GlobalVarServicePkgTest method testChangeAndAccessGlobalVarInDiffPkg.
@Test(description = "Test change global var in different package and access it", enabled = false)
public void testChangeAndAccessGlobalVarInDiffPkg() {
HTTPTestRequest cMsgChange = MessageUtils.generateHTTPMessage("/globalvar-pkg/change-global-var-diff-pkg", "GET");
Services.invokeNew(result, cMsgChange);
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/globalvar-second-pkg/get-changed-resource-level", "GET");
HTTPCarbonMessage response = Services.invokeNew(result, cMsg);
Assert.assertNotNull(response);
// Expected Json message : {"changeVarFloat":345432.454}
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("changeVarFloat").asText(), "345432.454");
}
Aggregations