Author: hiranya
Date: Sat Jul 13 05:49:38 2013
New Revision: 1502751
URL: http://svn.apache.org/r1502751
Log:
Further cleaned up the pass thru transport impl
Modified:
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/BufferFactory.java
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/DeferredMessageBuilder.java
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/ExpandingMessageFormatter.java
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/PassThroughTransportUtils.java
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/RelaySecurityMessageBuilderDispatchHandler.java
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/RelayUtils.java
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/SourceResponseFactory.java
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/StreamingOnRequestDataSource.java
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/TargetRequestFactory.java
Modified:
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/BufferFactory.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/BufferFactory.java?rev=1502751&r1=1502750&r2=1502751&view=diff
==============================================================================
---
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/BufferFactory.java
(original)
+++
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/BufferFactory.java
Sat Jul 13 05:49:38 2013
@@ -50,13 +50,11 @@ public class BufferFactory {
public ByteBuffer getBuffer() {
if (marker == -1) {
- //System.out.println("allocating marker -1");
return allocator.allocate(bufferSize);
} else {
lock.lock();
try {
if (marker >= 0) {
- // System.out.println("Returning buffer");
ByteBuffer b = buffers[marker];
buffers[marker] = null;
marker--;
Modified:
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/DeferredMessageBuilder.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/DeferredMessageBuilder.java?rev=1502751&r1=1502750&r2=1502751&view=diff
==============================================================================
---
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/DeferredMessageBuilder.java
(original)
+++
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/DeferredMessageBuilder.java
Sat Jul 13 05:49:38 2013
@@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.synapse.transport.passthru.util;
import org.apache.axiom.om.OMElement;
@@ -41,7 +42,6 @@ import javax.xml.stream.XMLStreamExcepti
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
public class DeferredMessageBuilder {
@@ -76,56 +76,42 @@ public class DeferredMessageBuilder {
return builders;
}
- public void addBuilder(String contentType, Builder builder) {
- builders.put(contentType, builder);
- }
-
- public void addFormatter(String contentType, MessageFormatter
messageFormatter) {
- formatters.put(contentType, messageFormatter);
- }
-
public Map<String, MessageFormatter> getFormatters() {
return formatters;
}
public OMElement getDocument(MessageContext msgCtx, InputStream in) throws
XMLStreamException, IOException {
-
-
- String contentType = (String)
msgCtx.getProperty(Constants.Configuration.CONTENT_TYPE);
- String _contentType =contentType;
- in = HTTPTransportUtils.handleGZip(msgCtx, in);
- if (contentType != null) {
- int j = contentType.indexOf(";");
- if (j > 0) {
- _contentType = contentType.substring(0, j);
- }
- }
-
-
- AxisConfiguration configuration =
- msgCtx.getConfigurationContext().getAxisConfiguration();
- Parameter useFallbackParameter =
configuration.getParameter(Constants.Configuration.USE_DEFAULT_FALLBACK_BUILDER);
-
- boolean useFallbackBuilder = false;
-
- if (useFallbackParameter !=null){
- useFallbackBuilder =
JavaUtils.isTrueExplicitly(useFallbackParameter.getValue(),useFallbackBuilder);
- }
-
- OMElement element = null;
+
+
+ String contentType = (String)
msgCtx.getProperty(Constants.Configuration.CONTENT_TYPE);
+ String _contentType = contentType;
+ in = HTTPTransportUtils.handleGZip(msgCtx, in);
+ if (contentType != null) {
+ int j = contentType.indexOf(";");
+ if (j > 0) {
+ _contentType = contentType.substring(0, j);
+ }
+ }
+
+ AxisConfiguration configuration =
+ msgCtx.getConfigurationContext().getAxisConfiguration();
+ Parameter useFallbackParameter =
configuration.getParameter(Constants.Configuration.USE_DEFAULT_FALLBACK_BUILDER);
+
+ boolean useFallbackBuilder = false;
+
+ if (useFallbackParameter != null) {
+ useFallbackBuilder =
JavaUtils.isTrueExplicitly(useFallbackParameter.getValue(), useFallbackBuilder);
+ }
+
+ OMElement element = null;
Builder builder;
if (contentType != null) {
// loading builder from externally..
- builder =
configuration.getMessageBuilder(_contentType,useFallbackBuilder);
+ builder = configuration.getMessageBuilder(_contentType,
useFallbackBuilder);
if (builder != null) {
try {
- /*try {
- throw new Exception("Building message");
- } catch (Exception e) {
- e.printStackTrace();
- }*/
- element = builder.processDocument(in,contentType, msgCtx);
+ element = builder.processDocument(in, contentType, msgCtx);
} catch (AxisFault axisFault) {
log.error("Error building message", axisFault);
throw axisFault;
@@ -135,12 +121,7 @@ public class DeferredMessageBuilder {
if (element == null) {
if (msgCtx.isDoingREST()) {
- try {
- element = BuilderUtil.getPOXBuilder(in,
null).getDocumentElement();
- } catch (XMLStreamException e) {
- log.error("Error building message using POX Builder", e);
- throw e;
- }
+ element = BuilderUtil.createPOXBuilder(in,
null).getDocumentElement();
} else {
// switch to default
builder = new SOAPBuilder();
@@ -160,82 +141,9 @@ public class DeferredMessageBuilder {
}
//setting up original contentType (resetting the content type)
- if(contentType != null && !contentType.isEmpty()){
- msgCtx.setProperty(Constants.Configuration.CONTENT_TYPE, contentType);
+ if (contentType != null && !contentType.isEmpty()) {
+ msgCtx.setProperty(Constants.Configuration.CONTENT_TYPE,
contentType);
}
return element;
}
-
- private Builder getBuilderForContentType(String contentType) {
- String type;
- int index = contentType.indexOf(';');
- if (index > 0) {
- type = contentType.substring(0, index);
- } else {
- type = contentType;
- }
-
- Builder builder = builders.get(type);
-
- if (builder == null) {
- builder = builders.get(type.toLowerCase());
- }
-
- if (builder == null) {
- Iterator<Map.Entry<String, Builder>> iterator =
builders.entrySet().iterator();
- while (iterator.hasNext() && builder == null) {
- Map.Entry<String, Builder> entry = iterator.next();
- String key = entry.getKey();
- if (contentType.matches(key)) {
- builder = entry.getValue();
- }
- }
- }
- return builder;
- }
-
- public static Builder createBuilder(String className) throws AxisFault {
- try {
- Class c = Class.forName(className);
- Object o = c.newInstance();
- if (o instanceof Builder) {
- return (Builder) o;
- }
- } catch (ClassNotFoundException e) {
- handleException("Builder class not found :" +
- className, e);
- } catch (IllegalAccessException e) {
- handleException("Cannot initiate Builder class :" +
- className, e);
- } catch (InstantiationException e) {
- handleException("Cannot initiate Builder class :" +
- className, e);
- }
- return null;
- }
-
- public static MessageFormatter createFormatter(String className) throws
AxisFault {
- try {
- Class c = Class.forName(className);
- Object o = c.newInstance();
- if (o instanceof MessageFormatter) {
- return (MessageFormatter) o;
- }
- } catch (ClassNotFoundException e) {
- handleException("MessageFormatter class not found :" +
- className, e);
- } catch (IllegalAccessException e) {
- handleException("Cannot initiate MessageFormatter class :" +
- className, e);
- } catch (InstantiationException e) {
- handleException("Cannot initiate MessageFormatter class :" +
- className, e);
- }
- return null;
- }
-
- private static void handleException(String message, Exception e) throws
AxisFault {
- log.error(message, e);
- throw new AxisFault(message, e);
- }
}
\ No newline at end of file
Modified:
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/ExpandingMessageFormatter.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/ExpandingMessageFormatter.java?rev=1502751&r1=1502750&r2=1502751&view=diff
==============================================================================
---
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/ExpandingMessageFormatter.java
(original)
+++
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/ExpandingMessageFormatter.java
Sat Jul 13 05:49:38 2013
@@ -27,7 +27,6 @@ import org.apache.axis2.transport.http.H
import org.apache.axis2.transport.http.SOAPMessageFormatter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.synapse.transport.passthru.util.DeferredMessageBuilder;
import javax.activation.DataHandler;
import javax.activation.DataSource;
Modified:
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/PassThroughTransportUtils.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/PassThroughTransportUtils.java?rev=1502751&r1=1502750&r2=1502751&view=diff
==============================================================================
---
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/PassThroughTransportUtils.java
(original)
+++
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/PassThroughTransportUtils.java
Sat Jul 13 05:49:38 2013
@@ -16,38 +16,30 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.synapse.transport.passthru.util;
import org.apache.axiom.om.OMOutputFormat;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.Constants;
import org.apache.axis2.transport.TransportUtils;
-import org.apache.axis2.util.JavaUtils;
-import org.apache.axis2.description.AxisService;
-import org.apache.axis2.description.Parameter;
-import org.apache.axis2.description.AxisOperation;
import org.apache.http.protocol.HTTP;
import org.apache.http.HttpStatus;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.synapse.transport.nhttp.NhttpConstants;
import org.apache.synapse.transport.passthru.PassThroughConstants;
import java.net.InetAddress;
-import java.net.SocketException;
-import java.net.NetworkInterface;
import java.util.Map;
import java.util.Iterator;
-import java.util.Enumeration;
-import java.util.Hashtable;
/**
* Utility methods used by the transport.
*/
public class PassThroughTransportUtils {
- private static Log log =
LogFactory.getLog(PassThroughTransportUtils.class);
+
+ private static final Log log =
LogFactory.getLog(PassThroughTransportUtils.class);
/**
* This method tries to determine the hostname of the given InetAddress
without
@@ -61,7 +53,7 @@ public class PassThroughTransportUtils {
* the value of {@link java.net.InetAddress#getHostAddress()} is returned.
*
* @param address The InetAddress whose hostname has to be determined
- * @return hostsname, if it can be determined. hostaddress, if not.
+ * @return hostname, if it can be determined. host address, if not.
*/
public static String getHostName(InetAddress address) {
String result;
@@ -87,8 +79,7 @@ public class PassThroughTransportUtils {
* @return the destination EPR
*/
public static EndpointReference getDestinationEPR(MessageContext
msgContext) {
-
- // Trasnport URL can be different from the WSA-To
+ // Transport URL can be different from the WSA-To
String transportURL = (String) msgContext.getProperty(
Constants.Configuration.TRANSPORT_URL);
@@ -162,8 +153,8 @@ public class PassThroughTransportUtils {
httpStatus = HttpStatus.SC_ACCEPTED;
} else {
// is this a fault message
- boolean handleFault = msgContext.getEnvelope() != null ?
- (msgContext.getEnvelope().getBody().hasFault() ||
msgContext.isProcessingFault()):false;
+ boolean handleFault = msgContext.getEnvelope() != null &&
+ (msgContext.getEnvelope().getBody().hasFault() ||
msgContext.isProcessingFault());
// shall faults be transmitted with HTTP 200
boolean faultsAsHttp200 =
@@ -192,111 +183,8 @@ public class PassThroughTransportUtils {
return httpStatus;
}
- /**
- * Whatever this method returns as the IP is ignored by the actual http/s
listener when
- * its getServiceEPR is invoked. This was originally copied from axis2
- *
- * @return Returns String.
- * @throws java.net.SocketException if the socket can not be accessed
- */
- public static String getIpAddress() throws SocketException {
- Enumeration e = NetworkInterface.getNetworkInterfaces();
- String address = "127.0.0.1";
-
- while (e.hasMoreElements()) {
- NetworkInterface netface = (NetworkInterface) e.nextElement();
- Enumeration addresses = netface.getInetAddresses();
-
- while (addresses.hasMoreElements()) {
- InetAddress ip = (InetAddress) addresses.nextElement();
- if (!ip.isLoopbackAddress() && isIP(ip.getHostAddress())) {
- return ip.getHostAddress();
- }
- }
- }
- return address;
- }
-
- private static boolean isIP(String hostAddress) {
- return hostAddress.split("[.]").length == 4;
- }
-
-
- /**
- * Returns the HTML text for the list of services deployed.
- * This can be delegated to another Class as well
- * where it will handle more options of GET messages.
- *
- * @param prefix to be used for the Service names
- * @param cfgCtx axis2 configuration context
- * @return the HTML to be displayed as a String
- */
- public String getServicesHTML(String prefix, ConfigurationContext cfgCtx) {
-
- Map services = cfgCtx.getAxisConfiguration().getServices();
- Hashtable erroneousServices =
cfgCtx.getAxisConfiguration().getFaultyServices();
- boolean servicesFound = false;
-
- StringBuffer resultBuf = new StringBuffer();
- resultBuf.append("<html><head><title>Axis2: Services</title></head>" +
"<body>");
-
- if ((services != null) && !services.isEmpty()) {
-
- servicesFound = true;
- resultBuf.append("<h2>" + "Deployed services" + "</h2>");
-
- for (Object service : services.values()) {
-
- AxisService axisService = (AxisService) service;
- Parameter parameter = axisService.getParameter(
- PassThroughConstants.HIDDEN_SERVICE_PARAM_NAME);
- if (axisService.getName().startsWith("__") ||
- (parameter != null &&
JavaUtils.isTrueExplicitly(parameter.getValue()))) {
- continue; // skip private services
- }
-
- Iterator iterator = axisService.getOperations();
- resultBuf.append("<h3><a
href=\"").append(prefix).append(axisService.getName()).append(
-
"?wsdl\">").append(axisService.getName()).append("</a></h3>");
-
- if (iterator.hasNext()) {
- resultBuf.append("Available operations <ul>");
-
- for (; iterator.hasNext();) {
- AxisOperation axisOperation = (AxisOperation)
iterator.next();
- resultBuf.append("<li>").append(
-
axisOperation.getName().getLocalPart()).append("</li>");
- }
- resultBuf.append("</ul>");
- } else {
- resultBuf.append("No operations specified for this
service");
- }
- }
- }
-
- if ((erroneousServices != null) && !erroneousServices.isEmpty()) {
- servicesFound = true;
- resultBuf.append("<hr><h2><font color=\"blue\">Faulty
Services</font></h2>");
- Enumeration faultyservices = erroneousServices.keys();
-
- while (faultyservices.hasMoreElements()) {
- String faultyserviceName = (String)
faultyservices.nextElement();
- resultBuf.append("<h3><font color=\"blue\">").append(
- faultyserviceName).append("</font></h3>");
- }
- }
-
- if (!servicesFound) {
- resultBuf.append("<h2>There are no services deployed</h2>");
- }
-
- resultBuf.append("</body></html>");
- return resultBuf.toString();
- }
-
public static OMOutputFormat getOMOutputFormat(MessageContext msgContext) {
-
- OMOutputFormat format = null;
+ OMOutputFormat format;
if(msgContext.getProperty(PassThroughConstants.MESSAGE_OUTPUT_FORMAT)
!= null){
format = (OMOutputFormat)
msgContext.getProperty(PassThroughConstants.MESSAGE_OUTPUT_FORMAT);
}else{
@@ -319,4 +207,9 @@ public class PassThroughTransportUtils {
return format;
}
+ public static boolean builderInvoked(MessageContext messageContext) {
+ return Boolean.TRUE.equals(messageContext.getProperty(
+ PassThroughConstants.MESSAGE_BUILDER_INVOKED));
+ }
+
}
Modified:
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/RelaySecurityMessageBuilderDispatchHandler.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/RelaySecurityMessageBuilderDispatchHandler.java?rev=1502751&r1=1502750&r2=1502751&view=diff
==============================================================================
---
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/RelaySecurityMessageBuilderDispatchHandler.java
(original)
+++
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/RelaySecurityMessageBuilderDispatchHandler.java
Sat Jul 13 05:49:38 2013
@@ -73,7 +73,7 @@ public class RelaySecurityMessageBuilder
String serviceOpPart =
Utils.getServiceAndOperationPart(filePart,
messageContext.getConfigurationContext().getServiceContextPath());
- AxisService axisService = null;
+ AxisService axisService;
// only service context path onwards
values will be taken
if
(messageContext.getConfigurationContext().getServiceContextPath() != null &&
@@ -121,19 +121,20 @@ public class RelaySecurityMessageBuilder
//if the request message is a POX and if authenticate enables,
which means a custom security header added to the SOAP header
//and in PT case, since the message is getting build forcefully we
need to make sure the POX security headers added by POXSecurityHandler
//is existing in the newly build soap envelope.
- if(_contentType != null && _contentType.equals(APPLICATION_XML) &&
header != null && header.getChildElements() != null ||
messageContext.isDoingREST()){
+ if(_contentType != null && _contentType.equals(APPLICATION_XML) &&
+ header != null && header.getChildElements() != null ||
messageContext.isDoingREST()){
try {
OMElement element =AXIOMUtil.stringToOM(header.toString());
OMNamespace omNamespace =
OMAbstractFactory.getOMFactory().createOMNamespace(WSS_WSSECURITY_SECEXT_1_0_XSD,
WSSE);
- SOAPHeaderBlock soapBloackingHeader =
OMAbstractFactory.getSOAP12Factory().createSOAPHeaderBlock("Security",omNamespace);
+ SOAPHeaderBlock soapBlockingHeader =
OMAbstractFactory.getSOAP12Factory().createSOAPHeaderBlock("Security",omNamespace);
OMElement securityHeader = (OMElement)
element.getFirstOMChild();
if (securityHeader != null) {
while
(securityHeader.getChildElements().hasNext()) {
- soapBloackingHeader.addChild((OMNode)
securityHeader.getChildElements().next());
+ soapBlockingHeader.addChild((OMNode)
securityHeader.getChildElements().next());
}
-
messageContext.getEnvelope().getHeader().addChild(soapBloackingHeader);
+
messageContext.getEnvelope().getHeader().addChild(soapBlockingHeader);
}
} catch (Exception e) {
log.error("Error while executing the message at
relaySecurity handler", e);
Modified:
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/RelayUtils.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/RelayUtils.java?rev=1502751&r1=1502750&r2=1502751&view=diff
==============================================================================
---
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/RelayUtils.java
(original)
+++
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/RelayUtils.java
Sat Jul 13 05:49:38 2013
@@ -58,15 +58,15 @@ public class RelayUtils {
private static boolean noAddressingHandler = false;
private static Boolean forcePTBuild = null;
-
- static{
- if(forcePTBuild == null){
- forcePTBuild
=PassThroughConfiguration.getInstance().getBooleanProperty(PassThroughConstants.FORCE_PASS_THROUGH_BUILDER);
- if(forcePTBuild ==null){
- forcePTBuild =true;
+ static {
+ if (forcePTBuild == null){
+ forcePTBuild =
PassThroughConfiguration.getInstance().getBooleanProperty(
+ PassThroughConstants.FORCE_PASS_THROUGH_BUILDER);
+ if (forcePTBuild == null){
+ forcePTBuild = true;
}
- //this to keep track ignore the builder operation eventhough content
level is enable.
+ //this to keep track ignore the builder operation even though
content level is enable.
}
}
@@ -80,12 +80,10 @@ public class RelayUtils {
XMLStreamException {
final Pipe pipe = (Pipe)
messageContext.getProperty(PassThroughConstants.PASS_THROUGH_PIPE);
- if (pipe != null &&
-
!Boolean.TRUE.equals(messageContext.getProperty(PassThroughConstants.MESSAGE_BUILDER_INVOKED))
&&
- forcePTBuild) {
+ if (pipe != null && forcePTBuild &&
+ !PassThroughTransportUtils.builderInvoked(messageContext)) {
InputStream in = pipe.getInputStream();
-
- builldMessage(messageContext, earlyBuild, in);
+ buildMessage(messageContext, earlyBuild, in);
return;
}
@@ -95,7 +93,6 @@ public class RelayUtils {
if (contentEle != null) {
OMNode node = contentEle.getFirstOMChild();
-
if (node != null && (node instanceof OMText)) {
OMText binaryDataNode = (OMText) node;
DataHandler dh = (DataHandler) binaryDataNode.getDataHandler();
@@ -124,42 +121,42 @@ public class RelayUtils {
}
}
- public static void builldMessage(MessageContext messageContext, boolean
earlyBuild, InputStream in) throws IOException, AxisFault {
- //
- BufferedInputStream bufferedInputStream= (BufferedInputStream)
messageContext.getProperty(PassThroughConstants.BUFFERED_INPUT_STREAM);
- if(bufferedInputStream != null){
- try{
+ public static void buildMessage(MessageContext messageContext,
+ boolean earlyBuild, InputStream in) throws
IOException {
+
+ BufferedInputStream bufferedInputStream = (BufferedInputStream)
messageContext.getProperty(
+ PassThroughConstants.BUFFERED_INPUT_STREAM);
+ if (bufferedInputStream != null){
+ try {
bufferedInputStream.reset();
bufferedInputStream.mark(0);
- }catch (Exception e) {
+ } catch (Exception e) {
//just ignore the error
}
-
- }else{
- bufferedInputStream =new BufferedInputStream(in);
- //TODO: need to handle properly for the moment lets
use around 100k buffer.
+ } else {
+ bufferedInputStream = new BufferedInputStream(in);
+ //TODO: need to handle properly; for the moment lets
use around 100k buffer.
bufferedInputStream.mark(128 * 1024);
-
messageContext.setProperty(PassThroughConstants.BUFFERED_INPUT_STREAM,
bufferedInputStream);
- }
+
messageContext.setProperty(PassThroughConstants.BUFFERED_INPUT_STREAM,
+ bufferedInputStream);
+ }
OMElement element = null;
try{
- element = messageBuilder.getDocument(messageContext,
bufferedInputStream != null?bufferedInputStream:in);
+ element = messageBuilder.getDocument(messageContext,
bufferedInputStream);
}catch (Exception e) {
- log.error("Error while building Passthrough stream",e);
+ log.error("Error while building PassThrough stream",e);
}
+
if (element != null) {
messageContext.setEnvelope(TransportUtils.createSOAPEnvelope(element));
messageContext.setProperty(DeferredMessageBuilder.RELAY_FORMATTERS_MAP,
messageBuilder.getFormatters());
-
messageContext.setProperty(PassThroughConstants.MESSAGE_BUILDER_INVOKED,
- Boolean.TRUE);
-
+
messageContext.setProperty(PassThroughConstants.MESSAGE_BUILDER_INVOKED,
Boolean.TRUE);
if (!earlyBuild) {
processAddressing(messageContext);
}
}
- return;
}
private static void processAddressing(MessageContext messageContext)
throws AxisFault {
@@ -197,14 +194,15 @@ public class RelayUtils {
messageContext.setProperty(AddressingConstants.DISABLE_ADDRESSING_FOR_IN_MESSAGES,
"false");
Object disableAddressingForOutGoing = null;
- if(messageContext.getProperty(
- AddressingConstants.DISABLE_ADDRESSING_FOR_OUT_MESSAGES)
!= null){
- disableAddressingForOutGoing =
messageContext.getProperty(AddressingConstants.DISABLE_ADDRESSING_FOR_OUT_MESSAGES);
+ if
(messageContext.getProperty(AddressingConstants.DISABLE_ADDRESSING_FOR_OUT_MESSAGES)
!= null){
+ disableAddressingForOutGoing = messageContext.getProperty(
+ AddressingConstants.DISABLE_ADDRESSING_FOR_OUT_MESSAGES);
}
addressingInHandler.invoke(messageContext);
- if(disableAddressingForOutGoing !=null){
-
messageContext.setProperty(AddressingConstants.DISABLE_ADDRESSING_FOR_OUT_MESSAGES,
disableAddressingForOutGoing);
+ if (disableAddressingForOutGoing !=null){
+
messageContext.setProperty(AddressingConstants.DISABLE_ADDRESSING_FOR_OUT_MESSAGES,
+ disableAddressingForOutGoing);
}
if (messageContext.getAxisOperation() == null) {
@@ -214,30 +212,32 @@ public class RelayUtils {
String mepString =
messageContext.getAxisOperation().getMessageExchangePattern();
if (isOneWay(mepString)) {
- Object requestResponseTransport =
messageContext.getProperty(RequestResponseTransport.TRANSPORT_CONTROL);
+ Object requestResponseTransport = messageContext.getProperty(
+ RequestResponseTransport.TRANSPORT_CONTROL);
if (requestResponseTransport != null) {
-
Boolean disableAck = getDisableAck(messageContext);
- if (disableAck == null || disableAck.booleanValue() == false) {
- ((RequestResponseTransport)
requestResponseTransport).acknowledgeMessage(messageContext);
+ if (disableAck == null || !disableAck) {
+ ((RequestResponseTransport)
requestResponseTransport).acknowledgeMessage(
+ messageContext);
}
}
- } else if (AddressingHelper.isReplyRedirected(messageContext) &&
AddressingHelper.isFaultRedirected(messageContext)) {
- if (mepString.equals(WSDL2Constants.MEP_URI_IN_OUT)
- || mepString.equals(WSDL2Constants.MEP_URI_IN_OUT)
- || mepString.equals(WSDL2Constants.MEP_URI_IN_OUT)) {
- // OR, if 2 way operation but the response is intended to not
use the response channel of a 2-way transport
- // then we don't need to keep the transport waiting.
-
- Object requestResponseTransport =
messageContext.getProperty(RequestResponseTransport.TRANSPORT_CONTROL);
+ } else if (AddressingHelper.isReplyRedirected(messageContext) &&
+ AddressingHelper.isFaultRedirected(messageContext)) {
+ if (mepString.equals(WSDL2Constants.MEP_URI_IN_OUT)) {
+ // OR, if 2 way operation but the response is intended to not
use the
+ // response channel of a 2-way transport then we don't need
to keep the
+ // transport waiting.
+ Object requestResponseTransport = messageContext.getProperty(
+ RequestResponseTransport.TRANSPORT_CONTROL);
if (requestResponseTransport != null) {
- // We should send an early ack to the transport whenever
possible, but some modules need
- // to use the back channel, so we need to check if they
have disabled this code.
+ // We should send an early ack to the transport whenever
possible, but
+ // some modules need to use the back channel, so we need
to check if they
+ // have disabled this code.
Boolean disableAck = getDisableAck(messageContext);
-
- if (disableAck == null || disableAck.booleanValue() ==
false) {
- ((RequestResponseTransport)
requestResponseTransport).acknowledgeMessage(messageContext);
+ if (disableAck == null || !disableAck) {
+ ((RequestResponseTransport)
requestResponseTransport).acknowledgeMessage(
+ messageContext);
}
}
@@ -248,17 +248,18 @@ public class RelayUtils {
private static Boolean getDisableAck(MessageContext msgContext) throws
AxisFault {
// We should send an early ack to the transport whenever possible, but
some modules need
// to use the back channel, so we need to check if they have disabled
this code.
- Boolean disableAck = (Boolean)
msgContext.getProperty(Constants.Configuration.DISABLE_RESPONSE_ACK);
- if(disableAck == null) {
- disableAck = (Boolean) (msgContext.getAxisService() != null ?
msgContext.getAxisService().getParameterValue(Constants.Configuration.DISABLE_RESPONSE_ACK)
: null);
+ Boolean disableAck = (Boolean) msgContext.getProperty(
+ Constants.Configuration.DISABLE_RESPONSE_ACK);
+ if (disableAck == null) {
+ disableAck = (Boolean) (msgContext.getAxisService() != null ?
+ msgContext.getAxisService().getParameterValue(
+ Constants.Configuration.DISABLE_RESPONSE_ACK) :
null);
}
return disableAck;
}
private static boolean isOneWay(String mepString) {
- return (mepString.equals(WSDL2Constants.MEP_URI_IN_ONLY)
- || mepString.equals(WSDL2Constants.MEP_URI_IN_ONLY)
- || mepString.equals(WSDL2Constants.MEP_URI_IN_ONLY));
+ return mepString.equals(WSDL2Constants.MEP_URI_IN_ONLY);
}
}
Modified:
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/SourceResponseFactory.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/SourceResponseFactory.java?rev=1502751&r1=1502750&r2=1502751&view=diff
==============================================================================
---
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/SourceResponseFactory.java
(original)
+++
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/SourceResponseFactory.java
Sat Jul 13 05:49:38 2013
@@ -32,37 +32,35 @@ import org.apache.synapse.transport.pass
import java.util.HashMap;
import java.util.Map;
-import java.util.Set;
public class SourceResponseFactory {
public static SourceResponse create(MessageContext msgContext,
SourceRequest sourceRequest,
SourceConfiguration
sourceConfiguration) {
+
// determine the status code to be sent
int statusCode =
PassThroughTransportUtils.determineHttpStatusCode(msgContext);
-
- SourceResponse sourceResponse =
- new SourceResponse(sourceConfiguration, statusCode,
sourceRequest);
+ SourceResponse sourceResponse = new SourceResponse(sourceConfiguration,
+ statusCode, sourceRequest);
// set any transport headers
Map transportHeaders = (Map)
msgContext.getProperty(MessageContext.TRANSPORT_HEADERS);
-
if (transportHeaders != null) {
addResponseHeader(sourceResponse, transportHeaders);
- }else{
- Boolean noEntityBody = (Boolean)
msgContext.getProperty(NhttpConstants.NO_ENTITY_BODY);
+ } else {
+ Boolean noEntityBody = (Boolean)
msgContext.getProperty(NhttpConstants.NO_ENTITY_BODY);
if (noEntityBody == null || Boolean.FALSE == noEntityBody) {
OMOutputFormat format =
NhttpUtil.getOMOutputFormat(msgContext);
transportHeaders = new HashMap();
MessageFormatter messageFormatter =
MessageFormatterDecoratorFactory.createMessageFormatterDecorator(msgContext);
- transportHeaders.put(HTTP.CONTENT_TYPE,
messageFormatter.getContentType(msgContext, format,
msgContext.getSoapAction()));
+ transportHeaders.put(HTTP.CONTENT_TYPE,
messageFormatter.getContentType(
+ msgContext, format, msgContext.getSoapAction()));
addResponseHeader(sourceResponse, transportHeaders);
}
}
-
return sourceResponse;
}
Modified:
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/StreamingOnRequestDataSource.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/StreamingOnRequestDataSource.java?rev=1502751&r1=1502750&r2=1502751&view=diff
==============================================================================
---
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/StreamingOnRequestDataSource.java
(original)
+++
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/StreamingOnRequestDataSource.java
Sat Jul 13 05:49:38 2013
@@ -74,7 +74,7 @@ public class StreamingOnRequestDataSourc
* need to cache it if it has not
* already cached.
*
- * @param lastUse
+ * @param lastUse Boolean value to set
*/
public void setLastUse(boolean lastUse) {
this.lastUse = lastUse;
Modified:
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/TargetRequestFactory.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/TargetRequestFactory.java?rev=1502751&r1=1502750&r2=1502751&view=diff
==============================================================================
---
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/TargetRequestFactory.java
(original)
+++
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/TargetRequestFactory.java
Sat Jul 13 05:49:38 2013
@@ -22,11 +22,9 @@ package org.apache.synapse.transport.pas
import org.apache.axiom.om.OMOutputFormat;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
-//import org.apache.axis2.util.MessageProcessorSelector;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.transport.MessageFormatter;
-import org.apache.axis2.transport.TransportUtils;
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.axis2.transport.http.SOAPMessageFormatter;
import org.apache.axis2.util.MessageProcessorSelector;
@@ -45,7 +43,7 @@ import java.util.Map;
public class TargetRequestFactory {
- private static Log log = LogFactory.getLog(TargetRequestFactory.class);
+ private static final Log log =
LogFactory.getLog(TargetRequestFactory.class);
public static TargetRequest create(MessageContext msgContext,
TargetConfiguration configuration)
throws AxisFault {
@@ -57,10 +55,10 @@ public class TargetRequestFactory {
}
// basic request
- Boolean noEntityBody = (Boolean)
msgContext.getProperty(PassThroughConstants.NO_ENTITY_BODY);
-
- if(msgContext.getEnvelope().getBody().getFirstElement() != null){
- noEntityBody =false;
+ Boolean noEntityBody = (Boolean) msgContext.getProperty(
+ PassThroughConstants.NO_ENTITY_BODY);
+ if (msgContext.getEnvelope().getBody().getFirstElement() != null){
+ noEntityBody = false;
}
EndpointReference epr =
PassThroughTransportUtils.getDestinationEPR(msgContext);
@@ -73,7 +71,6 @@ public class TargetRequestFactory {
configuration.isPreserveServerHeader(),
configuration.isPreserveUserAgentHeader());
-
Object o =
msgContext.getProperty(MessageContext.TRANSPORT_HEADERS);
if (o != null && o instanceof Map) {
Map headers = (Map) o;
@@ -84,10 +81,11 @@ public class TargetRequestFactory {
entry.getValue() instanceof String) {
if
(!HTTPConstants.HEADER_HOST.equalsIgnoreCase((String) entry.getKey())) {
request.addHeader((String) entry.getKey(),
(String) entry.getValue());
- }else {
-
if(msgContext.getProperty(NhttpConstants.REQUEST_HOST_HEADER) != null) {
- request.addHeader((String) (String)
entry.getKey(),
-
(String)msgContext.getProperty(NhttpConstants.REQUEST_HOST_HEADER));
+ } else {
+ if(
msgContext.getProperty(NhttpConstants.REQUEST_HOST_HEADER) != null) {
+ request.addHeader((String) entry.getKey(),
+ (String) msgContext.getProperty(
+
NhttpConstants.REQUEST_HOST_HEADER));
}
}
}
@@ -100,7 +98,8 @@ public class TargetRequestFactory {
}
// version
- String forceHttp10 = (String)
msgContext.getProperty(PassThroughConstants.FORCE_HTTP_1_0);
+ String forceHttp10 = (String) msgContext.getProperty(
+ PassThroughConstants.FORCE_HTTP_1_0);
if ("true".equals(forceHttp10)) {
request.setVersion(HttpVersion.HTTP_1_0);
}
@@ -142,7 +141,8 @@ public class TargetRequestFactory {
if (formatter != null) {
String contentType= formatter.getContentType(msgCtx, format,
msgCtx.getSoapAction());
- //keep the formatter information to prevent multipart boundary
override (this will be the content writing to header)
+ //keep the formatter information to prevent multipart boundary
override
+ // (this will be the content writing to header)
msgCtx.setProperty(PassThroughConstants.MESSAGE_OUTPUT_FORMAT,
format);
return contentType;