cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r752520 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/ main/java/org/apache/cxf/jaxrs/client/ main/java/org/apache/cxf/jaxrs/impl/ main/java/org/apache/cxf/jaxrs/interceptor/ main/java/org/apache/cxf/jaxrs/provider/ ...
Date Wed, 11 Mar 2009 16:54:21 GMT
Author: sergeyb
Date: Wed Mar 11 16:54:20 2009
New Revision: 752520

URL: http://svn.apache.org/viewvc?rev=752520&view=rev
Log:
JAXRS : getting rid of ProviderFactory singletons

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ProvidersImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java?rev=752520&r1=752519&r2=752520&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java Wed Mar 11 16:54:20 2009
@@ -36,6 +36,7 @@
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.endpoint.EndpointException;
 import org.apache.cxf.endpoint.EndpointImpl;
+import org.apache.cxf.jaxrs.provider.ProviderFactory;
 import org.apache.cxf.service.Service;
 import org.apache.cxf.service.model.BindingInfo;
 import org.apache.cxf.service.model.EndpointInfo;
@@ -209,4 +210,16 @@
             throw new WebApplicationException(Response.Status.NOT_FOUND);
         }
     }
+    
+    protected ProviderFactory setupFactory(Endpoint ep) { 
+        ProviderFactory factory = ProviderFactory.getInstance(); 
+        if (entityProviders != null) {
+            factory.setUserProviders(entityProviders); 
+        }
+        if (schemaLocations != null) {
+            factory.setSchemaLocations(schemaLocations);
+        }
+        ep.put(ProviderFactory.class.getName(), factory);
+        return factory;
+    }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java?rev=752520&r1=752519&r2=752520&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java Wed Mar 11 16:54:20 2009
@@ -46,7 +46,6 @@
 import org.apache.cxf.jaxrs.model.OperationResourceInfoStack;
 import org.apache.cxf.jaxrs.model.URITemplate;
 import org.apache.cxf.jaxrs.provider.ProviderFactory;
-import org.apache.cxf.jaxrs.utils.HttpUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.message.Exchange;
@@ -106,8 +105,6 @@
                                             exchange.getInMessage());
         }
 
