SCOUT-106, SCOUT-107 turns out the spec requires the javax.xml.registry.queryManagerURL to be defined (you should throw an InvalidRequestException rather then defaulting it to something)

git-svn-id: https://svn.apache.org/repos/asf/juddi/scout/trunk@1240536 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/pom.xml b/pom.xml
index 0e13aa1..8a1dd16 100644
--- a/pom.xml
+++ b/pom.xml
@@ -8,7 +8,7 @@
 	</parent>
 	<groupId>org.apache.juddi.scout</groupId>
 	<artifactId>scout</artifactId>
-	<version>1.2.6-SNAPSHOT</version>
+	<version>1.2.5-SNAPSHOT</version>
 	<packaging>bundle</packaging>
 
 	<properties>
diff --git a/src/main/java/org/apache/ws/scout/registry/ConnectionFactoryImpl.java b/src/main/java/org/apache/ws/scout/registry/ConnectionFactoryImpl.java
index 07c4a21..93036f4 100644
--- a/src/main/java/org/apache/ws/scout/registry/ConnectionFactoryImpl.java
+++ b/src/main/java/org/apache/ws/scout/registry/ConnectionFactoryImpl.java
@@ -23,6 +23,7 @@
 import javax.xml.registry.Connection;

 import javax.xml.registry.ConnectionFactory;

 import javax.xml.registry.FederatedConnection;

+import javax.xml.registry.InvalidRequestException;

 import javax.xml.registry.JAXRException;

 import javax.xml.registry.UnsupportedCapabilityException;

 

@@ -63,6 +64,9 @@
 

     public Connection createConnection() throws JAXRException

     {

+        //The JAXR spec requires the queryManagerURL to be defined

+        String queryManagerURL = properties.getProperty(QUERYMANAGER_PROPERTY);

+        if (queryManagerURL==null) throw new InvalidRequestException("Missing required property " + QUERYMANAGER_PROPERTY);

         return new ConnectionImpl(properties);

     }

 

diff --git a/src/main/java/org/apache/ws/scout/registry/ConnectionImpl.java b/src/main/java/org/apache/ws/scout/registry/ConnectionImpl.java
index 29c1c68..5cd0fca 100644
--- a/src/main/java/org/apache/ws/scout/registry/ConnectionImpl.java
+++ b/src/main/java/org/apache/ws/scout/registry/ConnectionImpl.java
@@ -21,6 +21,7 @@
 import java.util.Set;

 

 import javax.xml.registry.Connection;

+import javax.xml.registry.InvalidRequestException;

 import javax.xml.registry.JAXRException;

 import javax.xml.registry.RegistryService;

 

@@ -53,7 +54,7 @@
     private String uddiVersion;

     UDDIClerkManager manager = null;

 

-    public ConnectionImpl(Properties properties)

