cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1209591 - in /cxf/branches/2.4.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Fri, 02 Dec 2011 17:14:55 GMT
Author: sergeyb
Date: Fri Dec  2 17:14:55 2011
New Revision: 1209591

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

........
  r1209588 | sergeyb | 2011-12-02 17:08:58 +0000 (Fri, 02 Dec 2011) | 1 line
  
  [CXF-3950] Adding XMLInstruction annotation - no substitution is supported at the moment
........

Added:
    cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/XMLInstruction.java
      - copied unchanged from r1209588, cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/XMLInstruction.java
Modified:
    cxf/branches/2.4.x-fixes/   (props changed)
    cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
    cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
    cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java

Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
    svn:mergeinfo = /cxf/trunk:1209588

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

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java?rev=1209591&r1=1209590&r2=1209591&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
Fri Dec  2 17:14:55 2011
@@ -56,7 +56,9 @@ import javax.xml.transform.Source;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.jaxb.NamespaceMapper;
 import org.apache.cxf.jaxrs.ext.MessageContext;
+import org.apache.cxf.jaxrs.ext.xml.XMLInstruction;
 import org.apache.cxf.jaxrs.ext.xml.XMLSource;
+import org.apache.cxf.jaxrs.utils.AnnotationUtils;
 import org.apache.cxf.jaxrs.utils.HttpUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.jaxrs.utils.JAXBUtils;
@@ -71,6 +73,7 @@ import org.apache.cxf.staxutils.transfor
 @Provider
 public class JAXBElementProvider extends AbstractJAXBProvider  {
     private static final String XML_PI_START = "<?xml version=\"1.0\" encoding=\"";
+    
     private static final List<String> MARSHALLER_PROPERTIES =
         Arrays.asList(new String[] {Marshaller.JAXB_ENCODING,
                                     Marshaller.JAXB_FORMATTED_OUTPUT,
@@ -234,7 +237,7 @@ public class JAXBElementProvider extends
                 Object actualObject = checkAdapter(obj, cls, anns, true);
                 Class<?> actualClass = obj != actualObject || cls.isInterface() 
                     ? actualObject.getClass() : cls;
-                marshal(actualObject, actualClass, genericType, encoding, os, m);
+                marshal(actualObject, actualClass, genericType, encoding, os, m, anns);
             }
         } catch (JAXBException e) {
             handleJAXBException(e);
@@ -344,6 +347,12 @@ public class JAXBElementProvider extends
     
     protected void marshal(Object obj, Class<?> cls, Type genericType, 
                            String enc, OutputStream os, MediaType mt) throws Exception {
+        marshal(obj, cls, genericType, enc, os, mt, new Annotation[]{});
+    }
+    
+    protected void marshal(Object obj, Class<?> cls, Type genericType, 
+                           String enc, OutputStream os, MediaType mt,
+                           Annotation[] anns) throws Exception {
         obj = convertToJaxbElementIfNeeded(obj, cls, genericType);
         if (obj instanceof JAXBElement && cls != JAXBElement.class) {
             cls = JAXBElement.class;
@@ -354,9 +363,24 @@ public class JAXBElementProvider extends
             setNamespaceMapper(ms, nsPrefixes);
         }
         addAttachmentMarshaller(ms);
+        addProcessingInstructions(ms, anns);
         marshal(obj, cls, genericType, enc, os, mt, ms);
     }
     
+    private void addProcessingInstructions(Marshaller ms, Annotation[] anns) throws Exception
{
+        XMLInstruction pi = AnnotationUtils.getAnnotation(anns, XMLInstruction.class);
+        if (pi != null) {
+            String value = pi.value();
+            // Should we even consider adding a base URI here ?
+            // Relative references may be resolved OK, to be verified
+            try {
+                ms.setProperty("com.sun.xml.bind.xmlHeaders", value);
+            } catch (PropertyException ex) {
+                ms.setProperty("com.sun.xml.internal.bind.xmlHeaders", value);
+            }
+        }
+    }
+    
     protected void addAttachmentMarshaller(Marshaller ms) {
         Collection<Attachment> attachments = getAttachments(true);
         if (attachments != null) {

Modified: cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=1209591&r1=1209590&r2=1209591&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
(original)
+++ cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
Fri Dec  2 17:14:55 2011
@@ -78,6 +78,7 @@ import org.apache.cxf.helpers.XMLUtils;
 import org.apache.cxf.jaxrs.ext.Oneway;
 import org.apache.cxf.jaxrs.ext.search.SearchCondition;
 import org.apache.cxf.jaxrs.ext.search.SearchContext;
+import org.apache.cxf.jaxrs.ext.xml.XMLInstruction;
 import org.apache.cxf.phase.PhaseInterceptorChain;
 
 @Path("/bookstore")
@@ -208,6 +209,7 @@ public class BookStore {
     @GET
     @Path("name-in-query")
     @Produces("application/xml")
+    @XMLInstruction("<!DOCTYPE Something SYSTEM 'my.dtd'><?xmlstylesheet href='common.css'?>")
     public Book getBookFromQuery(@QueryParam("name") String name) {
         return new Book(name, 321L);
     }

Modified: cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1209591&r1=1209590&r2=1209591&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Fri Dec  2 17:14:55 2011
@@ -134,6 +134,19 @@ public class JAXRSClientServerBookTest e
     }
     
     @Test
+    public void testProcessingInstruction() throws Exception {
+        
+        String endpointAddress =
+            "http://localhost:" + PORT + "/bookstore/name-in-query"; 
+        WebClient wc = WebClient.create(endpointAddress);
+        String name = "Many        spaces";
+        wc.query("name", name);
+        String content = wc.get(String.class);
+        assertTrue(content.contains("<!DOCTYPE Something SYSTEM 'my.dtd'>"));
+        assertTrue(content.contains("<?xmlstylesheet href='common.css'?>"));
+    }
+    
+    @Test
     public void testGetBookWithColonMarks() throws Exception {
         
         // URLEncoder will turn ":" into "%3A" but ':' is actually



Mime
View raw message