ws-wsrf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sc...@apache.org
Subject svn commit: r326145 - in /webservices/wsrf/trunk/src: java/org/apache/ws/resource/ java/org/apache/ws/resource/impl/ test/ test/org/apache/ws/resource/properties/ webapp/WEB-INF/classes/
Date Tue, 18 Oct 2005 16:27:58 GMT
Author: scamp
Date: Tue Oct 18 09:27:49 2005
New Revision: 326145

URL: http://svn.apache.org/viewcvs?rev=326145&view=rev
Log:
fixed unit test for new config...added code in WsrfRuntime to init jndi...moved getBaseWebappUrl
to WsrfRuntime

Modified:
    webservices/wsrf/trunk/src/java/org/apache/ws/resource/WsrfRuntime.java
    webservices/wsrf/trunk/src/java/org/apache/ws/resource/impl/AbstractResourceHome.java
    webservices/wsrf/trunk/src/test/org/apache/ws/resource/properties/AbstractResourcePropertiesTestCase.java
    webservices/wsrf/trunk/src/test/wsrf-config.xml
    webservices/wsrf/trunk/src/webapp/WEB-INF/classes/wsrf-config.xml

Modified: webservices/wsrf/trunk/src/java/org/apache/ws/resource/WsrfRuntime.java
URL: http://svn.apache.org/viewcvs/webservices/wsrf/trunk/src/java/org/apache/ws/resource/WsrfRuntime.java?rev=326145&r1=326144&r2=326145&view=diff
==============================================================================
--- webservices/wsrf/trunk/src/java/org/apache/ws/resource/WsrfRuntime.java (original)
+++ webservices/wsrf/trunk/src/java/org/apache/ws/resource/WsrfRuntime.java Tue Oct 18 09:27:49
2005
@@ -24,6 +24,7 @@
 import org.apache.ws.util.jndi.XmlBeanJndiUtils;
 import org.apache.ws.util.spring.ClassEditor;
 import org.apache.ws.util.spring.QNameEditor;
+import org.apache.naming.java.javaURLContextFactory;
 import org.springframework.beans.factory.ListableBeanFactory;
 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
 import org.springframework.beans.factory.support.AbstractBeanDefinition;
@@ -33,9 +34,12 @@
 import javax.naming.InitialContext;
 import javax.naming.NameNotFoundException;
 import javax.naming.NamingException;
+import javax.naming.Context;
 import javax.xml.namespace.QName;
 import java.io.InputStream;
 import java.net.URL;
+import java.net.MalformedURLException;
+import java.net.UnknownHostException;
 import java.util.Properties;
 
 /**
@@ -43,7 +47,10 @@
  */
 public class WsrfRuntime
 {
-
+    static
+    {
+        initJndiProvider();    
+    }
     private static final Log LOG = LogFactory.getLog( WsrfRuntime.class );
     private static final Messages MSG = MessagesImpl.getInstance();
 
@@ -63,6 +70,10 @@
     public static final String JNDI_CONFIG_DIALECT = "jndi.config.dialect";
     public static final String JNDI_CONFIG_LOCATION = "jndi.config.location";
 
+    private static final String PLACEHOLDER_IPADDRESS = "$IP_ADDRESS$";
+    private static final String PLACEHOLDER_HOSTNAME = "$HOST_NAME$";
+
+
     private WsrfRuntime()
     {
     }
@@ -72,6 +83,11 @@
         return INSTANCE;
     }
 
+    private static void initJndiProvider()
+    {
+        System.setProperty( Context.INITIAL_CONTEXT_FACTORY, javaURLContextFactory.class.getName()
);
+        System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.commons.naming");
+    }
     /**
      * Initializes the WSRF runtime - should only be called once.
      *
@@ -158,10 +174,139 @@
         return m_baseWebappUrl;
     }
 
+    /**
+     * Sets the base webapp url.
+     * <p/>
+     * The URL should contin the webapp context name. (i.e. http://127.0.0.1:8080/wsrf)
+     * <p/>
+     * The URL may contain one of the following:
+     * <p/>
+     * <ol> <li>the marker &lt;IP_ADDRESS> in which case we will attempt
to determine the IP address at runtime. i.e.
+     * http://&lt;IP_ADDRESS>:8080/wsrf (Do not use on multi-homed systems)</li>
<li>the marker &lt;HOST_NAME> in which
+     * case we will attempt to determine the host name at runtime i.e. http://&lt;HOST_NAME>:8080/wsrf
  </li> <li>NO
+     * Marker in which case whatever value you add will be static and used. i.e. http://myhostname:8080/wsrf
 </li>
+     * </ol>
+     *
+     * @param baseWebappUrl The base webapp url containing the webapp context. (i.e. http://127.0.0.1:8080/wsrf)
+     */
     public void setBaseWebappUrl( URL baseWebappUrl )
