cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r812542 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ rt/frontend/jaxrs/src/t...
Date Tue, 08 Sep 2009 15:09:58 GMT
Author: sergeyb
Date: Tue Sep  8 15:09:57 2009
New Revision: 812542

URL: http://svn.apache.org/viewvc?rev=812542&view=rev
Log:
JAXRS : minor updates to JSON and multiparts code

Modified:
    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/WebClient.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Multipart.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisJSONProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisJSONProviderTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSDataBindingTest.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java

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=812542&r1=812541&r2=812542&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
Tue Sep  8 15:09:57 2009
@@ -332,7 +332,7 @@
     }
 
     @SuppressWarnings("unchecked")
-    protected void writeBody(Object o, Message m, Class<?> cls, Type type, Annotation[]
anns, 
+    protected void writeBody(Object o, Message outMessage, Class<?> cls, Type type,
Annotation[] anns, 
         MultivaluedMap<String, String> headers, OutputStream os) {
         
         if (o == null) {
@@ -341,11 +341,11 @@
         
         MediaType contentType = MediaType.valueOf(headers.getFirst("Content-Type")); 
         
-        MessageBodyWriter mbw = ProviderFactory.getInstance(m).createMessageBodyWriter(
-            cls, type, anns, contentType, m);
+        MessageBodyWriter mbw = ProviderFactory.getInstance(outMessage).createMessageBodyWriter(
+            cls, type, anns, contentType, outMessage);
         if (mbw == null) {
             mbw = ProviderFactory.getInstance().createMessageBodyWriter(
-                      cls, type, anns, contentType, m);
+                      cls, type, anns, contentType, outMessage);
         }
         if (mbw != null) {
             try {
@@ -362,7 +362,7 @@
     }
     
     @SuppressWarnings("unchecked")
-    protected Object readBody(Response r, HttpURLConnection conn, Message inMessage, Class<?>
cls, 
+    protected Object readBody(Response r, HttpURLConnection conn, Message outMessage, Class<?>
cls, 
                               Type type, Annotation[] anns) {
 
         InputStream inputStream = (InputStream)r.getEntity();
@@ -384,11 +384,11 @@
         
         MediaType contentType = getResponseContentType(r);
         
-        MessageBodyReader mbr = ProviderFactory.getInstance(inMessage).createMessageBodyReader(
-            cls, type, anns, contentType, inMessage);
+        MessageBodyReader mbr = ProviderFactory.getInstance(outMessage).createMessageBodyReader(
+            cls, type, anns, contentType, outMessage);
         if (mbr == null) {
             ProviderFactory.getInstance().createMessageBodyReader(
-                cls, type, anns, contentType, inMessage);
+                cls, type, anns, contentType, outMessage);
         }
         if (mbr != null) {
             try {

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=812542&r1=812541&r2=812542&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
Tue Sep  8 15:09:57 2009
@@ -402,7 +402,7 @@
                           OperationResourceInfo ori, Object[] params, int bodyIndex, 
                           MultivaluedMap<ParameterType, Parameter> types,
                           List<Object> pathParams) throws Throwable {
-        Message m = createMessage(ori.getHttpMethod(), headers, uri);
+        Message outMessage = createMessage(ori.getHttpMethod(), headers, uri);
         if (pathParams.size() != 0) { 
             List<String> vars = ori.getURITemplate().getVariables();
             MultivaluedMap<String, String> templatesMap =  new MetadataMap<String,
String>(vars.size());
@@ -411,29 +411,29 @@
                     templatesMap.add(vars.get(i), pathParams.get(i).toString());
                 }
             }
-            m.put(URITemplate.TEMPLATE_PARAMETERS, templatesMap);
+            outMessage.put(URITemplate.TEMPLATE_PARAMETERS, templatesMap);
         }
         
         boolean isForm = types.containsKey(ParameterType.FORM);
         if (bodyIndex != -1 || isForm) {
-            m.setContent(OperationResourceInfo.class, ori);
-            m.put("BODY_INDEX", bodyIndex);
+            outMessage.setContent(OperationResourceInfo.class, ori);
+            outMessage.put("BODY_INDEX", bodyIndex);
             Object body = isForm ? handleForm(types, params) : params[bodyIndex];
             MessageContentsList contents = new MessageContentsList(new Object[]{body});
-            m.setContent(List.class, contents);
-            m.getInterceptorChain().add(new BodyWriter());
+            outMessage.setContent(List.class, contents);
+            outMessage.getInterceptorChain().add(new BodyWriter());
         }
         
         // execute chain    
         try {
-            m.getInterceptorChain().doIntercept(m);
+            outMessage.getInterceptorChain().doIntercept(outMessage);
         } catch (Throwable ex) {
             // we'd like a user to get the whole Response anyway if needed
         }
         
         // TODO : this needs to be done in an inbound chain instead
-        HttpURLConnection connect = (HttpURLConnection)m.get(HTTPConduit.KEY_HTTP_CONNECTION);
-        return handleResponse(connect, m, ori);
+        HttpURLConnection connect = (HttpURLConnection)outMessage.get(HTTPConduit.KEY_HTTP_CONNECTION);
+        return handleResponse(connect, outMessage, ori);
         
     }
     
@@ -481,31 +481,32 @@
         }
         
         @SuppressWarnings("unchecked")
-        public void handleMessage(Message m) throws Fault {
+        public void handleMessage(Message outMessage) throws Fault {
             
-            OperationResourceInfo ori = m.getContent(OperationResourceInfo.class);
-            OutputStream os = m.getContent(OutputStream.class);
+            OperationResourceInfo ori = outMessage.getContent(OperationResourceInfo.class);
+            OutputStream os = outMessage.getContent(OutputStream.class);
             if (os == null || ori == null) {
                 return;
             }
-            MessageContentsList objs = MessageContentsList.getContentsList(m);
+            MessageContentsList objs = MessageContentsList.getContentsList(outMessage);
             if (objs == null || objs.size() == 0) {
                 return;
             }
-            MultivaluedMap<String, String> headers = (MultivaluedMap)m.get(Message.PROTOCOL_HEADERS);
+            MultivaluedMap<String, String> headers = 
+                (MultivaluedMap)outMessage.get(Message.PROTOCOL_HEADERS);
             Method method = ori.getMethodToInvoke();
-            int bodyIndex = (Integer)m.get("BODY_INDEX");
+            int bodyIndex = (Integer)outMessage.get("BODY_INDEX");
             Method aMethod = ori.getAnnotatedMethod();
             Annotation[] anns = aMethod == null || bodyIndex == -1 ? new Annotation[0] 
                                                   : aMethod.getParameterAnnotations()[bodyIndex];
             Object body = objs.get(0);
             try {
                 if (bodyIndex != -1) {
-                    writeBody(body, m, body.getClass(), 
+                    writeBody(body, outMessage, body.getClass(), 
                               method.getGenericParameterTypes()[bodyIndex],
                               anns, headers, os);
                 } else {
-                    writeBody(body, m, body.getClass(), body.getClass(), 
+                    writeBody(body, outMessage, body.getClass(), body.getClass(), 
                               anns, headers, os);
                 }
                 os.flush();

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java?rev=812542&r1=812541&r2=812542&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java Tue
Sep  8 15:09:57 2009
@@ -612,20 +612,22 @@
         }
         
         @SuppressWarnings("unchecked")
-        public void handleMessage(Message m) throws Fault {
+        public void handleMessage(Message outMessage) throws Fault {
             
-            OutputStream os = m.getContent(OutputStream.class);
+            OutputStream os = outMessage.getContent(OutputStream.class);
             if (os == null) {
                 return;
             }
-            MessageContentsList objs = MessageContentsList.getContentsList(m);
+            MessageContentsList objs = MessageContentsList.getContentsList(outMessage);
             if (objs == null || objs.size() == 0) {
                 return;
             }
-            MultivaluedMap<String, String> headers = (MultivaluedMap)m.get(Message.PROTOCOL_HEADERS);
+            MultivaluedMap<String, String> headers = 
+                (MultivaluedMap)outMessage.get(Message.PROTOCOL_HEADERS);
             Object body = objs.get(0);
             try {
-                writeBody(body, m, body.getClass(), body.getClass(), new Annotation[]{},
headers, os);
+                writeBody(body, outMessage, body.getClass(), body.getClass(), new Annotation[]{},

+                          headers, os);
                 os.flush();
             } catch (Exception ex) {
                 throw new Fault(ex);

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Multipart.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Multipart.java?rev=812542&r1=812541&r2=812542&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Multipart.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Multipart.java
Tue Sep  8 15:09:57 2009
@@ -27,6 +27,6 @@
 @Target({ElementType.PARAMETER, ElementType.FIELD, ElementType.METHOD })
 @Retention(RetentionPolicy.RUNTIME)
 public @interface Multipart {
-    String value() default "root";
+    String value() default "";
     String type() default "*/*";
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisJSONProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisJSONProvider.java?rev=812542&r1=812541&r2=812542&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisJSONProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisJSONProvider.java
Tue Sep  8 15:09:57 2009
@@ -54,11 +54,17 @@
     private List<String> arrayKeys;
     private boolean serializeAsArray;
     private boolean dropRootElement;
+    private boolean ignoreNamespaces;
+        
     private ConcurrentHashMap<String, String> namespaceMap = new ConcurrentHashMap<String,
String>();
 
     public AegisJSONProvider() {
     }
 
+    public void setIgnoreNamespaces(boolean ignoreNamespaces) {
+        this.ignoreNamespaces = ignoreNamespaces;
+    }
+    
     public void setDropRootElement(boolean dropRootElement) {
         this.dropRootElement = dropRootElement;
     }
@@ -117,9 +123,10 @@
 
     @Override
     protected XMLStreamWriter createStreamWriter(QName typeQName, OutputStream os) throws
Exception {
-        XMLStreamWriter writer = JSONUtils.createStreamWriter(os, typeQName, writeXsiType,
namespaceMap,
-                                                              serializeAsArray, arrayKeys,
dropRootElement);
-        return writer;
+        
+        XMLStreamWriter writer = JSONUtils.createStreamWriter(os, typeQName, 
+             writeXsiType && !ignoreNamespaces, namespaceMap, serializeAsArray, arrayKeys,
dropRootElement);
+        return JSONUtils.createIgnoreNsWriterIfNeeded(writer, ignoreNamespaces);
     }
 
     @Override
@@ -132,4 +139,5 @@
         return JSONUtils.createStreamReader(is, readXsiType, namespaceMap);
     }
 
+
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProvider.java?rev=812542&r1=812541&r2=812542&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProvider.java
Tue Sep  8 15:09:57 2009
@@ -49,6 +49,11 @@
     private boolean readXsiType = true;
     private boolean dropRootElement;
     private boolean ignoreMixedContent; 
+    private boolean ignoreNamespaces;
+    
+    public void setIgnoreNamespaces(boolean ignoreNamespaces) {
+        this.ignoreNamespaces = ignoreNamespaces;
+    }
     
     public void setDropRootElement(boolean dropRootElement) {
         this.dropRootElement = dropRootElement;
@@ -88,9 +93,10 @@
         } else {
             qname = getQName(InjectionUtils.getActualType(genericType));
         }
-        XMLStreamWriter writer = JSONUtils.createStreamWriter(os, qname, writeXsiType, namespaceMap,

-                                            serializeAsArray, arrayKeys, dropRootElement);
-        return JSONUtils.createIgnoreMixedContentWriterIfNeeded(writer, ignoreMixedContent);
+        XMLStreamWriter writer = JSONUtils.createStreamWriter(os, qname, 
+             writeXsiType && !ignoreNamespaces, namespaceMap, serializeAsArray, arrayKeys,
dropRootElement);
+        writer = JSONUtils.createIgnoreMixedContentWriterIfNeeded(writer, ignoreMixedContent);
+        return JSONUtils.createIgnoreNsWriterIfNeeded(writer, ignoreNamespaces);
     }
     
     @Override

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java?rev=812542&r1=812541&r2=812542&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java
Tue Sep  8 15:09:57 2009
@@ -19,6 +19,8 @@
 
 package org.apache.cxf.jaxrs.provider;
 
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -39,7 +41,10 @@
 import javax.ws.rs.ext.MessageBodyWriter;
 import javax.ws.rs.ext.Provider;
 
+import org.apache.cxf.attachment.AttachmentUtil;
 import org.apache.cxf.jaxrs.ext.MessageContext;
+import org.apache.cxf.jaxrs.ext.multipart.Attachment;
+import org.apache.cxf.jaxrs.ext.multipart.ContentDisposition;
 import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.jaxrs.utils.AnnotationUtils;
@@ -76,17 +81,21 @@
     }
 
     public Object readFrom(
-        Class<Object> clazz, Type genericType, Annotation[] annotations, MediaType
type, 
+        Class<Object> clazz, Type genericType, Annotation[] annotations, MediaType
mt, 
         MultivaluedMap<String, String> headers, InputStream is) 
         throws IOException {
         try {
-           
-            if (MultipartBody.class.isAssignableFrom(clazz)) {
-                return AttachmentUtils.getMultipartBody(mc);
+            if (mt.isCompatible(MediaType.MULTIPART_FORM_DATA_TYPE)) {
+                MultipartBody body = AttachmentUtils.getMultipartBody(mc);
+                if (MultipartBody.class.isAssignableFrom(clazz)) {
+                    return body;
+                } else if (Attachment.class.isAssignableFrom(clazz)) {
+                    return body.getRootAttachment();
+                }  
             }
             
             MultivaluedMap<String, String> params = createMap(clazz);
-            populateMap(params, is, type,
+            populateMap(params, is, mt,
                         AnnotationUtils.getAnnotation(annotations, Encoded.class) == null);
             validateMap(params);
             return params;
@@ -138,15 +147,18 @@
     }
 
     public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations,

-                               MediaType mediaType) {
-        return isSupported(type, genericType, annotations, mediaType);
+                               MediaType mt) {
+        return isSupported(type, genericType, annotations, mt)
+            || mt.getType().equalsIgnoreCase("multipart")
+            && mt.isCompatible(MediaType.MULTIPART_FORM_DATA_TYPE) && File.class
== type;
     }
 
     private boolean isSupported(Class<?> type, Type genericType, Annotation[] annotations,

                                 MediaType mt) {
         return MultivaluedMap.class.isAssignableFrom(type)
-            || mt.isCompatible(MediaType.MULTIPART_FORM_DATA_TYPE)
-            && MultipartBody.class.isAssignableFrom(type);
+            || mt.getType().equalsIgnoreCase("multipart") 
+            && mt.isCompatible(MediaType.MULTIPART_FORM_DATA_TYPE)
+            && (MultipartBody.class.isAssignableFrom(type) || Attachment.class.isAssignableFrom(type));
     }
     
     @SuppressWarnings("unchecked")
@@ -155,7 +167,12 @@
         throws IOException, WebApplicationException {
         
         if (mt.isCompatible(MediaType.MULTIPART_FORM_DATA_TYPE)) {
-            MultipartBody body = (MultipartBody)obj;
+            Object body = obj;
+            if (obj.getClass() == File.class) {
+                File f = (File)obj;
+                ContentDisposition cd = new ContentDisposition("attachment;filename=" + f.getName());
+                body = new Attachment(AttachmentUtil.BODY_ATTACHMENT_ID, new FileInputStream(f),
cd);
+            }
             MultipartProvider provider = new MultipartProvider();
             provider.setMessageContext(mc);
             provider.writeTo(body, body.getClass(), body.getClass(), anns, mt, headers, os);

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java?rev=812542&r1=812541&r2=812542&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
Tue Sep  8 15:09:57 2009
@@ -71,6 +71,11 @@
     private boolean ignoreMixedContent; 
     private boolean writeXsiType = true;
     private boolean readXsiType = true;
+    private boolean ignoreNamespaces;
+    
+    public void setIgnoreNamespaces(boolean ignoreNamespaces) {
+        this.ignoreNamespaces = ignoreNamespaces;
+    }
     
     @Context
     public void setMessageContext(MessageContext mc) {
@@ -305,10 +310,11 @@
     protected XMLStreamWriter createWriter(Object actualObject, Class<?> actualClass,

         Type genericType, String enc, OutputStream os, boolean isCollection) throws Exception
{
         QName qname = getQName(actualClass, genericType, actualObject, true);
-        XMLStreamWriter writer = JSONUtils.createStreamWriter(os, qname, writeXsiType, 
-                                             namespaceMap, serializeAsArray, arrayKeys,
-                                             isCollection || dropRootElement);
-        return JSONUtils.createIgnoreMixedContentWriterIfNeeded(writer, ignoreMixedContent);
+        XMLStreamWriter writer = JSONUtils.createStreamWriter(os, qname, 
+             writeXsiType && !ignoreNamespaces, namespaceMap, serializeAsArray, arrayKeys,
+             isCollection || dropRootElement);
+        writer = JSONUtils.createIgnoreMixedContentWriterIfNeeded(writer, ignoreMixedContent);
+        return JSONUtils.createIgnoreNsWriterIfNeeded(writer, ignoreNamespaces);
     }
     
     protected void marshal(Object actualObject, Class<?> actualClass, 

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONUtils.java?rev=812542&r1=812541&r2=812542&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONUtils.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONUtils.java
Tue Sep  8 15:09:57 2009
@@ -91,6 +91,11 @@
         return ignoreMixedContent ? new IgnoreMixedContentWriter(writer) : writer; 
     }
     
+    public static XMLStreamWriter createIgnoreNsWriterIfNeeded(XMLStreamWriter writer, 
+                                                               boolean ignoreNamespaces)
{
+        return ignoreNamespaces ? new IgnoreNsWriter(writer) : writer; 
+    }
+    
     private static String getKey(MappedNamespaceConvention convention, QName qname) throws
Exception {
         return convention.createKey(qname.getPrefix(), 
                                     qname.getNamespaceURI(),
@@ -242,4 +247,27 @@
 
         
     }
+    
+    private static class IgnoreNsWriter extends DelegatingXMLStreamWriter {
+        
+        public IgnoreNsWriter(XMLStreamWriter writer) {
+            super(writer);
+        }
+
+        public void writeStartElement(String prefix, String local, String uri) throws XMLStreamException
{
+            super.writeStartElement(local);
+        }
+        
+        public void writeStartElement(String uri, String local) throws XMLStreamException
{
+            super.writeStartElement(local);
+        }
+        
+        public void setPrefix(String pfx, String uri) throws XMLStreamException {
+            // completed
+        }
+        
+        public void setDefaultNamespace(String uri) throws XMLStreamException {
+            // completed
+        }
+    }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java?rev=812542&r1=812541&r2=812542&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
Tue Sep  8 15:09:57 2009
@@ -251,9 +251,18 @@
         } else {
             dh = getHandlerForObject(obj, cls, genericType, anns, mimeType, id);
         }
-        String contentId = id == 0 ? AttachmentUtil.BODY_ATTACHMENT_ID : Integer.toString(id);
+        String contentId = getContentId(anns, id);
+        
         return new Attachment(contentId, dh, new MetadataMap<String, String>());
     }
+
+    private String getContentId(Annotation[] anns, int id) {
+        Multipart part = AnnotationUtils.getAnnotation(anns, Multipart.class);
+        if (part != null && !"".equals(part.value())) {
+            return part.value();
+        }
+        return id == 0 ? AttachmentUtil.BODY_ATTACHMENT_ID : Integer.toString(id);
+    }
     
     @SuppressWarnings("unchecked")
     private DataHandler getHandlerForObject(Object obj, 

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisJSONProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisJSONProviderTest.java?rev=812542&r1=812541&r2=812542&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisJSONProviderTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisJSONProviderTest.java
Tue Sep  8 15:09:57 2009
@@ -25,6 +25,7 @@
 import java.lang.reflect.Method;
 import java.lang.reflect.Type;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.InvalidPropertiesFormatException;
 import java.util.List;
@@ -147,14 +148,77 @@
     
     @Test
     public void testWriteCollection() throws Exception {
-        String json = writeCollection();
+        String json = writeCollection(true, false, null, true, false);
         assertEquals("{\"ns1.ArrayOfAegisTestBean\":{\"@xsi.type\":\"ns1:ArrayOfAegisTestBean\","
-            + "\"ns1.AegisTestBean\":{\"@xsi.type\":\"ns1:AegisTestBean\",\"ns1.boolValue\":true,"
-            + "\"ns1.strValue\":\"hovercraft\"}}}", json);
+            + "\"ns1.AegisTestBean\":[{\"@xsi.type\":\"ns1:AegisTestBean\",\"ns1.boolValue\":true,"
+            + "\"ns1.strValue\":\"hovercraft\"},{\"@xsi.type\":\"ns1:AegisTestBean\","
+            + "\"ns1.boolValue\":true,\"ns1.strValue\":\"hovercraft2\"}]}}", json);
     }
     
-    private String writeCollection() throws Exception {
+    @Test
+    public void testWriteCollectionNoXsiType() throws Exception {
+        String json = writeCollection(false, false, null, true, false);
+        assertEquals("{\"ns1.ArrayOfAegisTestBean\":{"
+                     + "\"ns1.AegisTestBean\":[{\"ns1.boolValue\":true,"
+                     + "\"ns1.strValue\":\"hovercraft\"},{"
+                     + "\"ns1.boolValue\":true,\"ns1.strValue\":\"hovercraft2\"}]}}", json);
+    }
+    
+    @Test
+    public void testWriteCollectionNoXsiTypeArrayKey() throws Exception {
+        String json = writeCollection(false, false, "ns1.AegisTestBean", true, false);
+        assertEquals("{\"ns1.ArrayOfAegisTestBean\":{"
+            + "\"ns1.AegisTestBean\":[{\"ns1.boolValue\":true,\"ns1.strValue\":\"hovercraft\"},"
+            + "{\"ns1.boolValue\":true,\"ns1.strValue\":\"hovercraft2\"}]}}", json);
+    }
+    
+    @Test
+    public void testWriteCollectionIgnoreNs() throws Exception {
+        String json = writeCollection(false, false, "ns1.AegisTestBean", true, true);
+        assertEquals("{\"ArrayOfAegisTestBean\":{"
+            + "\"AegisTestBean\":[{\"boolValue\":true,\"strValue\":\"hovercraft\"},"
+            + "{\"boolValue\":true,\"strValue\":\"hovercraft2\"}]}}", json);
+    }
+    
+    @Test
+    public void testWriteCollectionNoXsiTypeSingleBeanArrayKey() throws Exception {
+        String json = writeCollection(false, false, "AegisTestBean", false, true);
+        assertEquals("{\"ArrayOfAegisTestBean\":{"
+            + "\"AegisTestBean\":[{\"boolValue\":true,\"strValue\":\"hovercraft\"}"
+            + "]}}", json);
+    }
+    
+    @Test
+    public void testWriteCollectionNoXsiTypeSingleBean() throws Exception {
+        String json = writeCollection(false, false, null, false, false);
+        assertEquals("{\"ns1.ArrayOfAegisTestBean\":{"
+            + "\"ns1.AegisTestBean\":{\"ns1.boolValue\":true,\"ns1.strValue\":\"hovercraft\"}"
+            + "}}", json);
+    }
+    
+    @Test
+    public void testWriteCollectionNoXsiTypeDropRootElement() throws Exception {
+        String json = writeCollection(false, true, null, true, false);
+        assertEquals("{"
+                     + "\"ns1.AegisTestBean\":[{\"ns1.boolValue\":true,"
+                     + "\"ns1.strValue\":\"hovercraft\"},{"
+                     + "\"ns1.boolValue\":true,\"ns1.strValue\":\"hovercraft2\"}]}", json);
+    }
+    
+    private String writeCollection(boolean writeXsiType, 
+                                   boolean dropRootElement,
+                                   String arrayKey,
+                                   boolean twoBeans,
+                                   boolean ignoreNs) 
+        throws Exception {
         AegisJSONProvider<List<AegisTestBean>> p = new AegisJSONProvider<List<AegisTestBean>>();
+        p.setWriteXsiType(writeXsiType);
+        p.setDropRootElement(dropRootElement);
+        p.setIgnoreNamespaces(ignoreNs);
+        if (arrayKey != null) {
+            p.setSerializeAsArray(true);
+            p.setArrayKeys(Collections.singletonList(arrayKey));
+        }
         AbstractAegisProvider.clearContexts();
         ByteArrayOutputStream os = new ByteArrayOutputStream();
         AegisTestBean bean = new AegisTestBean();
@@ -162,6 +226,12 @@
         bean.setStrValue("hovercraft");
         List<AegisTestBean> beans = new ArrayList<AegisTestBean>();
         beans.add(bean);
+        if (twoBeans) {
+            AegisTestBean bean2 = new AegisTestBean();
+            bean2.setBoolValue(Boolean.TRUE);
+            bean2.setStrValue("hovercraft2");
+            beans.add(bean2);
+        }
         Method m = CollectionsResource.class.getMethod("getAegisBeans", new Class[] {});
         p.writeTo(beans, m.getReturnType(), m.getGenericReturnType(), AegisTestBean.class
             .getAnnotations(), MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String,
Object>(), os);
@@ -172,7 +242,7 @@
     
     @Test
     public void testReadCollection() throws Exception {
-        String json = writeCollection();         
+        String json = writeCollection(true, false, null, true, false);         
         byte[] simpleBytes = json.getBytes("utf-8");
         Method m = CollectionsResource.class.getMethod("getAegisBeans", new Class[] {});
       
         AegisJSONProvider<List<AegisTestBean>> p = new AegisJSONProvider<List<AegisTestBean>>();
@@ -180,10 +250,13 @@
         // is that reasonable?
         List<AegisTestBean> list = p.readFrom(null, m.getGenericReturnType(), null,

                                               null, null, new ByteArrayInputStream(simpleBytes));
-        assertEquals(1, list.size());
+        assertEquals(2, list.size());
         AegisTestBean bean = list.get(0);
         assertEquals("hovercraft", bean.getStrValue());
         assertEquals(Boolean.TRUE, bean.getBoolValue());
+        bean = list.get(1);
+        assertEquals("hovercraft2", bean.getStrValue());
+        assertEquals(Boolean.TRUE, bean.getBoolValue());
     }
     
     @Test

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=812542&r1=812541&r2=812542&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
Tue Sep  8 15:09:57 2009
@@ -56,7 +56,6 @@
 import org.apache.cxf.jaxrs.model.ProviderInfo;
 import org.apache.cxf.jaxrs.resources.Book;
 import org.apache.cxf.jaxrs.resources.SuperBook;
-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;
@@ -247,7 +246,8 @@
         verifyProvider(byte[].class, BinaryDataProvider.class, "*/*");
         verifyProvider(InputStream.class, BinaryDataProvider.class, "image/png");
         MessageBodyWriter writer = ProviderFactory.getInstance()
-            .createMessageBodyWriter(File.class, null, null, JAXRSUtils.ALL_TYPES, null);
+            .createMessageBodyWriter(File.class, null, null, MediaType.APPLICATION_OCTET_STREAM_TYPE,

+                                     new MessageImpl());
         assertTrue(BinaryDataProvider.class == writer.getClass());
     }
     

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSDataBindingTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSDataBindingTest.java?rev=812542&r1=812541&r2=812542&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSDataBindingTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSDataBindingTest.java
Tue Sep  8 15:09:57 2009
@@ -43,7 +43,7 @@
     @BeforeClass
     public static void startServers() throws Exception {
         assertTrue("server did not launch correctly", 
-                   launchServer(BookDataBindingServer.class, true));
+                   launchServer(BookDataBindingServer.class));
     }
     
     

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java?rev=812542&r1=812541&r2=812542&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
Tue Sep  8 15:09:57 2009
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.systest.jaxrs;
 
+import java.io.File;
 import java.io.InputStream;
 import java.lang.annotation.Annotation;
 import java.util.ArrayList;
@@ -329,7 +330,29 @@
         assertTrue(Arrays.equals(image1, image2));
         ContentDisposition cd2 = body2.getRootAttachment().getContentDisposition();
         assertEquals("attachment;filename=java.jpg", cd2.toString());
-        assertEquals("java.jpg", cd.getParameter("filename"));
+        assertEquals("java.jpg", cd2.getParameter("filename"));
+    }
+    
+    @Test
+    public void testUploadImageFromForm2() throws Exception {
+        File file = 
+            new File(getClass().getResource("/org/apache/cxf/systest/jaxrs/resources/java.jpg").getFile());
+        String address = "http://localhost:9085/bookstore/books/formimage";
+        WebClient client = WebClient.create(address);
+        HTTPConduit conduit = WebClient.getConfig(client).getHttpConduit();
+        conduit.getClient().setReceiveTimeout(1000000);
+        conduit.getClient().setConnectionTimeout(1000000);
+        client.type("multipart/form-data").accept("multipart/form-data");
+        
+        MultipartBody body2 = client.post(file, MultipartBody.class);
+        InputStream is2 = body2.getRootAttachment().getDataHandler().getInputStream();
+        byte[] image1 = IOUtils.readBytesFromStream(
+            getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg"));
+        byte[] image2 = IOUtils.readBytesFromStream(is2);
+        assertTrue(Arrays.equals(image1, image2));
+        ContentDisposition cd2 = body2.getRootAttachment().getContentDisposition();
+        assertEquals("attachment;filename=java.jpg", cd2.toString());
+        assertEquals("java.jpg", cd2.getParameter("filename"));
     }
     
     private void doAddBook(String address, String resourceName, int status) throws Exception
{



Mime
View raw message