cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r911011 - in /cxf/branches/2.2.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/ rt/frontend/jaxrs/s...
Date Wed, 17 Feb 2010 15:11:38 GMT
Author: sergeyb
Date: Wed Feb 17 15:11:37 2010
New Revision: 911011

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

........
  r910964 | sergeyb | 2010-02-17 13:20:41 +0000 (Wed, 17 Feb 2010) | 1 line
  
  Support for 'hiding' service contracts
........

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/JAXRSServerFactoryBean.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestPreprocessorTest.java
    cxf/branches/2.2.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
    cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultithreadedClientTest.java
    cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
    cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml

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

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/JAXRSServerFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java?rev=911011&r1=911010&r2=911011&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
Wed Feb 17 15:11:37 2010
@@ -22,6 +22,7 @@
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 
@@ -39,6 +40,7 @@
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.provider.ProviderFactory;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
+import org.apache.cxf.message.MessageUtils;
 import org.apache.cxf.service.factory.ServiceConstructionException;
 import org.apache.cxf.service.invoker.Invoker;
 
@@ -103,7 +105,7 @@
             }
             
             ProviderFactory factory = setupFactory(ep);
-            
+            checkIfPrivate(factory, ep);
             factory.setRequestPreprocessor(
                 new RequestPreprocessor(languageMappings, extensionMappings));
             if (rc != null) {
@@ -127,6 +129,20 @@
         return server;
     }
 