+    { //todo we may need to figure out a way to stop everything if this method fails.
+        //the url is nonexistant
+        if ( ( baseWebappUrl == null ) || baseWebappUrl.equals( "" ) )
+        {
+            try
+            {
+                try {
+					m_baseWebappUrl = getDefaultUrl();
+					LOG.fatal( "The baseWebappUrl from the wsrf-config.xml file was invalid! Defaulting
to: "
+	                        + m_baseWebappUrl );
+				} catch (MalformedURLException e) {
+					LOG.fatal(
+			                "Unable to get build baseWebappURL.", e );
+				}
+
+            }
+            catch ( java.net.UnknownHostException e )
+            {
+                try {
+					m_baseWebappUrl = new URL("http://127.0.0.1:8080/wsrf");
+					LOG.fatal(
+	                        "The baseWebappUrl from the wsrf-config.xml file was invalid! Unable
to determine host IP address using java.net.InetAddress.getLocalHost().getHostAddress() defaulting
to: "
+	                                + m_baseWebappUrl, e );
+				} catch (MalformedURLException e1) {
+					LOG.fatal(
+			                "Unable to get build baseWebappURL.", e );
+				}
+
+                return;
+            }
+        }
+
+        //the url is not to be modified
+        else if ( ( baseWebappUrl.getHost().indexOf( PLACEHOLDER_IPADDRESS ) == -1 )
+                && ( baseWebappUrl.getHost().indexOf( PLACEHOLDER_HOSTNAME ) == -1
) )
+        {
+            m_baseWebappUrl = baseWebappUrl;
+            return;
+        }
+
+        //url will need to be built
+        //define localhost to be used
+        java.net.InetAddress localHost = null;
+
+        try
+        {
+            localHost = java.net.InetAddress.getLocalHost();
+        }
+        catch ( java.net.UnknownHostException e )
+        {
+            LOG.fatal(
+                    "Unable to get the InetAddress for localhost using InetAddress.getLocalHost().
 Defaults will be used.  This may cause problems with EndpointReferences in Resources." );
+        }
+
+        String sBaseUrl = baseWebappUrl.toString();
+        if ( sBaseUrl.indexOf( PLACEHOLDER_IPADDRESS ) > -1 )
+        {
+            String ipAddress = null;
+            if ( localHost == null )
+            {
+                ipAddress = "127.0.0.1";
+            }
+            else
+            {
+                ipAddress = localHost.getHostAddress();
+            }
+
+            try {
+				m_baseWebappUrl =
+					new URL (sBaseUrl.substring( 0,
+							sBaseUrl.indexOf( PLACEHOLDER_IPADDRESS ) ) + ipAddress
+				                + sBaseUrl.substring( sBaseUrl.indexOf( PLACEHOLDER_IPADDRESS )
+				                + PLACEHOLDER_IPADDRESS.length() ));
+			} catch (MalformedURLException e) {
+				LOG.fatal(
+                "Unable to get build baseWebappURL.", e );
+			}
+            return;
+        } //end if
+
+        else if ( sBaseUrl.indexOf( PLACEHOLDER_HOSTNAME ) > -1 )
+        {
+            String hostname = null;
+            if ( localHost == null )
+            {
+                hostname = "127.0.0.1";
+            }
+            else
+            {
+                hostname = localHost.getHostName();
+            }
+
+            try {
+				m_baseWebappUrl =
+					new URL(sBaseUrl.substring( 0,
+				        		sBaseUrl.indexOf( PLACEHOLDER_HOSTNAME ) ) + hostname
+				                + sBaseUrl.substring( sBaseUrl.indexOf( PLACEHOLDER_HOSTNAME )
+				                + PLACEHOLDER_HOSTNAME.length() ));
+			} catch (MalformedURLException e) {
+				LOG.fatal(
+		                "Unable to get build baseWebappURL.", e );
+			}
+            return;
+        } //end else if
+    }
+    /**
+     * DOCUMENT_ME
+     *
+     * @return DOCUMENT_ME
+     * @throws UnknownHostException
+     *
+     */
+    protected URL getDefaultUrl() throws MalformedURLException, UnknownHostException
     {
-        m_baseWebappUrl = baseWebappUrl;
+      return  new URL("http://" + java.net.InetAddress.getLocalHost().getHostAddress() +
":8080/wsrf");
     }
+
 
     private String getResourceHomeJndiName( String portComponentName )
     {

Modified: webservices/wsrf/trunk/src/java/org/apache/ws/resource/impl/AbstractResourceHome.java
URL: http://svn.apache.org/viewcvs/webservices/wsrf/trunk/src/java/org/apache/ws/resource/impl/AbstractResourceHome.java?rev=326145&r1=326144&r2=326145&view=diff
==============================================================================
--- webservices/wsrf/trunk/src/java/org/apache/ws/resource/impl/AbstractResourceHome.java
(original)
+++ webservices/wsrf/trunk/src/java/org/apache/ws/resource/impl/AbstractResourceHome.java
Tue Oct 18 09:27:49 2005
@@ -128,8 +128,6 @@
     * A static key used only for registering Singleton Resources
     */
     private static final Object SINGLETON_KEY = new Object();
-    private static final String PLACEHOLDER_IPADDRESS = "$IP_ADDRESS$";
-    private static final String PLACEHOLDER_HOSTNAME = "$HOST_NAME$";
 
     /**
      * DOCUMENT_ME
@@ -143,10 +141,6 @@
     private QName m_resourceIdRefParamName;
     private String m_wsdlTargetNamespace;
 
-    /**
-     * The baseURL obtained via JNDI config, used as the basis for the endpoint URL.
-     */
-    private String m_baseWebappUrl;
 
     /**
      * DOCUMENT_ME
@@ -204,7 +198,7 @@
     public EndpointReference getEndpointReference( Object resourceId )
     {
         String endpointAddress =
-                JaxRpcPlatform.getJaxRpcPlatform().getEndpointUrl( getBaseWebappUrl(),
+                JaxRpcPlatform.getJaxRpcPlatform().getEndpointUrl( WsrfRuntime.getRuntime().getBaseWebappUrl().toString(),
                         getServiceName().getLocalPart() );
         String wsAddressingURI = getNamespaceSet().getAddressingNamespace();
 
@@ -327,114 +321,7 @@
      */
     public abstract String getServicePortName();
 
-    /**
-     * Sets the base webapp url.
-     * <p/>
-     * The URL should contin the webapp context name. (i.e. http://127.0.0.1:8080/wsrf)
-     * <p/>
-     * The URL may contain one of the following:
-     * <p/>
-     * <ol> <li>the marker &lt;IP_ADDRESS> in which case we will attempt
to determine the IP address at runtime. i.e.
-     * http://&lt;IP_ADDRESS>:8080/wsrf (Do not use on multi-homed systems)</li>
<li>the marker &lt;HOST_NAME> in which
-     * case we will attempt to determine the host name at runtime i.e. http://&lt;HOST_NAME>:8080/wsrf
  </li> <li>NO
-     * Marker in which case whatever value you add will be static and used. i.e. http://myhostname:8080/wsrf
 </li>
-     * </ol>
-     *
-     * @param baseWebappUrl The base webapp url containing the webapp context. (i.e. http://127.0.0.1:8080/wsrf)
-     */
-    public void setBaseWebappUrl( String baseWebappUrl )
-    { //todo we may need to figure out a way to stop everything if this method fails.
-        //the url is nonexistant
-        if ( ( baseWebappUrl == null ) || baseWebappUrl.equals( "" ) )
-        {
-            try
-            {
-                m_baseWebappUrl = getDefaultUrl();
-                LOG.fatal( "The baseWebappUrl from the jndi-config.xml file was invalid!
Defaulting to: "
-                        + m_baseWebappUrl );
-            }
-            catch ( java.net.UnknownHostException e )
-            {
-                m_baseWebappUrl = "http://127.0.0.1:8080/wsrf";
-                LOG.fatal(
-                        "The baseWebappUrl from the jndi-config.xml file was invalid! Unable
to determine host IP address using java.net.InetAddress.getLocalHost().getHostAddress() defaulting
to: "
-                                + m_baseWebappUrl, e );
-                return;
-            }
-        }
-
-        //the url is not to be modified
-        else if ( ( baseWebappUrl.indexOf( PLACEHOLDER_IPADDRESS ) == -1 )
-                && ( baseWebappUrl.indexOf( PLACEHOLDER_HOSTNAME ) == -1 ) )
-        {
-            m_baseWebappUrl = baseWebappUrl;
-            return;
-        }
-
-        //url will need to be built
-        //define localhost to be used
-        java.net.InetAddress localHost = null;
-
-        try
-        {
-            localHost = java.net.InetAddress.getLocalHost();
-        }
-        catch ( java.net.UnknownHostException e )
-        {
-            LOG.fatal(
-                    "Unable to get the InetAddress for localhost using InetAddress.getLocalHost().
 Defaults will be used.  This may cause problems with EndpointReferences in Resources." );
-        }
-
-        if ( baseWebappUrl.indexOf( PLACEHOLDER_IPADDRESS ) > -1 )
-        {
-            String ipAddress = null;
-            if ( localHost == null )
-            {
-                ipAddress = "127.0.0.1";
-            }
-            else
-            {
-                ipAddress = localHost.getHostAddress();
-            }
-
-            m_baseWebappUrl =
-                    baseWebappUrl.substring( 0,
-                            baseWebappUrl.indexOf( PLACEHOLDER_IPADDRESS ) ) + ipAddress
-                            + baseWebappUrl.substring( baseWebappUrl.indexOf( PLACEHOLDER_IPADDRESS
)
-                            + PLACEHOLDER_IPADDRESS.length() );
-            return;
-        } //end if
-
-        else if ( baseWebappUrl.indexOf( PLACEHOLDER_HOSTNAME ) > -1 )
-        {
-            String hostname = null;
-            if ( localHost == null )
-            {
-                hostname = "127.0.0.1";
-            }
-            else
-            {
-                hostname = localHost.getHostName();
-            }
 
-            m_baseWebappUrl =
-                    baseWebappUrl.substring( 0,
-                            baseWebappUrl.indexOf( PLACEHOLDER_HOSTNAME ) ) + hostname
-                            + baseWebappUrl.substring( baseWebappUrl.indexOf( PLACEHOLDER_HOSTNAME
)
-                            + PLACEHOLDER_HOSTNAME.length() );
-            return;
-        } //end else if
-    }
-
-    /**
-     * Returns the base webapp url which includes the webapp context. (i.e. http://127.0.0.1:8080/wsrf)
-     *
-     * @return base webapp url
-     */
-    public String getBaseWebappUrl()
-    {
-        return m_baseWebappUrl;
-    }
 
     /**
      * Returns true if the home has been initialized, else false
@@ -538,14 +425,14 @@
         {
             m_resources = getResourceMap();  // in case this.init() was never called for
some reason
         }
-        
+
         try
         {
             initEndpointReference( resource );
             resource.init();
         }
         catch ( RuntimeException re )
-        {
+        {    re.printStackTrace();
             throw new RuntimeException( MSG.getMessage( Keys.FAILED_TO_INIT_RESOURCE, resource,
re ), re );
         }
         LOG.debug( MSG.getMessage( Keys.ADDING_RESOURCE_WITH_ID,
@@ -827,18 +714,6 @@
      */
     protected abstract Map getResourceMap();
 
-    /**
-     * DOCUMENT_ME
-     *
-     * @return DOCUMENT_ME
-     *
-     * @throws java.net.UnknownHostException DOCUMENT_ME
-     */
-    protected String getDefaultUrl()
-            throws java.net.UnknownHostException
-    {
-        return "http://" + java.net.InetAddress.getLocalHost().getHostAddress() + ":8080/wsrf";
-    }
 
     /**
      * This method uses reflection to create an instance of a Resource which contains an
empty constructor.  It will not
@@ -1166,4 +1041,4 @@
             }
         }
     }
-}
\ No newline at end of file
+}

Modified: webservices/wsrf/trunk/src/test/org/apache/ws/resource/properties/AbstractResourcePropertiesTestCase.java
URL: http://svn.apache.org/viewcvs/webservices/wsrf/trunk/src/test/org/apache/ws/resource/properties/AbstractResourcePropertiesTestCase.java?rev=326145&r1=326144&r2=326145&view=diff
==============================================================================
--- webservices/wsrf/trunk/src/test/org/apache/ws/resource/properties/AbstractResourcePropertiesTestCase.java
(original)
+++ webservices/wsrf/trunk/src/test/org/apache/ws/resource/properties/AbstractResourcePropertiesTestCase.java
Tue Oct 18 09:27:49 2005
@@ -19,13 +19,17 @@
 import org.apache.commons.io.CopyUtils;
 import org.apache.ws.resource.properties.impl.XmlBeansResourcePropertySet;
 import org.apache.ws.resource.properties.impl.XmlBeansResourcePropertySetMetaData;
+import org.apache.ws.resource.WsrfRuntime;
 import org.apache.ws.util.jndi.XmlBeanJndiUtils;
 import org.apache.xmlbeans.XmlException;
 import org.apache.xmlbeans.XmlObject;
 import org.apache.xmlbeans.impl.common.XmlErrorPrinter;
 import org.apache.xmlbeans.impl.tool.SchemaCompiler;
+import org.apache.naming.java.javaURLContextFactory;
 import org.oasisOpen.docs.wsrf.x2004.x10.wsrfWSResourceMetadataDescriptor10Draft01.DefinitionsDocument;
 import org.oasisOpen.docs.wsrf.x2004.x10.wsrfWSResourceMetadataDescriptor10Draft01.MetadataDescriptorType;
+
+import javax.naming.Context;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
@@ -33,6 +37,7 @@
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLClassLoader;
+import java.util.Properties;
 
 /**
  * Base class for test cases for WSRP portType impls.
@@ -71,7 +76,7 @@
    {
       try
       {
-         XmlBeanJndiUtils.initJNDI(  );
+         WsrfRuntime.getRuntime().init(new Properties());
          compileSushiPropsXsd(  );
       }
       catch ( Exception e )
@@ -137,8 +142,8 @@
     * @throws MetaDataViolationException DOCUMENT_ME
     */
    protected void initResourcePropsDoc(  )
-   throws XmlException, 
-          IOException, 
+   throws XmlException,
+          IOException,
           MetaDataViolationException
    {
       InputStream in =

Modified: webservices/wsrf/trunk/src/test/wsrf-config.xml
URL: http://svn.apache.org/viewcvs/webservices/wsrf/trunk/src/test/wsrf-config.xml?rev=326145&r1=326144&r2=326145&view=diff
==============================================================================
--- webservices/wsrf/trunk/src/test/wsrf-config.xml (original)
+++ webservices/wsrf/trunk/src/test/wsrf-config.xml Tue Oct 18 09:27:49 2005
@@ -2,44 +2,18 @@
 
 <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
 
-<beans>
+    <beans>
 
-  <bean name="global/DefaultParameters" class="org.apache.ws.util.jndi.DefaultParameters">
-    <property name="factory">
-      <value>org.apache.ws.util.jndi.BeanFactory</value>
-    </property>
-  </bean>
+      <bean name="global/WsrfRuntime" class="org.apache.ws.resource.WsrfRuntime" factory-method="getRuntime">
+        <property name="baseWebappUrl">
+           <!--
+          The value of the baseWebappUrl property may contain the following:
+           o the marker $IP_ADDRESS$ in which case we will attempt to determine the IP address
at runtime. (Do not use on multi-homed systems)
+           o the marker $HOST_NAME$ in which case we will attempt to determine the host name
at runtime
+           o NO Marker in which case whatever value you add will be static and used.
+           -->
+           <value>http://$IP_ADDRESS$:8080/wsrf</value>
+        </property>
+      </bean>
 
-  <bean name="test/mybean" class="org.apache.ws.resource.TestBean">
-    <property name="myList">
-      <list>
-        <value>a list element followed by a reference</value>
-        <ref bean="global/DefaultParameters"/>
-      </list>
-    </property>
-    <property name="myMap">
-      <map>
-        <entry>
-          <key>
-            <value>yup an entry</value>
-          </key>
-          <value>just some string</value>
-        </entry>
-        <entry>
-          <key>
-            <value>yup a ref</value>
-          </key>
-          <ref bean="global/DefaultParameters"/>
-        </entry>
-      </map>
-    </property>
-  </bean>
-
-  <bean name="resource/filesystem" class="org.apache.ws.resource.example.filesystem.FilesystemHome"
init-method="init">
-    <property name="portComponentName"><value>filesystem</value></property>
-    <property name="serviceClass"><value>org.apache.ws.resource.example.filesystem.FilesystemService</value></property>
-    <property name="resourceClass"><value>org.apache.ws.resource.example.filesystem.FilesystemResource</value></property>
-    <property name="resourceIdentifierReferenceParameterName"><value>{http://ws.apache.org/resource/example/filesystem}ResourceIdentifier</value></property>
-  </bean>
-
-</beans>
+    </beans>

Modified: webservices/wsrf/trunk/src/webapp/WEB-INF/classes/wsrf-config.xml
URL: http://svn.apache.org/viewcvs/webservices/wsrf/trunk/src/webapp/WEB-INF/classes/wsrf-config.xml?rev=326145&r1=326144&r2=326145&view=diff
==============================================================================
--- webservices/wsrf/trunk/src/webapp/WEB-INF/classes/wsrf-config.xml (original)
+++ webservices/wsrf/trunk/src/webapp/WEB-INF/classes/wsrf-config.xml Tue Oct 18 09:27:49
2005
@@ -1,6 +1,6 @@
-    <?xml version="1.0"?>
+<?xml version="1.0"?>
 
-    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
+<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
 
     <beans>
 



Mime
View raw message