Skip to content

Commit b2885c6

Browse files
authored
Remove dependency on commons-httpclient (#308)
`commons-httpclient:commons-httpclient` is only used for the `HttpStatus` class.
1 parent 5666494 commit b2885c6

File tree

5 files changed

+114
-13
lines changed

5 files changed

+114
-13
lines changed

core/pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@
3838
<groupId>org.slf4j</groupId>
3939
<artifactId>slf4j-api</artifactId>
4040
</dependency>
41-
<dependency>
42-
<groupId>commons-httpclient</groupId>
43-
<artifactId>commons-httpclient</artifactId>
44-
</dependency>
4541
<dependency>
4642
<groupId>org.junit.jupiter</groupId>
4743
<artifactId>junit-jupiter</artifactId>

core/src/main/java/org/openapitools/openapidiff/core/output/ConsoleRender.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import java.util.Map;
1111
import java.util.Map.Entry;
1212
import java.util.Optional;
13-
import org.apache.commons.httpclient.HttpStatus;
1413
import org.apache.commons.lang3.StringUtils;
1514
import org.openapitools.openapidiff.core.model.*;
1615
import org.openapitools.openapidiff.core.utils.RefPointer;
@@ -120,7 +119,7 @@ private String itemResponse(String title, String code) {
120119
StringBuilder sb = new StringBuilder();
121120
String status = "";
122121
if (!code.equals("default")) {
123-
status = HttpStatus.getStatusText(Integer.parseInt(code));
122+
status = HttpStatus.getReasonPhrase(Integer.parseInt(code));
124123
}
125124
sb.append(StringUtils.repeat(' ', 4))
126125
.append("- ")
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/java/org/apache/commons/httpclient/HttpStatus.java,v 1.18 2004/05/02 11:21:13 olegk Exp $
3+
* $Revision: 480424 $
4+
* $Date: 2006-11-29 06:56:49 +0100 (Wed, 29 Nov 2006) $
5+
*
6+
* ====================================================================
7+
*
8+
* Licensed to the Apache Software Foundation (ASF) under one or more
9+
* contributor license agreements. See the NOTICE file distributed with
10+
* this work for additional information regarding copyright ownership.
11+
* The ASF licenses this file to You under the Apache License, Version 2.0
12+
* (the "License"); you may not use this file except in compliance with
13+
* the License. You may obtain a copy of the License at
14+
*
15+
* http://www.apache.org/licenses/LICENSE-2.0
16+
*
17+
* Unless required by applicable law or agreed to in writing, software
18+
* distributed under the License is distributed on an "AS IS" BASIS,
19+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20+
* See the License for the specific language governing permissions and
21+
* limitations under the License.
22+
* ====================================================================
23+
*
24+
* This software consists of voluntary contributions made by many
25+
* individuals on behalf of the Apache Software Foundation. For more
26+
* information on the Apache Software Foundation, please see
27+
* <http://www.apache.org/>.
28+
*
29+
*/
30+
package org.openapitools.openapidiff.core.output;
31+
32+
import java.util.HashMap;
33+
import java.util.Map;
34+
35+
/**
36+
* Constants enumerating the HTTP status codes. All status codes defined in RFC1945 (HTTP/1.0,
37+
* RFC2616 (HTTP/1.1), and RFC2518 (WebDAV) are supported.
38+
*/
39+
public final class HttpStatus {
40+
41+
private static final Map<Integer, String> REASON_PHRASES = new HashMap<>();
42+
43+
static {
44+
REASON_PHRASES.put(100, "Continue");
45+
REASON_PHRASES.put(101, "Switching Protocols");
46+
REASON_PHRASES.put(102, "Processing");
47+
REASON_PHRASES.put(200, "OK");
48+
REASON_PHRASES.put(201, "Created");
49+
REASON_PHRASES.put(202, "Accepted");
50+
REASON_PHRASES.put(203, "Non Authoritative Information");
51+
REASON_PHRASES.put(204, "No Content");
52+
REASON_PHRASES.put(205, "Reset Content");
53+
REASON_PHRASES.put(206, "Partial Content");
54+
REASON_PHRASES.put(207, "Multi-Status");
55+
REASON_PHRASES.put(300, "Multiple Choices");
56+
REASON_PHRASES.put(301, "Moved Permanently");
57+
REASON_PHRASES.put(302, "Moved Temporarily");
58+
REASON_PHRASES.put(303, "See Other");
59+
REASON_PHRASES.put(304, "Not Modified");
60+
REASON_PHRASES.put(305, "Use Proxy");
61+
REASON_PHRASES.put(307, "Temporary Redirect");
62+
REASON_PHRASES.put(400, "Bad Request");
63+
REASON_PHRASES.put(401, "Unauthorized");
64+
REASON_PHRASES.put(402, "Payment Required");
65+
REASON_PHRASES.put(403, "Forbidden");
66+
REASON_PHRASES.put(404, "Not Found");
67+
REASON_PHRASES.put(405, "Method Not Allowed");
68+
REASON_PHRASES.put(406, "Not Acceptable");
69+
REASON_PHRASES.put(407, "Proxy Authentication Required");
70+
REASON_PHRASES.put(408, "Request Timeout");
71+
REASON_PHRASES.put(409, "Conflict");
72+
REASON_PHRASES.put(410, "Gone");
73+
REASON_PHRASES.put(411, "Length Required");
74+
REASON_PHRASES.put(412, "Precondition Failed");
75+
REASON_PHRASES.put(413, "Request Too Long");
76+
REASON_PHRASES.put(414, "Request-URI Too Long");
77+
REASON_PHRASES.put(415, "Unsupported Media Type");
78+
REASON_PHRASES.put(416, "Requested Range Not Satisfiable");
79+
REASON_PHRASES.put(417, "Expectation Failed");
80+
REASON_PHRASES.put(419, "Insufficient Space On Resource");
81+
REASON_PHRASES.put(420, "Method Failure");
82+
REASON_PHRASES.put(422, "Unprocessable Entity");
83+
REASON_PHRASES.put(423, "Locked");
84+
REASON_PHRASES.put(424, "Failed Dependency");
85+
REASON_PHRASES.put(500, "Internal Server Error");
86+
REASON_PHRASES.put(501, "Not Implemented");
87+
REASON_PHRASES.put(502, "Bad Gateway");
88+
REASON_PHRASES.put(503, "Service Unavailable");
89+
REASON_PHRASES.put(504, "Gateway Timeout");
90+
REASON_PHRASES.put(505, "Http Version Not Supported");
91+
REASON_PHRASES.put(507, "Insufficient Storage");
92+
}
93+
94+
/**
95+
* Get the reason phrase for a particular status code.
96+
*
97+
* <p>This method always returns the English text as specified in the relevant RFCs and is not
98+
* internationalized.
99+
*
100+
* @param statusCode the numeric status code
101+
* @return the reason phrase associated with the given status code or null if the status code is
102+
* not recognized.
103+
*/
104+
public static String getReasonPhrase(int statusCode) {
105+
if (statusCode < 0) {
106+
throw new IllegalArgumentException("status code may not be negative");
107+
}
108+
return REASON_PHRASES.get(statusCode);
109+
}
110+
111+
private HttpStatus() {}
112+
}

core/src/main/java/org/openapitools/openapidiff/core/output/MarkdownRender.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import io.swagger.v3.oas.models.responses.ApiResponse;
1414
import java.util.List;
1515
import java.util.Map;
16-
import org.apache.commons.httpclient.HttpStatus;
1716
import org.apache.commons.lang3.StringUtils;
1817
import org.openapitools.openapidiff.core.model.*;
1918
import org.openapitools.openapidiff.core.utils.RefPointer;
@@ -156,7 +155,7 @@ protected String itemResponse(String title, String code, String description) {
156155
StringBuilder sb = new StringBuilder();
157156
String status = "";
158157
if (!code.equals("default")) {
159-
status = HttpStatus.getStatusText(Integer.parseInt(code));
158+
status = HttpStatus.getReasonPhrase(Integer.parseInt(code));
160159
}
161160
sb.append(format("%s : **%s %s**\n", title, code, status));
162161
sb.append(metadata(description));

pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,6 @@
146146
<artifactId>logback-classic</artifactId>
147147
<version>1.2.10</version>
148148
</dependency>
149-
<dependency>
150-
<groupId>commons-httpclient</groupId>
151-
<artifactId>commons-httpclient</artifactId>
152-
<version>3.1</version>
153-
</dependency>
154149
<dependency>
155150
<groupId>org.assertj</groupId>
156151
<artifactId>assertj-core</artifactId>

0 commit comments

Comments
 (0)