cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r833911 [1/2] - in /cxf/branches/2.2.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ rt/fro...
Date Sun, 08 Nov 2009 18:46:08 GMT
Author: sergeyb
Date: Sun Nov  8 18:46:07 2009
New Revision: 833911

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

........
  r833909 | sergeyb | 2009-11-08 18:32:41 +0000 (Sun, 08 Nov 2009) | 1 line
  
  JAXRS: improving multipart/form-data support and adding more options for customizing in/out XML/JSON
........

Added:
    cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/attachmentFormJaxb
      - copied unchanged from r833909, cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/attachmentFormJaxb
    cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/attachmentFormJson
      - copied unchanged from r833909, cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/attachmentFormJson
    cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/attachmentFormJsonFiles
      - copied unchanged from r833909, cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/attachmentFormJsonFiles
    cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/attachmentFormJsonJaxb
      - copied unchanged from r833909, cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/attachmentFormJsonJaxb
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/ext/MessageContextImpl.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/ContentDisposition.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MediaTypeHeaderProvider.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.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/MultipartProvider.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java
    cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
    cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
    cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
    cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
    cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_get_chapter1.txt

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
    svn:mergeinfo = /cxf/trunk:833909

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/ext/MessageContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java?rev=833911&r1=833910&r2=833911&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java (original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java Sun Nov  8 18:46:07 2009
@@ -34,12 +34,14 @@
 import javax.servlet.http.HttpServletResponse;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Request;
 import javax.ws.rs.core.SecurityContext;
 import javax.ws.rs.core.UriInfo;
 import javax.ws.rs.ext.ContextResolver;
 import javax.ws.rs.ext.Providers;
 
+import org.apache.cxf.attachment.AttachmentDeserializer;
 import org.apache.cxf.attachment.AttachmentImpl;
 import org.apache.cxf.attachment.AttachmentUtil;
 import org.apache.cxf.endpoint.Endpoint;
@@ -49,7 +51,9 @@
 import org.apache.cxf.jaxrs.interceptor.AttachmentInputInterceptor;
 import org.apache.cxf.jaxrs.interceptor.AttachmentOutputInterceptor;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
+import org.apache.cxf.message.ExchangeImpl;
 import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageImpl;
 
 public class MessageContextImpl implements MessageContext {
 
@@ -59,8 +63,10 @@
     }
     
     public Object get(Object key) {
-        if (MultipartBody.INBOUND_MESSAGE_ATTACHMENTS.equals(key.toString())) {
-            return createAttachments(MultipartBody.INBOUND_MESSAGE_ATTACHMENTS);
+        String keyValue = key.toString();
+        if (MultipartBody.INBOUND_MESSAGE_ATTACHMENTS.equals(keyValue)
+            || (MultipartBody.INBOUND_MESSAGE_ATTACHMENTS + ".embedded").equals(keyValue)) {
+            return createAttachments(key.toString());
         }
         return m.get(key);
     }
@@ -171,12 +177,29 @@
     
     private MultipartBody createAttachments(String propertyName) {
         Message inMessage = m.getExchange().getInMessage();
+        boolean embeddedAttachment = inMessage.get("org.apache.cxf.multipart.embedded") != null;
+        
         Object o = inMessage.get(propertyName);
         if (o != null) {
             return (MultipartBody)o;
         }
-        new AttachmentInputInterceptor().handleMessage(inMessage);
         
+        if (embeddedAttachment) {
+            inMessage = new MessageImpl();
+            inMessage.setExchange(new ExchangeImpl());
+            inMessage.put(AttachmentDeserializer.ATTACHMENT_DIRECTORY, 
+                m.getExchange().getInMessage().get(AttachmentDeserializer.ATTACHMENT_DIRECTORY));
+            inMessage.put(AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD, 
+                m.getExchange().getInMessage().get(AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD));
+            inMessage.setContent(InputStream.class, 
+                m.getExchange().getInMessage().get("org.apache.cxf.multipart.embedded.input"));
+            inMessage.put(Message.CONTENT_TYPE, 
+                m.getExchange().getInMessage().get("org.apache.cxf.multipart.embedded.ctype").toString());
+        }
+        
+        
+        new AttachmentInputInterceptor().handleMessage(inMessage);
+    
         List<Attachment> newAttachments = new LinkedList<Attachment>();
         try {
             Attachment first = new Attachment(AttachmentUtil.createAttachment(
@@ -187,6 +210,7 @@
             throw new WebApplicationException(500);
         }
         
+    
         Collection<org.apache.cxf.message.Attachment> childAttachments = inMessage.getAttachments();
         if (childAttachments == null) {
             childAttachments = Collections.emptyList();
@@ -195,7 +219,10 @@
         for (org.apache.cxf.message.Attachment a : childAttachments) {
             newAttachments.add(new Attachment(a));
         }
-        MultipartBody body = new MultipartBody(newAttachments, getHttpHeaders().getMediaType(), false);
+        MediaType mt = embeddedAttachment 
+            ? (MediaType)inMessage.get("org.apache.cxf.multipart.embedded.ctype")
+            : getHttpHeaders().getMediaType();
+        MultipartBody body = new MultipartBody(newAttachments, mt, false);
         inMessage.put(propertyName, body);
         return body;
     }

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/ContentDisposition.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/ContentDisposition.java?rev=833911&r1=833910&r2=833911&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/ContentDisposition.java (original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/ContentDisposition.java Sun Nov  8 18:46:07 2009
@@ -41,7 +41,7 @@
             String v = values.get(i).trim();
             if (v.startsWith(name)) {
                 String[] parts = v.split("=");
-                return parts.length == 2 ? parts[1].trim() : ""; 
+                return parts.length == 2 ? parts[1].trim().replace("\"", "").replace("'", "") : ""; 
             }
         }
         return null;
@@ -51,7 +51,8 @@
         Map<String, String> map = new LinkedHashMap<String, String>();
         for (int i = 1; i < values.size(); i++) {
             String[] parts = values.get(i).split("=");
-            map.put(parts[0].trim(), parts.length == 2 ? parts[1].trim() : ""); 
+            map.put(parts[0].trim(), parts.length == 2 
+                    ? parts[1].trim().replace("\"", "").replace("'", "") : ""); 
         }
         return map;
     }

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MediaTypeHeaderProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MediaTypeHeaderProvider.java?rev=833911&r1=833910&r2=833911&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MediaTypeHeaderProvider.java (original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MediaTypeHeaderProvider.java Sun Nov  8 18:46:07 2009
@@ -65,7 +65,7 @@
                     throw new IllegalArgumentException("Wrong media type  parameter, seperator is missing");
                 }
                 parameters.put(token.substring(0, equalSign).trim().toLowerCase(), 
-                               token.substring(equalSign + 1).trim().toLowerCase());
+                               token.substring(equalSign + 1).trim());
             }
             
         }

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java?rev=833911&r1=833910&r2=833911&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java (original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java Sun Nov  8 18:46:07 2009
@@ -28,10 +28,12 @@
 
 public class OperationResourceInfoComparator implements Comparator<OperationResourceInfo> {
     
+    private static final String HEAD_METHOD = "HEAD";
+    private boolean headMethod;
     private Message message;
-    private ResourceComparator rc; 
+    private ResourceComparator rc;    
 
-    public OperationResourceInfoComparator(Message m) {
+    public OperationResourceInfoComparator(Message m, String method) {
         this.message = m;
         if (message != null) {
             Object o = m.getExchange().get(Endpoint.class).get("org.apache.cxf.jaxrs.comparator");
@@ -39,6 +41,7 @@
                 rc = (ResourceComparator)o;
             }
         }
+        headMethod = HEAD_METHOD.equals(method);
     }
     
     public int compare(OperationResourceInfo e1, OperationResourceInfo e2) {
@@ -55,6 +58,15 @@
             // subresource method takes precedence over a subresource locator
             return e1.getHttpMethod() != null ? -1 : 1;
         }
+        
+        if (headMethod) {
+            if (HEAD_METHOD.equals(e1.getHttpMethod())) {
+                return -1;
+            } else if (HEAD_METHOD.equals(e2.getHttpMethod())) {
+                return 1;
+            }
+                
+        }
 
             
         int result = URITemplate.compareTemplates(

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java?rev=833911&r1=833910&r2=833911&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java (original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java Sun Nov  8 18:46:07 2009
@@ -19,6 +19,8 @@
 
 package org.apache.cxf.jaxrs.provider;
 
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.io.UnsupportedEncodingException;
@@ -26,7 +28,12 @@
 import java.lang.reflect.Array;
 import java.lang.reflect.Type;
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.ResourceBundle;
@@ -51,7 +58,12 @@
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.adapters.XmlAdapter;
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+import javax.xml.namespace.NamespaceContext;
 import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
 import javax.xml.validation.Schema;
 
 import org.apache.cxf.common.i18n.BundleUtils;
@@ -62,10 +74,15 @@
 import org.apache.cxf.jaxb.JAXBContextProxy;
 import org.apache.cxf.jaxb.JAXBUtils;
 import org.apache.cxf.jaxrs.ext.MessageContext;
+import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.jaxrs.utils.AnnotationUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.jaxrs.utils.schemas.SchemaHandler;
+import org.apache.cxf.staxutils.DelegatingXMLStreamWriter;
+import org.apache.cxf.staxutils.DepthXMLStreamReader;
+import org.apache.cxf.staxutils.StaxStreamFilter;
+import org.apache.cxf.staxutils.StaxUtils;
 
 public abstract class AbstractJAXBProvider extends AbstractConfigurableProvider
     implements MessageBodyReader<Object>, MessageBodyWriter<Object> {
@@ -87,6 +104,15 @@
     protected boolean unmarshalAsJaxbElement;
     protected boolean marshalAsJaxbElement;
     
+    protected Map<String, String> outElementsMap;
+    protected Map<String, String> outAppendMap;
+    protected List<String> outDropElements;
+    protected List<String> inDropElements;
+    protected Map<String, String> inElementsMap;
+    protected Map<String, String> inAppendMap;
+    protected Map<String, String> inAppendAttributesMap;
+    private boolean attributesToElements;
+    
     private MessageContext mc;
     private Schema schema;
     private String collectionWrapperName;
@@ -198,7 +224,7 @@
         return convertStringToQName(name);
     }
     
-    private QName convertStringToQName(String name) {
+    protected static QName convertStringToQName(String name) {
         int ind1 = name.indexOf('{');
         if (ind1 != 0) {
             return new QName(name);
@@ -535,6 +561,97 @@
         throw new WebApplicationException(t, r);
     }
     
+    public void setOutTransformElements(Map<String, String> outElements) {
+        this.outElementsMap = outElements;
+    }
+    
+    public void setInAppendElements(Map<String, String> inElements) {
+        this.inAppendMap = inElements;
+    }
+    
+    public void setInAppendAttributes(Map<String, String> inElements) {
+        this.inAppendAttributesMap = inElements;
+    }
+    
+    public void setInTransformElements(Map<String, String> inElements) {
+        this.inElementsMap = inElements;
+    }
+    
+    public void setOutAppendElements(Map<String, String> map) {
+        this.outAppendMap = map;
+    }
+
+    public void setOutDropElements(List<String> dropElementsSet) {
+        this.outDropElements = dropElementsSet;
+    }
+
+    public void setInDropElements(List<String> dropElementsSet) {
+        this.inDropElements = dropElementsSet;
+    }
+    
+    protected static Set<QName> convertToSetOfQNames(List<String> dropEls) {
+        Set<QName> dropElements = Collections.emptySet();
+        if (dropEls != null) {
+            dropElements = new LinkedHashSet<QName>(dropEls.size());
+            for (String val : dropEls) {
+                dropElements.add(convertStringToQName(val));
+            }
+        }
+        return dropElements;
+    }
+    
+    protected XMLStreamReader createTransformReaderIfNeeded(XMLStreamReader reader, InputStream is) {
+        if (inDropElements != null) {
+            Set<QName> dropElements = convertToSetOfQNames(inDropElements);
+            reader = StaxUtils.createFilteredReader(createNewReaderIfNeeded(reader, is),
+                                               new StaxStreamFilter(dropElements.toArray(new QName[]{})));    
+        }
+        if (inElementsMap != null || inAppendMap != null || inAppendAttributesMap != null) {
+            reader = new InTransformReader(createNewReaderIfNeeded(reader, is),
+                                           inElementsMap, inAppendMap, inAppendAttributesMap);
+        }
+        return reader;
+    }
+    
+    protected XMLStreamWriter createTransformWriterIfNeeded(XMLStreamWriter writer,
+                                                            OutputStream os) {
+        if (outElementsMap != null || outDropElements != null 
+            || outAppendMap != null || attributesToElements) {
+            writer = createNewWriterIfNeeded(writer, os);
+            writer = new OutTransformWriter(writer, outElementsMap, outAppendMap,
+                                            outDropElements, attributesToElements);
+        }
+        return writer;
+    }
+    
+    protected XMLStreamReader createNewReaderIfNeeded(XMLStreamReader reader, InputStream is) {
+        return reader == null ? StaxUtils.createXMLStreamReader(is) : reader;
+    }
+    
+    protected XMLStreamWriter createNewWriterIfNeeded(XMLStreamWriter writer, OutputStream os) {
+        return writer == null ? StaxUtils.createXMLStreamWriter(os) : writer;
+    }
+    
+    protected static void convertToMapOfQNames(Map<String, String> map,
+                                               Map<QName, QName> elementsMap,
+                                               Map<String, String> nsMap) {
+        if (map != null) {
+            for (Map.Entry<String, String> entry : map.entrySet()) {
+                QName lname = convertStringToQName(entry.getKey());
+                QName rname = convertStringToQName(entry.getValue());
+                elementsMap.put(lname, rname);
+                if (nsMap != null) {
+                    nsMap.put(lname.getNamespaceURI(), rname.getNamespaceURI());
+                }
+            }
+        }
+    }
+    
+    
+    public void setAttributesToElements(boolean value) {
+        this.attributesToElements = value;
+    }
+
     @XmlRootElement
     protected static class CollectionWrapper {
         
@@ -579,4 +696,356 @@
         }
         
     }
+    
+    protected static class OutTransformWriter extends DelegatingXMLStreamWriter {
+        private Map<QName, QName> elementsMap = new HashMap<QName, QName>(5);
+        private Map<QName, QName> appendMap = new HashMap<QName, QName>(5);
+        private Map<String, String> nsMap = new HashMap<String, String>(5);
+        private Set<String> prefixes = new HashSet<String>(2);
+        private Set<String> writtenUris = new HashSet<String>(2);
+        
+        private Set<QName> dropElements;
+        private List<Integer> droppingIndexes = new LinkedList<Integer>();
+        private List<QName> appendedElements = new LinkedList<QName>();
+        private List<Integer> appendedIndexes = new LinkedList<Integer>();
+        private int currentDepth;
+        private boolean attributesToElements;
+        
+        public OutTransformWriter(XMLStreamWriter writer, 
+                                  Map<String, String> outMap,
+                                  Map<String, String> append,
+                                  List<String> dropEls,
+                                  boolean attributesToElements) {
+            super(writer);
+            convertToMapOfQNames(outMap, elementsMap, nsMap);
+            convertToMapOfQNames(append, appendMap, null);
+            dropElements = convertToSetOfQNames(dropEls);
+            this.attributesToElements = attributesToElements;
+        }
+
+        @Override
+        public void writeNamespace(String prefix, String uri) throws XMLStreamException {
+            if (matchesDropped()) {
+                return;
+            }
+            if (writtenUris.contains(uri)) {
+                return;
+            }
+            String value = nsMap.get(uri);
+            if (value != null && value.length() == 0) {
+                return;
+            }
+            super.writeNamespace(prefix, value != null ? value : uri);
+        }
+        
+        @Override
+        public void writeStartElement(String prefix, String local, String uri) throws XMLStreamException {
+            currentDepth++;
+            QName currentQName = new QName(uri, local);
+            
+            QName appendQName = appendMap.get(currentQName);
+            if (appendQName != null && !appendedElements.contains(appendQName)) {
+                currentDepth++;
+                String theprefix = uri.equals(appendQName.getNamespaceURI()) ? prefix : "";
+                write(new QName(appendQName.getNamespaceURI(), appendQName.getLocalPart(), theprefix));
+                if (theprefix.length() > 0) {
+                    super.writeNamespace(theprefix, uri);
+                    writtenUris.add(uri);
+                }
+                appendedElements.add(appendQName);
+                appendedIndexes.add(currentDepth - 2);
+            }
+            
+            if (dropElements.contains(currentQName)) {
+                droppingIndexes.add(currentDepth - 1);
+                return;
+            }
+            write(new QName(uri, local, prefix));
+        }
+        
+        @Override
+        public void writeEndElement() throws XMLStreamException {
+            --currentDepth;
+            if (indexRemoved(droppingIndexes)) {
+                return;
+            }
+            super.writeEndElement();
+            if (indexRemoved(appendedIndexes)) {
+                super.writeEndElement();
+            }
+        }
+        
+        @Override
+        public void writeCharacters(String text) throws XMLStreamException {
+            if (matchesDropped()) {
+                return;
+            }
+            super.writeCharacters(text);
+        }
+        
+        private void write(QName qname) throws XMLStreamException {
+            QName name = elementsMap.get(qname);
+            if (name == null) {
+                name = qname;
+            }
+            boolean writeNs = false;
+            String prefix = "";
+            if (name.getNamespaceURI().length() > 0) {
+                if (qname.getPrefix().length() == 0) {
+                    prefix = findUniquePrefix();
+                    writeNs = true;
+                } else {
+                    prefix = qname.getPrefix();
+                    prefixes.add(prefix);
+                }
+                prefixes.add(prefix);
+            }
+            super.writeStartElement(prefix, name.getLocalPart(), name.getNamespaceURI());
+            if (writeNs) {
+                this.writeNamespace(prefix, name.getNamespaceURI());
+            }
+        }
+        
+        private String findUniquePrefix() {
+            
+            int i = 0;
+            while (true) {
+                if (!prefixes.contains("ps" + ++i)) {
+                    return "ps" + i;
+                }
+            }
+        }
+        
+        private boolean matchesDropped() {
+            int size = droppingIndexes.size();
+            if (size > 0 && droppingIndexes.get(size - 1) == currentDepth - 1) {
+                return true;
+            }
+            return false;
+        }
+        
+        private boolean indexRemoved(List<Integer> indexes) {
+            int size = indexes.size();
+            if (size > 0 && indexes.get(size - 1) == currentDepth) {
+                indexes.remove(size - 1);
+                return true;
+            }
+            return false;
+        }
+        
+        @Override
+        public NamespaceContext getNamespaceContext() {
+            return new DelegatingNamespaceContext(super.getNamespaceContext(), nsMap);
+        }
+        
+        @Override
+        public void writeAttribute(String uri, String local, String value) throws XMLStreamException {
+            if (!attributesToElements) {
+                super.writeAttribute(uri, local, value);
+            } else {
+                writeAttributeAsElement(uri, local, value);
+            }
+        }
+
+        @Override
+        public void writeAttribute(String local, String value) throws XMLStreamException {
+            if (!attributesToElements) {
+                super.writeAttribute(local, value);
+            } else {
+                writeAttributeAsElement("", local, value);
+            }
+        }
+        
+        private void writeAttributeAsElement(String uri, String local, String value)
+            throws XMLStreamException {
+            this.writeStartElement(uri, local);
+            this.writeCharacters(value);
+            this.writeEndElement();
+        }
+    }
+    
+    private static class AttributeValue {
+        private String name;
+        private String value;
+        
+        public AttributeValue(String n, String v) {
+            this.name = n;
+            this.value = v;
+        }
+        
+        public String getName() {
+            return name;
+        }
+        
+        public String getValue() {
+            return value;
+        }
+    }
+    
+    protected static class InTransformReader extends DepthXMLStreamReader {
+        
+        private static final String INTERN_NAMES = "org.codehaus.stax2.internNames";
+        private static final String INTERN_NS = "org.codehaus.stax2.internNsUris";
+        
+        private Map<QName, QName> inElementsMap = new HashMap<QName, QName>(5);
+        private Map<QName, QName> inAppendMap = new HashMap<QName, QName>(5);
+        private Map<String, String> nsMap = new HashMap<String, String>(5);
+        private MultivaluedMap<QName, AttributeValue> inAttributes;
+        private QName currentQName;
+        private QName previousQName;
+        private List<AttributeValue> currentAttributes;
+        private int previousDepth = -1;
+        
+        public InTransformReader(XMLStreamReader reader, 
+                                 Map<String, String> inMap,
+                                 Map<String, String> appendMap,
+                                 Map<String, String> appendAttrMap) {
+            super(reader);
+            convertToMapOfQNames(inMap, inElementsMap, nsMap);
+            convertToMapOfQNames(appendMap, inAppendMap, null);
+            convertToMapOfAttributes(appendAttrMap);
+        }
+        
+        private void convertToMapOfAttributes(Map<String, String> map) {
+            if (map != null) {
+                inAttributes = new MetadataMap<QName, AttributeValue>();
+                for (Map.Entry<String, String> entry : map.entrySet()) {
+                    QName lname = convertStringToQName(entry.getKey());
+                    String[] values = entry.getValue().split(":");
+                    inAttributes.add(lname, new AttributeValue(values[0], values[1]));
+                }
+            }
+        }
+        
+        public int getAttributeCount() {
+            return currentAttributes == null ? super.getAttributeCount() 
+                : currentAttributes.size() + super.getAttributeCount();
+        }
+
+        public String getAttributeLocalName(int ind) {
+            if (currentAttributes == null) {
+                return super.getAttributeLocalName(ind);
+            } else {
+                int count = super.getAttributeCount();
+                return ind < count ? super.getAttributeLocalName(ind) 
+                    : currentAttributes.get(ind - count).getName(); 
+            }
+        }
+
+        public String getAttributeNamespace(int ind) {
+            return currentAttributes == null ? reader.getAttributeNamespace(ind) : "";
+        }
+
+        public String getAttributeValue(int ind) {
+            if (currentAttributes == null) {
+                return super.getAttributeValue(ind);
+            } else {
+                int count = super.getAttributeCount();
+                return ind < count ? super.getAttributeValue(ind) 
+                    : currentAttributes.get(ind - count).getValue(); 
+            }
+        }
+
+        public int next() throws XMLStreamException {
+            currentAttributes = null;
+            if (currentQName != null) {
+                return XMLStreamConstants.START_ELEMENT;
+            } else if (previousDepth != -1 && previousDepth == getDepth() + 1) {
+                previousDepth = -1;
+                return XMLStreamConstants.END_ELEMENT;
+            } else {
+                return super.next();
+            }
+        }
+        
+        public Object getProperty(String name) throws IllegalArgumentException {
+
+            if (INTERN_NAMES.equals(name) || INTERN_NS.equals(name)) {
+                return Boolean.FALSE;
+            }
+            return super.getProperty(name);
+        }
+
+        public String getLocalName() {
+            QName cQName = getCurrentName();
+            if (cQName != null) {
+                String name = cQName.getLocalPart();
+                resetCurrentQName();
+                return name;
+            }
+            return super.getLocalName();
+        }
+
+        private QName getCurrentName() {
+            return currentQName != null ? currentQName 
+                : previousQName != null ? previousQName : null;
+        }
+        
+        private void resetCurrentQName() {
+            currentQName = previousQName;
+            previousQName = null;
+        }
+        
+        public NamespaceContext getNamespaceContext() {
+            return new DelegatingNamespaceContext(super.getNamespaceContext(), nsMap);
+        }
+
+        public String getNamespaceURI() {
+         
+            QName theName = readCurrentElement();
+            if (inAttributes != null) {
+                currentAttributes = inAttributes.remove(theName);
+            }
+            QName appendQName = inAppendMap.remove(theName);
+            if (appendQName != null) {
+                previousDepth = getDepth();
+                previousQName = theName;
+                currentQName = appendQName;
+                return currentQName.getNamespaceURI();
+            }
+            QName expected = inElementsMap.get(theName);
+            if (expected == null) {
+                return theName.getNamespaceURI();
+            }
+            currentQName = expected;
+            return currentQName.getNamespaceURI();
+        }
+        
+        private QName readCurrentElement() {
+            if (currentQName != null) {
+                return currentQName;
+            }
+            String ns = super.getNamespaceURI();
+            String name = super.getLocalName();
+            return new QName(ns, name);
+        }
+    }
+
+    private static class DelegatingNamespaceContext implements NamespaceContext {
+
+        private NamespaceContext nc;
+        private Map<String, String> nsMap;
+        
+        public DelegatingNamespaceContext(NamespaceContext nc, Map<String, String> nsMap) {
+            this.nc = nc;
+            this.nsMap = nsMap;
+        }
+        
+        public String getNamespaceURI(String prefix) {
+            return nc.getNamespaceURI(prefix);
+        }
+
+        public String getPrefix(String ns) {
+            String value = nsMap.get(ns);
+            if (value != null && value.length() == 0) {
+                return null;
+            }
+            return value != null ? nc.getPrefix(value) : nc.getPrefix(ns);
+        }
+
+        public Iterator getPrefixes(String ns) {
+            return nc.getPrefixes(ns);
+        }
+        
+    }
 }

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java?rev=833911&r1=833910&r2=833911&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java (original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java Sun Nov  8 18:46:07 2009
@@ -186,9 +186,9 @@
     protected XMLStreamReader getStreamReader(InputStream is, Class<?> type, MediaType mt) {
         MessageContext mc = getContext();
         XMLStreamReader reader = mc != null ? mc.getContent(XMLStreamReader.class) : null;
+        reader = createTransformReaderIfNeeded(reader, is);
         if (InjectionUtils.isSupportedCollectionOrArray(type)) {
-            reader = reader == null ? StaxUtils.createXMLStreamReader(is) : reader;
-            return new JAXBCollectionWrapperReader(reader);
+            return new JAXBCollectionWrapperReader(createNewReaderIfNeeded(reader, is));
         } else {
             return reader;
         }
@@ -336,7 +336,7 @@
                 writer = StaxUtils.createXMLStreamWriter(os);
             }
         }
-        return writer;
+        return createTransformWriterIfNeeded(writer, os);
     }
     
     protected void marshalToOutputStream(Marshaller ms, Object obj, OutputStream os, MediaType mt) 
@@ -379,4 +379,6 @@
         }
         
     }
+    
+    
 }

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=833911&r1=833910&r2=833911&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 Sun Nov  8 18:46:07 2009
@@ -192,7 +192,8 @@
         if (BADGER_FISH_CONVENTION.equals(convention)) {
             return JSONUtils.createBadgerFishReader(is);
         } else {
-            return JSONUtils.createStreamReader(is, readXsiType, namespaceMap);
+            XMLStreamReader reader = JSONUtils.createStreamReader(is, readXsiType, namespaceMap);
+            return createTransformReaderIfNeeded(reader, is);
         }
     }
     
