cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1484415 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/ main/java/org/apache/cxf/jaxrs/impl/ main/java/org/apache/cxf/jaxrs/interceptor/ main/java/org/apache/cxf/jaxrs/provider/ main/java/org/apache/cxf/jaxrs/utils/ ...
Date Mon, 20 May 2013 10:14:20 GMT
Author: sergeyb
Date: Mon May 20 10:14:20 2013
New Revision: 1484415

URL: http://svn.apache.org/r1484415
Log:
[CXF-2007] More final API updates for this JIRA issue

Modified:
    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/impl/AbstractInterceptorContextImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorContextImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorMBW.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/HttpUtils.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/utils/HttpUtilsTest.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/JAXRSInvoker.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java?rev=1484415&r1=1484414&r2=1484415&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 Mon May
20 10:14:20 2013
@@ -22,7 +22,6 @@ package org.apache.cxf.jaxrs;
 
 import java.io.IOException;
 import java.lang.reflect.Method;
-import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.ResourceBundle;
@@ -48,11 +47,7 @@ import org.apache.cxf.jaxrs.impl.AsyncRe
 import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
-import org.apache.cxf.jaxrs.model.MethodInvocationInfo;
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
-import org.apache.cxf.jaxrs.model.OperationResourceInfoStack;
-import org.apache.cxf.jaxrs.model.Parameter;
-import org.apache.cxf.jaxrs.model.ParameterType;
 import org.apache.cxf.jaxrs.model.ProviderInfo;
 import org.apache.cxf.jaxrs.model.URITemplate;
 import org.apache.cxf.jaxrs.provider.ServerProviderFactory;
@@ -161,8 +156,6 @@ public class JAXRSInvoker extends Abstra
         
         if (!wasSuspended) {
             
-            pushOntoStack(ori, ClassHelper.getRealClass(resourceObject), inMessage);
-            
             final boolean contextsAvailable = cri.contextsAvailable();
             final boolean paramsAvailable = cri.paramsAvailable();
             if (contextsAvailable || paramsAvailable) {
@@ -419,32 +412,5 @@ public class JAXRSInvoker extends Abstra
         return result;
     }
 
-    private void pushOntoStack(OperationResourceInfo ori, Class<?> realClass, Message
msg) {
-        OperationResourceInfoStack stack = msg.get(OperationResourceInfoStack.class);
-        if (stack == null) {
-            stack = new OperationResourceInfoStack();
-            msg.put(OperationResourceInfoStack.class, stack);
-        }
-        
-        
-        @SuppressWarnings("unchecked")
-        MultivaluedMap<String, String> params = 
-            (MultivaluedMap<String, String>)msg.get(URITemplate.TEMPLATE_PARAMETERS);
-        List<String> values = null;
-        if (params == null || params.size() == 1) {
-            values = Collections.emptyList();
-        } else {
-            values = new ArrayList<String>(params.size() - 1);
-            for (Parameter pm : ori.getParameters()) {
-                if (pm.getType() == ParameterType.PATH) {
-                    List<String> paramValues = params.get(pm.getName());
-                    if (paramValues != null) {
-                        values.addAll(paramValues);
-                    }
-                    
-                }
-            }
-        }
-        stack.push(new MethodInvocationInfo(ori, realClass, values));
-    }
+    
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractInterceptorContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractInterceptorContextImpl.java?rev=1484415&r1=1484414&r2=1484415&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractInterceptorContextImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractInterceptorContextImpl.java
Mon May 20 10:14:20 2013
@@ -51,6 +51,9 @@ public class AbstractInterceptorContextI
     }
 
     public void setAnnotations(Annotation[] annotations) {
+        if (annotations == null) {
+            throw new NullPointerException();
+        }
         anns = annotations;
 
     }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java?rev=1484415&r1=1484414&r2=1484415&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java Mon
