cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1210128 - 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 Sun, 04 Dec 2011 16:01:01 GMT
Author: sergeyb
Date: Sun Dec  4 16:01:00 2011
New Revision: 1210128

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

........
  r1210127 | sergeyb | 2011-12-04 15:57:04 +0000 (Sun, 04 Dec 2011) | 1 line
  
  [CXF-3952] Adding SchemaLocation annotation
........

Added:
    cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/SchemaLocation.java
      - copied unchanged from r1210127, cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/SchemaLocation.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 (original)
+++ svn:mergeinfo Sun Dec  4 16:01:00 2011
@@ -1 +1 @@
-/cxf/trunk:1209588,1209728,1210114
+/cxf/trunk:1209588,1209728,1210114,1210127

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=1210128&r1=1210127&r2=1210128&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
Sun Dec  4 16:01:00 2011
@@ -57,6 +57,7 @@ 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.SchemaLocation;
 import org.apache.cxf.jaxrs.ext.xml.XMLInstruction;
 import org.apache.cxf.jaxrs.ext.xml.XMLSource;
 import org.apache.cxf.jaxrs.utils.AnnotationUtils;
@@ -74,13 +75,21 @@ 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 String NS_MAPPER_PROPERTY = "com.sun.xml.bind.namespacePrefixMapper";
+    private static final String NS_MAPPER_PROPERTY_INT = "com.sun.xml.internal.bind.namespacePrefixMapper";
+    private static final String XML_PI_PROPERTY = "com.sun.xml.bind.xmlHeaders";
+    private static final String XML_PI_PROPERTY_INT = "com.sun.xml.internal.bind.xmlHeaders";
     
     private static final List<String> MARSHALLER_PROPERTIES =
         Arrays.asList(new String[] {Marshaller.JAXB_ENCODING,
                                     Marshaller.JAXB_FORMATTED_OUTPUT,
                                     Marshaller.JAXB_FRAGMENT,
                                     Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION,
-                                    Marshaller.JAXB_SCHEMA_LOCATION});
+                                    Marshaller.JAXB_SCHEMA_LOCATION,
+                                    NS_MAPPER_PROPERTY,
+                                    NS_MAPPER_PROPERTY_INT,
+                                    XML_PI_PROPERTY,
+                                    XML_PI_PROPERTY_INT});
     
     private Map<String, Object> mProperties = Collections.emptyMap();
     private Map<String, String> nsPrefixes = Collections.emptyMap();
@@ -348,7 +357,7 @@ public class JAXBElementProvider extends
     
     protected static void setNamespaceMapper(Marshaller ms, Map<String, String> map)
throws Exception {
         NamespaceMapper nsMapper = new NamespaceMapper(map);
-        setMarshallerProp(ms, nsMapper, "namespacePrefixMapper");
+        setMarshallerProp(ms, nsMapper, NS_MAPPER_PROPERTY, NS_MAPPER_PROPERTY_INT);
     }
     
     protected void marshal(Object obj, Class<?> cls, Type genericType, 
@@ -370,6 +379,7 @@ public class JAXBElementProvider extends
         }
         addAttachmentMarshaller(ms);
         addProcessingInstructions(ms, anns);
+        addSchemaLocation(ms, anns);
         marshal(obj, cls, genericType, enc, os, mt, ms);
     }
     
@@ -384,15 +394,30 @@ public class JAXBElementProvider extends
                     getContext().getUriInfo().getBaseUriBuilder().path(relRef).build().toString();
                 value = value.substring(0, ind + 6) + absRef + "'?>";
             }
-            setMarshallerProp(ms, value, "xmlHeaders");
+            setMarshallerProp(ms, value, XML_PI_PROPERTY, XML_PI_PROPERTY_INT);
         }
     }
     
-    private static void setMarshallerProp(Marshaller ms, Object value, String name) throws
Exception {
+    private void addSchemaLocation(Marshaller ms, Annotation[] anns) throws Exception {
+        SchemaLocation sl = AnnotationUtils.getAnnotation(anns, SchemaLocation.class);
+        if (sl != null) {
+            String value = sl.value();
+            if (getContext() != null) {
+                value = 
+                    getContext().getUriInfo().getBaseUriBuilder().path(value).build().toString();
+            }
+            String propName = !sl.noNamespace() 
+                ? Marshaller.JAXB_SCHEMA_LOCATION : Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION;
+            ms.setProperty(propName, value);
+        }
+    }
+    
+    private static void setMarshallerProp(Marshaller ms, Object value, 
+                                          String name1, String name2) throws Exception {
         try {
-            ms.setProperty("com.sun.xml.bind." + name, value);
+            ms.setProperty(name1, value);
         } catch (PropertyException ex) {
-            ms.setProperty("com.sun.xml.internal.bind." + name, value);
+            ms.setProperty(name2, value);
         }
         
     }

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=1210128&r1=1210127&r2=1210128&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
Sun Dec  4 16:01:00 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.SchemaLocation;
 import org.apache.cxf.jaxrs.ext.xml.XMLInstruction;
 import org.apache.cxf.phase.PhaseInterceptorChain;
 
@@ -210,6 +211,7 @@ public class BookStore {
     @Path("name-in-query")
     @Produces("application/xml")
     @XMLInstruction("<!DOCTYPE Something SYSTEM 'my.dtd'><?xmlstylesheet href='common.css'?>")
+    @SchemaLocation("book.xsd")
     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=1210128&r1=1210127&r2=1210128&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
Sun Dec  4 16:01:00 2011
@@ -141,8 +141,11 @@ public class JAXRSClientServerBookTest e
         String name = "Many        spaces";
         wc.query("name", name);
         String content = wc.get(String.class);
+        System.out.println(content);
         assertTrue(content.contains("<!DOCTYPE Something SYSTEM 'my.dtd'>"));
         assertTrue(content.contains("<?xmlstylesheet href='" + base + "/common.css'?>"));
+        assertTrue(content.contains("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""));
+        assertTrue(content.contains("xsi:schemaLocation=\"" + base + "/book.xsd\""));
     }
     
     @Test



Mime
View raw message