KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mx4j > tools > adaptor > http > HttpException


1 /*
2
3  * Copyright (C) The MX4J Contributors.
4
5  * All rights reserved.
6
7  *
8
9  * This software is distributed under the terms of the MX4J License version 1.0.
10
11  * See the terms of the MX4J License in the documentation provided with this software.
12
13  */

14
15 package mx4j.tools.adaptor.http;
16
17
18 import java.io.IOException JavaDoc;
19 import javax.xml.parsers.DocumentBuilder JavaDoc;
20 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
21 import javax.xml.parsers.ParserConfigurationException JavaDoc;
22
23 import org.w3c.dom.Document JavaDoc;
24 import org.w3c.dom.Element JavaDoc;
25
26
27 /**
28  * HttpException is emitted when an error parsing an HTTP request appears
29  *
30  * @version $Revision: 1.3 $
31  */

32
33 public class HttpException extends IOException JavaDoc
34
35 {
36
37    /**
38     * Error code
39     */

40
41    protected int code;
42
43
44    /**
45     * Constructor for the HttpException object
46     *
47     * @param code Error code
48     * @param description Description
49     */

50
51    public HttpException(int code, String JavaDoc description)
52
53    {
54
55       super(description);
56
57       this.code = code;
58
59    }
60
61
62    /**
63     * Return the exception code
64     */

65
66    public int getCode()
67
68    {
69
70       return code;
71
72    }
73
74
75    public Document JavaDoc getResponseDoc()
76    {
77
78       try
79
80       {
81
82          DocumentBuilderFactory JavaDoc factory = DocumentBuilderFactory.newInstance();
83
84          DocumentBuilder JavaDoc builder = factory.newDocumentBuilder();
85
86          Document JavaDoc document = builder.newDocument();
87
88
89          Element JavaDoc root = document.createElement("HttpException");
90
91          root.setAttribute("code", Integer.toString(code));
92
93          root.setAttribute("description", getMessage());
94
95          document.appendChild(root);
96
97          return document;
98
99       }
100
101       catch (ParserConfigurationException JavaDoc e)
102
103       {
104
105          return null;
106
107       }
108
109    }
110
111 }
112
113
Popular Tags