use of org.apache.synapse.transport.passthru.Pipe in project wso2-synapse by wso2.
the class MessageHelper method cloneAxis2MessageContextForAggregate.
private static org.apache.axis2.context.MessageContext cloneAxis2MessageContextForAggregate(org.apache.axis2.context.MessageContext mc) throws AxisFault {
org.apache.axis2.context.MessageContext newMC = clonePartiallyForAggregate(mc);
newMC.setEnvelope(cloneSOAPEnvelope(mc.getEnvelope()));
newMC.setOptions(cloneOptions(mc.getOptions()));
newMC.setServiceContext(mc.getServiceContext());
newMC.setOperationContext(mc.getOperationContext());
newMC.setAxisMessage(mc.getAxisMessage());
if (newMC.getAxisMessage() != null) {
newMC.getAxisMessage().setParent(mc.getAxisOperation());
}
newMC.setAxisService(mc.getAxisService());
// copying transport related parts from the original
newMC.setTransportIn(mc.getTransportIn());
newMC.setTransportOut(mc.getTransportOut());
newMC.setProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO, mc.getProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO));
newMC.setProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS, getClonedTransportHeaders(mc));
if (newMC.getProperty(PassThroughConstants.PASS_THROUGH_PIPE) != null) {
// clone passthrough pipe here..writer...
// newMC.setProperty(PassThroughConstants.CLONE_PASS_THROUGH_PIPE_REQUEST,true);
NHttpServerConnection conn = (NHttpServerConnection) newMC.getProperty("pass-through.Source-Connection");
if (conn != null) {
SourceConfiguration sourceConfiguration = (SourceConfiguration) newMC.getProperty("PASS_THROUGH_SOURCE_CONFIGURATION");
Pipe pipe = new Pipe(conn, sourceConfiguration.getBufferFactory().getBuffer(), "source", sourceConfiguration);
newMC.setProperty(PassThroughConstants.PASS_THROUGH_PIPE, pipe);
}
}
return newMC;
}
use of org.apache.synapse.transport.passthru.Pipe in project wso2-synapse by wso2.
the class RelayUtils method buildMessage.
public static void buildMessage(MessageContext messageContext, boolean earlyBuild) throws IOException, XMLStreamException {
final Pipe pipe = (Pipe) messageContext.getProperty(PassThroughConstants.PASS_THROUGH_PIPE);
if (messageContext.getProperty(Constants.Configuration.CONTENT_TYPE) != null) {
if (log.isDebugEnabled()) {
log.debug("Content Type is " + messageContext.getProperty(Constants.Configuration.CONTENT_TYPE));
}
if (pipe != null && !Boolean.TRUE.equals(messageContext.getProperty(PassThroughConstants.MESSAGE_BUILDER_INVOKED)) && forcePTBuild) {
InputStream in = pipe.getInputStream();
Object http_sc = messageContext.getProperty(NhttpConstants.HTTP_SC);
if (http_sc != null && http_sc instanceof Integer && http_sc.equals(202)) {
if (in != null) {
InputStream bis = new ReadOnlyBIS(in);
int c = bis.read();
if (c == -1) {
messageContext.setProperty(PassThroughConstants.MESSAGE_BUILDER_INVOKED, Boolean.TRUE);
messageContext.setProperty(PassThroughConstants.NO_ENTITY_BODY, Boolean.TRUE);
return;
}
bis.reset();
in = bis;
}
}
builldMessage(messageContext, earlyBuild, in);
return;
}
} else {
if (log.isDebugEnabled()) {
log.debug("Content Type is null and the message is not build");
}
messageContext.setProperty(PassThroughConstants.MESSAGE_BUILDER_INVOKED, Boolean.TRUE);
return;
}
}
use of org.apache.synapse.transport.passthru.Pipe in project wso2-synapse by wso2.
the class TargetRequestFactory method create.
public static TargetRequest create(MessageContext msgContext, HttpRoute route, TargetConfiguration configuration) throws AxisFault {
try {
String httpMethod = (String) msgContext.getProperty(Constants.Configuration.HTTP_METHOD);
if (httpMethod == null) {
httpMethod = "POST";
}
// basic request
Boolean noEntityBody = (Boolean) msgContext.getProperty(PassThroughConstants.NO_ENTITY_BODY);
if (msgContext.getEnvelope().getBody().getFirstElement() != null) {
noEntityBody = false;
}
EndpointReference epr = PassThroughTransportUtils.getDestinationEPR(msgContext);
URL url = new URL(epr.getAddress());
TargetRequest request = new TargetRequest(configuration, route, url, httpMethod, noEntityBody == null || !noEntityBody);
// otherwise Host header will not replaced after first call
if (msgContext.getProperty(NhttpConstants.REQUEST_HOST_HEADER) != null) {
Object headers = msgContext.getProperty(MessageContext.TRANSPORT_HEADERS);
if (headers != null) {
Map headersMap = (Map) headers;
if (!headersMap.containsKey(HTTPConstants.HEADER_HOST)) {
headersMap.put(HTTPConstants.HEADER_HOST, msgContext.getProperty(NhttpConstants.REQUEST_HOST_HEADER));
}
}
}
// headers
PassThroughTransportUtils.removeUnwantedHeaders(msgContext, configuration);
Object o = msgContext.getProperty(MessageContext.TRANSPORT_HEADERS);
if (o != null && o instanceof Map) {
Map headers = (Map) o;
for (Object entryObj : headers.entrySet()) {
Map.Entry entry = (Map.Entry) entryObj;
if (entry.getValue() != null && entry.getKey() instanceof String && entry.getValue() instanceof String) {
if (HTTPConstants.HEADER_HOST.equalsIgnoreCase((String) entry.getKey()) && !configuration.isPreserveHttpHeader(HTTPConstants.HEADER_HOST)) {
if (msgContext.getProperty(NhttpConstants.REQUEST_HOST_HEADER) != null) {
request.addHeader((String) entry.getKey(), (String) msgContext.getProperty(NhttpConstants.REQUEST_HOST_HEADER));
}
} else {
request.addHeader((String) entry.getKey(), (String) entry.getValue());
}
}
}
}
String cType = getContentType(msgContext, configuration.isPreserveHttpHeader(HTTP.CONTENT_TYPE));
if (cType != null && (!httpMethod.equals(HTTPConstants.HTTP_METHOD_GET) && !RelayUtils.isDeleteRequestWithoutPayload(msgContext))) {
String messageType = (String) msgContext.getProperty(NhttpConstants.MESSAGE_TYPE);
if (messageType != null) {
boolean builderInvoked = false;
final Pipe pipe = (Pipe) msgContext.getProperty(PassThroughConstants.PASS_THROUGH_PIPE);
if (pipe != null) {
builderInvoked = Boolean.TRUE.equals(msgContext.getProperty(PassThroughConstants.MESSAGE_BUILDER_INVOKED));
}
// skip of setting formatter specific content Type
if (messageType.indexOf(HTTPConstants.MEDIA_TYPE_MULTIPART_RELATED) == -1 && messageType.indexOf(HTTPConstants.MEDIA_TYPE_MULTIPART_FORM_DATA) == -1) {
Map msgCtxheaders = (Map) o;
if (msgCtxheaders != null && !cType.isEmpty()) {
msgCtxheaders.put(HTTP.CONTENT_TYPE, cType);
}
request.addHeader(HTTP.CONTENT_TYPE, cType);
}
// boundary related content type at Content-Type header
if (builderInvoked && (((messageType.indexOf(HTTPConstants.MEDIA_TYPE_MULTIPART_RELATED) != -1) || (messageType.indexOf(HTTPConstants.MEDIA_TYPE_MULTIPART_FORM_DATA) != -1)))) {
request.addHeader(HTTP.CONTENT_TYPE, cType);
}
} else {
request.addHeader(HTTP.CONTENT_TYPE, cType);
}
}
// version
String forceHttp10 = (String) msgContext.getProperty(PassThroughConstants.FORCE_HTTP_1_0);
if ("true".equals(forceHttp10)) {
request.setVersion(HttpVersion.HTTP_1_0);
}
// keep alive
String noKeepAlive = (String) msgContext.getProperty(PassThroughConstants.NO_KEEPALIVE);
if ("true".equals(noKeepAlive) || PassThroughConfiguration.getInstance().isKeepAliveDisabled()) {
request.setKeepAlive(false);
}
// port
int port = url.getPort();
request.setPort(port);
// chunk
String disableChunking = (String) msgContext.getProperty(PassThroughConstants.DISABLE_CHUNKING);
if ("true".equals(disableChunking)) {
request.setChunk(false);
}
// full url
String fullUrl = (String) msgContext.getProperty(PassThroughConstants.FULL_URI);
if ("true".equals(fullUrl)) {
request.setFullUrl(true);
}
// Add excess respsonse header.
String excessProp = NhttpConstants.EXCESS_TRANSPORT_HEADERS;
Map excessHeaders = (Map) msgContext.getProperty(excessProp);
if (excessHeaders != null) {
for (Iterator iterator = excessHeaders.keySet().iterator(); iterator.hasNext(); ) {
String key = (String) iterator.next();
for (String excessVal : (Collection<String>) excessHeaders.get(key)) {
request.addHeader(key, (String) excessVal);
}
}
}
return request;
} catch (MalformedURLException e) {
handleException("Invalid to address" + msgContext.getTo().getAddress(), e);
}
return null;
}
Aggregations