May 20 10:14:20 2013
@@ -175,22 +175,29 @@ public class UriInfoImpl implements UriI
         if (stack != null) {
             List<String> objects = new ArrayList<String>();
             List<String> uris = new LinkedList<String>();
-            StringBuilder sum = new StringBuilder("");
+            StringBuilder sumPath = new StringBuilder("");
             for (MethodInvocationInfo invocation : stack) {
+                List<String> templateObjects = invocation.getTemplateValues();    
           
                 OperationResourceInfo ori = invocation.getMethodInfo();
                 URITemplate[] paths = {
                     ori.getClassResourceInfo().getURITemplate(),
                     ori.getURITemplate()
                 };
+                if (paths[0] != null) {
+                    int count = paths[0].getVariables().size();
+                    List<String> rootObjects = new ArrayList<String>(count);
+                    for (int i = 0; i < count && i < templateObjects.size();
i++) {
+                        rootObjects.add(templateObjects.get(i));    
+                    }
+                    uris.add(0, createMatchedPath(paths[0].getValue(), rootObjects, decode));
+                }
                 for (URITemplate t : paths) {
                     if (t != null) {
-                        String v = t.getValue();
-                        sum.append("/" + (decode ? HttpUtils.pathDecode(v) : v));
+                        sumPath.append("/").append(t.getValue());
                     }
                 }
-                UriBuilder ub = UriBuilder.fromPath(sum.toString());
-                objects.addAll(invocation.getTemplateValues());
-                uris.add(0, ub.build(objects.toArray()).normalize().getRawPath());
+                objects.addAll(templateObjects);
+                uris.add(0, createMatchedPath(sumPath.toString(), objects, decode));
             }
             return uris;
         }
@@ -198,6 +205,10 @@ public class UriInfoImpl implements UriI
         return Collections.emptyList();
     }
 
+    private static String createMatchedPath(String uri, List<? extends Object> vars,
boolean decode) {
+        String uriPath = UriBuilder.fromPath(uri).buildFromEncoded(vars.toArray()).getRawPath();
+        return decode ? HttpUtils.pathDecode(uriPath) : uriPath;
+    }
     private String doGetPath(boolean decode, boolean addSlash) {
         String path = HttpUtils.getPathToMatch(message, addSlash);
         return decode ? HttpUtils.pathDecode(path) : path;

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorContextImpl.java?rev=1484415&r1=1484414&r2=1484415&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorContextImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorContextImpl.java
Mon May 20 10:14:20 2013
@@ -79,7 +79,11 @@ public class WriterInterceptorContextImp
             return;
         }
         WriterInterceptor next = writers.remove(0);
-        next.aroundWriteTo(this);
+        try {
+            next.aroundWriteTo(this);
+        } catch (IOException ex) {
+            throw ex;
+        }
     }
 
     @Override

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorMBW.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorMBW.java?rev=1484415&r1=1484414&r2=1484415&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorMBW.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorMBW.java
Mon May 20 10:14:20 2013
@@ -31,6 +31,7 @@ import javax.ws.rs.ext.WriterInterceptor
 import javax.ws.rs.ext.WriterInterceptorContext;
 
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.jaxrs.utils.HttpUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.message.Message;
 
@@ -59,6 +60,9 @@ public class WriterInterceptorMBW implem
         Object mtObject = headers.getFirst(HttpHeaders.CONTENT_TYPE);
         MediaType mt = mtObject == null ? c.getMediaType() : JAXRSUtils.toMediaType(mtObject.toString());
         m.put(Message.CONTENT_TYPE, mtObject.toString());
