You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ag...@apache.org on 2009/02/17 12:49:59 UTC

svn commit: r744967 - in /qpid/trunk/qpid/java/management/client/src: example/ example/org/apache/qpid/management/example/ main/java/org/apache/qpid/management/ main/java/org/apache/qpid/management/wsdm/capabilities/ main/java/org/apache/qpid/managemen...

Author: agazzarini
Date: Tue Feb 17 11:49:58 2009
New Revision: 744967

URL: http://svn.apache.org/viewvc?rev=744967&view=rev
Log:
QPID-1606 : Connect example + Connect interface Improvements

Added:
    qpid/trunk/qpid/java/management/client/src/example/ConnectWithBroker.out.ok
    qpid/trunk/qpid/java/management/client/src/example/org/apache/qpid/management/example/ConnectWithBrokerExample.java
    qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/common/UnableToConnectWithBrokerFault.java
Modified:
    qpid/trunk/qpid/java/management/client/src/example/org/apache/qpid/management/example/AbstractQManExample.java
    qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/Names.java
    qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/QManAdapterCapability.java
    qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/common/QManFault.java

Added: qpid/trunk/qpid/java/management/client/src/example/ConnectWithBroker.out.ok
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/management/client/src/example/ConnectWithBroker.out.ok?rev=744967&view=auto
==============================================================================
--- qpid/trunk/qpid/java/management/client/src/example/ConnectWithBroker.out.ok (added)
+++ qpid/trunk/qpid/java/management/client/src/example/ConnectWithBroker.out.ok Tue Feb 17 11:49:58 2009
@@ -0,0 +1,81 @@
+                 ConnectWithBrokerExample 
+-------------------------------------------------------------------
+
+This example shows how to connect QMan with a broker using
+the adapter interface.
+
+Type enter to proceed...
+
+[CLIENT TRACE] SOAP envelope contents (outgoing):
+
+<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
+    <soap:Header>
+        <wsa:To xmlns:wsa="http://www.w3.org/2005/08/addressing">http://romagazzarini:8080/qman/services/adapter</wsa:To>
+        <wsa:Action xmlns:wsa="http://www.w3.org/2005/08/addressing">http://amqp.apache.org/qpid/management/qman/Connect</wsa:Action>
+        <wsa:MessageID xmlns:wsa="http://www.w3.org/2005/08/addressing">uuid:48bf9a1b-f814-7391-b5cf-d163de4ac068</wsa:MessageID>
+        <wsa:From xmlns:wsa="http://www.w3.org/2005/08/addressing">
+            <wsa:Address>http://www.w3.org/2005/08/addressing/role/anonymous</wsa:Address>
+        </wsa:From>
+    </soap:Header>
+    <soap:Body>
+        <qman:Connect xmlns:qman="http://amqp.apache.org/qpid/management/qman">
+            <qman:host>sofia.gazzax.com</qman:host>
+            <qman:port>5672</qman:port>
+            <qman:username>test</qman:username>
+            <qman:password>a.gazzarini</qman:password>
+            <qman:virtualHost>p1ssw9rd</qman:virtualHost>
+            <qman:initialPoolCapacity>1</qman:initialPoolCapacity>
+            <qman:maxPoolCapacity>4</qman:maxPoolCapacity>
+            <qman:maxWaitTimeout>2000</qman:maxWaitTimeout>
+        </qman:Connect>
+    </soap:Body>
+</soap:Envelope>
+
+[CLIENT TRACE] SOAP envelope contents (incoming):
+
+<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
+    <soap:Header>
+        <wsa:To xmlns:wsa="http://www.w3.org/2005/08/addressing">http://www.w3.org/2005/08/addressing/role/anonymous</wsa:To>
+        <wsa:Action xmlns:wsa="http://www.w3.org/2005/08/addressing">http://www.w3.org/2005/08/addressing/fault</wsa:Action>
+        <wsa:MessageID xmlns:wsa="http://www.w3.org/2005/08/addressing">uuid:220bfe54-d5f4-4a04-794c-0f5d99a64567</wsa:MessageID>
+        <wsa:RelatesTo RelationshipType="wsa:Reply" xmlns:wsa="http://www.w3.org/2005/08/addressing">uuid:48bf9a1b-f814-7391-b5cf-d163de4ac068</wsa:RelatesTo>
+        <wsa:From xmlns:wsa="http://www.w3.org/2005/08/addressing">
+            <wsa:Address>http://romagazzarini:8080/qman/services/adapter</wsa:Address>
+        </wsa:From>
+    </soap:Header>
+    <soap:Body>
+        <soap:Fault>
+            <soap:Code xmlns:qman="http://amqp.apache.org/qpid/management/qman">
+                <soap:Value>qman:QMan</soap:Value>
+            </soap:Code>
+            <soap:Reason>
+                <soap:Text>Unable to connect with the requested broker. Underlying exception message was null</soap:Text>
+            </soap:Reason>
+            <soap:Detail>
+                <qman:OperationInvocationFault xmlns:qman="http://amqp.apache.org/qpid/management/qman">
+                    <wsrf-bf:Timestamp xmlns:wsrf-bf="http://docs.oasis-open.org/wsrf/bf-2">2009-02-17T10:37:08+01:00</wsrf-bf:Timestamp>
+                    <wsrf-bf:OriginatorReference xmlns:wsrf-bf="http://docs.oasis-open.org/wsrf/bf-2">
+                        <wsa:ReferenceParameters xmlns:wsa="http://www.w3.org/2005/08/addressing"/>
+                        <wsa:Address xmlns:wsa="http://www.w3.org/2005/08/addressing">http://romagazzarini:8080/qman/services/adapter</wsa:Address>
+                    </wsrf-bf:OriginatorReference>
+                    <qman:host>sofia.gazzax.com</qman:host>
+                    <qman:port>5672</qman:port>
+                    <qman:username>test</qman:username>
+                    <qman:virtualHost>p1ssw9rd</qman:virtualHost>
+                </qman:OperationInvocationFault>
+            </soap:Detail>
+        </soap:Fault>
+    </soap:Body>
+</soap:Envelope>
+
+-----------------------EXAMPLE FAILURE-----------
+Not well-defined exception was detected while
+running the example.
+org.apache.muse.ws.addressing.soap.SoapFault: Unable to connect with the requested broker. Underlying exception message was null
+	at org.apache.muse.core.AbstractResourceClient.invoke(AbstractResourceClient.java:298)
+	at org.apache.muse.core.AbstractResourceClient.invoke(AbstractResourceClient.java:232)
+	at org.apache.muse.core.AbstractResourceClient.invoke(AbstractResourceClient.java:211)
+	at org.apache.qpid.management.example.ConnectWithBrokerExample.executeExample(ConnectWithBrokerExample.java:146)
+	at org.apache.qpid.management.example.ConnectWithBrokerExample.execute(ConnectWithBrokerExample.java:97)
+	at org.apache.qpid.management.example.ConnectWithBrokerExample.main(ConnectWithBrokerExample.java:201)
+--------------------------------------------------------