@@ -342,7 +343,8 @@
              writeXsiType && !ignoreNamespaces, namespaceMap, serializeAsArray, arrayKeys,
              isCollection || dropRootElement);
         writer = JSONUtils.createIgnoreMixedContentWriterIfNeeded(writer, ignoreMixedContent);
-        return JSONUtils.createIgnoreNsWriterIfNeeded(writer, ignoreNamespaces);
+        writer = JSONUtils.createIgnoreNsWriterIfNeeded(writer, ignoreNamespaces);
+        return createTransformWriterIfNeeded(writer, os);
     }
     
     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/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=833911&r1=833910&r2=833911&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 Sun Nov  8 18:46:07 2009
@@ -61,7 +61,7 @@
 import org.apache.cxf.jaxrs.utils.multipart.AttachmentUtils;
 
 @Provider
-@Consumes({"multipart/related", "multipart/mixed", "multipart/alternative" })
+@Consumes({"multipart/related", "multipart/mixed", "multipart/alternative", "multipart/form-data" })
 @Produces({"multipart/related", "multipart/mixed", "multipart/alternative" })
 public class MultipartProvider extends AbstractConfigurableProvider
     implements MessageBodyReader<Object>, MessageBodyWriter<Object> {
@@ -88,7 +88,9 @@
     
     public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, 
                               MediaType mt) {
-        return isSupported(type, genericType, annotations, mt);
+        return isSupported(type, genericType, annotations, mt)
+             || (mt.getType().equals("multipart") && mt.getSubtype().equals("form-data") 
+                && !MultivaluedMap.class.isAssignableFrom(type));
     }
     
     private boolean isSupported(Class<?> type, Type genericType, Annotation[] annotations, 
@@ -119,7 +121,8 @@
         List<Attachment> infos = 
             AttachmentUtils.getAttachments(mc, attachmentDir, attachmentThreshold);
         
-        if (Collection.class.isAssignableFrom(c)) {
+        if (Collection.class.isAssignableFrom(c) 
+            && AnnotationUtils.getAnnotation(anns, Multipart.class) == null) {
             Class<?> actual = InjectionUtils.getActualType(t);
             actual = actual != null ? actual : Object.class;
             if (Attachment.class.isAssignableFrom(actual)) {
@@ -152,6 +155,13 @@
         } else if (Attachment.class.isAssignableFrom(c)) {
             return multipart;
         } else {
+            if (mediaTypeSupported(multipart.getContentType())) {
+                mc.put("org.apache.cxf.multipart.embedded", true);
+                mc.put("org.apache.cxf.multipart.embedded.ctype", multipart.getContentType());
+                mc.put("org.apache.cxf.multipart.embedded.input", 
+                       multipart.getDataHandler().getInputStream());
+                anns = new Annotation[]{};
+            }
             MessageBodyReader<Object> r = 
                 mc.getProviders().getMessageBodyReader((Class)c, t, anns, multipart.getContentType());
             if (r != null) {

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=833911&r1=833910&r2=833911&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java (original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java Sun Nov  8 18:46:07 2009
@@ -286,7 +286,8 @@
         
         SortedMap<OperationResourceInfo, MultivaluedMap<String, String>> candidateList = 
             new TreeMap<OperationResourceInfo, MultivaluedMap<String, String>>(
-                new OperationResourceInfoComparator(message));
+                new OperationResourceInfoComparator(message, httpMethod));
+
         MediaType requestType = requestContentType == null 
                                 ? ALL_TYPES : MediaType.valueOf(requestContentType);
         

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java?rev=833911&r1=833910&r2=833911&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java (original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java Sun Nov  8 18:46:07 2009
@@ -36,6 +36,7 @@
 import org.apache.cxf.common.logging.LogUtils;
 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.Multipart;
 import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
@@ -78,7 +79,12 @@
         if (attachmentThreshold != null) {
             mc.put(AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD, attachmentThreshold);
         }
-        return (MultipartBody)mc.get(MultipartBody.INBOUND_MESSAGE_ATTACHMENTS);
+        
+        boolean embeddedAttachment = mc.get("org.apache.cxf.multipart.embedded") != null;
+        String propertyName = embeddedAttachment ? MultipartBody.INBOUND_MESSAGE_ATTACHMENTS + ".embedded"
+            : MultipartBody.INBOUND_MESSAGE_ATTACHMENTS;
+                
+        return (MultipartBody)mc.get(propertyName);
     }
     
     public static List<Attachment> getAttachments(MessageContext mc, 
@@ -91,7 +97,7 @@
         Multipart id = AnnotationUtils.getAnnotation(anns, Multipart.class);
         if (id != null) {
             for (Attachment a : infos) {
-                if (a.getContentId().equals(id.value())) {
+                if (matchAttachmentId(a, id, mt)) {
                     checkMediaTypes(a.getContentType(), id.type());
                     return a;    
                 }
@@ -108,6 +114,17 @@
         
         return infos.size() > 0 ? infos.get(0) : null; 
     }
+    
+    private static boolean matchAttachmentId(Attachment at, Multipart mid, MediaType multipartType) {
+        if (at.getContentId().equals(mid.value())) {
+            return true;
+        }
+        ContentDisposition cd = at.getContentDisposition();
+        if (cd != null && mid.value().equals(cd.getParameter("name"))) {
+            return true;
+        }
+        return false;
+    }
 
     @SuppressWarnings("unchecked")
     public static <T> MultivaluedMap<String, T> populateFormMap(MessageContext mc, Class<T> cls) {

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java?rev=833911&r1=833910&r2=833911&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java (original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java Sun Nov  8 18:46:07 2009
@@ -44,6 +44,9 @@
 import javax.xml.bind.Marshaller;
 import javax.xml.bind.PropertyException;
 import javax.xml.bind.ValidationEventHandler;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.adapters.XmlAdapter;
 import javax.xml.bind.attachment.AttachmentMarshaller;
 import javax.xml.namespace.QName;
@@ -60,8 +63,11 @@
 import org.apache.cxf.jaxrs.provider.index.TestBean;
 import org.apache.cxf.jaxrs.resources.Book;
 import org.apache.cxf.jaxrs.resources.CollectionsResource;
+import org.apache.cxf.jaxrs.resources.ManyTags;
 import org.apache.cxf.jaxrs.resources.SuperBook;
+import org.apache.cxf.jaxrs.resources.TagVO;
 import org.apache.cxf.jaxrs.resources.TagVO2;
+import org.apache.cxf.jaxrs.resources.Tags;
 
 import org.junit.Assert;
 import org.junit.Test;
@@ -350,6 +356,328 @@
     }
     
     @Test
+    public void testInNsElementFromLocal() throws Exception {
+        String data = "<?xml version='1.0' encoding='UTF-8'?>"
+            + "<thetag><group>B</group><name>A</name></thetag>";
+        readTagVO2AfterTransform(data, "thetag");
+    }
+    
+    @Test
+    public void testInNsElementFromNsElement() throws Exception {
+        String data = "<?xml version='1.0' encoding='UTF-8'?>"
+            + "<t:thetag2 xmlns:t=\"http://bar\"><group>B</group><name>A</name></t:thetag2>";
+        readTagVO2AfterTransform(data, "{http://bar}thetag2");
+    }
+    
+    @Test
+    public void testInAppendElementNoNs() throws Exception {
+        String data = "<tags><list><group>b</group><name>a</name></list></tags>";
+        readAppendElementsNoNs(data, Collections.singletonMap("tags", "ManyTags"));
+    }
+    
+    @Test
+    public void testInAppendElementNoNs2() throws Exception {
+        String data = "<ManyTags><list><group>b</group><name>a</name></list></ManyTags>";
+        readAppendElementsNoNs(data, Collections.singletonMap("list", "tags"));
+    }
+    
+    @SuppressWarnings("unchecked")
+    private void readAppendElementsNoNs(String data, Map<String, String> appendMap) throws Exception {
+        JAXBElementProvider provider = new JAXBElementProvider();
+        provider.setInAppendElements(appendMap);
+        ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
+        Object o = provider.readFrom((Class)ManyTags.class, ManyTags.class,
+                      new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, String>(), is);
+        ManyTags holder = (ManyTags)o;
+        assertNotNull(holder);    
+        TagVO tag = holder.getTags().getTags().get(0);
+        assertEquals("a", tag.getName());
+        assertEquals("b", tag.getGroup());
+    }
+    
+    @Test
+    @SuppressWarnings("unchecked")
+    public void testInAppendAttributes() throws Exception {
+        String data = "<?xml version='1.0' encoding='UTF-8'?>"
+            + "<ns1:tagholder xmlns:ns1=\"http://tags\">"
+            + "<ns1:thetag><group>B</group><name>A</name></ns1:thetag></ns1:tagholder>";
+        JAXBElementProvider provider = new JAXBElementProvider();
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("{http://tags}tagholder", "attr:custom");
+        provider.setInAppendAttributes(map);
+        ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
+        Object o = provider.readFrom((Class)TagVO2Holder.class, TagVO2Holder.class,
+                      new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, String>(), is);
+        TagVO2Holder holder = (TagVO2Holder)o;
+        assertEquals("custom", holder.getAttribute());
+        TagVO2 tag2 = holder.getTagValue();
+        assertEquals("A", tag2.getName());
+        assertEquals("B", tag2.getGroup());
+    }
+    
+    @Test
+    @SuppressWarnings("unchecked")
+    public void testInDropElement() throws Exception {
+        String data = "<Extra><ManyTags><tags><list><group>b</group><name>a</name></list></tags>"
+            + "</ManyTags></Extra>";
+        JAXBElementProvider provider = new JAXBElementProvider();
+        provider.setInDropElements(Collections.singletonList("Extra"));
+        ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
+        Object o = provider.readFrom((Class)ManyTags.class, ManyTags.class,
+                      new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, String>(), is);
+        ManyTags holder = (ManyTags)o;
+        assertNotNull(holder);    
+        TagVO tag = holder.getTags().getTags().get(0);
+        assertEquals("a", tag.getName());
+        assertEquals("b", tag.getGroup());
+    }
+        
+    @Test
+    public void testInLocalFromLocal() throws Exception {
+        String data = "<?xml version='1.0' encoding='UTF-8'?>"
+            + "<thetag><group>B</group><name>A</name></thetag>";
+        readTagVOAfterTransform(data, "thetag");
+    }
+    
+    
+    @Test
+    public void testInLocalFromNsElement() throws Exception {
+        String data = "<?xml version='1.0' encoding='UTF-8'?>"
+            + "<t:thetag2 xmlns:t=\"http://bar\"><group>B</group><name>A</name></t:thetag2>";
+        readTagVOAfterTransform(data, "{http://bar}thetag2");
+    }
+    
+    
+    @SuppressWarnings("unchecked")
+    private void readTagVO2AfterTransform(String data, String keyValue) throws Exception {
+        JAXBElementProvider provider = new JAXBElementProvider();
+        Map<String, String> map = new HashMap<String, String>();
+        map.put(keyValue, "{http://tags}thetag");
+        provider.setInTransformElements(map);
+        ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
+        Object o = provider.readFrom((Class)TagVO2.class, TagVO2.class,
+                      new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, String>(), is);
+        TagVO2 tag2 = (TagVO2)o;
+        assertEquals("A", tag2.getName());
+        assertEquals("B", tag2.getGroup());    
+    }
+    
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testInNsElementsFromLocals() throws Exception {
+        String data = "<?xml version='1.0' encoding='UTF-8'?>"
+            + "<tagholder><thetag><group>B</group><name>A</name></thetag></tagholder>";
+        JAXBElementProvider provider = new JAXBElementProvider();
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("tagholder", "{http://tags}tagholder");
+        map.put("thetag", "{http://tags}thetag");
+        provider.setInTransformElements(map);
+        ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
+        Object o = provider.readFrom((Class)TagVO2Holder.class, TagVO2Holder.class,
+                      new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, String>(), is);
+        TagVO2Holder holder = (TagVO2Holder)o;
+        TagVO2 tag2 = holder.getTagValue();
+        assertEquals("A", tag2.getName());
+        assertEquals("B", tag2.getGroup());    
+    }
+    
+    @SuppressWarnings("unchecked")
+    private void readTagVOAfterTransform(String data, String keyValue) throws Exception {
+        JAXBElementProvider provider = new JAXBElementProvider();
+        Map<String, String> map = new HashMap<String, String>();
+        map.put(keyValue, "tagVO");
+        provider.setInTransformElements(map);
+        ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
+        Object o = provider.readFrom((Class)TagVO.class, TagVO.class,
+                      new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, String>(), is);
+        TagVO tag2 = (TagVO)o;
+        assertEquals("A", tag2.getName());
+        assertEquals("B", tag2.getGroup());    
+    }
+    
+    @Test
+    public void testOutAttributesAsElements() throws Exception {
+        JAXBElementProvider provider = new JAXBElementProvider();
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("{http://tags}thetag", "thetag");
+        map.put("{http://tags}tagholder", "tagholder");
+        provider.setOutTransformElements(map);
+        provider.setAttributesToElements(true);
+        TagVO2 tag = new TagVO2("A", "B");
+        TagVO2Holder holder = new TagVO2Holder();
+        holder.setTag(tag);
+        
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        provider.writeTo(holder, TagVO2Holder.class, TagVO2Holder.class,
+                       new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
+        String expected = "<?xml version='1.0' encoding='UTF-8'?><tagholder><attr>attribute</attr>"
+            + "<thetag><group>B</group><name>A</name></thetag></tagholder>";
+        assertEquals(expected, bos.toString());
+    }
+    
+    @Test
+    public void testOutAppendElementsDiffNs() throws Exception {
+        JAXBElementProvider provider = new JAXBElementProvider();
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("{http://tags}thetag", "{http://tagsvo2}t");
+        provider.setOutAppendElements(map);
+        TagVO2 tag = new TagVO2("A", "B");
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        provider.writeTo(tag, TagVO2.class, TagVO2.class,
+                       new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
+        String expected = "<?xml version='1.0' encoding='UTF-8'?><ps1:t xmlns:ps1=\"http://tagsvo2\">"
+            + "<ns2:thetag xmlns:ns2=\"http://tags\"><group>B</group><name>A</name></ns2:thetag></ps1:t>";
+        assertEquals(expected, bos.toString());
+    }
+    
+    @Test
+    public void testOutAppendNsElementBeforeLocal() throws Exception {
+        JAXBElementProvider provider = new JAXBElementProvider();
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("tagVO", "{http://tagsvo2}t");
+        provider.setOutAppendElements(map);
+        TagVO tag = new TagVO("A", "B");
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        provider.writeTo(tag, TagVO.class, TagVO.class,
+                       new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
+        String expected = "<?xml version='1.0' encoding='UTF-8'?><ps1:t xmlns:ps1=\"http://tagsvo2\">"
+            + "<tagVO><group>B</group><name>A</name></tagVO></ps1:t>";
+        assertEquals(expected, bos.toString());
+    }
+    
+    @Test
+    public void testOutAppendLocalBeforeLocal() throws Exception {
+        JAXBElementProvider provider = new JAXBElementProvider();
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("tagVO", "supertag");
+        provider.setOutAppendElements(map);
+        TagVO tag = new TagVO("A", "B");
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        provider.writeTo(tag, TagVO.class, TagVO.class,
+                       new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
+        String expected = "<?xml version='1.0' encoding='UTF-8'?>"
+            + "<supertag><tagVO><group>B</group><name>A</name></tagVO></supertag>";
+        assertEquals(expected, bos.toString());
+    }
+    
+    @Test
+    public void testOutAppendElementsSameNs() throws Exception {
+        JAXBElementProvider provider = new JAXBElementProvider();
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("{http://tags}thetag", "{http://tags}t");
+        provider.setOutAppendElements(map);
+        TagVO2 tag = new TagVO2("A", "B");
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        provider.writeTo(tag, TagVO2.class, TagVO2.class,
+                       new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
+        String expected = "<?xml version='1.0' encoding='UTF-8'?>"
+            + "<ns2:t xmlns:ns2=\"http://tags\"><ns2:thetag><group>B</group><name>A</name></ns2:thetag>"
+            + "</ns2:t>";
+        assertEquals(expected, bos.toString());
+    }
+    
+        
+    @Test
+    public void testOutElementsMapLocalNsToLocalNs() throws Exception {
+        JAXBElementProvider provider = new JAXBElementProvider();
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("{http://tags}thetag", "{http://tagsvo2}t");
+        provider.setOutTransformElements(map);
+        TagVO2 tag = new TagVO2("A", "B");
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        provider.writeTo(tag, TagVO2.class, TagVO2.class,
+                       new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
+        String expected = "<?xml version='1.0' encoding='UTF-8'?>"
+            + "<ns2:t xmlns:ns2=\"http://tagsvo2\"><group>B</group><name>A</name></ns2:t>";
+        assertEquals(expected, bos.toString());
+        
+    }
+    
+    @Test
+    public void testOutElementsMapLocalNsToLocal() throws Exception {
+        JAXBElementProvider provider = new JAXBElementProvider();
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("{http://tags}thetag", "t");
+        provider.setOutTransformElements(map);
+        TagVO2 tag = new TagVO2("A", "B");
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        provider.writeTo(tag, TagVO2.class, TagVO2.class,
+                       new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
+        String expected = "<?xml version='1.0' encoding='UTF-8'?>"
+            + "<t><group>B</group><name>A</name></t>";
+        assertEquals(expected, bos.toString());
+    }
+    
+    @Test
+    public void testOutElementsMapLocalToLocalNs() throws Exception {
+        JAXBElementProvider provider = new JAXBElementProvider();
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("tagVO", "{http://tags}thetag");
+        provider.setOutTransformElements(map);
+        TagVO tag = new TagVO("A", "B");
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        provider.writeTo(tag, TagVO.class, TagVO.class,
+                       new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
+        String expected = "<?xml version='1.0' encoding='UTF-8'?>"
+            + "<ps1:thetag xmlns:ps1=\"http://tags\"><group>B</group><name>A</name></ps1:thetag>";
+        assertEquals(expected, bos.toString());
+    }
+    
+    @Test
+    public void testOutElementsMapLocalToLocal() throws Exception {
+        JAXBElementProvider provider = new JAXBElementProvider();
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("tagVO", "thetag");
+        map.put("group", "group2");
+        provider.setOutTransformElements(map);
+        TagVO tag = new TagVO("A", "B");
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        provider.writeTo(tag, TagVO.class, TagVO.class,
+                       new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
+        String expected = "<?xml version='1.0' encoding='UTF-8'?>"
+            + "<thetag><group2>B</group2><name>A</name></thetag>";
+        assertEquals(expected, bos.toString());
+    }
+    
+    @Test
+    public void testDropElements() throws Exception {
+        JAXBElementProvider provider = new JAXBElementProvider();
+        List<String> list = new ArrayList<String>();
+        list.add("tagVO");
+        list.add("ManyTags");
+        list.add("list");
+        provider.setOutDropElements(list);
+        ManyTags many = new ManyTags();
+        Tags tags = new Tags();
+        tags.addTag(new TagVO("A", "B"));
+        tags.addTag(new TagVO("C", "D"));
+        many.setTags(tags);
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        provider.writeTo(many, ManyTags.class, ManyTags.class,
+                       new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
+        String expected = "<?xml version='1.0' encoding='UTF-8'?>"
+            + "<tags><group>B</group><name>A</name><group>D</group><name>C</name></tags>";
+        assertEquals(expected, bos.toString());
+    }
+    
+    @Test
+    public void testDropQualifiedElements() throws Exception {
+        JAXBElementProvider provider = new JAXBElementProvider();
+        List<String> list = new ArrayList<String>();
+        list.add("{http://tags}thetag");
+        list.add("name");
+        provider.setOutDropElements(list);
+        TagVO2 tag = new TagVO2("A", "B");
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        provider.writeTo(tag, TagVO2.class, TagVO2.class,
+                       new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
+        String expected = "<?xml version='1.0' encoding='UTF-8'?>"
+            + "<group>B</group>";
+        assertEquals(expected, bos.toString());
+
+    }
+    
+    @Test
     public void testReadUnqualifiedCollection() throws Exception {
         String data = "<Books><Book><id>123</id><name>CXF in Action</name>"
             + "</Book><Book><id>124</id><name>CXF Rocks</name></Book></Books>";
@@ -620,4 +948,25 @@
         }
         
     }
+    
+    @XmlRootElement(name = "tagholder", namespace = "http://tags")
+    public static class TagVO2Holder {
+        @XmlElement(name = "thetag", namespace = "http://tags")
+        private TagVO2 t;
+        @XmlAttribute
+        private String attr = "attribute"; 
+        
+        public void setTag(TagVO2 tag) {
+            this.t = tag;
+        }
+
+        public TagVO2 getTagValue() {
+            return t;
+        }
+
+        public String getAttribute() {
+            return attr;
+        }
+        
+    }
 }

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java?rev=833911&r1=833910&r2=833911&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java (original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java Sun Nov  8 18:46:07 2009
@@ -42,6 +42,7 @@
 import javax.xml.transform.stream.StreamSource;
 
 import org.apache.cxf.jaxrs.impl.MetadataMap;
+import org.apache.cxf.jaxrs.provider.JAXBElementProviderTest.TagVO2Holder;
 import org.apache.cxf.jaxrs.resources.Book;
 import org.apache.cxf.jaxrs.resources.CollectionsResource;
 import org.apache.cxf.jaxrs.resources.ManyTags;
@@ -53,7 +54,7 @@
 import org.junit.Assert;
 import org.junit.Ignore;
 import org.junit.Test;
-
+//CHECKSTYLE:OFF
 public class JSONProviderTest extends Assert {
 
     @Test
@@ -109,6 +110,22 @@
         assertEquals("b", tag.getGroup());
     }
     
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testReadFromQualifiedTag() throws Exception {
+        JSONProvider p = new JSONProvider();
+        Map<String, String> namespaceMap = new HashMap<String, String>();
+        namespaceMap.put("http://tags", "ns1");
+        p.setNamespaceMap(namespaceMap);
+        byte[] bytes = "{\"ns1.thetag\":{\"group\":\"b\",\"name\":\"a\"}}"
+            .getBytes();
+        Object tagsObject = p.readFrom((Class)TagVO2.class, null, null, 
+                                          null, null, new ByteArrayInputStream(bytes));
+        TagVO2 tag = (TagVO2)tagsObject;
+        assertEquals("a", tag.getName());
+        assertEquals("b", tag.getGroup());
+    }
+    
     @Test
     public void testReadFromUnwrappedTagWrapperName() throws Exception {
         JSONProvider p = new JSONProvider();
@@ -516,8 +533,346 @@
             "{\"ManyTags\":{\"tags\":{\"list\":[{\"group\":\"b\",\"name\":\"a\"}]}}}",
             s);
     }
+
+    @Test
+    @SuppressWarnings("unchecked")
+    public void testInDropElement() throws Exception {
+        String data = "{\"Extra\":{\"ManyTags\":{\"tags\":{\"list\":[{\"group\":\"b\",\"name\":\"a\"}]}}}}";
+        JSONProvider provider = new JSONProvider();
+        provider.setInDropElements(Collections.singletonList("Extra"));
+        ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
+        Object o = provider.readFrom((Class)ManyTags.class, ManyTags.class,
+                      new Annotation[0], MediaType.APPLICATION_JSON_TYPE, 
+                      new MetadataMap<String, String>(), is);
+        ManyTags holder = (ManyTags)o;
+        assertNotNull(holder);    
+        TagVO tag = holder.getTags().getTags().get(0);
+        assertEquals("a", tag.getName());
+        assertEquals("b", tag.getGroup());
+    }
+    
+    @Test
+    public void testInAppendElementNoNs() throws Exception {
+        String data = "{\"tags\":{\"list\":[{\"group\":\"b\",\"name\":\"a\"}]}}";
+        readAppendElementsNoNs(data, Collections.singletonMap("tags", "ManyTags"));
+    }
+    
+    @Test
+    public void testInAppendElementNoNs2() throws Exception {
+        String data = "{\"ManyTags\":{\"list\":[{\"group\":\"b\",\"name\":\"a\"}]}}";
+        readAppendElementsNoNs(data, Collections.singletonMap("list", "tags"));
+    }
+    
+    @SuppressWarnings("unchecked")
+    private void readAppendElementsNoNs(String data, Map<String, String> appendMap) throws Exception {
+        JSONProvider provider = new JSONProvider();
+        provider.setInAppendElements(appendMap);
+        ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
+        Object o = provider.readFrom((Class)ManyTags.class, ManyTags.class,
+                      new Annotation[0], MediaType.APPLICATION_JSON_TYPE, 
+                      new MetadataMap<String, String>(), is);
+        ManyTags holder = (ManyTags)o;
+        assertNotNull(holder);    
+        TagVO tag = holder.getTags().getTags().get(0);
+        assertEquals("a", tag.getName());
+        assertEquals("b", tag.getGroup());
+    }
+    
+    @Test
+    public void testInNsElementFromLocal() throws Exception {
+        String data = "{thetag:{\"group\":\"B\",\"name\":\"A\"}}";
+        readTagVO2AfterTransform(data, "thetag");
+    }
+    
+    @Test
+    public void testInNsElementFromNsElement() throws Exception {
+        String data = "{t.thetag2:{\"group\":\"B\",\"name\":\"A\"}}";
+        readTagVO2AfterTransform(data, "{http://bar}thetag2");
+    }
     
+    @Test
+    public void testInLocalFromLocal() throws Exception {
+        String data = "{thetag:{\"group\":\"B\",\"name\":\"A\"}}";
+        readTagVOAfterTransform(data, "thetag");
+    }
+    
+    @Test
+    public void testInLocalFromNsElement() throws Exception {
+        String data = "{t.thetag2:{\"group\":\"B\",\"name\":\"A\"}}";
+        readTagVOAfterTransform(data, "{http://bar}thetag2");
+    }
+    
+    @Test
+    @SuppressWarnings("unchecked")
+    public void testInAppendAttributes() throws Exception {
+        String data = "{t.tagholder:{t.thetag:{\"group\":\"B\",\"name\":\"A\"}}}";
+        JSONProvider provider = new JSONProvider();
+        Map<String, String> nsmap = new HashMap<String, String>();
+        nsmap.put("http://tags", "t");
+        provider.setNamespaceMap(nsmap);
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("{http://tags}tagholder", "attr:custom");
+        provider.setInAppendAttributes(map);
+        ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
+        Object o = provider.readFrom((Class)TagVO2Holder.class, TagVO2Holder.class,
+                      new Annotation[0], MediaType.APPLICATION_JSON_TYPE, 
+                      new MetadataMap<String, String>(), is);
+        TagVO2Holder holder = (TagVO2Holder)o;
+        assertEquals("custom", holder.getAttribute());
+        TagVO2 tag2 = holder.getTagValue();
+        assertEquals("A", tag2.getName());
+        assertEquals("B", tag2.getGroup());
+    }
+    
+    
+    @SuppressWarnings("unchecked")
+    private void readTagVO2AfterTransform(String data, String keyValue) throws Exception {
+        JSONProvider provider = new JSONProvider();
+        Map<String, String> map = new HashMap<String, String>();
+        map.put(keyValue, "{http://tags}thetag");
+        Map<String, String> nsmap = new HashMap<String, String>();
+        nsmap.put("http://bar", "t");
+        provider.setNamespaceMap(nsmap);
+        provider.setInTransformElements(map);
+        ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
+        Object o = provider.readFrom((Class)TagVO2.class, TagVO2.class,
+                      new Annotation[0], MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, String>(),
+                      is);
+        TagVO2 tag2 = (TagVO2)o;
+        assertEquals("A", tag2.getName());
+        assertEquals("B", tag2.getGroup());    
+    }
+    
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testInNsElementsFromLocals() throws Exception {
+        String data = "{tagholder:{thetag:{\"group\":\"B\",\"name\":\"A\"}}}";
+        JSONProvider provider = new JSONProvider();
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("tagholder", "{http://tags}tagholder");
+        map.put("thetag", "{http://tags}thetag");
+        provider.setInTransformElements(map);
+        ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
+        Object o = provider.readFrom((Class)TagVO2Holder.class, TagVO2Holder.class,
+                      new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, String>(), is);
+        TagVO2Holder holder = (TagVO2Holder)o;
+        TagVO2 tag2 = holder.getTagValue();
+        assertEquals("A", tag2.getName());
+        assertEquals("B", tag2.getGroup());    
+    }
+    
+    @Test
+    public void testOutAttributesAsElements() throws Exception {
+        JSONProvider provider = new JSONProvider();
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("{http://tags}thetag", "thetag");
+        map.put("{http://tags}tagholder", "tagholder");
+        provider.setOutTransformElements(map);
+        provider.setAttributesToElements(true);
+        TagVO2 tag = new TagVO2("A", "B");
+        TagVO2Holder holder = new TagVO2Holder();
+        holder.setTag(tag);
         
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        provider.writeTo(holder, TagVO2Holder.class, TagVO2Holder.class,
+                       new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
+        String expected = 
+            "{\"tagholder\":{\"attr\":\"attribute\",\"thetag\":{\"group\":\"B\",\"name\":\"A\"}}}";
+        assertEquals(expected, bos.toString());
+    }
+    
+    @SuppressWarnings("unchecked")
+    private void readTagVOAfterTransform(String data, String keyValue) throws Exception {
+        JSONProvider provider = new JSONProvider();
+        Map<String, String> map = new HashMap<String, String>();
+        map.put(keyValue, "tagVO");
+        provider.setInTransformElements(map);
+        Map<String, String> nsmap = new HashMap<String, String>();
+        nsmap.put("http://bar", "t");
+        provider.setNamespaceMap(nsmap);
+        ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
+        Object o = provider.readFrom((Class)TagVO.class, TagVO.class,
+                      new Annotation[0], MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, String>(),
+                      is);
+        TagVO tag2 = (TagVO)o;
+        assertEquals("A", tag2.getName());
+        assertEquals("B", tag2.getGroup());    
+    }
+    
+    
+    @Test
+    @Ignore
+    // name:A is lost
+    public void testDropElementsIgnored() throws Exception {
+        JSONProvider provider = new JSONProvider();
+        List<String> list = new ArrayList<String>();
+        list.add("ManyTags");
+        list.add("list");
+        list.add("tags");
+        provider.setOutDropElements(list);
+        ManyTags many = new ManyTags();
+        Tags tags = new Tags();
+        tags.addTag(new TagVO("A", "B"));
+        tags.addTag(new TagVO("C", "D"));
+        many.setTags(tags);
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        provider.writeTo(many, ManyTags.class, ManyTags.class,
+                       new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
+        System.out.println(bos.toString());
+    }
+ 
+    @Test
+    public void testDropElements() throws Exception {
+        JSONProvider provider = new JSONProvider();
+        List<String> list = new ArrayList<String>();
+        list.add("ManyTags");
+        list.add("tags");
+        provider.setOutDropElements(list);
+        ManyTags many = new ManyTags();
+        Tags tags = new Tags();
+        tags.addTag(new TagVO("A", "B"));
+        tags.addTag(new TagVO("C", "D"));
+        many.setTags(tags);
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        provider.writeTo(many, ManyTags.class, ManyTags.class,
+                       new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
+        String expected = "{\"list\":[{\"group\":\"B\",\"name\":\"A\"},"
+            + "{\"group\":\"D\",\"name\":\"C\"}]}";
+        assertEquals(expected, bos.toString());
+    }
+    
+    
+    @Test
+    public void testDropQualifiedElements() throws Exception {
+        JSONProvider provider = new JSONProvider();
+        List<String> list = new ArrayList<String>();
+        list.add("{http://tags}thetag");
+        list.add("name");
+        provider.setOutDropElements(list);
+        TagVO2 tag = new TagVO2("A", "B");
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        provider.writeTo(tag, TagVO2.class, TagVO2.class,
+                       new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
+        String expected = "{\"group\":\"B\"}";
+        assertEquals(expected, bos.toString());
+    }
+    
+    @Test
+    public void testOutAppendNsElementBeforeLocal() throws Exception {
+        JSONProvider provider = new JSONProvider();
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("tagVO", "{http://tagsvo2}t");
+        provider.setOutAppendElements(map);
+        TagVO tag = new TagVO("A", "B");
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        provider.writeTo(tag, TagVO.class, TagVO.class,
+                       new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
+        String expected = "{\"ps1.t\":{\"tagVO\":{\"group\":\"B\",\"name\":\"A\"}}}";
+        assertEquals(expected, bos.toString());
+    }
+    
+    @Test
+    public void testOutAppendLocalBeforeLocal() throws Exception {
+        JSONProvider provider = new JSONProvider();
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("tagVO", "supertag");
+        provider.setOutAppendElements(map);
+        TagVO tag = new TagVO("A", "B");
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        provider.writeTo(tag, TagVO.class, TagVO.class,
+                       new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
+        String expected = "{\"supertag\":{\"tagVO\":{\"group\":\"B\",\"name\":\"A\"}}}";
+        assertEquals(expected, bos.toString());
+    }
+    
+    @Test
+    public void testOutAppendElementsSameNs() throws Exception {
+        JSONProvider provider = new JSONProvider();
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("{http://tags}thetag", "{http://tags}t");
+        provider.setOutAppendElements(map);
+        TagVO2 tag = new TagVO2("A", "B");
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        provider.writeTo(tag, TagVO2.class, TagVO2.class,
+                       new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
+        String expected = "{\"ns1.t\":{\"ns1.thetag\":{\"group\":\"B\",\"name\":\"A\"}}}";
+        assertEquals(expected, bos.toString());
+    }
+    
+    @Test
+    public void testOutAppendElementsDiffNs() throws Exception {
+        JSONProvider provider = new JSONProvider();
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("{http://tags}thetag", "{http://tagsvo2}t");
+        provider.setOutAppendElements(map);
+        TagVO2 tag = new TagVO2("A", "B");
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        provider.writeTo(tag, TagVO2.class, TagVO2.class,
+                       new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
+        String expected = "{\"ps1.t\":{\"ns1.thetag\":{\"group\":\"B\",\"name\":\"A\"}}}";
+        assertEquals(expected, bos.toString());
+    }
+    
+    @Test
+    public void testOutElementsMapLocalNsToLocalNs() throws Exception {
+        JSONProvider provider = new JSONProvider();
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("{http://tags}thetag", "{http://tagsvo2}t");
+        provider.setOutTransformElements(map);
+        TagVO2 tag = new TagVO2("A", "B");
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        provider.writeTo(tag, TagVO2.class, TagVO2.class,
+                       new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
+        String expected = "{\"ns2.t\":{\"group\":\"B\",\"name\":\"A\"}}";
+        assertEquals(expected, bos.toString());
+    }
+    
+
+    @Test
+    public void testOutElementsMapLocalNsToLocal() throws Exception {
+        JSONProvider provider = new JSONProvider();
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("{http://tags}thetag", "t");
+        provider.setOutTransformElements(map);
+        TagVO2 tag = new TagVO2("A", "B");
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        provider.writeTo(tag, TagVO2.class, TagVO2.class,
+                       new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
+        String expected = "{\"t\":{\"group\":\"B\",\"name\":\"A\"}}";
+        assertEquals(expected, bos.toString());
+    }
+    
+    @Test
+    public void testOutElementsMapLocalToLocalNs() throws Exception {
+        JSONProvider provider = new JSONProvider();
+        Map<String, String> namespaceMap = new HashMap<String, String>();
+        namespaceMap.put("http://tags", "ns1");
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("tagVO", "{http://tags}thetag");
+        provider.setOutTransformElements(map);
+        TagVO tag = new TagVO("A", "B");
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        provider.writeTo(tag, TagVO.class, TagVO.class,
+                       new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
+        String expected = "{\"ps1.thetag\":{\"group\":\"B\",\"name\":\"A\"}}";
+        assertEquals(expected, bos.toString());
+    }
+    
+    @Test
+    public void testOutElementsMapLocalToLocal() throws Exception {
+        JSONProvider provider = new JSONProvider();
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("tagVO", "supertag");
+        map.put("group", "group2");
+        provider.setOutTransformElements(map);
+        TagVO tag = new TagVO("A", "B");
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        provider.writeTo(tag, TagVO.class, TagVO.class,
+                       new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
+        String expected = "{\"supertag\":{\"group2\":\"B\",\"name\":\"A\"}}";
+        assertEquals(expected, bos.toString());
+    }
+    
     private TagVO createTag(String name, String group) {
         return new TagVO(name, group);
     }
@@ -577,6 +932,5 @@
         }
     }
 
-    
-
 }
+//CHECKSTYLE:ON
\ No newline at end of file

Modified: cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=833911&r1=833910&r2=833911&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original)
+++ cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Sun Nov  8 18:46:07 2009
@@ -38,6 +38,7 @@
 import javax.ws.rs.DELETE;
 import javax.ws.rs.DefaultValue;
 import javax.ws.rs.GET;
+import javax.ws.rs.HEAD;
 import javax.ws.rs.HeaderParam;
 import javax.ws.rs.MatrixParam;
 import javax.ws.rs.POST;
@@ -242,6 +243,18 @@
         return doGetBook(id);
     }
     
+    @GET
+    @Path("/getheadbook/")
+    public Book getBookGetHead() throws Exception {
+        return doGetBook("123");
+    }
+    
+    @HEAD
+    @Path("/getheadbook/")
+    public Response getBookGetHead2() throws Exception {
+        return Response.ok().header("HEAD_HEADER", "HEAD_HEADER_VALUE").build();
+    }
+    
     
     @GET
     @Path("/bookquery")

Modified: cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=833911&r1=833910&r2=833911&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java (original)
+++ cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java Sun Nov  8 18:46:07 2009
@@ -55,7 +55,7 @@
     @BeforeClass
     public static void startServers() throws Exception {
         assertTrue("server did not launch correctly",
-                   launchServer(BookServer.class));
+                   launchServer(BookServer.class, true));
     }
     
     
@@ -386,28 +386,44 @@
     }
     
     @Test
-    public void testGetBook123WebClient() throws Exception {
+    public void testGetHeadBook123WebClient() throws Exception {
+        String address = "http://localhost:9080/bookstore/getheadbook/";
+        WebClient client = WebClient.create(address);
+        Response r = client.head();
+        assertEquals("HEAD_HEADER_VALUE", r.getMetadata().getFirst("HEAD_HEADER"));
+    }
+    
+    @Test
+    public void testGetHeadBook123WebClient2() throws Exception {
+        String address = "http://localhost:9080/bookstore/getheadbook/";
+        WebClient client = WebClient.create(address);
+        Book b = client.get(Book.class);
+        assertEquals(b.getId(), 123L);
+    }
+    
+    @Test
+    public void testGetBook123WithProxy() throws Exception {
         BookStore bs = JAXRSClientFactory.create("http://localhost:9080", BookStore.class);
         Book b = bs.getBook("123");
         assertEquals(b.getId(), 123);
     }
     
     @Test
-    public void testDeleteWithWebClient() throws Exception {
+    public void testDeleteWithProxy() throws Exception {
         BookStore bs = JAXRSClientFactory.create("http://localhost:9080", BookStore.class);
         Response r = bs.deleteBook("123");
         assertEquals(200, r.getStatus());
     }
     
     @Test
-    public void testCreatePut() throws Exception {
+    public void testCreatePutWithProxy() throws Exception {
         BookStore bs = JAXRSClientFactory.create("http://localhost:9080", BookStore.class);
         Response r = bs.createBook(777L);
         assertEquals(200, r.getStatus());
     }
     
     @Test
-    public void testUpdateWithWebClient() throws Exception {
+    public void testUpdateWithProxy() throws Exception {
         BookStore bs = JAXRSClientFactory.create("http://localhost:9080", BookStore.class);
         Book book = new Book();
         book.setId(888);
@@ -427,6 +443,7 @@
                                "application/xml", 200);
     }
     
+    
     @Test
     public void testGetBook123() throws Exception {
         getAndCompareAsStrings("http://localhost:9080/bookstore/books/123",
@@ -552,7 +569,7 @@
         getAndCompareAsStrings(
             "http://localhost:9080/bookstore/booksubresourceobject/123/chaptersobject/sub/1",
             "resources/expected_get_chapter1.txt", "application/xml",
-            "application/xml;charset=iso-8859-1", 200);
+            "application/xml;charset=ISO-8859-1", 200);
     }
     
     @Test
@@ -560,7 +577,7 @@
         
         getAndCompareAsStrings("http://localhost:9080/bookstore/booksubresource/123/chapters/1",
                                "resources/expected_get_chapter1.txt",
-                               "application/xml", "application/xml;charset=iso-8859-1", 200);
+                               "application/xml", "application/xml;charset=ISO-8859-1", 200);
     }
     
     @Test
@@ -579,7 +596,7 @@
                                "application/xml", 200);
         getAndCompareAsStrings("http://localhost:9080/bookstore/booksubresource/123/chapters/sub/1/recurse2",
                                "resources/expected_get_chapter1.txt",
-                               "application/xml", "application/xml;charset=iso-8859-1", 200);
+                               "application/xml", "application/xml;charset=ISO-8859-1", 200);
     }
     
     @Test
@@ -588,7 +605,7 @@
         getAndCompareAsStrings(
             "http://localhost:9080/bookstore/booksubresource/123/chapters/sub/1/recurse2/ids",
             "resources/expected_get_chapter1.txt",
-            "application/xml", "application/xml;charset=iso-8859-1", 200);
+            "application/xml", "application/xml;charset=ISO-8859-1", 200);
     }
     
     @Test



Mime
View raw message