Fix NPE in HttpSupport

Bug: 483366
Change-Id: I107f1b44e0e6371e3cfbd1cc18a970412e1fc679
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
Matthias Sohn 2015-12-02 13:11:20 +01:00
parent 2647d024af
commit f8eee3963a
1 changed files with 14 additions and 13 deletions

View File

@ -100,7 +100,7 @@
public class HttpClientConnection implements HttpConnection { public class HttpClientConnection implements HttpConnection {
HttpClient client; HttpClient client;
String urlStr; URL url;
HttpUriRequest req; HttpUriRequest req;
@ -176,16 +176,19 @@ public void setBuffer(TemporaryBuffer buffer) {
/** /**
* @param urlStr * @param urlStr
* @throws MalformedURLException
*/ */
public HttpClientConnection(String urlStr) { public HttpClientConnection(String urlStr) throws MalformedURLException {
this(urlStr, null); this(urlStr, null);
} }
/** /**
* @param urlStr * @param urlStr
* @param proxy * @param proxy
* @throws MalformedURLException
*/ */
public HttpClientConnection(String urlStr, Proxy proxy) { public HttpClientConnection(String urlStr, Proxy proxy)
throws MalformedURLException {
this(urlStr, proxy, null); this(urlStr, proxy, null);
} }
@ -193,10 +196,12 @@ public HttpClientConnection(String urlStr, Proxy proxy) {
* @param urlStr * @param urlStr
* @param proxy * @param proxy
* @param cl * @param cl
* @throws MalformedURLException
*/ */
public HttpClientConnection(String urlStr, Proxy proxy, HttpClient cl) { public HttpClientConnection(String urlStr, Proxy proxy, HttpClient cl)
throws MalformedURLException {
this.client = cl; this.client = cl;
this.urlStr = urlStr; this.url = new URL(urlStr);
this.proxy = proxy; this.proxy = proxy;
} }
@ -206,11 +211,7 @@ public int getResponseCode() throws IOException {
} }
public URL getURL() { public URL getURL() {
try { return url;
return new URL(urlStr);
} catch (MalformedURLException e) {
return null;
}
} }
public String getResponseMessage() throws IOException { public String getResponseMessage() throws IOException {
@ -250,11 +251,11 @@ public void setRequestProperty(String name, String value) {
public void setRequestMethod(String method) throws ProtocolException { public void setRequestMethod(String method) throws ProtocolException {
this.method = method; this.method = method;
if ("GET".equalsIgnoreCase(method)) //$NON-NLS-1$ if ("GET".equalsIgnoreCase(method)) //$NON-NLS-1$
req = new HttpGet(urlStr); req = new HttpGet(url.toString());
else if ("PUT".equalsIgnoreCase(method)) //$NON-NLS-1$ else if ("PUT".equalsIgnoreCase(method)) //$NON-NLS-1$
req = new HttpPut(urlStr); req = new HttpPut(url.toString());
else if ("POST".equalsIgnoreCase(method)) //$NON-NLS-1$ else if ("POST".equalsIgnoreCase(method)) //$NON-NLS-1$
req = new HttpPost(urlStr); req = new HttpPost(url.toString());
else { else {
this.method = null; this.method = null;
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();