UnableToConnectWithBrokerFault.java
01 /*
02  *
03  * Licensed to the Apache Software Foundation (ASF) under one
04  * or more contributor license agreements.  See the NOTICE file
05  * distributed with this work for additional information
06  * regarding copyright ownership.  The ASF licenses this file
07  * to you under the Apache License, Version 2.0 (the
08  * "License"); you may not use this file except in compliance
09  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  */
21 package org.apache.qpid.management.wsdm.common;
22 
23 import javax.xml.namespace.QName;
24 
25 import org.apache.muse.util.xml.XmlUtils;
26 import org.apache.muse.ws.addressing.EndpointReference;
27 import org.apache.qpid.management.Names;
28 import org.w3c.dom.Document;
29 import org.w3c.dom.Element;
30 
31 /**
32  * This is the exception encapsulating the fault that will be thrown in case of 
33  * broker connection failure.
34  
35  @author Andrea Gazzarini
36  */
37 public class UnableToConnectWithBrokerFault extends QManFault 
38 {
39   private static final long serialVersionUID = 5977379710882983474L;
40 
41   private String _host;
42   private int _port;
43   private String _username;
44   private String _virtualHostName;
45   
46   /**
47    * Builds a new exception with the given endpoint reference and connection data.
48    
49    @param host the requested qpid host.
50    @param port the requested qpid port.
51    @param username the username used for estabilishing connection.
52    @param virtualHostName the name of the target virtual host..
53    */
54   public UnableToConnectWithBrokerFault(
55       EndpointReference endpointReference, 
56       String host,
57       int port,
58       String username,
59       String virtualHostName,
60       String message
61   {
62     super(
63         endpointReference,
64         new QName(
65             Names.NAMESPACE_URI,
66             "UnableToConnectFault",
67             Names.PREFIX),
68         String.format("Unable to connect with the requested broker. Underlying exception message was %s",message));
69     this._host = host;
70     this._port = port;
71     this._username = username;
72     this._virtualHostName = virtualHostName;
73   }
74   
75   @Override
76   public Element getDetail()
77   {
78     Element detail = super.getDetail();
79     Document owner = detail.getOwnerDocument();
80     detail.appendChild(XmlUtils.createElement(owner, Names.HOST_QNAME,_host));
81     detail.appendChild(XmlUtils.createElement(owner, Names.PORT_QNAME,_port));
82     detail.appendChild(XmlUtils.createElement(owner, Names.USERNAME_QNAME,_username));
83     detail.appendChild(XmlUtils.createElement(owner, Names.VIRTUAL_HOST_QNAME,_virtualHostName));
84     return detail;
85   }
86 }