Modified: qpid/trunk/qpid/java/management/client/src/example/org/apache/qpid/management/example/AbstractQManExample.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/management/client/src/example/org/apache/qpid/management/example/AbstractQManExample.java?rev=744967&r1=744966&r2=744967&view=diff
==============================================================================
--- qpid/trunk/qpid/java/management/client/src/example/org/apache/qpid/management/example/AbstractQManExample.java (original)
+++ qpid/trunk/qpid/java/management/client/src/example/org/apache/qpid/management/example/AbstractQManExample.java Tue Feb 17 11:49:58 2009
@@ -32,7 +32,7 @@
  */
 public abstract class AbstractQManExample
 {
-	private final static String LINE_SEPARATOR = System.getProperty("line.separator","\n");
+	final static String LINE_SEPARATOR = System.getProperty("line.separator","\n");
 	protected final static String PREFIX = "qman";
 
 	/**
@@ -104,7 +104,7 @@
 		}
 	}		
 	
-	private void waitForUserInput(String message) throws IOException {
+	protected void waitForUserInput(String message) throws IOException {
 		System.out.println(message);
 		System.in.read();
 	}
@@ -118,7 +118,7 @@
 	 * @param port the port where QMan is running.
 	 * @throws Exception when the example fails (not at application level).
 	 */
-	abstract void executeExample(String host, int port) throws Exception;
+	void executeExample(String host, int port) throws Exception{};
 	
 	/**
 	 * Returns the endpoint reference of the adapter service.

Added: qpid/trunk/qpid/java/management/client/src/example/org/apache/qpid/management/example/ConnectWithBrokerExample.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/management/client/src/example/org/apache/qpid/management/example/ConnectWithBrokerExample.java?rev=744967&view=auto
==============================================================================
--- qpid/trunk/qpid/java/management/client/src/example/org/apache/qpid/management/example/ConnectWithBrokerExample.java (added)
+++ qpid/trunk/qpid/java/management/client/src/example/org/apache/qpid/management/example/ConnectWithBrokerExample.java Tue Feb 17 11:49:58 2009
@@ -0,0 +1,240 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.management.example;
+
+import javax.xml.namespace.QName;
+
+import org.apache.muse.core.proxy.ProxyHandler;
+import org.apache.muse.core.proxy.ReflectionProxyHandler;
+import org.apache.muse.ws.addressing.EndpointReference;
+import org.apache.muse.ws.resource.remote.WsResourceClient;
+
+/**
+ * This example shows how to connect QMan with a broker using the adapter interface.
+ * As you can see the interface is very simple and requests you the following parameters :
+ * 
+ * <ul>
+ * 	<li>hostname : the host (hostname or ip) where the broker is running;</li>
+ * 	<li>port : the port number of the running broker;</li>
+ * 	<li>virtual host  : the name of the virtual host;</li>
+ * 	<li>username : the username that will be used for estabilshing connection.</li>
+ * 	<li>password : the password that will be used for estabilshing connection.</li>
+ * 	<li>initial pool capacity : the initial size of broker connection pool. </li>
+ * 	<li>maximum pool capacity :  the max allowed size of broker connection pool.</li>
+ * 	<li>maximum wait timeout  :  the max wait timeout for retrieving connections.</li>
+ * </ul>
+ * 
+ * @author Andrea Gazzarini
+ */
+public class ConnectWithBrokerExample extends AbstractQManExample
+{
+	
+	/**
+	 * Executes the connect example.
+	 * Although not specified explicitly, the input array MUST contains in the following order :
+	 * 
+	 * <ul>
+	 * 	<li>host : the hostname where QMan is running;</li>
+	 * 	<li>port : the port number where QMan is running;</li>
+	 * 	<li>qpid host : the host  name where QPid is running;</li>
+	 * 	<li>qpid port : the port number where Qpid is running;</li>
+	 * 	<li>virtual host : the virtual host name;</li>
+	 * 	<li>username : the username that will be used for estabilshing connection.</li>
+	 * 	<li>password : the password that will be used for estabilshing connection.</li>
+	 * 	<li>initial pool capacity : the initial size of broker connection pool. </li>
+	 * 	<li>maximum pool capacity :  the max allowed size of broker connection pool.</li>
+	 * 	<li>maximum wait timeout  :  the max wait timeout for retrieving connections.</li>
+	 * </ul>
+	 * 
+	 * Note that this example differs from the others (and therefore is overriding the execute() method) because 
+	 * in this case we are not using the "standard" WSRF interface but instead an additional custom 
+	 * "operation" on a WS-Resource.
+	 * 
+	 * @param arguments the commadn line arguments.
+	 */
+	void execute(String [] arguments)
+	{
+		if (arguments.length != 10){
+			printUsageAndExit("invalid command line was given.");
+		}
+
+		try 
+		{
+			// 1) Parses command line arguments...
+			String host = arguments[0];
+			int port = Integer.parseInt(arguments[1]);
+			String qpidHost = arguments[2];
+			int qpidPort = Integer.parseInt(arguments[3]);
+			String virtualHost = arguments[4];
+			String username = arguments[5];
+			String password = arguments[6];
+			int initPoolCapacity = Integer.parseInt(arguments[7]);
+			int maxPoolCapacity = Integer.parseInt(arguments[8]);
+			long maxWaitTimeout = Long.parseLong(arguments[9]);
+			
+			printOutExampleDescription();
+			
+			waitForUserInput("Type enter to proceed...");
+			
+			executeExample(
+					host, 
+					port,
+					qpidHost,
+					qpidPort,
+					virtualHost,
+					username,
+					password,
+					initPoolCapacity,
+					maxPoolCapacity,
+					maxWaitTimeout);
+			
+		} catch(NumberFormatException exception)
+		{
+			printUsageAndExit("Unable to run the example. Please ensure that all numeric values are correctly supplied.");
+		} catch(Exception exception)
+		{
+			System.out.println("-----------------------EXAMPLE FAILURE-----------");
+			System.out.println("Not well-defined exception was detected while");
+			System.out.println("running the example.");
+			exception.printStackTrace(System.out);
+			System.out.println("--------------------------------------------------------");						
+		}
+	}			
+	
+	/** 
+	 * Connects QMan with a broker.
+	 * 
+	 *@param host the hostname where QMan is running;
+	 *@param port the port number where QMan is running;
+	 *@param qpidHost the host  name where QPid is running;
+	 *@param qpidPort the port number where Qpid is running;
+	 *@param virtualHost the virtual host name;
+	 *@param username the username that will be used for estabilshing connection.
+	 *@param password the password that will be used for estabilshing connection.
+	 *@param initPoolCapacity the initial size of broker connection pool. 
+	 *@param maxPoolCapacity the max allowed size of broker connection pool.
+	 *@param maxWaitTimeout the max wait timeout for retrieving connections.
+	 *
+	 * @throws Exception when the example fails (not at application level).
+	 */
+	void executeExample(String host, int port, String qpidHost, int qpidPort, String virtualHost, String username, String password, int initPoolCapacity, int maxPoolCapacity, long maxWaitTimeout) throws Exception
+	{		
+		// 1) Creates an endpoint reference of the adapter service...
+		EndpointReference adapterEndpointReference = getAdapterEndpointReference(host, port);
+		WsResourceClient adapterClient = new WsResourceClient(adapterEndpointReference);
+		adapterClient.setTrace(true);
+		
+		// 2) Creates the Adapter service client...
+		adapterClient.invoke(
+				getProxyHandler(), 
+				new Object[]{
+					qpidHost,
+					qpidPort,
+					username,
+					password,
+					virtualHost,
+					initPoolCapacity,
+					maxPoolCapacity,
+					maxWaitTimeout});
+	}
+	
+	/**
+	 * Prints out a description of this example.
+	 */
+	void printOutExampleDescription()
+	{
+		System.out.println("                 "+getClass().getSimpleName()+" ");
+		System.out.println("-------------------------------------------------------------------");
+		System.out.println();
+		System.out.println("This example shows how to connect QMan with a broker using");
+		System.out.println("the adapter interface.");
+		System.out.println();
+	}
+
+	/**
+	 * A proxy handler is a module needed in order to make a capability 
+	 * service invocation.
+	 * It contains logic to serialize and deserialize request, response, input and 
+	 * output parameters during a web service invocation.
+	 * 
+	 * @return a proxy handler.
+	 */
+	private ProxyHandler getProxyHandler()
+	{
+        ProxyHandler handler = new ReflectionProxyHandler();
+        handler.setAction("http://amqp.apache.org/qpid/management/qman/Connect");
+        handler.setRequestName(new QName("http://amqp.apache.org/qpid/management/qman", "Connect", PREFIX));
+        handler.setRequestParameterNames(new QName[]{
+        		new QName("http://amqp.apache.org/qpid/management/qman", "host", PREFIX),
+                new QName("http://amqp.apache.org/qpid/management/qman", "port", PREFIX),
+                new QName("http://amqp.apache.org/qpid/management/qman", "username", PREFIX),
+                new QName("http://amqp.apache.org/qpid/management/qman", "password", PREFIX),
+                new QName("http://amqp.apache.org/qpid/management/qman", "virtualHost", PREFIX),
+                new QName("http://amqp.apache.org/qpid/management/qman", "initialPoolCapacity", PREFIX),
+                new QName("http://amqp.apache.org/qpid/management/qman", "maxPoolCapacity", PREFIX),
+                new QName("http://amqp.apache.org/qpid/management/qman", "maxWaitTimeout", PREFIX)});
+        handler.setResponseName(new QName("http://amqp.apache.org/qpid/management/qman", "ConnectResponse", PREFIX));
+        handler.setReturnType(null);
+        return handler;
+	}
+	
+	public static void main(String[] arguments)
+	{
+		new ConnectWithBrokerExample().execute(arguments);
+	}
+	
+	static void printUsageAndExit(String reason)
+	{
+		StringBuilder builder = new StringBuilder();
+		builder.append("WARNING! Unable to run this sample : ")
+			.append(reason)
+			.append(LINE_SEPARATOR)
+			.append("-------------------------------------------------------------")
+			.append(LINE_SEPARATOR)			
+			.append("Expected command line args for this sample are :")
+			.append(LINE_SEPARATOR)
+			.append(LINE_SEPARATOR)
+			.append("1) host : ip or host name where QMan is running.")
+			.append(LINE_SEPARATOR)
+			.append("2) port : port number where QMan is running.")
+			.append(LINE_SEPARATOR)
+			.append("3) qpid host : port number where Qpid is running.")
+			.append(LINE_SEPARATOR)
+			.append("4) qpid port : port number where Qpid is running.")
+			.append(LINE_SEPARATOR)
+			.append("5) virtual host : virtual host name.")
+			.append(LINE_SEPARATOR)
+			.append("6) username : port number where QMan is running.")
+			.append(LINE_SEPARATOR)
+			.append("7) password : port number where QMan is running.")
+			.append(LINE_SEPARATOR)
+			.append("8) initial pool capacity : port number where QMan is running.")
+			.append(LINE_SEPARATOR)
+			.append("9) max pool capacity : port number where QMan is running.")
+			.append(LINE_SEPARATOR)
+			.append("10) max wait timeout : port number where QMan is running.")
+			.append(LINE_SEPARATOR)
+			
+			.append("------------------------------------------------------------");
+		System.out.println(builder);
+		System.exit(1);
+	}	
+}
\ No newline at end of file

Modified: qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/Names.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/Names.java?rev=744967&r1=744966&r2=744967&view=diff
==============================================================================
--- qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/Names.java (original)
+++ qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/Names.java Tue Feb 17 11:49:58 2009
@@ -170,11 +170,31 @@
 			"EventsLifeCycleTopic",
 			Names.PREFIX);
 	
