cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1200850 - in /cxf/trunk/rt: frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/ frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ frontend/jaxrs/src/test/java/org/...
Date Fri, 11 Nov 2011 12:23:38 GMT
Author: sergeyb
Date: Fri Nov 11 12:23:37 2011
New Revision: 1200850

URL: http://svn.apache.org/viewvc?rev=1200850&view=rev
Log:
[CXF-3902] Simplifying wadl queries a bit

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestPreprocessorTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/FormattedServiceListWriter.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/UnformattedServiceListWriter.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java?rev=1200850&r1=1200849&r2=1200850&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
Fri Nov 11 12:23:37 2011
@@ -53,6 +53,8 @@ public class RequestPreprocessor {
         SHORTCUTS.put("text", "text/*");
         SHORTCUTS.put("xml", "application/xml");
         SHORTCUTS.put("atom", "application/atom+xml");
+        SHORTCUTS.put("html", "text/html");
+        SHORTCUTS.put("wadl", "application/vnd.sun.wadl+xml");
         // more to come
     }
     
@@ -79,7 +81,7 @@ public class RequestPreprocessor {
         handleTypeQuery(m, queries);
         handleCType(m, queries);
         handleMethod(m, queries, new HttpHeadersImpl(m));
-        Response r = checkMetadataRequest(m);
+        Response r = checkMetadataRequest(m, u);
         if (r == null) {
             r = checkCodeRequest(m);
         }
@@ -158,6 +160,9 @@ public class RequestPreprocessor {
     private void handleCType(Message m, MultivaluedMap<String, String> queries) {
         String type = queries.getFirst(CTYPE_QUERY);
         if (type != null) {
+            if (SHORTCUTS.containsKey(type)) {
+                type = SHORTCUTS.get(type);
+            }
             m.put(Message.CONTENT_TYPE, type);
         }
     }
@@ -176,7 +181,7 @@ public class RequestPreprocessor {
      * has been selected are handy. Consider implementing this method as part of the QueryHandler,
      * we will need to save the list of ClassResourceInfos on the EndpointInfo though
      */
-    public Response checkMetadataRequest(Message m) {
+    public Response checkMetadataRequest(Message m, UriInfo ui) {
         String originalRequestURI = (String)m.get(Message.REQUEST_URI);
         String query = (String)m.get(Message.QUERY_STRING);
         if (query != null && query.contains(WadlGenerator.WADL_QUERY)) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java?rev=1200850&r1=1200849&r2=1200850&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
Fri Nov 11 12:23:37 2011
@@ -109,7 +109,8 @@ public class WadlGenerator implements Re
     public static final String WADL_QUERY = "_wadl";
     public static final MediaType WADL_TYPE = MediaType.valueOf("application/vnd.sun.wadl+xml");
     public static final String WADL_NS = "http://wadl.dev.java.net/2009/02";
-
+    
+    private static final MediaType DEFAULT_MEDIA_TYPE = MediaType.APPLICATION_XML_TYPE; 
     private static final Logger LOG = LogUtils.getL7dLogger(WadlGenerator.class);
     private static final String JAXB_DEFAULT_NAMESPACE = "##default";
     private static final String JAXB_DEFAULT_NAME = "##default";
@@ -137,6 +138,7 @@ public class WadlGenerator implements Re
     private List<String> privateAddresses;
     private String applicationTitle;
     private String nsPrefix = DEFAULT_NS_PREFIX;
+    private MediaType defaultMediaType = DEFAULT_MEDIA_TYPE;
     
     public WadlGenerator() {
 
@@ -182,9 +184,9 @@ public class WadlGenerator implements Re
 
         HttpHeaders headers = new HttpHeadersImpl(m);
         List<MediaType> accepts = headers.getAcceptableMediaTypes();
-        MediaType type = accepts.contains(MediaType.APPLICATION_XML_TYPE)
-            ? MediaType.APPLICATION_XML_TYPE : accepts.contains(MediaType.APPLICATION_JSON_TYPE)

-                ? MediaType.APPLICATION_JSON_TYPE : WADL_TYPE;
+        MediaType type = accepts.contains(WADL_TYPE)
+            ? WADL_TYPE : accepts.contains(MediaType.APPLICATION_JSON_TYPE) 
+                ? MediaType.APPLICATION_JSON_TYPE : defaultMediaType;
         
         Response response = getExistingWadl(m, ui, type);
         if (response != null) {
@@ -1460,6 +1462,10 @@ public class WadlGenerator implements Re
         this.ignoreRequests = ignoreRequests;
     }
 
+    public void setDefaultMediaType(String mt) {
+        this.defaultMediaType = MediaType.valueOf(mt);
+    }
+
     private static class SchemaConverter extends DelegatingXMLStreamWriter {
         private static final String SCHEMA_LOCATION = "schemaLocation";
         private Map<String, String> locsMap;

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java?rev=1200850&r1=1200849&r2=1200850&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
Fri Nov 11 12:23:37 2011
@@ -70,7 +70,7 @@ import org.apache.cxf.staxutils.transfor
 @Consumes({"application/xml", "application/*+xml", "text/xml" })
 @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,
@@ -247,7 +247,7 @@ public class JAXBElementProvider extends
     }
 
     protected void marshalCollection(Class<?> originalCls, Object collection, 
-                                     Type genericType, String encoding, OutputStream os,

+                                     Type genericType, String enc, OutputStream os, 
                                      MediaType m, Annotation[] anns) 
         throws Exception {
         
@@ -276,6 +276,9 @@ public class JAXBElementProvider extends
                                               .entity(message).build());
         }
         
+        StringBuilder prefix = new StringBuilder();
+        prefix.append(XML_PI_START + (enc == null ? "UTF-8" : enc) + "\"?>");
+        os.write(prefix.toString().getBytes());
         String startTag = null;
         String endTag = null;
         if (qname.getNamespaceURI().length() > 0) {
@@ -291,11 +294,11 @@ public class JAXBElementProvider extends
             XmlJavaTypeAdapter adapter = 
                 org.apache.cxf.jaxrs.utils.JAXBUtils.getAdapter(firstObj.getClass(), anns);
             marshalCollectionMember(JAXBUtils.useAdapter(firstObj, adapter, true), 
-                                    actualClass, genericType, encoding, os, m, 
+                                    actualClass, genericType, enc, os, m, 
                                     qname.getNamespaceURI());
             while (it.hasNext()) {
                 marshalCollectionMember(JAXBUtils.useAdapter(it.next(), adapter, true), actualClass,

-                                        genericType, encoding, os, m, 
+                                        genericType, enc, os, m, 
                                         qname.getNamespaceURI());
             }
         }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestPreprocessorTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestPreprocessorTest.java?rev=1200850&r1=1200849&r2=1200850&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestPreprocessorTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestPreprocessorTest.java
Fri Nov 11 12:23:37 2011
@@ -27,12 +27,12 @@ import java.util.TreeMap;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.jaxrs.JAXRSServiceImpl;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
-import org.apache.cxf.jaxrs.model.wadl.WadlGenerator;
 import org.apache.cxf.jaxrs.provider.ProviderFactory;
 import org.apache.cxf.jaxrs.utils.ResourceUtils;
 import org.apache.cxf.message.Exchange;
@@ -87,7 +87,7 @@ public class RequestPreprocessorTest ext
         sqh.preprocess(m, new UriInfoImpl(m, null));
         Response r = m.getExchange().get(Response.class);
         assertNotNull(r);
-        assertEquals(WadlGenerator.WADL_TYPE.toString(),
+        assertEquals(MediaType.APPLICATION_XML,
                      r.getMetadata().getFirst(HttpHeaders.CONTENT_TYPE));
     }
     

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java?rev=1200850&r1=1200849&r2=1200850&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
Fri Nov 11 12:23:37 2011
@@ -280,7 +280,7 @@ public class WadlGeneratorTest extends A
     
     private void checkResponse(Response r) throws Exception {
         assertNotNull(r);
-        assertEquals(WadlGenerator.WADL_TYPE.toString(),
+        assertEquals(MediaType.APPLICATION_XML,
                      r.getMetadata().getFirst(HttpHeaders.CONTENT_TYPE));
 //        File f = new File("test.xml");
 //        f.delete();
@@ -295,6 +295,7 @@ public class WadlGeneratorTest extends A
     @Test
     public void testMultipleRootResources() throws Exception {
         WadlGenerator wg = new WadlGenerator();
+        wg.setDefaultMediaType(WadlGenerator.WADL_TYPE.toString());
         ClassResourceInfo cri1 = 
             ResourceUtils.createClassResourceInfo(BookStore.class, BookStore.class, true,
true);
         ClassResourceInfo cri2 = 
@@ -304,7 +305,8 @@ public class WadlGeneratorTest extends A
         cris.add(cri2);
         Message m = mockMessage("http://localhost:8080/baz", "/bar", WadlGenerator.WADL_QUERY,
cris);
         Response r = wg.handleRequest(m, null);
-        checkResponse(r);
+        assertEquals(WadlGenerator.WADL_TYPE.toString(),
+                     r.getMetadata().getFirst(HttpHeaders.CONTENT_TYPE));
         Document doc = DOMUtils.readXml(new StringReader(r.getEntity().toString()));
         checkGrammars(doc.getDocumentElement(), "thebook", "thebook2", "thechapter");
         List<Element> els = getWadlResourcesInfo(doc, "http://localhost:8080/baz",
2);

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java?rev=1200850&r1=1200849&r2=1200850&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
Fri Nov 11 12:23:37 2011
@@ -395,7 +395,8 @@ public class JAXBElementProviderTest ext
                          org.apache.cxf.jaxrs.fortest.jaxb.SuperBook.class,
                          new Annotation[0], MediaType.TEXT_XML_TYPE, 
                          new MetadataMap<String, Object>(), bos);
-        String expected = "<ns1:SuperBooks xmlns:ns1=\"http://superbooks\">"
+        String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+            + "<ns1:SuperBooks xmlns:ns1=\"http://superbooks\">"
             + "<ns1:SuperBook xmlns:ns2=\"http://books\" xmlns:ns1=\"http://superbooks\"><id>123</id>"
             + "<name>CXF in Action</name><superId>124</superId></ns1:SuperBook></ns1:SuperBooks>";
         assertEquals(expected, bos.toString());
@@ -795,7 +796,8 @@ public class JAXBElementProviderTest ext
         provider.writeTo(list, ArrayList.class, type,
             new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(),
bos);
     
-        String expected = "<tagholders><tagholder><attr>attribute</attr>"
+        String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+            + "<tagholders><tagholder><attr>attribute</attr>"
             + "<thetag><group>B</group><name>A</name></thetag></tagholder></tagholders>";
         assertEquals(expected, bos.toString());
     }

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/FormattedServiceListWriter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/FormattedServiceListWriter.java?rev=1200850&r1=1200849&r2=1200850&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/FormattedServiceListWriter.java
(original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/FormattedServiceListWriter.java
Fri Nov 11 12:23:37 2011
@@ -166,7 +166,7 @@ public class FormattedServiceListWriter 
         writer.write("<span class=\"field\">Endpoint address:</span> " + "<span
class=\"value\">"
                      + absoluteURL + "</span>");
         writer.write("<br/><span class=\"field\">WADL :</span> " + "<a
href=\"" + absoluteURL
-                     + "?_wadl&_type=xml\">" + absoluteURL + "?_wadl&type=xml"
+ "</a>");
+                     + "?_wadl\">" + absoluteURL + "?_wadl" + "</a>");
         addAtomLinkIfNeeded(absoluteURL, atomMap, writer);
         writer.write("</td></tr>");
     }

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/UnformattedServiceListWriter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/UnformattedServiceListWriter.java?rev=1200850&r1=1200849&r2=1200850&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/UnformattedServiceListWriter.java
(original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/UnformattedServiceListWriter.java
Fri Nov 11 12:23:37 2011
@@ -67,7 +67,7 @@ public class UnformattedServiceListWrite
                                                   AbstractDestination[] destinations) throws
IOException {
         for (AbstractDestination sd : destinations) {
             String address = getAbsoluteAddress(baseAddress, sd);
-            writer.write(address + "?_wadl&_type=xml\n");
+            writer.write(address + "?_wadl\n");
         }
     }
 



Mime
View raw message