cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r829906 - in /cxf/trunk: api/src/main/java/org/apache/cxf/transport/ common/common/src/main/java/org/apache/cxf/resource/ rt/core/src/main/java/org/apache/cxf/bus/extension/
Date Mon, 26 Oct 2009 19:15:12 GMT
Author: dkulp
Date: Mon Oct 26 19:15:12 2009
New Revision: 829906

URL: http://svn.apache.org/viewvc?rev=829906&view=rev
Log:
[CXF-2497] Use conduits for all the http wsdl retrieval
to allow configuration of timeouts, auth stuff, etc...

Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/transport/TransportURIResolver.java
    cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/URIResolver.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/DeferredMap.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/Extension.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManager.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManagerImpl.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/transport/TransportURIResolver.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/transport/TransportURIResolver.java?rev=829906&r1=829905&r2=829906&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/transport/TransportURIResolver.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/transport/TransportURIResolver.java Mon Oct
26 19:15:12 2009
@@ -23,6 +23,8 @@
 import java.io.InputStream;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.util.HashSet;
+import java.util.Set;
 
 import org.xml.sax.InputSource;
 
@@ -40,6 +42,17 @@
  * 
  */
 public class TransportURIResolver extends ExtendedURIResolver {
+    private static final Set<String> DEFAULT_URI_RESOLVER_HANDLES = new HashSet<String>();
+    static {
+        //bunch we really don't want to have the conduits checked for
+        //as we know the conduits don't handle.  No point
+        //wasting the time checking/loading conduits and such
+        DEFAULT_URI_RESOLVER_HANDLES.add("file");
+        DEFAULT_URI_RESOLVER_HANDLES.add("classpath");
+        DEFAULT_URI_RESOLVER_HANDLES.add("wsjar");
+        DEFAULT_URI_RESOLVER_HANDLES.add("jar");
+        DEFAULT_URI_RESOLVER_HANDLES.add("zip");
+    }
     protected Bus bus;
     
     public TransportURIResolver(Bus b) {
@@ -62,51 +75,55 @@
             base = null;
         }
         try {
-            if (base == null || !"https".equals(base.getScheme())) {
+            if (base == null 
+                || DEFAULT_URI_RESOLVER_HANDLES.contains(base.getScheme())) {
                 is = super.resolve(curUri, baseUri);
             }
         } catch (Exception ex) {
             //nothing
         }
-        if (is == null && base != null && base.getScheme() != null) {
+        if (is == null && base != null 
+            && base.getScheme() != null) {
             try {
                 ConduitInitiator ci = bus.getExtension(ConduitInitiatorManager.class)
                     .getConduitInitiatorForUri(base.toString());
-                EndpointInfo info = new EndpointInfo();
-                info.setAddress(base.toString());
-                final Conduit c = ci.getConduit(info);
-                Message message = new MessageImpl();
-                Exchange exch = new ExchangeImpl();
-                message.setExchange(exch);
-                
-                message.put(Message.HTTP_REQUEST_METHOD, "GET");
-                c.setMessageObserver(new MessageObserver() {
-                    public void onMessage(Message message) {
-                        LoadingByteArrayOutputStream bout = new LoadingByteArrayOutputStream();
-                        try {
-                            IOUtils.copy(message.getContent(InputStream.class), bout);
-                            message.getExchange().put(InputStream.class, bout.createInputStream());
-                            c.close(message);
-                        } catch (IOException e) {
-                            //ignore
+                if (ci != null) {
+                    EndpointInfo info = new EndpointInfo();
+                    info.setAddress(base.toString());
+                    final Conduit c = ci.getConduit(info);
+                    Message message = new MessageImpl();
+                    Exchange exch = new ExchangeImpl();
+                    message.setExchange(exch);
+                    
+                    message.put(Message.HTTP_REQUEST_METHOD, "GET");
+                    c.setMessageObserver(new MessageObserver() {
+                        public void onMessage(Message message) {
+                            LoadingByteArrayOutputStream bout = new LoadingByteArrayOutputStream();
+                            try {
+                                IOUtils.copy(message.getContent(InputStream.class), bout);
+                                message.getExchange().put(InputStream.class, bout.createInputStream());
+                                c.close(message);
+                            } catch (IOException e) {
+                                //ignore
+                            }
                         }
-                    }
-                });
-                c.prepare(message);
-                c.close(message);
-                InputStream ins = exch.get(InputStream.class);
-                resourceOpened.addElement(ins);
-                InputSource src = new InputSource(ins);
-                src.setPublicId(base.toString());
-                src.setSystemId(base.toString());
-                lastestImportUri = base.toString();
-                currentResolver.unresolve();
-                return src;
+                    });
+                    c.prepare(message);
+                    c.close(message);
+                    InputStream ins = exch.get(InputStream.class);
+                    resourceOpened.addElement(ins);
+                    InputSource src = new InputSource(ins);
+                    src.setPublicId(base.toString());
+                    src.setSystemId(base.toString());
+                    lastestImportUri = base.toString();
+                    currentResolver.unresolve();
+                    return src;
+                }
             } catch (Exception e) {
                 //ignore
             }
         }
-        if (is == null && "https".equals(base.getScheme())) {
+        if (is == null && !DEFAULT_URI_RESOLVER_HANDLES.contains(base.getScheme()))
{
             is = super.resolve(curUri, baseUri);            
         }
         return is;

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/URIResolver.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/URIResolver.java?rev=829906&r1=829905&r2=829906&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/URIResolver.java (original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/URIResolver.java Mon Oct
26 19:15:12 2009
@@ -158,6 +158,8 @@
                             huc.setRequestProperty("Proxy-Authorization", "Basic " + encoded);
                         }
                     }
+                    huc.setConnectTimeout(30000);
+                    huc.setReadTimeout(60000);
                     is =  huc.getInputStream();
                 } catch (ClassCastException ex) {
                     is = url.openStream();

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/DeferredMap.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/DeferredMap.java?rev=829906&r1=829905&r2=829906&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/DeferredMap.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/DeferredMap.java Mon Oct
26 19:15:12 2009
@@ -33,7 +33,7 @@
     }
     
     public void undefer() {
-        em.activateAll();
+        em.activateAllByType(type);
     }
     
 

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/Extension.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/Extension.java?rev=829906&r1=829905&r2=829906&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/Extension.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/Extension.java Mon Oct 26
19:15:12 2009
@@ -29,6 +29,7 @@
 public class Extension {
 
     private String className;
+    private Class<?> clazz;
     private String interfaceName;
     private boolean deferred;
     private Collection<String> namespaces = new ArrayList<String>();
@@ -54,11 +55,22 @@
         return buf.toString();        
     }
     
+    Class<?> getClassObject(ClassLoader cl) {
+        if (clazz == null) {
+            try {
+                clazz = cl.loadClass(className);
+            } catch (ClassNotFoundException ex) {
+                throw new ExtensionException(ex);
+            }
+        }
+        return clazz;
+    }
     String getClassname() {
         return className;
     }
     
     void setClassname(String i) {
+        clazz = null;
         className = i;
     }
        
@@ -85,7 +97,7 @@
     Object load(ClassLoader cl, Bus b) {
         Object obj = null;
         try {
-            Class<?> cls = cl.loadClass(className);
+            Class<?> cls = getClassObject(cl);
             try {
                 //if there is a Bus constructor, use it.
                 if (b != null) {
@@ -96,8 +108,6 @@
                 //ignore
             }
             obj = cls.newInstance();
-        } catch (ClassNotFoundException ex) {
-            throw new ExtensionException(ex);
         } catch (IllegalAccessException ex) {
             throw new ExtensionException(ex);
         } catch (InstantiationException ex) {

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManager.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManager.java?rev=829906&r1=829905&r2=829906&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManager.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManager.java Mon
Oct 26 19:15:12 2009
@@ -22,6 +22,8 @@
 public interface ExtensionManager {
     void activateAll();
     
+    <T> void activateAllByType(Class<T> type);
+    
     void activateViaNS(String namespace);
     
     <T> T getExtension(String ns, Class<T> type);

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManagerImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManagerImpl.java?rev=829906&r1=829905&r2=829906&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManagerImpl.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManagerImpl.java
Mon Oct 26 19:15:12 2009
@@ -26,6 +26,7 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Enumeration;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -115,7 +116,19 @@
             activateViaNS(deferred.keySet().iterator().next());
         }
     }
-
+    public <T> void activateAllByType(Class<T> type) {
+        for (Map.Entry<String, Collection<Extension>> e : deferred.entrySet())
{
+            Iterator<Extension> it = e.getValue().iterator();
+            while (it.hasNext()) {
+                Extension ex = it.next();
+                if (type.isAssignableFrom(ex.getClassObject(loader))) {
+                    loadAndRegister(ex);
+                    it.remove();
+                }
+            }
+        }
+    }
+    
     final void load(String resource) throws IOException {
         Enumeration<URL> urls = Thread.currentThread().getContextClassLoader().getResources(resource);
         while (urls.hasMoreElements()) {



Mime
View raw message