-        String baseAddress = HttpUtils.getOriginalAddress(exchange.getInMessage());
-
         List<Object> params = null;
         if (request instanceof List) {
             params = CastUtils.cast((List<?>)request);
@@ -125,10 +122,9 @@
             result = invoke(exchange, resourceObject, methodToInvoke, params);
         } catch (Fault ex) {
             Response excResponse = JAXRSUtils.convertFaultToResponse(ex.getCause(), 
-                                                                     baseAddress,
                                                                      exchange.getInMessage());
             if (excResponse == null) {
-                ProviderFactory.getInstance(baseAddress).clearThreadLocalProxies();
+                ProviderFactory.getInstance(exchange.getInMessage()).clearThreadLocalProxies();
                 ClassResourceInfo criRoot =
                     (ClassResourceInfo)exchange.get(JAXRSInInterceptor.ROOT_RESOURCE_CLASS);
                 if (criRoot != null) {
@@ -195,7 +191,6 @@
                 return this.invoke(exchange, newParams, newResourceObjects);
             } catch (WebApplicationException ex) {
                 Response excResponse = JAXRSUtils.convertFaultToResponse(ex, 
-                                                                         baseAddress,
                                                                          exchange.getInMessage());
                 return new MessageContentsList(excResponse);
             }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java?rev=752520&r1=752519&r2=752520&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java Wed Mar 11 16:54:20 2009
@@ -94,14 +94,9 @@
                 ep.getService().setInvoker(invoker);
             }
             
-            if (entityProviders != null) {
-                ProviderFactory.getInstance(getAddress()).setUserProviders(entityProviders); 
-            }
-            if (schemaLocations != null) {
-                ProviderFactory.getInstance(getAddress()).setSchemaLocations(schemaLocations);
-            }
+            ProviderFactory factory = setupFactory(ep);
             
-            ProviderFactory.getInstance(getAddress()).setRequestPreprocessor(
+            factory.setRequestPreprocessor(
                 new RequestPreprocessor(languageMappings, extensionMappings));
             
             

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java?rev=752520&r1=752519&r2=752520&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java Wed Mar 11 16:54:20 2009
@@ -329,7 +329,7 @@
         
         MediaType contentType = MediaType.valueOf(headers.getFirst("Content-Type")); 
         
-        MessageBodyWriter mbw = ProviderFactory.getInstance(baseURI.getPath()).createMessageBodyWriter(
+        MessageBodyWriter mbw = ProviderFactory.getInstance(m).createMessageBodyWriter(
             cls, type, anns, contentType, m);
         if (mbw == null) {
             mbw = ProviderFactory.getInstance().createMessageBodyWriter(
@@ -364,7 +364,7 @@
         
         MediaType contentType = getResponseContentType(r);
         
-        MessageBodyReader mbr = ProviderFactory.getInstance(baseURI.getPath()).createMessageBodyReader(
+        MessageBodyReader mbr = ProviderFactory.getInstance(inMessage).createMessageBodyReader(
             cls, type, anns, contentType, inMessage);
         if (mbr == null) {
             ProviderFactory.getInstance().createMessageBodyReader(
@@ -481,6 +481,7 @@
         exchange.setOutMessage(m);
         exchange.put(Bus.class, bus);
         exchange.put(MessageObserver.class, new ClientMessageObserver());
+        exchange.put(Endpoint.class, conduitSelector.getEndpoint());
         exchange.setOneWay(false);
         m.setExchange(exchange);
         

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java?rev=752520&r1=752519&r2=752520&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java Wed Mar 11 16:54:20 2009
@@ -181,16 +181,13 @@
         return index;
     }
     
-    private static void checkResponse(String basePath, Method m, Response r) throws Throwable {
+    private static void checkResponse(Method m, Response r, Message message) throws Throwable {
         
         int status = r.getStatus();
         
         if (status >= 400) {
             
-            ResponseExceptionMapper<?> mapper = findExceptionMapper(m, basePath);
-            if (mapper == null) {
-                mapper = findExceptionMapper(m, "/");
-            }
+            ResponseExceptionMapper<?> mapper = findExceptionMapper(m, message);
             if (mapper != null) {
                 Throwable t = mapper.fromResponse(r);
                 if (t != null) {
@@ -202,8 +199,8 @@
         }
     }
     
-    private static ResponseExceptionMapper<?> findExceptionMapper(Method m, String base) {
-        ProviderFactory pf = ProviderFactory.getInstance(base);
+    private static ResponseExceptionMapper<?> findExceptionMapper(Method m, Message message) {
+        ProviderFactory pf = ProviderFactory.getInstance(message);
         for (Class<?> exType : m.getExceptionTypes()) {
             ResponseExceptionMapper<?> mapper = pf.createResponseExceptionMapper(exType);
             if (mapper != null) {
@@ -405,7 +402,7 @@
         throws Throwable {
         Response r = setResponseBuilder(connect).clone().build();
         Method method = ori.getMethodToInvoke();
-        checkResponse(getBaseURI().getPath(), method, r);
+        checkResponse(method, r, inMessage);
         if (method.getReturnType() == Void.class) { 
             return null;
         }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java?rev=752520&r1=752519&r2=752520&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java Wed Mar 11 16:54:20 2009
@@ -35,7 +35,6 @@
 import org.apache.cxf.jaxrs.JAXRSServiceImpl;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
-import org.apache.cxf.jaxrs.provider.ProviderFactory;
 import org.apache.cxf.jaxrs.utils.AnnotationUtils;
 import org.apache.cxf.service.Service;
 
@@ -162,11 +161,6 @@
         if (headers != null) {
             client.headers(headers);
         }
-        if (entityProviders != null) {
-            ProviderFactory.getInstance().setUserProviders(entityProviders); 
-        }
-        if (schemaLocations != null) {
-            ProviderFactory.getInstance().setSchemaLocations(schemaLocations);
-        }
+        setupFactory(ep);
     }
 } 

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ProvidersImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ProvidersImpl.java?rev=752520&r1=752519&r2=752520&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ProvidersImpl.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ProvidersImpl.java Wed Mar 11 16:54:20 2009
@@ -41,23 +41,22 @@
     
     public <T> MessageBodyReader<T> getMessageBodyReader(
          Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
-        return ProviderFactory.getInstance((String)m.get(Message.BASE_PATH)).createMessageBodyReader(
+        return ProviderFactory.getInstance(m).createMessageBodyReader(
             type, genericType, annotations, mediaType, m);
     }
 
     public <T> MessageBodyWriter<T> getMessageBodyWriter(
         Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
-        return ProviderFactory.getInstance((String)m.get(Message.BASE_PATH)).createMessageBodyWriter(
+        return ProviderFactory.getInstance(m).createMessageBodyWriter(
                    type, genericType, annotations, mediaType, m);
     }
 
     public <T> ContextResolver<T> getContextResolver(Class<T> contextType, MediaType mediaType) {
-        return ProviderFactory.getInstance((String)m.get(Message.BASE_PATH))
-            .createContextResolver(contextType, m, mediaType);
+        return ProviderFactory.getInstance(m).createContextResolver(contextType, m, mediaType);
     }
 
     public <T extends Throwable> ExceptionMapper<T> getExceptionMapper(Class<T> type) {
-        return ProviderFactory.getInstance((String)m.get(Message.BASE_PATH)).createExceptionMapper(type, m);
+        return ProviderFactory.getInstance(m).createExceptionMapper(type, m);
     }
 
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java?rev=752520&r1=752519&r2=752520&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java Wed Mar 11 16:54:20 2009
@@ -61,15 +61,12 @@
 
     public void handleMessage(Message message) {
         
-        
-        String originalAddress = HttpUtils.getOriginalAddress(message);
-        
         try {
-            processRequest(message, originalAddress);
+            processRequest(message);
         } catch (RuntimeException ex) {
-            Response excResponse = JAXRSUtils.convertFaultToResponse(ex, originalAddress, message);
+            Response excResponse = JAXRSUtils.convertFaultToResponse(ex, message);
             if (excResponse == null) {
-                ProviderFactory.getInstance(originalAddress).clearThreadLocalProxies();
+                ProviderFactory.getInstance(message).clearThreadLocalProxies();
                 throw ex;
             }
             message.getExchange().put(Response.class, excResponse);
@@ -78,15 +75,14 @@
         
     }
     
-    private void processRequest(Message message, String originalAddress) {
+    private void processRequest(Message message) {
         
         if (message.getExchange().get(OperationResourceInfo.class) != null) {
             // it's a suspended invocation;
             return;
         }
         
-        RequestPreprocessor rp = 
-            ProviderFactory.getInstance(originalAddress).getRequestPreprocessor();
+        RequestPreprocessor rp = ProviderFactory.getInstance(message).getRequestPreprocessor();
         if (rp != null) {
             rp.preprocess(message, new UriInfoImpl(message, null));
         }
@@ -129,8 +125,7 @@
         String httpMethod = (String)message.get(Message.HTTP_REQUEST_METHOD);
         OperationResourceInfo ori = null;     
         
-        List<ProviderInfo<RequestHandler>> shs = 
-            ProviderFactory.getInstance(originalAddress).getRequestHandlers();
+        List<ProviderInfo<RequestHandler>> shs = ProviderFactory.getInstance(message).getRequestHandlers();
         for (ProviderInfo<RequestHandler> sh : shs) {
             String newAcceptTypes = (String)message.get(Message.ACCEPT_CONTENT_TYPE);
             if (!acceptTypes.equals(newAcceptTypes) || ori == null) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java?rev=752520&r1=752519&r2=752520&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java Wed Mar 11 16:54:20 2009
@@ -45,7 +45,6 @@
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
 import org.apache.cxf.jaxrs.model.ProviderInfo;
 import org.apache.cxf.jaxrs.provider.ProviderFactory;
-import org.apache.cxf.jaxrs.utils.HttpUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.message.Exchange;
@@ -65,11 +64,10 @@
 
     public void handleMessage(Message message) {
         
-        String baseAddress = HttpUtils.getOriginalAddress(message.getExchange().getInMessage());
         try {
-            processResponse(message, baseAddress);
+            processResponse(message);
         } finally {
-            ProviderFactory.getInstance(baseAddress).clearThreadLocalProxies();
+            ProviderFactory.getInstance(message).clearThreadLocalProxies();
             ClassResourceInfo cri =
                 (ClassResourceInfo)message.getExchange().get(JAXRSInInterceptor.ROOT_RESOURCE_CLASS);
             if (cri != null) {
@@ -80,7 +78,7 @@
 
     }
     
-    private void processResponse(Message message, String baseAddress) {
+    private void processResponse(Message message) {
         
         MessageContentsList objs = MessageContentsList.getContentsList(message);
         if (objs == null || objs.size() == 0) {
@@ -101,7 +99,7 @@
                 .getName());
 
             List<ProviderInfo<ResponseHandler>> handlers = 
-                ProviderFactory.getInstance(baseAddress).getResponseHandlers();
+                ProviderFactory.getInstance(message).getResponseHandlers();
             for (ProviderInfo<ResponseHandler> rh : handlers) {
                 Response r = rh.getProvider().handleResponse(message, ori, response);
                 if (r != null) {
@@ -109,7 +107,7 @@
                 }
             }
             
-            serializeMessage(message, response, ori, baseAddress, true);        
+            serializeMessage(message, response, ori, true);        
             
         } else {
             message.put(Message.RESPONSE_CODE, 204);
@@ -120,7 +118,6 @@
     private void serializeMessage(Message message, 
                                   Response response, 
                                   OperationResourceInfo ori,
-                                  String baseAddress,
                                   boolean firstTry) {
         message.put(Message.RESPONSE_CODE, response.getStatus());
         Map<String, List<String>> theHeaders = 
@@ -148,7 +145,7 @@
         MessageBodyWriter writer = null;
         MediaType responseType = null;
         for (MediaType type : availableContentTypes) { 
-            writer = ProviderFactory.getInstance(baseAddress)
+            writer = ProviderFactory.getInstance(message)
                 .createMessageBodyWriter(targetType, 
                       invoked != null ? invoked.getGenericReturnType() : null, 
                       invoked != null ? invoked.getAnnotations() : new Annotation[]{}, 
@@ -191,9 +188,9 @@
             }
             
         } catch (IOException ex) {
-            handleWriteException(message, response, ori, baseAddress, ex, responseObj, firstTry);
+            handleWriteException(message, response, ori, ex, responseObj, firstTry);
         } catch (Throwable ex) {
-            handleWriteException(message, response, ori, baseAddress, ex, responseObj, firstTry);
+            handleWriteException(message, response, ori, ex, responseObj, firstTry);
         }
     }
     
@@ -247,15 +244,14 @@
     private void handleWriteException(Message message, 
                                          Response response, 
                                          OperationResourceInfo ori,
-                                         String baseAddress,
                                          Throwable ex,
                                          Object responseObj,
                                          boolean firstTry) {
         OutputStream out = message.getContent(OutputStream.class);
         if (firstTry) {
-            Response excResponse = JAXRSUtils.convertFaultToResponse(ex, baseAddress, message);
+            Response excResponse = JAXRSUtils.convertFaultToResponse(ex, message);
             if (excResponse != null) {
-                serializeMessage(message, excResponse, ori, baseAddress, false);
+                serializeMessage(message, excResponse, ori, false);
             }
         } else {
             message.put(Message.RESPONSE_CODE, 500);

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java?rev=752520&r1=752519&r2=752520&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java Wed Mar 11 16:54:20 2009
@@ -26,10 +26,8 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
-import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
-import java.util.Map;
 
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.ext.ContextResolver;
@@ -37,6 +35,7 @@
 import javax.ws.rs.ext.MessageBodyReader;
 import javax.ws.rs.ext.MessageBodyWriter;
 
+import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.jaxrs.client.ResponseExceptionMapper;
 import org.apache.cxf.jaxrs.ext.ParameterHandler;
 import org.apache.cxf.jaxrs.ext.RequestHandler;
@@ -51,11 +50,7 @@
 
 public final class ProviderFactory {
     
-    private static final Map<String, ProviderFactory> FACTORIES = 
-        new HashMap<String, ProviderFactory>();
     private static final ProviderFactory SHARED_FACTORY = new ProviderFactory();
-    private static final ProviderFactory DEFAULT_FACTORY = new ProviderFactory(); 
-    private static final String SLASH = "/"; 
     
     static {
         SHARED_FACTORY.setProviders(new JAXBElementProvider(),
@@ -91,25 +86,14 @@
     }
     
     public static ProviderFactory getInstance() {
-        return getInstance("/");
+        return new ProviderFactory();
     }
     
-    public static ProviderFactory getInstance(String baseAddress) {
-        if (SLASH.equals(baseAddress)) {
-            return DEFAULT_FACTORY;
-        }
-        
-        ProviderFactory pf = null;
-        synchronized (ProviderFactory.class) { 
-            pf = FACTORIES.get(baseAddress);
-            if (pf == null) {
-                pf = new ProviderFactory();
-                FACTORIES.put(baseAddress, pf);
-            }
-        }
-        return pf;
+    public static ProviderFactory getInstance(Message m) {
+        Endpoint e = m.getExchange().get(Endpoint.class);
+        return (ProviderFactory)e.get(ProviderFactory.class.getName());
     }
-
+    
     public static ProviderFactory getSharedInstance() {
         return SHARED_FACTORY;
     }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=752520&r1=752519&r2=752520&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java Wed Mar 11 16:54:20 2009
@@ -167,7 +167,7 @@
     public static Object handleParameter(String value, 
                                          Class<?> pClass, 
                                          ParameterType pType,
-                                         String basePath) {
+                                         Message message) {
         
         if (value == null) {
             return null;
@@ -209,8 +209,8 @@
             result = evaluateFactoryMethod(value, pClass, pType, methodNames[1]);
         }
         
-        if (basePath != null) {
-            ParameterHandler<?> pm = ProviderFactory.getInstance(basePath)
+        if (message != null) {
+            ParameterHandler<?> pm = ProviderFactory.getInstance(message)
                 .createParameterHandler(pClass);
             if (pm != null) {
                 result = pm.fromString(value);
@@ -260,7 +260,7 @@
     }
     
     public static Object handleBean(Class<?> paramType, MultivaluedMap<String, String> values,
-                                    ParameterType pType, String basePath) {
+                                    ParameterType pType, Message message) {
         Object bean = null;
         try {
             bean = paramType.newInstance();
@@ -277,7 +277,7 @@
                     && m.getParameterTypes().length == 1) {
                     Object paramValue = handleParameter(entry.getValue().get(0), 
                                                         m.getParameterTypes()[0],
-                                                        pType, basePath);
+                                                        pType, message);
                     if (paramValue != null) {
                         injectThroughMethod(bean, m, paramValue);
                         injected = true;
@@ -291,7 +291,7 @@
             for (Field f : paramType.getFields()) {
                 if (f.getName().equalsIgnoreCase(entry.getKey())) {
                     Object paramValue = handleParameter(entry.getValue().get(0), 
-                                                        f.getType(), pType, basePath);
+                                                        f.getType(), pType, message);
                     if (paramValue != null) {
                         injectFieldValue(f, bean, paramValue);
                         break;
@@ -305,14 +305,14 @@
     
     @SuppressWarnings("unchecked")
     public static Object injectIntoList(Type genericType, List<String> values,
-                                        boolean decoded, ParameterType pathParam, String basePath) {
+                                        boolean decoded, ParameterType pathParam, Message message) {
         Class<?> realType = InjectionUtils.getActualType(genericType);
         values = checkPathSegment(values, realType, pathParam);
         List theValues = new ArrayList();
         for (String r : values) {
             String value = decodeValue(r, decoded, pathParam);
             
-            Object o = InjectionUtils.handleParameter(value, realType, pathParam, basePath);
+            Object o = InjectionUtils.handleParameter(value, realType, pathParam, message);
             if (o != null) {
                 theValues.add(o);
             }
@@ -326,7 +326,7 @@
     public static Object injectIntoSet(Type genericType, List<String> values, 
                                        boolean sorted, 
                                        boolean decoded, 
-                                       ParameterType pathParam, String basePath) {
+                                       ParameterType pathParam, Message message) {
         Class<?> realType = InjectionUtils.getActualType(genericType);
         
         values = checkPathSegment(values, realType, pathParam);
@@ -334,7 +334,7 @@
         Set theValues = sorted ? new TreeSet() : new HashSet();
         for (String r : values) {
             String value = decodeValue(r, decoded, pathParam);
-            Object o = InjectionUtils.handleParameter(value, realType, pathParam, basePath);
+            Object o = InjectionUtils.handleParameter(value, realType, pathParam, message);
             if (o != null) {
                 theValues.add(o);
             }
@@ -368,7 +368,7 @@
                                                String defaultValue,
                                                boolean decoded,
                                                ParameterType pathParam,
-                                               String basePath) {
+                                               Message message) {
         
         if (paramValues == null) {
             if (defaultValue != null) {
@@ -385,13 +385,13 @@
         
         if (List.class.isAssignableFrom(paramType)) {
             return InjectionUtils.injectIntoList(genericType, paramValues, decoded, pathParam,
-                                                 basePath);
+                                                 message);
         } else if (Set.class.isAssignableFrom(paramType)) {
             return InjectionUtils.injectIntoSet(genericType, paramValues, false, decoded, pathParam,
-                                                basePath);
+                                                message);
         } else if (SortedSet.class.isAssignableFrom(paramType)) {
             return InjectionUtils.injectIntoSet(genericType, paramValues, true, decoded, pathParam,
-                                                basePath);
+                                                message);
         } else {
             String result = null;
             if (paramValues.size() > 0) {
@@ -401,7 +401,7 @@
             }
             if (result != null) {
                 result = decodeValue(result, decoded, pathParam);
-                return InjectionUtils.handleParameter(result, paramType, pathParam, basePath);
+                return InjectionUtils.handleParameter(result, paramType, pathParam, message);
             } else {
                 return null;
             }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=752520&r1=752519&r2=752520&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java Wed Mar 11 16:54:20 2009
@@ -516,13 +516,11 @@
                 }
             }
             
-            String basePath = HttpUtils.getOriginalAddress(m);
-            
             if ("".equals(key)) {
                 return InjectionUtils.handleBean(pClass, 
                                                  params, 
                                                  ParameterType.MATRIX,
-                                                 basePath);
+                                                 m);
             } else {
                 List<String> values = params.get(key);
                 return InjectionUtils.createParameterObject(values, 
@@ -531,7 +529,7 @@
                                                             defaultValue,
                                                             false,
                                                             ParameterType.MATRIX,
-                                                            basePath);
+                                                            m);
             }
         }
         
@@ -560,9 +558,8 @@
             FormUtils.populateMapFromMultipart(params, body, decode);
         }
         
-        String basePath = HttpUtils.getOriginalAddress(m);
         if ("".equals(key)) {
-            return InjectionUtils.handleBean(pClass, params, ParameterType.FORM, basePath);
+            return InjectionUtils.handleBean(pClass, params, ParameterType.FORM, m);
         } else {
             List<String> results = params.get(key);
     
@@ -572,7 +569,7 @@
                                                         defaultValue,
                                                         false,
                                                         ParameterType.FORM,
-                                                        basePath);
+                                                        m);
              
         }
     }
@@ -594,14 +591,13 @@
         if (values != null && values.isEmpty()) {
             values = null;
         }
-        String basePath = HttpUtils.getOriginalAddress(m);
         return InjectionUtils.createParameterObject(values, 
                                                     pClass, 
                                                     genericType,
                                                     defaultValue,
                                                     false,
                                                     ParameterType.HEADER,
-                                                    basePath);
+                                                    m);
              
         
     }
@@ -621,8 +617,7 @@
             return c;
         }
         
-        String basePath = HttpUtils.getOriginalAddress(m);
-        return InjectionUtils.handleParameter(c.getValue(), pClass, ParameterType.COOKIE, basePath);
+        return InjectionUtils.handleParameter(c.getValue(), pClass, ParameterType.COOKIE, m);
     }
     
     public static <T> T createContextValue(Message m, Type genericType, Class<T> clazz) {
@@ -658,7 +653,7 @@
     
     public static ContextResolver<?> createContextResolver(Type genericType, Message m) {
         if (genericType instanceof ParameterizedType) {
-            return ProviderFactory.getInstance(HttpUtils.getOriginalAddress(m)).createContextResolver(
+            return ProviderFactory.getInstance(m).createContextResolver(
                       ((ParameterizedType)genericType).getActualTypeArguments()[0], m);
         }
         return null;
@@ -697,10 +692,9 @@
                                            String defaultValue,
                                            boolean  decoded) {
         
-        String basePath = HttpUtils.getOriginalAddress(m);
         String parameterName = uriParamAnnotation.value();
         if ("".equals(parameterName)) {
-            return InjectionUtils.handleBean(paramType, values, ParameterType.PATH, basePath);
+            return InjectionUtils.handleBean(paramType, values, ParameterType.PATH, m);
         } else {
             List<String> results = values.get(parameterName);
             return InjectionUtils.createParameterObject(results, 
@@ -709,7 +703,7 @@
                                                     defaultValue,
                                                     decoded,
                                                     ParameterType.PATH,
-                                                    basePath);
+                                                    m);
         }
     }
     
@@ -724,11 +718,10 @@
                                           boolean decode) {
         String queryName = queryParam.value();
 
-        String basePath = HttpUtils.getOriginalAddress(m);
         if ("".equals(queryName)) {
             return InjectionUtils.handleBean(paramType, 
                                              new UriInfoImpl(m, null).getQueryParameters(),
-                                             ParameterType.QUERY, basePath);
+                                             ParameterType.QUERY, m);
         } else {
             List<String> results = getStructuredParams((String)m.get(Message.QUERY_STRING),
                                        "&",
@@ -739,7 +732,7 @@
                                                         genericType,
                                                         defaultValue,
                                                         false,
-                                                        ParameterType.QUERY, basePath);
+                                                        ParameterType.QUERY, m);
              
         }
     }
@@ -789,7 +782,7 @@
         
         MessageBodyReader provider = null;
         for (MediaType type : types) { 
-            provider = ProviderFactory.getInstance(HttpUtils.getOriginalAddress(m))
+            provider = ProviderFactory.getInstance(m)
                 .createMessageBodyReader(targetTypeClass,
                                          parameterType,
                                          parameterAnnotations,
@@ -953,10 +946,10 @@
     }
     
     @SuppressWarnings("unchecked")
-    public static Response convertFaultToResponse(Throwable ex, String baseAddress, Message inMessage) {
+    public static Response convertFaultToResponse(Throwable ex, Message inMessage) {
         
         ExceptionMapper mapper = 
-            ProviderFactory.getInstance(baseAddress).createExceptionMapper(ex.getClass(), inMessage);
+            ProviderFactory.getInstance(inMessage).createExceptionMapper(ex.getClass(), inMessage);
         if (mapper != null) {
             Response excResponse = mapper.toResponse(ex);
             if (excResponse != null) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java?rev=752520&r1=752519&r2=752520&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java Wed Mar 11 16:54:20 2009
@@ -46,6 +46,7 @@
 
 import org.apache.abdera.model.Entry;
 import org.apache.abdera.model.Feed;
+import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.jaxrs.Customer;
 import org.apache.cxf.jaxrs.CustomerParameterHandler;
@@ -54,7 +55,11 @@
 import org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper;
 import org.apache.cxf.jaxrs.model.ProviderInfo;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.ExchangeImpl;
+import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
+import org.easymock.classextension.EasyMock;
 
 import org.junit.Assert;
 import org.junit.Before;
@@ -70,12 +75,23 @@
     
     @Test
     public void testMultipleFactories() {
-        assertSame(ProviderFactory.getInstance(), ProviderFactory.getInstance());
-        assertSame(ProviderFactory.getInstance("/"), ProviderFactory.getInstance("/"));
-        assertSame(ProviderFactory.getInstance(), ProviderFactory.getInstance("/"));
         assertNotSame(ProviderFactory.getInstance(), ProviderFactory.getSharedInstance());
-        assertSame(ProviderFactory.getInstance("/bar"), ProviderFactory.getInstance("/bar"));
-        assertNotSame(ProviderFactory.getInstance("/bar"), ProviderFactory.getInstance("/"));
+        assertSame(ProviderFactory.getSharedInstance(), ProviderFactory.getSharedInstance());
+        assertNotSame(ProviderFactory.getInstance(), ProviderFactory.getInstance());
+    }
+    
+    @Test
+    public void testGetFactoryInboundMessage() {
+        ProviderFactory factory = ProviderFactory.getInstance();
+        Message m = new MessageImpl();
+        Exchange e = new ExchangeImpl();
+        m.setExchange(e);
+        Endpoint endpoint = EasyMock.createMock(Endpoint.class);
+        endpoint.get(ProviderFactory.class.getName());
+        EasyMock.expectLastCall().andReturn(factory);
+        EasyMock.replay(endpoint);
+        e.put(Endpoint.class, endpoint);
+        assertSame(ProviderFactory.getInstance(m), factory);
     }
     
     @Test
@@ -186,25 +202,26 @@
         assertTrue(BinaryDataProvider.class == writer.getClass());
     }
     
-    private void verifyProvider(Class<?> type, Class<?> provider, String mediaType,
-                                String errorMessage) 
+    private void verifyProvider(ProviderFactory pf, Class<?> type, Class<?> provider, String mediaType) 
         throws Exception {
         
+        if (pf == null) {
+            pf = ProviderFactory.getInstance();
+        }
+        
         MediaType mType = MediaType.valueOf(mediaType);
         
-        MessageBodyReader reader = ProviderFactory.getInstance()
-            .createMessageBodyReader(type, null, null, mType, new MessageImpl());
-        assertSame(errorMessage, provider, reader.getClass());
+        MessageBodyReader reader = pf.createMessageBodyReader(type, null, null, mType, new MessageImpl());
+        assertSame("Unexpected provider found", provider, reader.getClass());
     
-        MessageBodyWriter writer = ProviderFactory.getInstance()
-            .createMessageBodyWriter(type, null, null, mType, new MessageImpl());
-        assertTrue(errorMessage, provider == writer.getClass());
+        MessageBodyWriter writer = pf.createMessageBodyWriter(type, null, null, mType, new MessageImpl());
+        assertTrue("Unexpected provider found", provider == writer.getClass());
     }
     
     
     private void verifyProvider(Class<?> type, Class<?> provider, String mediaType) 
         throws Exception {
-        verifyProvider(type, provider, mediaType, "Unexpected provider found");
+        verifyProvider(null, type, provider, mediaType);
         
     }
        
@@ -215,18 +232,19 @@
     
     @Test
     public void testGetAtomProvider() throws Exception {
-        ProviderFactory.getInstance().setUserProviders(
+        ProviderFactory factory = ProviderFactory.getInstance();
+        factory.setUserProviders(
              Arrays.asList(
                   new Object[]{new AtomEntryProvider(), new AtomFeedProvider()}));
-        verifyProvider(Entry.class, AtomEntryProvider.class, "application/atom+xml");
-        verifyProvider(Feed.class, AtomFeedProvider.class, "application/atom+xml");
+        verifyProvider(factory, Entry.class, AtomEntryProvider.class, "application/atom+xml");
+        verifyProvider(factory, Feed.class, AtomFeedProvider.class, "application/atom+xml");
     }
     
     @Test
     public void testGetStringProviderUsingProviderDeclaration() throws Exception {
         ProviderFactory pf = ProviderFactory.getInstance();
         pf.registerUserProvider(new TestStringProvider());
-        verifyProvider(String.class, TestStringProvider.class, "text/html");
+        verifyProvider(pf, String.class, TestStringProvider.class, "text/html");
     }    
     
     @Test
@@ -239,8 +257,8 @@
     public void testRegisterCustomJSONEntityProvider() throws Exception {
         ProviderFactory pf = ProviderFactory.getInstance();
         pf.registerUserProvider(new CustomJSONProvider());
-        verifyProvider(org.apache.cxf.jaxrs.resources.Book.class, CustomJSONProvider.class, 
-                       "application/json", "User-registered provider was not returned first");
+        verifyProvider(pf, org.apache.cxf.jaxrs.resources.Book.class, CustomJSONProvider.class, 
+                       "application/json");
     }
     
     
@@ -259,8 +277,8 @@
         ProviderFactory pf = (ProviderFactory)ProviderFactory.getInstance();
         pf.registerUserProvider(new CustomWidgetProvider());
         
-        verifyProvider(org.apache.cxf.jaxrs.resources.Book.class, CustomWidgetProvider.class, 
-                       "application/widget", "User-registered provider was not returned first");
+        verifyProvider(pf, org.apache.cxf.jaxrs.resources.Book.class, CustomWidgetProvider.class, 
+                       "application/widget");
     }
     
     private int indexOf(List<? extends Object> providerInfos, Class providerType) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java?rev=752520&r1=752519&r2=752520&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java Wed Mar 11 16:54:20 2009
@@ -44,6 +44,7 @@
 import javax.ws.rs.ext.Providers;
 import javax.xml.bind.JAXBContext;
 
+import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.jaxrs.Customer;
 import org.apache.cxf.jaxrs.CustomerGender;
 import org.apache.cxf.jaxrs.CustomerParameterHandler;
@@ -67,6 +68,8 @@
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
 import org.apache.cxf.jaxrs.model.URITemplate;
 import org.apache.cxf.jaxrs.provider.ProviderFactory;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.ExchangeImpl;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
 import org.apache.cxf.transport.http.AbstractHTTPDestination;
@@ -528,7 +531,7 @@
         Class[] argType = {UUID.class, CustomerGender.class, CustomerGender.class};
         Method m = Customer.class.getMethod("testFromStringParam", argType);
         UUID u = UUID.randomUUID();
-        MessageImpl messageImpl = new MessageImpl();
+        Message messageImpl = createMessage();
         messageImpl.put(Message.QUERY_STRING, "p1=" + u.toString() + "&p2=1&p3=2");
         List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
                                                            null, 
@@ -542,11 +545,12 @@
     
     @Test
     public void testCustomerParameter() throws Exception {
-        ProviderFactory.getInstance().registerUserProvider(
+        Message messageImpl = createMessage();
+        ProviderFactory.getInstance(messageImpl).registerUserProvider(
             new CustomerParameterHandler());
         Class[] argType = {Customer.class};
         Method m = Customer.class.getMethod("testCustomerParam", argType);
-        MessageImpl messageImpl = new MessageImpl();
+        
         messageImpl.put(Message.QUERY_STRING, "p1=Fred");
         List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
                                                            null, 
@@ -560,7 +564,7 @@
     public void testWrongType() throws Exception {
         Class[] argType = {HashMap.class};
         Method m = Customer.class.getMethod("testWrongType", argType);
-        MessageImpl messageImpl = new MessageImpl();
+        Message messageImpl = createMessage();
         messageImpl.put(Message.QUERY_STRING, "p1=1");
         try {
             JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
@@ -907,7 +911,7 @@
         
         Customer c = new Customer();
         
-        Message m = new MessageImpl();
+        Message m = createMessage();
         m.put(Message.PROTOCOL_HEADERS, new HashMap<String, List<String>>());
         
         InjectionUtils.injectContextFields(c, ori.getClassResourceInfo(), m);
@@ -926,7 +930,7 @@
         Customer c = new Customer();
         cri.setResourceProvider(new SingletonResourceProvider(c));
                 
-        Message m = new MessageImpl();
+        Message m = createMessage();
         m.put(Message.PROTOCOL_HEADERS, new HashMap<String, List<String>>());
         ServletContext servletContextMock = EasyMock.createNiceMock(ServletContext.class);
         m.put(AbstractHTTPDestination.HTTP_CONTEXT, servletContextMock);
@@ -1045,10 +1049,10 @@
                                          cri);
         ori.setHttpMethod("GET");
         
+        Message m = createMessage();
         ContextResolver<JAXBContext> cr = new JAXBContextProvider();
-        ProviderFactory.getInstance().registerUserProvider(cr);
+        ProviderFactory.getInstance(m).registerUserProvider(cr);
         
-        Message m = new MessageImpl();
         m.put(Message.BASE_PATH, "/");    
         List<Object> params = 
             JAXRSUtils.processParameters(ori, new MetadataMap<String, String>(), m);
@@ -1063,11 +1067,11 @@
         cri.setResourceProvider(new PerRequestResourceProvider(Customer.class));
         OperationResourceInfo ori = new OperationResourceInfo(null, cri);
         
+        Message m = createMessage();
         Customer c = new Customer();
         ContextResolver<JAXBContext> cr = new JAXBContextProvider();
-        ProviderFactory.getInstance().registerUserProvider(cr);
+        ProviderFactory.getInstance(m).registerUserProvider(cr);
         
-        Message m = new MessageImpl();
         m.put(Message.BASE_PATH, "/");    
         InjectionUtils.injectContextFields(c, ori.getClassResourceInfo(), m);
         assertSame(cr.getClass(), c.getContextResolver().getClass());
@@ -1090,7 +1094,7 @@
         EasyMock.replay(response);
         EasyMock.replay(context);
         
-        Message m = new MessageImpl();
+        Message m = createMessage();
         m.put(AbstractHTTPDestination.HTTP_REQUEST, request);
         m.put(AbstractHTTPDestination.HTTP_RESPONSE, response);
         m.put(AbstractHTTPDestination.HTTP_CONTEXT, context);
@@ -1128,7 +1132,7 @@
         values.putSingle("id1", "1");
         values.putSingle("id2", "2");
         
-        Message m = new MessageImpl();
+        Message m = createMessage();
         
         
         List<Object> params = 
@@ -1161,4 +1165,18 @@
         
         return null;
     }
+    
+    private Message createMessage() {
+        ProviderFactory factory = ProviderFactory.getInstance();
+        Message m = new MessageImpl();
+        Exchange e = new ExchangeImpl();
+        m.setExchange(e);
+        e.setInMessage(m);
+        Endpoint endpoint = EasyMock.createMock(Endpoint.class);
+        endpoint.get(ProviderFactory.class.getName());
+        EasyMock.expectLastCall().andReturn(factory).anyTimes();
+        EasyMock.replay(endpoint);
+        e.put(Endpoint.class, endpoint);
+        return m;
+    }
 }



Mime
View raw message