+    public ConnectionImpl(Properties properties) throws InvalidRequestException

     {

         postalScheme = properties.getProperty(ConnectionFactoryImpl.POSTALADDRESSSCHEME_PROPERTY);

         String val = properties.getProperty(ConnectionFactoryImpl.MAXROWS_PROPERTY);

diff --git a/src/main/java/org/apache/ws/scout/registry/RegistryImpl.java b/src/main/java/org/apache/ws/scout/registry/RegistryImpl.java
index 7d8397c..cfa017b 100644
--- a/src/main/java/org/apache/ws/scout/registry/RegistryImpl.java
+++ b/src/main/java/org/apache/ws/scout/registry/RegistryImpl.java
@@ -34,6 +34,7 @@
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.registry.InvalidRequestException;
 import javax.xml.transform.stream.StreamSource;
 
 import org.apache.commons.logging.Log;
@@ -105,8 +106,6 @@
 
 public class RegistryImpl implements IRegistry {
 
-	public static final String DEFAULT_INQUIRY_ENDPOINT        = "http://localhost:8080/juddi/inquiry";
-	public static final String DEFAULT_PUBLISH_ENDPOINT        = "http://localhost:8080/juddi/publish";
 	public static final String DEFAULT_ADMIN_ENDPOINT          = "http://localhost:8080/juddi/admin";
 	public static final String DEFAULT_TRANSPORT_CLASS         = "org.apache.ws.scout.transport.SaajTransport";
 	public static final String DEFAULT_SECURITY_PROVIDER       = "com.sun.net.ssl.internal.ssl.Provider";
@@ -135,26 +134,32 @@
 
 	/**
 	 * Creates a new instance of RegistryImpl.
+	 * @throws InvalidRequestException 
 	 */
-	public RegistryImpl(Properties props) {
+	public RegistryImpl(Properties props) throws InvalidRequestException {
 		super();
 
 		this.init(props);
 	}
 
 	/**
+	 * @throws InvalidRequestException 
 	 * 
 	 */
-	private void init(Properties props) {
+	private void init(Properties props) throws InvalidRequestException {
 		// We need to have a non-null Properties
 		// instance so initialization takes place.
 		if (props == null) props = new Properties();
 
 		// Override defaults with specific specific values
 		try {
-			setInquiryURI(new URI(props.getProperty(ConnectionFactoryImpl.QUERYMANAGER_PROPERTY,DEFAULT_INQUIRY_ENDPOINT)));
-			setPublishURI(new URI(props.getProperty(ConnectionFactoryImpl.LIFECYCLEMANAGER_PROPERTY, DEFAULT_PUBLISH_ENDPOINT)));
-			setSecurityURI(new URI(props.getProperty(ConnectionFactoryImpl.SECURITYMANAGER_PROPERTY, getPublishURI().toString())));
+			setInquiryURI(new URI(props.getProperty(ConnectionFactoryImpl.QUERYMANAGER_PROPERTY)));
+			if (props.containsKey(ConnectionFactoryImpl.LIFECYCLEMANAGER_PROPERTY)) {
+			    setPublishURI(new URI(props.getProperty(ConnectionFactoryImpl.LIFECYCLEMANAGER_PROPERTY)));
+			}
+			String securityURL = props.getProperty(ConnectionFactoryImpl.SECURITYMANAGER_PROPERTY, 
+			        props.getProperty(ConnectionFactoryImpl.LIFECYCLEMANAGER_PROPERTY));
+			if (securityURL!=null) setSecurityURI(new URI(securityURL));
 			setAdminURI(new URI(props.getProperty(ConnectionFactoryImpl.ADMIN_ENDPOINT_PROPERTY, DEFAULT_ADMIN_ENDPOINT)));
 			setSecurityProvider(props.getProperty(ConnectionFactoryImpl.SECURITY_PROVIDER_PROPERTY, DEFAULT_SECURITY_PROVIDER));
 			setProtocolHandler(props.getProperty(ConnectionFactoryImpl.PROTOCOL_HANDLER_PROPERTY, DEFAULT_PROTOCOL_HANDLER));
@@ -165,9 +170,8 @@
 			JAXBContext context = JAXBContextUtil.getContext(JAXBContextUtil.UDDI_V2_VERSION);
             unmarshaller = context.createUnmarshaller(); 
             marshaller = context.createMarshaller();
-            
 		} catch (URISyntaxException muex) {
-			throw new RuntimeException(muex);
+			throw new InvalidRequestException(muex.getMessage(),muex);
 		} catch(JAXBException e) {
            throw new RuntimeException(e);
         }
diff --git a/src/main/java/org/apache/ws/scout/registry/RegistryV3Impl.java b/src/main/java/org/apache/ws/scout/registry/RegistryV3Impl.java
index bb471e4..9d42986 100644
--- a/src/main/java/org/apache/ws/scout/registry/RegistryV3Impl.java
+++ b/src/main/java/org/apache/ws/scout/registry/RegistryV3Impl.java
@@ -35,6 +35,7 @@
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.registry.InvalidRequestException;
 import javax.xml.transform.stream.StreamSource;
 
 import org.apache.commons.logging.Log;
@@ -144,17 +145,19 @@
 
 	/**
 	 * Creates a new instance of RegistryImpl.
+	 * @throws InvalidRequestException 
 	 */
-	public RegistryV3Impl(Properties props, String nodeName, String managerName) {
+	public RegistryV3Impl(Properties props, String nodeName, String managerName) throws InvalidRequestException {
 		super();
 
 		this.init(props, nodeName, managerName);
 	}
 
 	/**
+	 * @throws InvalidRequestException 
 	 * 
 	 */
-	private void init(Properties props, String nodeName, String managerName) {
+	private void init(Properties props, String nodeName, String managerName) throws InvalidRequestException {
 	    this.nodeName = nodeName;
 	    this.managerName = managerName;
         // We need to have a non-null Properties
@@ -182,7 +185,7 @@
             marshaller = context.createMarshaller();
             
         } catch (URISyntaxException muex) {
-            throw new RuntimeException(muex);
+            throw new InvalidRequestException(muex.getMessage(), muex);
         } catch(JAXBException e) {
            throw new RuntimeException(e);
         }
diff --git a/src/test/java/org/apache/ws/scout/registry/ConnectionFactoryTest.java b/src/test/java/org/apache/ws/scout/registry/ConnectionFactoryTest.java
index 5e29e29..3dedd40 100644
--- a/src/test/java/org/apache/ws/scout/registry/ConnectionFactoryTest.java
+++ b/src/test/java/org/apache/ws/scout/registry/ConnectionFactoryTest.java
@@ -141,18 +141,24 @@
     public void testCreateConnectionWithNullLifeCycleURL() throws JAXRException {

         Properties properties = new Properties();

         properties.setProperty(ConnectionFactoryImpl.QUERYMANAGER_PROPERTY, "http://localhost");

-        factory.setProperties(properties);

-        Connection c = factory.createConnection();

+        Connection c = null;

         try {

+            factory.setProperties(properties);

+            c = factory.createConnection();

             assertEquals(ConnectionImpl.class, c.getClass());

+        } catch (Exception e) {

+            fail("it's ok to have a null lifeCycleURL");

         } finally {

-            c.close();

+            if (c!=null) c.close();

         }

     }

 

     public void testCreateConnectionWithNullQueryURL() {

         try {

             factory.createConnection();

+            fail("should have thrown an InvalidRequestException");

+        } catch (InvalidRequestException ire) {

+            //expected

         } catch (Exception e) {

             fail("threw Exception");

         }