Skip to content

Commit e3d743e

Browse files
authored
Update httpclient (#57)
1 parent 0f418dc commit e3d743e

File tree

2 files changed

+40
-25
lines changed

2 files changed

+40
-25
lines changed

pom.xml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,14 @@ under the License.
268268
<version>4.2</version>
269269
</dependency>
270270
<dependency>
271-
<groupId>commons-httpclient</groupId>
272-
<artifactId>commons-httpclient</artifactId>
273-
<version>3.1</version>
271+
<groupId>org.apache.httpcomponents</groupId>
272+
<artifactId>httpcore</artifactId>
273+
<version>4.4.16</version>
274+
</dependency>
275+
<dependency>
276+
<groupId>org.apache.httpcomponents</groupId>
277+
<artifactId>httpclient</artifactId>
278+
<version>4.5.14</version>
274279
</dependency>
275280
<dependency>
276281
<groupId>commons-io</groupId>

src/main/java/org/apache/maven/plugins/jira/JiraHelper.java

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@
1818
*/
1919
package org.apache.maven.plugins.jira;
2020

21+
import java.io.IOException;
2122
import java.text.NumberFormat;
2223
import java.text.ParsePosition;
2324
import java.util.HashMap;
2425
import java.util.Map;
2526

26-
import org.apache.commons.httpclient.HttpClient;
27-
import org.apache.commons.httpclient.methods.GetMethod;
27+
import org.apache.http.HttpEntity;
28+
import org.apache.http.HttpResponse;
29+
import org.apache.http.client.HttpClient;
30+
import org.apache.http.client.methods.HttpGet;
31+
import org.apache.http.util.EntityUtils;
2832
import org.apache.maven.plugin.logging.Log;
2933

3034
/**
@@ -87,21 +91,29 @@ static Map<String, String> getJiraUrlAndProjectId(String issueManagementUrl) {
8791
/**
8892
* Try to get a JIRA pid from the issue management URL.
8993
*
90-
* @param log Used to tell the user what happened
91-
* @param issueManagementUrl The URL to the issue management system
92-
* @param client The client used to connect to JIRA
93-
* @return The JIRA id for the project, or null if it can't be found
94+
* @param log used to tell the user what happened
95+
* @param issueManagementUrl the URL to the issue management system
96+
* @param client the client used to connect to JIRA
97+
* @return the JIRA id for the project, or null if it can't be found
9498
*/
9599
public static String getPidFromJira(Log log, String issueManagementUrl, HttpClient client) {
96100
String jiraId = null;
97-
GetMethod gm = new GetMethod(issueManagementUrl);
101+
HttpGet request = new HttpGet(issueManagementUrl);
98102

99103
String projectPage;
100104
try {
101-
client.executeMethod(gm);
105+
HttpResponse response = client.execute(request);
102106
log.debug("Successfully reached JIRA.");
103-
projectPage = gm.getResponseBodyAsString();
104-
} catch (Exception e) {
107+
HttpEntity entity = response.getEntity();
108+
if (entity != null) {
109+
projectPage = EntityUtils.toString(entity);
110+
} else {
111+
if (log.isDebugEnabled()) {
112+
log.error("Unable to read the JIRA project page");
113+
}
114+
return null;
115+
}
116+
} catch (IOException e) {
105117
if (log.isDebugEnabled()) {
106118
log.error("Unable to reach the JIRA project page:", e);
107119
} else {
@@ -131,44 +143,42 @@ private JiraHelper() {
131143
* Parse out the base URL for JIRA and the JIRA project name from the issue management URL. The issue management URL
132144
* is assumed to be of the format http(s)://host:port/browse/{projectname}
133145
*
134-
* @param issueManagementUrl The URL to the issue management system
146+
* @param issueManagementUrl the URL to the issue management system
135147
* @return A <code>Map</code> containing the URL and project name
136148
* @since 2.8
137149
*/
138150
public static Map<String, String> getJiraUrlAndProjectName(String issueManagementUrl) {
139151
final int indexBrowse = issueManagementUrl.indexOf("/browse/");
140152

141-
String jiraUrl;
142-
String project;
153+
HashMap<String, String> urlMap = new HashMap<>(4);
143154

144155
if (indexBrowse != -1) {
145-
jiraUrl = issueManagementUrl.substring(0, indexBrowse);
156+
String jiraUrl = issueManagementUrl.substring(0, indexBrowse);
157+
urlMap.put("url", jiraUrl);
146158

147159
final int indexBrowseEnd = indexBrowse + "/browse/".length();
148160

149161
final int indexProject = issueManagementUrl.indexOf("/", indexBrowseEnd);
150162

151163
if (indexProject != -1) {
152164
// Project name has trailing '/'
153-
project = issueManagementUrl.substring(indexBrowseEnd, indexProject);
165+
String project = issueManagementUrl.substring(indexBrowseEnd, indexProject);
166+
urlMap.put("project", project);
154167
} else {
155168
// Project name without trailing '/'
156-
project = issueManagementUrl.substring(indexBrowseEnd);
169+
String project = issueManagementUrl.substring(indexBrowseEnd);
170+
urlMap.put("project", project);
157171
}
158172
} else {
159173
throw new IllegalArgumentException("Invalid browse URL");
160174
}
161175

162-
HashMap<String, String> urlMap = new HashMap<>(4);
163-
urlMap.put("url", jiraUrl);
164-
urlMap.put("project", project);
165-
166176
return urlMap;
167177
}
168178

169179
/**
170-
* @param url URL.
171-
* @return the base URL.
180+
* @param url URL
181+
* @return the base URL
172182
* @since 2.8
173183
*/
174184
public static String getBaseUrl(String url) {

0 commit comments

Comments
 (0)