Author: alessio.soldano(a)jboss.com
Date: 2009-09-15 10:17:45 -0400 (Tue, 15 Sep 2009)
New Revision: 10694
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/CommonClient.java
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/HTTPRemotingConnection.java
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/RemoteConnection.java
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/SOAPProtocolConnectionHTTP.java
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/transport/NettyClient.java
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/transport/WSResponseHandler.java
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPConnectionImpl.java
Log:
[JBWS-2753] Using response handler for one-way message exchanges too to correctly handle
response headers
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/CommonClient.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/CommonClient.java 2009-09-15
14:13:16 UTC (rev 10693)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/CommonClient.java 2009-09-15
14:17:45 UTC (rev 10694)
@@ -340,7 +340,7 @@
addSessionInfo(reqMessage, callProps);
RemoteConnection remoteConnection = new
RemoteConnectionFactory().getRemoteConnection(epInfo);
- MessageAbstraction resMessage = remoteConnection.invoke(reqMessage, epInfo,
oneway, maintainSession);
+ MessageAbstraction resMessage = remoteConnection.invoke(reqMessage, epInfo,
oneway);
if (shouldMaintainSession())
saveSessionInfo(callProps, getRequestContext());
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/HTTPRemotingConnection.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/HTTPRemotingConnection.java 2009-09-15
14:13:16 UTC (rev 10693)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/HTTPRemotingConnection.java 2009-09-15
14:17:45 UTC (rev 10694)
@@ -87,17 +87,12 @@
this.chunkSize = chunkSize;
}
- public MessageAbstraction invoke(MessageAbstraction reqMessage, Object endpoint,
boolean oneway) throws IOException
- {
- return this.invoke(reqMessage, endpoint, oneway, true);
- }
-
/**
* Sends the given message to the specified endpoint.
*
* A null reqMessage signifies a HTTP GET request.
*/
- public MessageAbstraction invoke(MessageAbstraction reqMessage, Object endpoint,
boolean oneway, boolean maintainSession) throws IOException
+ public MessageAbstraction invoke(MessageAbstraction reqMessage, Object endpoint,
boolean oneway) throws IOException
{
if (endpoint == null)
throw new IllegalArgumentException("Given endpoint cannot be null");
@@ -152,7 +147,7 @@
populateHeaders(reqMessage, additionalHeaders);
//Trace the outgoing message
MessageTrace.traceMessage("Outgoing Request Message", reqMessage);
- MessageAbstraction resMessage = (MessageAbstraction)client.invoke(reqMessage,
targetAddress, !oneway || maintainSession, additionalHeaders, callProps);
+ MessageAbstraction resMessage = (MessageAbstraction)client.invoke(reqMessage,
targetAddress, oneway, additionalHeaders, callProps);
//Trace the incoming response message
MessageTrace.traceMessage("Incoming Response Message", resMessage);
return resMessage;
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/RemoteConnection.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/RemoteConnection.java 2009-09-15
14:13:16 UTC (rev 10693)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/RemoteConnection.java 2009-09-15
14:17:45 UTC (rev 10694)
@@ -39,6 +39,4 @@
UnMarshaller getUnmarshaller();
MessageAbstraction invoke(MessageAbstraction reqMessage, Object endpoint, boolean
oneway) throws IOException;
-
- MessageAbstraction invoke(MessageAbstraction reqMessage, Object endpoint, boolean
oneway, boolean maintainSession) throws IOException;
}
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/SOAPProtocolConnectionHTTP.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/SOAPProtocolConnectionHTTP.java 2009-09-15
14:13:16 UTC (rev 10693)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/SOAPProtocolConnectionHTTP.java 2009-09-15
14:17:45 UTC (rev 10694)
@@ -53,7 +53,7 @@
}
@Override
- public MessageAbstraction invoke(MessageAbstraction reqMessage, Object endpoint,
boolean oneway, boolean maintainSession) throws IOException
+ public MessageAbstraction invoke(MessageAbstraction reqMessage, Object endpoint,
boolean oneway) throws IOException
{
try
{
@@ -66,7 +66,7 @@
if (reqMessage != null && soapMessage.saveRequired())
soapMessage.saveChanges();
- return super.invoke(reqMessage, endpoint, oneway, maintainSession);
+ return super.invoke(reqMessage, endpoint, oneway);
}
catch (SOAPException ex)
{
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/transport/NettyClient.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/transport/NettyClient.java 2009-09-15
14:13:16 UTC (rev 10693)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/transport/NettyClient.java 2009-09-15
14:17:45 UTC (rev 10694)
@@ -22,16 +22,12 @@
package org.jboss.ws.core.client.transport;
import java.io.IOException;
-import java.io.InputStream;
import java.io.OutputStream;
import java.net.ConnectException;
-import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.channels.ClosedChannelException;
import java.util.Map;
-import java.util.concurrent.Executor;
-import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@@ -41,14 +37,11 @@
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;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelFactory;
import org.jboss.netty.channel.ChannelFuture;
-import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;
import org.jboss.netty.handler.codec.http.DefaultHttpRequest;
import org.jboss.netty.handler.codec.http.HttpHeaders;
import org.jboss.netty.handler.codec.http.HttpMessage;
@@ -108,15 +101,14 @@
*
* @param reqMessage The request message
* @param targetAddress The target address
- * @param waitForResponse A boolean saying if the method should wait for the
results before returning. Waiting is required for two-ways invocations
+ * @param oneway True for one-way message exchanges
* and when maintaining sessions using cookies.
* @param additionalHeaders Additional http headers to be added to the request
* @param callProps
* @return
* @throws IOException
*/
- public Object invoke(Object reqMessage, String targetAddress, boolean waitForResponse,
Map<String, Object> additionalHeaders, Map<String, Object> callProps)
- throws IOException
+ public Object invoke(Object reqMessage, String targetAddress, boolean oneway,
Map<String, Object> additionalHeaders, Map<String, Object> callProps) throws
IOException
{
URL target;
try
@@ -136,12 +128,8 @@
setActualTimeout(callProps);
channel = transport.getChannel(timeout);
- WSResponseHandler responseHandler = null;
- if (waitForResponse)
- {
- responseHandler = new WSResponseHandler();
- NettyHelper.setResponseHandler(channel, responseHandler);
- }
+ WSResponseHandler responseHandler = new WSResponseHandler();
+ NettyHelper.setResponseHandler(channel, responseHandler);
//Send the HTTP request
HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, reqMessage !=
null ? HttpMethod.POST : HttpMethod.GET, targetAddress);
@@ -159,19 +147,12 @@
{
writeFuture.awaitUninterruptibly();
}
- if (!waitForResponse)
- {
- //No need to wait for the result, just wait for the write to be completed.
- return null;
- }
- Object resMessage = null;
//Get the response
Future<Result> futureResult = responseHandler.getFutureResult();
Result result = timeout == null ? futureResult.get() : futureResult.get(timeout,
TimeUnit.MILLISECONDS);
resHeaders = result.getResponseHeaders();
- InputStream is = result.getResponse();
- resMessage = unmarshaller.read(is, resHeaders);
+ Object resMessage = oneway ? null : unmarshaller.read(result.getResponse(),
resHeaders);
//Update props with response headers (required to maintain session using
cookies)
callProps.clear();
@@ -214,7 +195,7 @@
}
finally
{
- if (channel != null && waitForResponse)
+ if (channel != null)
{
NettyHelper.clearResponseHandler(channel);
}
@@ -365,16 +346,8 @@
{
for (String key : headers.keySet())
{
- try
- {
- String header = (String)headers.get(key);
- message.addHeader(key, header.replaceAll("[\r\n\f]", "
"));
- }
- catch (Exception e)
- {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
+ String header = (String)headers.get(key);
+ message.addHeader(key, header.replaceAll("[\r\n\f]", " "));
}
}
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/transport/WSResponseHandler.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/transport/WSResponseHandler.java 2009-09-15
14:13:16 UTC (rev 10693)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/transport/WSResponseHandler.java 2009-09-15
14:17:45 UTC (rev 10694)
@@ -83,6 +83,10 @@
ChannelBuffer content = response.getContent();
result.setResponse(new ChannelBufferInputStream(content));
}
+ catch (Throwable t)
+ {
+ future.setException(t);
+ }
finally
{
future.done();
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPConnectionImpl.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPConnectionImpl.java 2009-09-15
14:13:16 UTC (rev 10693)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPConnectionImpl.java 2009-09-15
14:17:45 UTC (rev 10694)
@@ -140,7 +140,7 @@
try
{
remotingConnection = getRemotingConnection(endpoint);
- MessageAbstraction resMessage =
remotingConnection.invoke((SOAPMessageImpl)reqMessage, endpoint, oneway, false);
+ MessageAbstraction resMessage =
remotingConnection.invoke((SOAPMessageImpl)reqMessage, endpoint, oneway);
return resMessage;
}
catch (Exception ex)