cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r812917 - in /cxf/branches/2.2.x-fixes: ./ 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/fr...
Date Wed, 09 Sep 2009 12:11:10 GMT
Author: sergeyb
Date: Wed Sep  9 12:11:09 2009
New Revision: 812917

URL: http://svn.apache.org/viewvc?rev=812917&view=rev
Log:
Merged revisions 812542 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r812542 | sergeyb | 2009-09-08 16:09:57 +0100 (Tue, 08 Sep 2009) | 1 line
  
  JAXRS : minor updates to JSON and multiparts code
........

Modified:
    cxf/branches/2.2.x-fixes/   (props changed)
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Multipart.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProvider.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONUtils.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
    cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Sep  9 12:11:09 2009
@@ -1 +1 @@
-/cxf/trunk:782728-782730,783097,783294,783396,784059,784181-784184,784893,784895,785279-785282,785468,785621,785624,785651,785734,785866,786142,786271-786272,786395,786512,786514,786582-786583,786638,786647,786850,787200,787269,787277-787279,787290-787291,787305,787323,787366,787849,788030,788060,788187,788444,788451,788703,788752,788774,788819-788820,789013,789371,789387,789420,789527-789530,789704-789705,789788,789811,789896-789901,790074,790094,790134,790188,790294,790553,790637-790644,790868,791301,791354,791538,791753,791947,792007,792096,792183,792261-792265,792271,792604,792683-792685,792975,792985,793059,793570,794297,794396,794680,794728,794771,794778-794780,794892,795044,795104,795160,795583,795907,796022-796023,796352,796593,796741,796780,796994-796997,797117,797159,797192,797194,797231-797233,797442,797505,797517,797534,797581-797583,797587,797640,797651,797699,797882-797883,798344-798346,798363,798461,798479,798533,798551,798557,798561-798562,798570,798573,79858
 4,798654,798748-798749,798816,798891,798929-798930,799245,799267,799439,799448,799637,799723-799724,799792,800453,800497-800498,801380-801381,801447,801962,802892,803056,803129,803174,803419,803460,803493,803689,804002,804175,804276,805784,805907,805909,806020-806021,806023,806405-806406,806576,806602-806604,806620,806627,806631,806633,806638,806687,806876,806922,806979-806982,807181,807205,807295,807748,807807,808035,808069,808085,808107,808464,808488,808731,808885,808925,809082-809083,809162,809190,809417-809626,809631,809663,809706,809738,809962,810090,810143,810349,810376,810513,810526,810927,811013,811148-811149,811175,811183,811387,811467-811468,811680,811696,812232
+/cxf/trunk:782728-782730,783097,783294,783396,784059,784181-784184,784893,784895,785279-785282,785468,785621,785624,785651,785734,785866,786142,786271-786272,786395,786512,786514,786582-786583,786638,786647,786850,787200,787269,787277-787279,787290-787291,787305,787323,787366,787849,788030,788060,788187,788444,788451,788703,788752,788774,788819-788820,789013,789371,789387,789420,789527-789530,789704-789705,789788,789811,789896-789901,790074,790094,790134,790188,790294,790553,790637-790644,790868,791301,791354,791538,791753,791947,792007,792096,792183,792261-792265,792271,792604,792683-792685,792975,792985,793059,793570,794297,794396,794680,794728,794771,794778-794780,794892,795044,795104,795160,795583,795907,796022-796023,796352,796593,796741,796780,796994-796997,797117,797159,797192,797194,797231-797233,797442,797505,797517,797534,797581-797583,797587,797640,797651,797699,797882-797883,798344-798346,798363,798461,798479,798533,798551,798557,798561-798562,798570,798573,79858
 4,798654,798748-798749,798816,798891,798929-798930,799245,799267,799439,799448,799637,799723-799724,799792,800453,800497-800498,801380-801381,801447,801962,802892,803056,803129,803174,803419,803460,803493,803689,804002,804175,804276,805784,805907,805909,806020-806021,806023,806405-806406,806576,806602-806604,806620,806627,806631,806633,806638,806687,806876,806922,806979-806982,807181,807205,807295,807748,807807,808035,808069,808085,808107,808464,808488,808731,808885,808925,809082-809083,809162,809190,809417-809626,809631,809663,809706,809738,809962,810090,810143,810349,810376,810513,810526,810927,811013,811148-811149,811175,811183,811387,811467-811468,811680,811696,812232,812542

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java?rev=812917&r1=812916&r2=812917&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
Wed Sep  9 12:11:09 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/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java?rev=812917&r1=812916&r2=812917&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
Wed Sep  9 12:11:09 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/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java?rev=812917&r1=812916&r2=812917&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
Wed Sep  9 12:11:09 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/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Multipart.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Multipart.java?rev=812917&r1=812916&r2=812917&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Multipart.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Multipart.java
Wed Sep  9 12:11:09 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/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProvider.java?rev=812917&r1=812916&r2=812917&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProvider.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProvider.java
Wed Sep  9 12:11:09 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/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java?rev=812917&r1=812916&r2=812917&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java
Wed Sep  9 12:11:09 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/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java?rev=812917&r1=812916&r2=812917&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
Wed Sep  9 12:11:09 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/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONUtils.java?rev=812917&r1=812916&r2=812917&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONUtils.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONUtils.java
Wed Sep  9 12:11:09 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/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java?rev=812917&r1=812916&r2=812917&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
Wed Sep  9 12:11:09 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/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java?rev=812917&r1=812916&r2=812917&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
Wed Sep  9 12:11:09 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/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java?rev=812917&r1=812916&r2=812917&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
(original)
+++ cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
Wed Sep  9 12:11:09 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