Author: alessio.soldano(a)jboss.com
Date: 2009-07-16 12:34:38 -0400 (Thu, 16 Jul 2009)
New Revision: 10328
Added:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/feature/ChunkedEncodingFeature.java
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/StubExt.java
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/NettyClient.java
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/client/ClientFeatureProcessor.java
Log:
[JBWS-2694] Simpler approach to disable chunked encoding: a) adding prop in the request
context or b) using the custom ChunkedEncodingFeature when getting the port
Modified: stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/StubExt.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/StubExt.java 2009-07-16
13:14:53 UTC (rev 10327)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/StubExt.java 2009-07-16
16:34:38 UTC (rev 10328)
@@ -71,6 +71,8 @@
static final String PROPERTY_AUTH_TYPE_WSSE = "org.jboss.ws.authType.wsse";
/** Enable MTOM on the stub */
static final String PROPERTY_MTOM_ENABLED= "org.jboss.ws.mtom.enabled";
+ /** HTTP chunk size */
+ static final String PROPERTY_CHUNKED_ENCODING_SIZE =
"http://org.jboss.ws/http#chunksize";
/**
* Get the endpoint meta data for this stub
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/NettyClient.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/NettyClient.java 2009-07-16
13:14:53 UTC (rev 10327)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/NettyClient.java 2009-07-16
16:34:38 UTC (rev 10328)
@@ -34,6 +34,7 @@
import javax.xml.rpc.Stub;
import javax.xml.ws.BindingProvider;
+import org.jboss.logging.Logger;
import org.jboss.netty.bootstrap.ClientBootstrap;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBufferOutputStream;
@@ -73,6 +74,7 @@
{
public static final String RESPONSE_CODE = "ResponseCode";
public static final String RESPONSE_CODE_MESSAGE = "ResponseCodeMessage";
+ private static Logger log = Logger.getLogger(NettyClient.class);
private Marshaller marshaller;
private UnMarshaller unmarshaller;
@@ -181,7 +183,7 @@
request.addHeader(HttpHeaders.Names.HOST, target.getHost());
request.addHeader(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
setAdditionalHeaders(request, additionalHeaders);
- setActualChunkedLength(request);
+ setActualChunkedLength(request, callProps);
setAuthorization(request, callProps);
ChannelFuture writeFuture = writeRequest(channel, request, reqMessage);
@@ -326,7 +328,7 @@
*
* @param message
*/
- protected void setActualChunkedLength(HttpRequest message)
+ protected void setActualChunkedLength(HttpRequest message, Map<String, Object>
callProps)
{
if (HttpMethod.POST.equals(message.getMethod()))
{
@@ -340,6 +342,20 @@
String sizeValue =
config.getProperty(EndpointProperty.CHUNKED_ENCODING_SIZE);
if (sizeValue != null)
chunkSize = Integer.valueOf(sizeValue);
+
+ //override using call props
+ try
+ {
+ Object obj = callProps.get(StubExt.PROPERTY_CHUNKED_ENCODING_SIZE);
+ if (obj != null) //explicit 0 value is required to disable chunked mode
+ chunkSize = (Integer)obj;
+ }
+ catch (Exception e)
+ {
+ log.warn("Can't set chunk size from call properties, illegal
value provided!");
+ }
+
+ //fastinfoset always disable chunking
if (epMetaData.isFeatureEnabled(FastInfosetFeature.class))
chunkSize = 0;
}
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/client/ClientFeatureProcessor.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/client/ClientFeatureProcessor.java 2009-07-16
13:14:53 UTC (rev 10327)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/client/ClientFeatureProcessor.java 2009-07-16
16:34:38 UTC (rev 10328)
@@ -22,6 +22,7 @@
package org.jboss.ws.core.jaxws.client;
import java.util.List;
+import java.util.Map;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.RespectBindingFeature;
@@ -33,8 +34,10 @@
import javax.xml.ws.soap.SOAPBinding;
import org.jboss.logging.Logger;
+import org.jboss.ws.core.StubExt;
import org.jboss.ws.core.jaxws.binding.BindingExt;
import org.jboss.ws.extensions.addressing.jaxws.WSAddressingClientHandler;
+import org.jboss.ws.feature.ChunkedEncodingFeature;
import org.jboss.ws.feature.FastInfosetFeature;
import org.jboss.ws.feature.JsonEncodingFeature;
import org.jboss.ws.feature.SchemaValidationFeature;
@@ -70,6 +73,7 @@
supportedFeatures.addFeature(new AddressingFeature());
supportedFeatures.addFeature(new MTOMFeature());
supportedFeatures.addFeature(new RespectBindingFeature());
+ supportedFeatures.addFeature(new ChunkedEncodingFeature());
}
public static <T> void processFeature(WebServiceFeature feature,
EndpointMetaData epMetaData, T stub)
@@ -81,12 +85,12 @@
processAddressingFeature(feature, epMetaData, stub);
processMTOMFeature(feature, epMetaData, stub);
processRespectBindingFeature(feature, epMetaData, stub);
+ processChunkedEncodingFeature(feature, epMetaData, stub);
epMetaData.addFeature(feature);
}
/**
- * Returns true or false depending on the provided WebServiceFeature being an
AddressingFeature or not.
- * In the former case, addressing is setup.
+ * Setup addressing
*
* @param <T>
* @param feature
@@ -107,8 +111,7 @@
}
/**
- * Returns true or false depending on the provided WebServiceFeature being an
MTOMFeature or not.
- * In the former case, mtom is setup.
+ * Setup http chunked encoding
*
* @param <T>
* @param feature
@@ -116,6 +119,24 @@
* @param stub
* @return
*/
+ private static <T> void processChunkedEncodingFeature(WebServiceFeature feature,
EndpointMetaData epMetaData, T stub)
+ {
+ if (feature instanceof ChunkedEncodingFeature)
+ {
+ Map<String, Object> ctx = ((BindingProvider)stub).getRequestContext();
+ ctx.put(StubExt.PROPERTY_CHUNKED_ENCODING_SIZE,
((ChunkedEncodingFeature)feature).getChunkSize());
+ }
+ }
+
+ /**
+ * Setup MTOM
+ *
+ * @param <T>
+ * @param feature
+ * @param epMetaData
+ * @param stub
+ * @return
+ */
private static <T> void processMTOMFeature(WebServiceFeature feature,
EndpointMetaData epMetaData, T stub)
{
if (feature instanceof MTOMFeature)
@@ -126,9 +147,9 @@
}
/**
- * Returns true or false depending on the provided WebServiceFeature being an
RespectBindingFeature or not.
- * In the former case, the respect binding checks are performed.
*
+ * Perform respect binding checks
+ *
* @param <T>
* @param feature
* @param epMetaData
Added:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/feature/ChunkedEncodingFeature.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/feature/ChunkedEncodingFeature.java
(rev 0)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/feature/ChunkedEncodingFeature.java 2009-07-16
16:34:38 UTC (rev 10328)
@@ -0,0 +1,100 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.feature;
+
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.WebServiceFeature;
+
+import org.jboss.ws.Constants;
+
+/**
+ * This feature represents the use of http chunked encoding
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 16-Jul-2009
+ */
+public final class ChunkedEncodingFeature extends WebServiceFeature
+{
+ /**
+ * Constant value identifying the FastInfosetFeature
+ */
+ public static final String ID = Constants.NS_JBOSSWS_URI +
"/features/chunkedencoding";
+
+ protected int chunkSize = 1024;
+
+ /**
+ * Create an <code>ChunkedEncodingFeature</code>.
+ * The instance created will be enabled.
+ */
+ public ChunkedEncodingFeature()
+ {
+ this.enabled = true;
+ }
+
+ /**
+ * Creates a <code>ChunkedEncodingFeature</code>.
+ *
+ * @param enabled specifies if this feature should be enabled or not
+ */
+ public ChunkedEncodingFeature(boolean enabled)
+ {
+ this.enabled = enabled;
+ if (!enabled)
+ {
+ this.chunkSize = 0;
+ }
+ }
+
+ /**
+ * Creates a <code>ChunkedEncodingFeature</code> and set the provided
chunk size (chunkSize == 0 turns off chunked encoding).
+ *
+ * @param chunkSize the chunk size in bytes
+ */
+ public ChunkedEncodingFeature(int chunkSize)
+ {
+ if (chunkSize < 0)
+ {
+ throw new WebServiceException("ChunkedEncodingFeature.chunkSize must be
>= 0, actual value: " + chunkSize);
+ }
+ this.chunkSize = chunkSize;
+ this.enabled = (chunkSize > 0);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getID()
+ {
+ return ID;
+ }
+
+ /**
+ * Gets the configured chunksize
+ *
+ * @return the current chunksize in bytes
+ */
+ public int getChunkSize()
+ {
+ return chunkSize;
+ }
+}
Property changes on:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/feature/ChunkedEncodingFeature.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF