cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1211044 - in /cxf/branches/2.4.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ rt/transports...
Date Tue, 06 Dec 2011 17:33:17 GMT
Author: sergeyb
Date: Tue Dec  6 17:33:16 2011
New Revision: 1211044

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

........
  r1211043 | sergeyb | 2011-12-06 17:31:03 +0000 (Tue, 06 Dec 2011) | 1 line
  
  [CXF-3952] Renaming SchemaLocation to XSISchemaLocation, adding http.base.path property
........

Added:
    cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/XSISchemaLocation.java
      - copied unchanged from r1211043, cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/XSISchemaLocation.java
Removed:
    cxf/branches/2.4.x-fixes/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/ext/MessageContextImpl.java
    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/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
    cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.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/JAXRSClientServerResourceCreatedSpringBookTest.java

Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Dec  6 17:33:16 2011
@@ -1 +1 @@
-/cxf/trunk:1210875
+/cxf/trunk:1210875,1211043

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/ext/MessageContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java?rev=1211044&r1=1211043&r2=1211044&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
Tue Dec  6 17:33:16 2011
@@ -78,9 +78,9 @@ public class MessageContextImpl implemen
             return m.getExchange().getOutMessage().get(Message.ATTACHMENTS);
         }
         Object value = m.get(key);
-        if (value == null && isRequestor()) {
+        if (value == null && m.getExchange() != null) {
             Message inMessage = m.getExchange().getInMessage();
-            if (inMessage != null) {
+            if (inMessage != null && inMessage != m) {
                 value = inMessage.get(key);
             }
         } 

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=1211044&r1=1211043&r2=1211044&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
Tue Dec  6 17:33:16 2011
@@ -39,6 +39,7 @@ import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.ext.Provider;
 import javax.xml.bind.JAXBElement;
 import javax.xml.bind.JAXBException;
@@ -57,9 +58,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.SchemaLocation;
 import org.apache.cxf.jaxrs.ext.xml.XMLInstruction;
 import org.apache.cxf.jaxrs.ext.xml.XMLSource;
+import org.apache.cxf.jaxrs.ext.xml.XSISchemaLocation;
 import org.apache.cxf.jaxrs.utils.AnnotationUtils;
 import org.apache.cxf.jaxrs.utils.HttpUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
@@ -93,11 +94,16 @@ public class JAXBElementProvider extends
     
     private Map<String, Object> mProperties = Collections.emptyMap();
     private Map<String, String> nsPrefixes = Collections.emptyMap();
+    private String xmlResourceOffset = "";
     
     public JAXBElementProvider() {
         
     }
     
+    public void setXmlResourceOffset(String value) {
+        xmlResourceOffset = value;
+    }
+    
     public void setNamespacePrefixes(Map<String, String> prefixes) {
         nsPrefixes = prefixes;
     }
@@ -388,10 +394,9 @@ public class JAXBElementProvider extends
         if (pi != null) {
             String value = pi.value();
             int ind = value.indexOf("href='");
-            if (ind > 0 && getContext() != null) {
+            if (ind > 0) {
                 String relRef = value.substring(ind + 6, value.length() - 3);
-                String absRef = 
-                    getContext().getUriInfo().getBaseUriBuilder().path(relRef).build().toString();
+                String absRef = buildAbsoluteXMLResourceURI(relRef);
                 value = value.substring(0, ind + 6) + absRef + "'?>";
             }
             setMarshallerProp(ms, value, XML_PI_PROPERTY, XML_PI_PROPERTY_INT);
@@ -399,19 +404,31 @@ public class JAXBElementProvider extends
     }
     
     private void addSchemaLocation(Marshaller ms, Annotation[] anns) throws Exception {
-        SchemaLocation sl = AnnotationUtils.getAnnotation(anns, SchemaLocation.class);
+        XSISchemaLocation sl = AnnotationUtils.getAnnotation(anns, XSISchemaLocation.class);
         if (sl != null) {
-            String value = sl.value();
-            if (getContext() != null) {
-                value = 
-                    getContext().getUriInfo().getBaseUriBuilder().path(value).build().toString();
-            }
+            String value = buildAbsoluteXMLResourceURI(sl.value());
             String propName = !sl.noNamespace() 
                 ? Marshaller.JAXB_SCHEMA_LOCATION : Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION;
             ms.setProperty(propName, value);
         }
     }
     
+    private String buildAbsoluteXMLResourceURI(String path) {
+        MessageContext mc = getContext();
+        if (mc != null) {
+            String httpBasePath = (String)mc.get("http.base.path");
+            UriBuilder builder = null;
+            if (httpBasePath != null) {
+                builder = UriBuilder.fromPath(httpBasePath);
+            } else {
+                builder = mc.getUriInfo().getBaseUriBuilder();
+            }
+            return builder.path(path).path(xmlResourceOffset).build().toString();
+        } else {
+            return path; 
+        }
+    }
+    
     private static void setMarshallerProp(Marshaller ms, Object value, 
                                           String name1, String name2) throws Exception {
         try {

Modified: cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java?rev=1211044&r1=1211043&r2=1211044&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
Tue Dec  6 17:33:16 2011
@@ -96,6 +96,7 @@ public abstract class AbstractHTTPDestin
     public static final String CXF_ASYNC_CONTEXT = "cxf.async.context";
 
     public static final String SERVICE_REDIRECTION = "http.service.redirection";
+    private static final String HTTP_BASE_PATH = "http.base.path";
     
     private static final Logger LOG = LogUtils.getL7dLogger(AbstractHTTPDestination.class);
     
@@ -254,8 +255,10 @@ public abstract class AbstractHTTPDestin
         inMessage.put(HTTP_CONTEXT_MATCH_STRATEGY, contextMatchStrategy);
         
         inMessage.put(Message.HTTP_REQUEST_METHOD, req.getMethod());
-        inMessage.put(Message.REQUEST_URI, req.getRequestURI());
-        inMessage.put(Message.REQUEST_URL, req.getRequestURL().toString());
+        String requestURI = req.getRequestURI();
+        inMessage.put(Message.REQUEST_URI, requestURI);
+        String requestURL = req.getRequestURL().toString();
+        inMessage.put(Message.REQUEST_URL, requestURL);
         String contextPath = req.getContextPath();
         if (contextPath == null) {
             contextPath = "";
@@ -266,6 +269,16 @@ public abstract class AbstractHTTPDestin
         }
         String contextServletPath = contextPath + servletPath;
         inMessage.put(Message.PATH_INFO, contextServletPath + req.getPathInfo());
+        int index = requestURL.indexOf(requestURI);
+        if (index > 0) {
+            // Can be useful for referencing resources with URIs not covered by CXFServlet.
+            // For example, if we a have web application name 'app' and CXFServlet listening

+            // on "/services/*" then having HTTP_BASE_PATH pointing to say 
+            // http://localhost:8080/app will make it easy to refer to non CXF resources
+            String schemaInfo = requestURL.substring(0, index);
+            String basePathWithContextOnly = schemaInfo + contextPath;
+            inMessage.put(HTTP_BASE_PATH, basePathWithContextOnly);
+        }
         String contentType = req.getContentType();
         inMessage.put(Message.CONTENT_TYPE, contentType);
         setEncoding(inMessage, req, contentType);

Modified: cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java?rev=1211044&r1=1211043&r2=1211044&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java
Tue Dec  6 17:33:16 2011
@@ -66,6 +66,7 @@ public abstract class AbstractHTTPServle
         STATIC_CONTENT_TYPES.put("txt", "text/plain");
         STATIC_CONTENT_TYPES.put("css", "text/css");
         STATIC_CONTENT_TYPES.put("pdf", "application/pdf");
+        STATIC_CONTENT_TYPES.put("xsd", "application/xml");
         // TODO : add more types if needed
     }
     

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=1211044&r1=1211043&r2=1211044&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
Tue Dec  6 17:33:16 2011
@@ -78,8 +78,8 @@ 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.jaxrs.ext.xml.XSISchemaLocation;
 import org.apache.cxf.phase.PhaseInterceptorChain;
 
 @Path("/bookstore")
@@ -211,7 +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")
+    @XSISchemaLocation("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/JAXRSClientServerResourceCreatedSpringBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringBookTest.java?rev=1211044&r1=1211043&r2=1211044&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringBookTest.java
(original)
+++ cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringBookTest.java
Tue Dec  6 17:33:16 2011
@@ -35,7 +35,7 @@ public class JAXRSClientServerResourceCr
     @BeforeClass
     public static void startServers() throws Exception {
         assertTrue("server did not launch correctly",
-                   launchServer(BookServerResourceCreatedSpring.class));
+                   launchServer(BookServerResourceCreatedSpring.class, true));
     }
     
     @Test



Mime
View raw message