+        
+        HttpUtils.convertHeaderValuesToStringIfNeeded(headers);
+        
         writer.writeTo(c.getEntity(), 
                        c.getType(), 
                        c.getGenericType(), 

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=1484415&r1=1484414&r2=1484415&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
Mon May 20 10:14:20 2013
@@ -221,6 +221,7 @@ public class JAXRSOutInterceptor extends
             responseHeaders.putSingle(HttpHeaders.CONTENT_LENGTH, "0");
             responseHeaders.remove(HttpHeaders.CONTENT_TYPE);
             message.remove(Message.CONTENT_TYPE);
+            HttpUtils.convertHeaderValuesToStringIfNeeded(responseHeaders);
             return;
         }
         

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=1484415&r1=1484414&r2=1484415&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
Mon May 20 10:14:20 2013
@@ -99,7 +99,7 @@ public abstract class ProviderFactory {
     private List<ProviderInfo<ContextProvider<?>>> contextProviders = 
         new ArrayList<ProviderInfo<ContextProvider<?>>>(1);
     
-    private ParamConverterProvider newParamConverter;
+    private List<ParamConverterProvider> newParamConverters;
     
     // List of injected providers
     private Collection<ProviderInfo<?>> injectedProviders = 
@@ -251,12 +251,15 @@ public abstract class ProviderFactory {
     
     public <T> ParamConverter<T> createParameterHandler(Class<T> paramType)
{
         
-        if (newParamConverter != null) {
-            return newParamConverter.getConverter(paramType, null, null);
-        } else {
-            return null;
-        }
-        
+        if (newParamConverters != null) {
+            for (ParamConverterProvider newParamConverter : newParamConverters) {
+                ParamConverter<T> converter = newParamConverter.getConverter(paramType,
null, null);
+                if (converter != null) {
+                    return converter;
+                }
+            }
+        } 
+        return null;
     }
     
     protected <T> void handleMapper(List<T> candidates, 
@@ -509,7 +512,10 @@ public abstract class ProviderFactory {
             if (ParamConverterProvider.class.isAssignableFrom(providerCls)) {
                 //TODO: review the possibility of ParamConverterProvider needing to have
Contexts injected
                 Object converter = provider.getProvider();
-                newParamConverter = (ParamConverterProvider)converter;
+                if (newParamConverters == null) {
+                    newParamConverters = new LinkedList<ParamConverterProvider>();
+                }
+                newParamConverters.add((ParamConverterProvider)converter);
             }
         }
         sortReaders();

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java?rev=1484415&r1=1484414&r2=1484415&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java Mon
May 20 10:14:20 2013
@@ -42,6 +42,8 @@ import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.PathSegment;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriBuilder;
+import javax.ws.rs.ext.RuntimeDelegate;
+import javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate;
 
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.logging.LogUtils;
@@ -49,6 +51,7 @@ import org.apache.cxf.common.util.String
 import org.apache.cxf.common.util.UrlUtils;
 import org.apache.cxf.jaxrs.impl.HttpHeadersImpl;
 import org.apache.cxf.jaxrs.impl.PathSegmentImpl;
+import org.apache.cxf.jaxrs.impl.RuntimeDelegateImpl;
 import org.apache.cxf.jaxrs.model.ParameterType;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.service.model.EndpointInfo;
@@ -66,8 +69,8 @@ public final class HttpUtils {
     private static final String REQUEST_PATH_TO_MATCH_SLASH = "path_to_match_slash";
     
     private static final String HTTP_SCHEME = "http";
+    private static final String LOCAL_HOST_IP_ADDRESS = "127.0.0.1";
     private static final String ANY_IP_ADDRESS = "0.0.0.0";
-    private static final String ANY_IP_ADDRESS_START = "://0.0.0.0";
     private static final int DEFAULT_HTTP_PORT = 80;
         
     private static final Pattern ENCODE_PATTERN = Pattern.compile("%[0-9a-fA-F][0-9a-fA-F]");
@@ -194,6 +197,28 @@ public final class HttpUtils {
         return Headers.toHttpDate(date);
     }
     
+    public static void convertHeaderValuesToStringIfNeeded(Map<String, List<Object>>
headers) {
+        // In theory there could be custom RuntimeDelegates with custom header handlers
+        RuntimeDelegate rd = RuntimeDelegate.getInstance();
+        if (rd instanceof RuntimeDelegateImpl || rd == null) {
+            return;
+        }
+        for (Map.Entry<String, List<Object>> entry : headers.entrySet()) {
+            List<Object> values = entry.getValue();
+            if (!values.isEmpty()) {
+                @SuppressWarnings("unchecked")
+                HeaderDelegate<Object> hd = 
+                    (HeaderDelegate<Object>)rd.createHeaderDelegate(values.get(0).getClass());
+                if (hd != null) {
+                    for (int i = 0; i < values.size(); i++) {
+                        values.set(i, hd.toString(values.get(i)));
+                    }
+                }
+            }
+        }
+        
+    }
+    
     public static Date getHttpDate(String value) {
         if (value == null) {
             return null;
@@ -275,13 +300,20 @@ public final class HttpUtils {
         HttpServletRequest request = 
             (HttpServletRequest)message.get(AbstractHTTPDestination.HTTP_REQUEST);
         boolean absolute = u.isAbsolute();
-        if (request != null && (!absolute || u.toString().contains(ANY_IP_ADDRESS_START)))
{
+        if (request != null && (!absolute || isLocalHostOrAnyIpAddress(u))) {
             String serverAndPort = request.getServerName();
             boolean localAddressUsed = false;
-            if (absolute && ANY_IP_ADDRESS.equals(serverAndPort)) {
-                serverAndPort = request.getLocalAddr();
-                localAddressUsed = true;
+            if (absolute) {
+                if (ANY_IP_ADDRESS.equals(serverAndPort)) {
+                    serverAndPort = request.getLocalAddr();
+                    localAddressUsed = true;
+                }
+                if (LOCAL_HOST_IP_ADDRESS.equals(serverAndPort)) {
+                    serverAndPort = "localhost";
+                    localAddressUsed = true;
+                }
             }
+            
                 
             int port = localAddressUsed ? request.getLocalPort() : request.getServerPort();
             if (port != DEFAULT_HTTP_PORT) {
@@ -292,14 +324,20 @@ public final class HttpUtils {
                 u = URI.create(base + u.toString());
             } else {
                 int originalPort = u.getPort();
-                String replaceValue = originalPort == -1 ? ANY_IP_ADDRESS
-                    : ANY_IP_ADDRESS + ":" + originalPort;
+                String hostValue = u.getHost().equals(ANY_IP_ADDRESS) 
+                    ? ANY_IP_ADDRESS : LOCAL_HOST_IP_ADDRESS;
+                String replaceValue = originalPort == -1 ? hostValue : hostValue + ":" +
originalPort;
                 u = URI.create(u.toString().replace(replaceValue, serverAndPort));
             }
         }
         return u;
     }
     
+    private static boolean isLocalHostOrAnyIpAddress(URI u) {
+        String host = u.getHost();
+        return host != null && (LOCAL_HOST_IP_ADDRESS.equals(host)) || ANY_IP_ADDRESS.equals(host);
+    }
+    
     public static void resetRequestURI(Message m, String requestURI) {
         m.remove(REQUEST_PATH_TO_MATCH_SLASH);
         m.remove(REQUEST_PATH_TO_MATCH);

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=1484415&r1=1484414&r2=1484415&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 Mon
May 20 10:14:20 2013
@@ -135,8 +135,10 @@ import org.apache.cxf.jaxrs.model.BeanPa
 import org.apache.cxf.jaxrs.model.BeanResourceInfo;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.model.ClassResourceInfoComparator;
+import org.apache.cxf.jaxrs.model.MethodInvocationInfo;
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
 import org.apache.cxf.jaxrs.model.OperationResourceInfoComparator;
+import org.apache.cxf.jaxrs.model.OperationResourceInfoStack;
 import org.apache.cxf.jaxrs.model.Parameter;
 import org.apache.cxf.jaxrs.model.ParameterType;
 import org.apache.cxf.jaxrs.model.ProviderInfo;
@@ -251,7 +253,7 @@ public final class JAXRSUtils {
     public static List<MediaType> getMediaTypes(String[] values) {
         List<MediaType> supportedMimeTypes = new ArrayList<MediaType>(values.length);
         for (int i = 0; i < values.length; i++) {
-            supportedMimeTypes.add(toMediaType(values[i]));    
+            supportedMimeTypes.addAll(parseMediaTypes(values[i]));    
         }
         return supportedMimeTypes;
     }
@@ -497,6 +499,7 @@ public final class JAXRSUtils {
                                                                                   MEDIA_TYPE_Q_PARAM,

                                                                                   MEDIA_TYPE_QS_PARAM));
             }
+            pushOntoStack(ori, matchedValues, message);
             return ori;
         }
         
@@ -1375,6 +1378,7 @@ public final class JAXRSUtils {
                     httpHeaders.putSingle(HttpHeaders.CONTENT_LENGTH, Long.toString(size));
                 }
             }
+            HttpUtils.convertHeaderValuesToStringIfNeeded(httpHeaders);
             writer.writeTo(entity, type, genericType, annotations, mediaType,
                            httpHeaders, 
                            entityStream);
@@ -1808,4 +1812,33 @@ public final class JAXRSUtils {
     public static ClassResourceInfo getRootResource(Message m) {
         return (ClassResourceInfo)m.getExchange().get(JAXRSUtils.ROOT_RESOURCE_CLASS);
     }
+    
+    public static void pushOntoStack(OperationResourceInfo ori,
+                                     MultivaluedMap<String, String> params,
+                                     Message msg) {
+        OperationResourceInfoStack stack = msg.get(OperationResourceInfoStack.class);
+        if (stack == null) {
+            stack = new OperationResourceInfoStack();
+            msg.put(OperationResourceInfoStack.class, stack);
+        }
+        
+        
+        List<String> values = null;
+        if (params.size() <= 1) {
+            values = Collections.emptyList();
+        } else {
+            values = new ArrayList<String>(params.size() - 1);
+            for (Parameter pm : ori.getParameters()) {
+                if (pm.getType() == ParameterType.PATH) {
+                    List<String> paramValues = params.get(pm.getName());
+                    if (paramValues != null) {
+                        values.addAll(paramValues);
+                    }
+                    
+                }
+            }
+        }
+        Class<?> realClass = ori.getClassResourceInfo().getServiceClass();
+        stack.push(new MethodInvocationInfo(ori, realClass, values));
+    }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java?rev=1484415&r1=1484414&r2=1484415&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java
Mon May 20 10:14:20 2013
@@ -191,6 +191,14 @@ public class HttpUtilsTest extends Asser
     
     @Test
     public void testReplaceAnyIPAddressWithPort() {
+        doTestReplaceAnyIPAddressWithPort(true);
+    }
+    @Test
+    public void testReplaceLHostIPAddressWithPort() {
+        doTestReplaceAnyIPAddressWithPort(false);
+    }
+    
+    private void doTestReplaceAnyIPAddressWithPort(boolean anyIp) {
         Message m = new MessageImpl();
         HttpServletRequest req = EasyMock.createMock(HttpServletRequest.class);
         m.put(AbstractHTTPDestination.HTTP_REQUEST, req);
@@ -201,7 +209,8 @@ public class HttpUtilsTest extends Asser
         req.getServerPort();
         EasyMock.expectLastCall().andReturn(8080);
         EasyMock.replay(req);
-        URI u = HttpUtils.toAbsoluteUri(URI.create("http://0.0.0.0:8080/bar/foo"), m);
+        String host = anyIp ? "0.0.0.0" : "127.0.0.1";
+        URI u = HttpUtils.toAbsoluteUri(URI.create("http://" + host + ":8080/bar/foo"), m);
         assertEquals("http://localhost:8080/bar/foo", u.toString());
     }
     

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=1484415&r1=1484414&r2=1484415&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
Mon May 20 10:14:20 2013
@@ -366,6 +366,27 @@ public class JAXRSUtilsTest extends Asse
     }
     
     @Test
+    public void testGetMediaTypes() {
+        List<MediaType> types = JAXRSUtils.getMediaTypes(new String[]{"text/xml"});
+        assertEquals(1, types.size());
+        assertEquals(MediaType.TEXT_XML_TYPE, types.get(0));
+    }
+    @Test
+    public void testGetMediaTypes2() {
+        List<MediaType> types = JAXRSUtils.getMediaTypes(new String[]{"text/xml", "text/plain"});
+        assertEquals(2, types.size());
+        assertEquals(MediaType.TEXT_XML_TYPE, types.get(0));
+        assertEquals(MediaType.TEXT_PLAIN_TYPE, types.get(1));
+    }
+    @Test
+    public void testGetMediaTypes3() {
+        List<MediaType> types = JAXRSUtils.getMediaTypes(new String[]{"text/xml, text/plain"});
+        assertEquals(2, types.size());
+        assertEquals(MediaType.TEXT_XML_TYPE, types.get(0));
+        assertEquals(MediaType.TEXT_PLAIN_TYPE, types.get(1));
+    }
+    
+    @Test
     public void testFindTargetResourceClassWithTemplates() throws Exception {
         JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
         sf.setResourceClasses(org.apache.cxf.jaxrs.resources.BookStoreTemplates.class);
@@ -446,12 +467,12 @@ public class JAXRSUtilsTest extends Asse
         String contentTypes = "*/*";
         
         OperationResourceInfo ori = findTargetResourceClass(resources,
-               null, "/bookstore/books/123", "GET", new MetadataMap<String, String>(),
contentTypes,
+               createMessage2(), "/bookstore/books/123", "GET", new MetadataMap<String,
String>(), contentTypes,
                getTypes("*/*"));       
         assertNotNull(ori);
         assertEquals("getBook", ori.getMethodToInvoke().getName());
         
-        ori = findTargetResourceClass(resources, null, 
+        ori = findTargetResourceClass(resources, createMessage2(), 
             "/bookstore/books/123/true/chapter/1", "GET", new MetadataMap<String, String>(),
contentTypes,
             getTypes("*/*"));       
         assertNotNull(ori);



Mime
View raw message