+	public final static QName HOST_QNAME = new QName(
+			Names.NAMESPACE_URI,
+			"host",
+			Names.PREFIX);
+
+	public final static QName PORT_QNAME = new QName(
+			Names.NAMESPACE_URI,
+			"port",
+			Names.PREFIX);
+
+	public final static QName USERNAME_QNAME= new QName(
+			Names.NAMESPACE_URI,
+			"username",
+			Names.PREFIX);
+
+	public final static QName VIRTUAL_HOST_QNAME= new QName(
+			Names.NAMESPACE_URI,
+			"virtualHost",
+			Names.PREFIX);
+
 	public final static QName UNKNOWN_OBJECT_TYPE_LIFECYLE_TOPIC_NAME= new QName(
 			Names.NAMESPACE_URI,
 			"UnclassifiedLifeCycleTopic",
 			Names.PREFIX);
-	
+
 	
 	public final static String NAME_ATTRIBUTE = "name";
 	public final static String MODIFIABILITY = "modifiability";
@@ -191,4 +211,6 @@
 	
 	public final static String ADAPTER_HOST_PROPERTY_NAME = "qman.host";		
 	public final static String ADAPTER_PORT_PROPERTY_NAME = "qman.port";	
+	
+	
 }
\ No newline at end of file

Modified: qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/QManAdapterCapability.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/QManAdapterCapability.java?rev=744967&r1=744966&r2=744967&view=diff
==============================================================================
--- qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/QManAdapterCapability.java (original)
+++ qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/QManAdapterCapability.java Tue Feb 17 11:49:58 2009
@@ -53,6 +53,7 @@
 import org.apache.qpid.management.configuration.Configuration;
 import org.apache.qpid.management.jmx.EntityLifecycleNotification;
 import org.apache.qpid.management.wsdm.common.ThreadSessionManager;