+    @SuppressWarnings("unchecked")
+    protected void checkIfPrivate(ProviderFactory factory, Endpoint ep) {
+        if (MessageUtils.isTrue(ep.get("org.apache.cxf.endpoint.private"))) {
+            List<String> addresses = 
+                (List<String>)getBus().getProperty("org.apache.cxf.private.endpoints");
+            if (addresses == null) {
+                addresses = new LinkedList<String>();
+            }
+            addresses.add(getAddress());
+            
+            bus.setProperty("org.apache.cxf.private.endpoints", addresses);
+        }
+    }
+    
     protected void applyFeatures() {
         if (getFeatures() != null) {
             for (AbstractFeature feature : getFeatures()) {

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java?rev=911011&r1=911010&r2=911011&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
Wed Feb 17 15:11:37 2010
@@ -49,6 +49,7 @@
         SHORTCUTS.put("json", "application/json");
         SHORTCUTS.put("text", "text/*");
         SHORTCUTS.put("xml", "application/xml");
+        SHORTCUTS.put("atom", "application/atom+xml");
         // more to come
     }
     

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java?rev=911011&r1=911010&r2=911011&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
Wed Feb 17 15:11:37 2010
@@ -92,6 +92,7 @@
 import org.apache.cxf.jaxrs.utils.ResourceUtils;
 import org.apache.cxf.jaxrs.utils.schemas.SchemaHandler;
 import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageUtils;
 import org.apache.cxf.service.Service;
 import org.apache.cxf.staxutils.DelegatingXMLStreamWriter;
 import org.apache.cxf.staxutils.StaxUtils;
@@ -119,6 +120,7 @@
     private List<URI> externalSchemaLinks;
     private Map<String, List<String>> externalQnamesMap; 
     private ElementQNameResolver resolver;
+    private List<String> privateAddresses;
     
     public Response handleRequest(Message m, ClassResourceInfo resource) {
         
@@ -131,6 +133,10 @@
             return null;
         }
         
+        if (isPrivate(m)) {
+            return Response.status(401).build();
+        }
+        
         StringBuilder sbMain = new StringBuilder();
         sbMain.append("<application xmlns=\"").append(getNamespace())
               .append("\" xmlns:xs=\"").append(XmlSchemaConstants.XSD_NAMESPACE_URI).append("\"");
@@ -1056,6 +1062,18 @@
         this.resolver = resolver;
     }
     
+    public void setPrivateAddresses(List<String> privateAddresses) {
+        this.privateAddresses = privateAddresses;
+    }
+    
+    public List<String> getPrivateAddresses() {
+        return privateAddresses;
+    }
+
+    private boolean isPrivate(Message m) {
+        return MessageUtils.isTrue(m.getContextualProperty("org.apache.cxf.endpoint.private"));

+    }
+    
     private static class SchemaConverter extends DelegatingXMLStreamWriter {
         private static final String SCHEMA_LOCATION = "schemaLocation";
         private Map<String, String> locsMap;    

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestPreprocessorTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestPreprocessorTest.java?rev=911011&r1=911010&r2=911011&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestPreprocessorTest.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestPreprocessorTest.java
Wed Feb 17 15:11:37 2010
@@ -114,6 +114,7 @@
                                 String methodHeader) {
         Message m = new MessageImpl();
         m.put("org.apache.cxf.http.case_insensitive_queries", false);
+        m.put("org.apache.cxf.endpoint.private", false);
         Exchange e = new ExchangeImpl();
         m.setExchange(e);
         control.reset();

Modified: cxf/branches/2.2.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java?rev=911011&r1=911010&r2=911011&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
Wed Feb 17 15:11:37 2010
@@ -208,6 +208,7 @@
         return ret; 
     }
     
+    @SuppressWarnings("unchecked")
     protected void generateServiceList(HttpServletRequest request, HttpServletResponse response)
         throws IOException {        
         response.setContentType("text/html; charset=UTF-8");        
@@ -235,8 +236,10 @@
         List<ServletDestination> destinations = getServletDestinations();
             
         if (destinations.size() > 0) {
-            writeSOAPEndpoints(response, destinations);
-            writeRESTfulEndpoints(response, destinations);
+            List<String> privateEndpoints = 
+                (List<String>)bus.getProperty("org.apache.cxf.private.endpoints");
+            writeSOAPEndpoints(response, destinations, privateEndpoints);
+            writeRESTfulEndpoints(response, destinations, privateEndpoints);
         } else {
             response.getWriter().write("<span class=\"heading\">No services have been
found.</span>");
         }
@@ -244,14 +247,17 @@
         response.getWriter().write("</body></html>");
     }
 
-    private void writeSOAPEndpoints(HttpServletResponse response, List<ServletDestination>
destinations)
+    private void writeSOAPEndpoints(HttpServletResponse response, List<ServletDestination>
destinations,
+                                    List<String> privateEndpoints)
         throws IOException {
         response.getWriter().write("<span class=\"heading\">Available SOAP services:</span><br/>");
         response.getWriter().write("<table " + (serviceListStyleSheet == null
                 ? "cellpadding=\"1\" cellspacing=\"1\" border=\"1\" width=\"100%\"" : "")
+ ">");
         for (ServletDestination sd : destinations) {
+            
             if (null != sd.getEndpointInfo().getName() 
-                && null != sd.getEndpointInfo().getInterface()) {
+                && null != sd.getEndpointInfo().getInterface()
+                && !isPrivate(sd.getEndpointInfo(), privateEndpoints)) {
                 response.getWriter().write("<tr><td>");
                 response.getWriter().write("<span class=\"porttypename\">"
                         + sd.getEndpointInfo().getInterface().getName().getLocalPart()
@@ -280,13 +286,15 @@
     }
     
     
-    private void writeRESTfulEndpoints(HttpServletResponse response, List<ServletDestination>
destinations)
+    private void writeRESTfulEndpoints(HttpServletResponse response, List<ServletDestination>
destinations,
+                                       List<String> privateEndpoints)
         throws IOException {
         
         List<ServletDestination> restfulDests = new ArrayList<ServletDestination>();
         for (ServletDestination sd : destinations) {
             // use some more reasonable check - though this one seems to be the only option
at the moment
-            if (null == sd.getEndpointInfo().getInterface()) {
+            if (null == sd.getEndpointInfo().getInterface() 
+                && !isPrivate(sd.getEndpointInfo(), privateEndpoints)) {
                 restfulDests.add(sd);
             }
         }
@@ -297,21 +305,30 @@
         response.getWriter().write("<span class=\"heading\">Available RESTful services:</span><br/>");
         response.getWriter().write("<table " + (serviceListStyleSheet == null
                 ? "cellpadding=\"1\" cellspacing=\"1\" border=\"1\" width=\"100%\"" : "")
+ ">");
-        for (ServletDestination sd : destinations) {
-            if (null == sd.getEndpointInfo().getInterface()) {
-                response.getWriter().write("<tr><td>");
-                String address = sd.getEndpointInfo().getAddress();
-                response.getWriter().write("<span class=\"field\">Endpoint address:</span>
"
-                        + "<span class=\"value\">" + address + "</span>");
-                response.getWriter().write("<br/><span class=\"field\">WADL :</span>
"
-                        + "<a href=\"" + address + "?_wadl&_type=xml\">"
-                        + address + "?_wadl&type=xml" + "</a>");
-                response.getWriter().write("</td></tr>");
-            }    
+        for (ServletDestination sd : restfulDests) {
+            response.getWriter().write("<tr><td>");
+            String address = sd.getEndpointInfo().getAddress();
+            response.getWriter().write("<span class=\"field\">Endpoint address:</span>
"
+                    + "<span class=\"value\">" + address + "</span>");
+            response.getWriter().write("<br/><span class=\"field\">WADL :</span>
"
+                    + "<a href=\"" + address + "?_wadl&_type=xml\">"
+                    + address + "?_wadl&type=xml" + "</a>");
+            response.getWriter().write("</td></tr>");
         }
         response.getWriter().write("</table>");
     }
     
+    private boolean isPrivate(EndpointInfo ei, List<String> privateAddresses) {
+        if (privateAddresses != null) {
+            for (String s : privateAddresses) {
+                if (ei.getAddress().endsWith(s)) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+    
     private void renderStyleSheet(HttpServletRequest request,
             HttpServletResponse response) throws IOException {
         response.setContentType("text/css; charset=UTF-8");

Modified: cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultithreadedClientTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultithreadedClientTest.java?rev=911011&r1=911010&r2=911011&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultithreadedClientTest.java
(original)
+++ cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultithreadedClientTest.java
Wed Feb 17 15:11:37 2010
@@ -45,7 +45,7 @@
     @BeforeClass
     public static void startServers() throws Exception {
         assertTrue("server did not launch correctly",
-                   launchServer(BookServer.class, true));
+                   launchServer(BookServer.class));
     }
     
     @Test

Modified: cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java?rev=911011&r1=911010&r2=911011&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
(original)
+++ cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
Wed Feb 17 15:11:37 2010
@@ -73,7 +73,7 @@
     @BeforeClass
     public static void startServers() throws Exception {
         assertTrue("server did not launch correctly", 
-                   launchServer(BookServerRestSoap.class, true));
+                   launchServer(BookServerRestSoap.class));
     }
     
     @Test
@@ -477,10 +477,29 @@
         BookStoreJaxrsJaxws store = service.getBookPort();
         Book book = store.getBook(new Long(123));
         assertEquals("id is wrong", book.getId(), 123);
-        
+    }
+    
+    @Test
+    public void testServiceListingsAndWadl() throws Exception {
         String listings = 
             getStringFromInputStream(getHttpInputStream("http://localhost:9092/test/services"));
         assertNotNull(listings);
+        assertTrue(listings.contains("http://localhost:9092/test/services/soap/bookservice?wsdl"));
+        assertTrue(listings.contains("http://localhost:9092/test/services/soap/bookservice2?wsdl"));
+        
+        assertTrue(listings.contains("http://localhost:9092/test/services/rest?_wadl&type=xml"));
+        assertEquals(200, WebClient.create(
+            "http://localhost:9092/test/services/rest?_wadl&type=xml").get().getStatus());
+        assertTrue(listings.contains("http://localhost:9092/test/services/rest2?_wadl&type=xml"));
+        assertEquals(200, WebClient.create(
+            "http://localhost:9092/test/services/rest2?_wadl&type=xml").get().getStatus());
+        assertFalse(listings.contains("http://localhost:9092/test/services/rest3?_wadl&type=xml"));
+        assertEquals(401, WebClient.create(
+            "http://localhost:9092/test/services/rest3?_wadl&type=xml").get().getStatus());
+        
+         
+        
+        assertFalse(listings.contains("Atom Log Feed"));
     }
     
     @Test

Modified: cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml?rev=911011&r1=911010&r2=911011&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml
(original)
+++ cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml
Wed Feb 17 15:11:37 2010
@@ -99,7 +99,9 @@
     <jaxrs:inInterceptors>
       <ref bean="fastInfosetInInterceptor" />
     </jaxrs:inInterceptors>
-    		   
+    <jaxrs:properties>
+      <entry key="org.apache.cxf.endpoint.private" value="true"/>
+    </jaxrs:properties>    		   
   </jaxrs:server> 
 
   <bean id="jaxbProvider" class="org.apache.cxf.jaxrs.provider.JAXBElementProvider">



Mime
View raw message