Author: chris.laprun(a)jboss.com
Date: 2010-03-03 11:33:01 -0500 (Wed, 03 Mar 2010)
New Revision: 1951
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/handler/RequestHeaderClientHandler.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/services/SOAPServiceFactory.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/services/ServiceWrapper.java
Log:
- GTNWSRP-6: Insert RequestHeaderClientHandler into the binding handler chain as this was
previously not done.
This is done programmatically so that we can ensure that this handler will always be
there and won't interfere
with potential customer customization.
- Moved customization of WS service object to ServiceWrapper as it's the whole point
of wrapping the service. :)
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/handler/RequestHeaderClientHandler.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/handler/RequestHeaderClientHandler.java 2010-03-03
16:27:38 UTC (rev 1950)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/handler/RequestHeaderClientHandler.java 2010-03-03
16:33:01 UTC (rev 1951)
@@ -1,6 +1,6 @@
/*
* JBoss, a division of Red Hat
- * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * Copyright 2010, Red Hat Middleware, LLC, and individual
* contributors as indicated by the @authors tag. See the
* copyright.txt in the distribution for a full listing of
* individual contributors.
@@ -50,9 +50,11 @@
*/
public class RequestHeaderClientHandler implements SOAPHandler<SOAPMessageContext>
{
- private static final ThreadLocal local = new ThreadLocal();
+ private static final ThreadLocal<CurrentInfo> local = new
ThreadLocal<CurrentInfo>();
private static final RFC2109Spec cookieParser = new RFC2109Spec();
private static final Logger log =
LoggerFactory.getLogger(RequestHeaderClientHandler.class);
+ private static final String SET_COOKIE = "Set-Cookie";
+ private static final String COOKIE = "Cookie";
public Set<QName> getHeaders()
{
@@ -125,7 +127,7 @@
if (cookie.length() != 0)
{
- mimeHeaders.setHeader("Cookie", cookie.toString());
+ mimeHeaders.setHeader(COOKIE, cookie.toString());
}
return true;
@@ -136,7 +138,7 @@
SOAPMessageContext smc = (SOAPMessageContext)msgContext;
SOAPMessage message = smc.getMessage();
MimeHeaders mimeHeaders = message.getMimeHeaders();
- String[] cookieValues = mimeHeaders.getHeader("Set-Cookie");
+ String[] cookieValues = mimeHeaders.getHeader(SET_COOKIE);
if (cookieValues != null)
{
@@ -288,7 +290,7 @@
public static void setCurrentGroupId(String groupId)
{
- CurrentInfo currentInfo = (CurrentInfo)local.get();
+ CurrentInfo currentInfo = local.get();
if (currentInfo == null)
{
throw new IllegalStateException("Cannot set current group id when the
current info hasn't been initialized.");
@@ -298,7 +300,7 @@
private static CurrentInfo getCurrentInfo(boolean createIfNeeded)
{
- CurrentInfo info = (CurrentInfo)local.get();
+ CurrentInfo info = local.get();
if (info == null && createIfNeeded)
{
info = new CurrentInfo(null, new ProducerSessionInformation());
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/services/SOAPServiceFactory.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/services/SOAPServiceFactory.java 2010-03-03
16:27:38 UTC (rev 1950)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/services/SOAPServiceFactory.java 2010-03-03
16:33:01 UTC (rev 1951)
@@ -59,7 +59,6 @@
private boolean failed;
private boolean available;
private int msBeforeTimeOut = DEFAULT_TIMEOUT_MS;
- private static final String JBOSS_WS_STUBEXT_PROPERTY_CHUNKED_ENCODING_SIZE =
"http://org.jboss.ws/http#chunksize";
public <T> T getService(Class<T> clazz) throws Exception
{
@@ -108,17 +107,9 @@
{
log.debug("Setting the end point to: " + portAddress);
}
- Map<String, Object> requestContext =
((BindingProvider)service).getRequestContext();
- requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, portAddress);
- // Set org.jboss.ws.core.StubExt.PROPERTY_CHUNKED_ENCODING_SIZE to 0 to
deactive chunked encoding for
- // better interoperability as Oracle's producer doesn't support it,
for example.
- // See
https://jira.jboss.org/jira/browse/JBWS-2884 and
- //
http://community.jboss.org/wiki/JBossWS-NativeUserGuide#Chunked_encoding_...
- requestContext.put(JBOSS_WS_STUBEXT_PROPERTY_CHUNKED_ENCODING_SIZE, 0);
+ T result = ServiceWrapper.getServiceWrapper(clazz, service, portAddress,
this);
- T result = ServiceWrapper.getServiceWrapper(clazz, service, this);
-
// if we managed to retrieve a service, we're probably available
setFailed(false);
setAvailable(true);
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/services/ServiceWrapper.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/services/ServiceWrapper.java 2010-03-03
16:27:38 UTC (rev 1950)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/services/ServiceWrapper.java 2010-03-03
16:33:01 UTC (rev 1951)
@@ -1,6 +1,6 @@
/*
* JBoss, a division of Red Hat
- * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * Copyright 2010, Red Hat Middleware, LLC, and individual
* contributors as indicated by the @authors tag. See the
* copyright.txt in the distribution for a full listing of
* individual contributors.
@@ -23,10 +23,16 @@
package org.gatein.wsrp.services;
+import org.gatein.wsrp.handler.RequestHeaderClientHandler;
+
+import javax.xml.ws.Binding;
import javax.xml.ws.BindingProvider;
+import javax.xml.ws.handler.Handler;
import javax.xml.ws.soap.SOAPFaultException;
import java.lang.reflect.ParameterizedType;
import java.rmi.RemoteException;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Map;
/**
@@ -49,6 +55,9 @@
private static final String SUN_WS_TIMEOUT =
"com.sun.xml.ws.request.timeout";
private static final String IBM_WS_TIMEOUT = "com.ibm.SOAP.requestTimeout";
+ private static final RequestHeaderClientHandler REQUEST_HEADER_CLIENT_HANDLER = new
RequestHeaderClientHandler();
+ private static final String JBOSS_WS_STUBEXT_PROPERTY_CHUNKED_ENCODING_SIZE =
"http://org.jboss.ws/http#chunksize";
+
protected ServiceWrapper(Object service, ManageableServiceFactory parentFactory)
{
if (service == null)
@@ -60,7 +69,7 @@
// set timeout properties for different WS stacks
BindingProvider bindingProvider = (BindingProvider)service;
- setTimeout(bindingProvider, parentFactory);
+ setTimeout(bindingProvider.getRequestContext(), parentFactory);
Class tClass =
(Class)((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[0];
@@ -75,18 +84,50 @@
this.parentFactory = parentFactory;
}
- private static void setTimeout(BindingProvider bindingProvider,
ManageableServiceFactory parentFactory)
+ private static void setTimeout(Map<String, Object> requestContext,
ManageableServiceFactory parentFactory)
{
- Map<String, Object> requestContext = bindingProvider.getRequestContext();
- requestContext.put(JBOSS_WS_TIMEOUT, parentFactory.getWSOperationTimeOut());
- requestContext.put(SUN_WS_TIMEOUT, parentFactory.getWSOperationTimeOut());
- requestContext.put(IBM_WS_TIMEOUT, parentFactory.getWSOperationTimeOut());
+ int timeout = parentFactory.getWSOperationTimeOut();
+ requestContext.put(JBOSS_WS_TIMEOUT, timeout);
+ requestContext.put(SUN_WS_TIMEOUT, timeout);
+ requestContext.put(IBM_WS_TIMEOUT, timeout);
}
- public static <T> T getServiceWrapper(Class<T> expectedServiceInterface,
Object service, ManageableServiceFactory parentFactory)
+ public static <T> T getServiceWrapper(Class<T> expectedServiceInterface,
Object service, String portAddress, ManageableServiceFactory parentFactory)
{
- // for now, only set timeouts
- setTimeout((BindingProvider)service, parentFactory);
+ BindingProvider bindingProvider = (BindingProvider)service;
+ Map<String, Object> requestContext = bindingProvider.getRequestContext();
+
+ // set timeout
+ setTimeout(requestContext, parentFactory);
+
+ // set port address
+ requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, portAddress);
+
+ // Set org.jboss.ws.core.StubExt.PROPERTY_CHUNKED_ENCODING_SIZE to 0 to deactive
chunked encoding for
+ // better interoperability as Oracle's producer doesn't support it, for
example.
+ // See
https://jira.jboss.org/jira/browse/JBWS-2884 and
+ //
http://community.jboss.org/wiki/JBossWS-NativeUserGuide#Chunked_encoding_...
+ requestContext.put(JBOSS_WS_STUBEXT_PROPERTY_CHUNKED_ENCODING_SIZE, 0);
+
+ // Add client side handler via JAX-WS API
+ Binding binding = bindingProvider.getBinding();
+ List<Handler> handlerChain = binding.getHandlerChain();
+ if (handlerChain != null)
+ {
+ // if we already have a handler chain, just add the request hearder handler if
it's not already in there
+ if (!handlerChain.contains(REQUEST_HEADER_CLIENT_HANDLER))
+ {
+ handlerChain.add(REQUEST_HEADER_CLIENT_HANDLER);
+ }
+ }
+ else
+ {
+ // otherwise, create a handler chain and add our handler to it
+ handlerChain = new ArrayList<Handler>(1);
+ handlerChain.add(REQUEST_HEADER_CLIENT_HANDLER);
+ }
+ binding.setHandlerChain(handlerChain);
+
return expectedServiceInterface.cast(service);
}