+import org.apache.qpid.management.wsdm.common.UnableToConnectWithBrokerFault;
 import org.apache.qpid.management.wsdm.muse.engine.WSDMAdapterEnvironment;
 import org.apache.qpid.management.wsdm.muse.serializer.ByteArraySerializer;
 import org.apache.qpid.management.wsdm.notifications.LifeCycleEvent;
@@ -347,7 +348,14 @@
 							long.class.getName()});
 		} catch(Exception exception)
 		{			
-			throw new SoapFault(exception);
+			LOGGER.error(Messages.QMAN_100017_UNABLE_TO_CONNECT,host,port);
+			throw new UnableToConnectWithBrokerFault(
+					getResource().getEndpointReference(),
+					host,
+					port,
+					username,
+					virtualHost,
+					exception.getMessage());
 		}
 	}
 		

Modified: qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/common/QManFault.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/common/QManFault.java?rev=744967&r1=744966&r2=744967&view=diff
==============================================================================
--- qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/common/QManFault.java (original)
+++ qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/common/QManFault.java Tue Feb 17 11:49:58 2009
@@ -35,7 +35,7 @@
 	private static final long serialVersionUID = 5977379710882983474L;
 	private final static QName SERVICE = new QName(
 			Names.NAMESPACE_URI,
-			"Service",
+			"QMan",
 			Names.PREFIX);
 	
 	private final static QName EXCEPTION_QNAME = new QName(

Added: qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/common/UnableToConnectWithBrokerFault.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/common/UnableToConnectWithBrokerFault.java?rev=744967&view=auto
==============================================================================
--- qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/common/UnableToConnectWithBrokerFault.java (added)
+++ qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/common/UnableToConnectWithBrokerFault.java Tue Feb 17 11:49:58 2009
@@ -0,0 +1,86 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.management.wsdm.common;
+
+import javax.xml.namespace.QName;
+
+import org.apache.muse.util.xml.XmlUtils;
+import org.apache.muse.ws.addressing.EndpointReference;
+import org.apache.qpid.management.Names;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * This is the exception encapsulating the fault that will be thrown in case of 
+ * broker connection failure.
+ * 
+ * @author Andrea Gazzarini
+ */
+public class UnableToConnectWithBrokerFault extends QManFault 
+{
+	private static final long serialVersionUID = 5977379710882983474L;
+
+	private String _host;
+	private int _port;
+	private String _username;
+	private String _virtualHostName;
+	
+	/**
+	 * Builds a new exception with the given endpoint reference and connection data.
+	 * 
+	 * @param host the requested qpid host.
+	 * @param port the requested qpid port.
+	 * @param username the username used for estabilishing connection.
+	 * @param virtualHostName the name of the target virtual host..
+	 */
+	public UnableToConnectWithBrokerFault(
+			EndpointReference endpointReference, 
+			String host,
+			int port,
+			String username,
+			String virtualHostName,
+			String message) 
+	{
+		super(
+				endpointReference,
+				new QName(
+						Names.NAMESPACE_URI,
+						"UnableToConnectFault",
+						Names.PREFIX),
+				String.format("Unable to connect with the requested broker. Underlying exception message was %s",message));
+		this._host = host;
+		this._port = port;
+		this._username = username;
+		this._virtualHostName = virtualHostName;
+	}
+	
+	@Override
+	public Element getDetail()
+	{
+		Element detail = super.getDetail();
+		Document owner = detail.getOwnerDocument();
+		detail.appendChild(XmlUtils.createElement(owner, Names.HOST_QNAME,_host));
+		detail.appendChild(XmlUtils.createElement(owner, Names.PORT_QNAME,_port));
+		detail.appendChild(XmlUtils.createElement(owner, Names.USERNAME_QNAME,_username));
+		detail.appendChild(XmlUtils.createElement(owner, Names.VIRTUAL_HOST_QNAME,_virtualHostName));
+		return detail;
+	}
+}
\ No newline at end of file



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org