You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Zhihong Zhang (JIRA)" <ji...@apache.org> on 2009/01/07 17:56:44 UTC
[jira] Created: (HTTPCLIENT-813) HttpClient throws NPE on Invalid
Port when used with MultiThreadedHttpConnectionManager
HttpClient throws NPE on Invalid Port when used with MultiThreadedHttpConnectionManager
---------------------------------------------------------------------------------------
Key: HTTPCLIENT-813
URL: https://issues.apache.org/jira/browse/HTTPCLIENT-813
Project: HttpComponents HttpClient
Issue Type: Bug
Components: HttpClient
Affects Versions: 3.1 Final
Environment: Linux AS 3.1/Java 1.5
Reporter: Zhihong Zhang
The HttpClient throws NullPointerException in the main thread when an invalid port (like 80001) is used in the URL. An IllegalArgumentException is thrown in TimeoutGuard thread.
Exception in thread "Timeout guard" java.lang.IllegalArgumentException: port out of range:80001
at java.net.InetSocketAddress.<init>(InetSocketAddress.java:118)
at java.net.Socket.<init>(Socket.java:240)
at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:80)
at org.apache.commons.httpclient.protocol.ControllerThreadSocketFactory$1.doit(ControllerThreadSocketFactory.java:91)
at org.apache.commons.httpclient.protocol.ControllerThreadSocketFactory$SocketTask.run(ControllerThreadSocketFactory.java:158)
at java.lang.Thread.run(Thread.java:613)
Exception in thread "main" java.lang.NullPointerException
at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:721)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1361)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
at com.aol.test.HttpTest$PoolingHttpConnector.doGet(HttpTest.java:47)
at com.aol.test.HttpTest.main(HttpTest.java:17)
It should throw a checked exception in main thread so caller can handle the error condition more gracefully.
The test program is attached. This is caused by a race condition and it's not always reproducible. Running in debugger shows a different behavior.
package com.aol.test;
import java.io.IOException;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
public class HttpTest {
public static void main(String[] args) {
PoolingHttpConnector conn = new PoolingHttpConnector();
try {
String response = conn.doGet("http://www.aol.com:80001");
System.out.println("Response='" + response + "'");
} catch (IOException e) {
e.printStackTrace();
}
}
static class PoolingHttpConnector {
public static final int MAX_TOTAL_CONNECTIONS = 16;
public static final int MAX_CONNECTIONS_PER_HOST = 8;
public static final int CONNECT_TIMEOUT = 5000;
public static final int SOCKET_TIMEOUT = 5000;
public static final boolean TCP_NO_DELAY = true;
private static MultiThreadedHttpConnectionManager poolManager;
private static HttpConnectionManagerParams httpParams;
private static HttpClient httpClient;
private static boolean initialized = false;
public PoolingHttpConnector()
{
initialize();
}
public String doGet(String url) throws IOException {
GetMethod method = new GetMethod(url);
try {
int status = httpClient.executeMethod(method);
String response = new String(method.getResponseBody());
if (status != HttpStatus.SC_OK)
throw new IOException("HTTP error: " + response);
return response;
} finally {
method.releaseConnection();
}
}
private synchronized void initialize() {
if (initialized)
return;
poolManager = new MultiThreadedHttpConnectionManager();
httpParams = new HttpConnectionManagerParams();
httpParams.setMaxTotalConnections(MAX_TOTAL_CONNECTIONS);
httpParams.setDefaultMaxConnectionsPerHost(MAX_CONNECTIONS_PER_HOST);
httpParams.setTcpNoDelay(TCP_NO_DELAY);
httpParams.setSoTimeout(SOCKET_TIMEOUT);
httpParams.setConnectionTimeout(CONNECT_TIMEOUT);
poolManager.setParams(httpParams);
httpClient = new HttpClient(poolManager);
initialized = true;
}
}
}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
[jira] Commented: (HTTPCLIENT-813) HttpClient throws NPE on Invalid
Port when used with MultiThreadedHttpConnectionManager
Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCLIENT-813?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12662026#action_12662026 ]
Oleg Kalnichevski commented on HTTPCLIENT-813:
----------------------------------------------
> You said 4.0 doesn't throw exception at all. That's not right behavior either. Since the input is invalid, it should throw a checked exception.
You may be right, but since JRE classes do not raise an exception, I do not think this is HttpClient's job to validate port numbers
> Do you have an estimate on the official release?
Q2 2009
Oleg
> HttpClient throws NPE on Invalid Port when used with MultiThreadedHttpConnectionManager
> ---------------------------------------------------------------------------------------
>
> Key: HTTPCLIENT-813
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-813
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Components: HttpClient
> Affects Versions: 3.1 Final
> Environment: Linux AS 3.1/Java 1.5
> Reporter: Zhihong Zhang
> Attachments: HttpTest.java, HttpTest2.java
>
>
> The HttpClient throws NullPointerException in the main thread when an invalid port (like 80001) is used in the URL. An IllegalArgumentException is thrown in TimeoutGuard thread.
>
> Exception in thread "Timeout guard" java.lang.IllegalArgumentException: port out of range:80001
> at java.net.InetSocketAddress.<init>(InetSocketAddress.java:118)
> at java.net.Socket.<init>(Socket.java:240)
> at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:80)
> at org.apache.commons.httpclient.protocol.ControllerThreadSocketFactory$1.doit(ControllerThreadSocketFactory.java:91)
> at org.apache.commons.httpclient.protocol.ControllerThreadSocketFactory$SocketTask.run(ControllerThreadSocketFactory.java:158)
> at java.lang.Thread.run(Thread.java:613)
> Exception in thread "main" java.lang.NullPointerException
> at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:721)
> at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1361)
> at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
> at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
> at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
> at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
> at com.aol.test.HttpTest$PoolingHttpConnector.doGet(HttpTest.java:47)
> at com.aol.test.HttpTest.main(HttpTest.java:17)
> It should throw a checked exception in main thread so caller can handle the error condition more gracefully.
> The test program is attached. This is caused by a race condition and it's not always reproducible. Running in debugger shows a different behavior.
> package com.aol.test;
> import java.io.IOException;
> import org.apache.commons.httpclient.HttpClient;
> import org.apache.commons.httpclient.HttpStatus;
> import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
> import org.apache.commons.httpclient.methods.GetMethod;
> import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
> public class HttpTest {
>
> public static void main(String[] args) {
> PoolingHttpConnector conn = new PoolingHttpConnector();
>
> try {
> String response = conn.doGet("http://www.aol.com:80001");
> System.out.println("Response='" + response + "'");
> } catch (IOException e) {
> e.printStackTrace();
> }
> }
> static class PoolingHttpConnector {
>
> public static final int MAX_TOTAL_CONNECTIONS = 16;
> public static final int MAX_CONNECTIONS_PER_HOST = 8;
> public static final int CONNECT_TIMEOUT = 5000;
> public static final int SOCKET_TIMEOUT = 5000;
> public static final boolean TCP_NO_DELAY = true;
>
> private static MultiThreadedHttpConnectionManager poolManager;
> private static HttpConnectionManagerParams httpParams;
> private static HttpClient httpClient;
> private static boolean initialized = false;
>
> public PoolingHttpConnector()
> {
> initialize();
> }
> public String doGet(String url) throws IOException {
> GetMethod method = new GetMethod(url);
>
> try {
> int status = httpClient.executeMethod(method);
> String response = new String(method.getResponseBody());
>
> if (status != HttpStatus.SC_OK)
> throw new IOException("HTTP error: " + response);
>
> return response;
>
> } finally {
> method.releaseConnection();
> }
> }
>
> private synchronized void initialize() {
> if (initialized)
> return;
>
> poolManager = new MultiThreadedHttpConnectionManager();
> httpParams = new HttpConnectionManagerParams();
>
> httpParams.setMaxTotalConnections(MAX_TOTAL_CONNECTIONS);
> httpParams.setDefaultMaxConnectionsPerHost(MAX_CONNECTIONS_PER_HOST);
> httpParams.setTcpNoDelay(TCP_NO_DELAY);
> httpParams.setSoTimeout(SOCKET_TIMEOUT);
> httpParams.setConnectionTimeout(CONNECT_TIMEOUT);
>
> poolManager.setParams(httpParams);
> httpClient = new HttpClient(poolManager);
> initialized = true;
> }
>
> }
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
[jira] Updated: (HTTPCLIENT-813) HttpClient throws NPE on Invalid
Port when used with MultiThreadedHttpConnectionManager
Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCLIENT-813?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Oleg Kalnichevski updated HTTPCLIENT-813:
-----------------------------------------
Fix Version/s: 4.0 Beta 3
> HttpClient throws NPE on Invalid Port when used with MultiThreadedHttpConnectionManager
> ---------------------------------------------------------------------------------------
>
> Key: HTTPCLIENT-813
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-813
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Components: HttpClient
> Affects Versions: 3.1 Final
> Environment: Linux AS 3.1/Java 1.5
> Reporter: Zhihong Zhang
> Fix For: 4.0 Beta 3
>
> Attachments: HttpTest.java, HttpTest2.java
>
>
> The HttpClient throws NullPointerException in the main thread when an invalid port (like 80001) is used in the URL. An IllegalArgumentException is thrown in TimeoutGuard thread.
>
> Exception in thread "Timeout guard" java.lang.IllegalArgumentException: port out of range:80001
> at java.net.InetSocketAddress.<init>(InetSocketAddress.java:118)
> at java.net.Socket.<init>(Socket.java:240)
> at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:80)
> at org.apache.commons.httpclient.protocol.ControllerThreadSocketFactory$1.doit(ControllerThreadSocketFactory.java:91)
> at org.apache.commons.httpclient.protocol.ControllerThreadSocketFactory$SocketTask.run(ControllerThreadSocketFactory.java:158)
> at java.lang.Thread.run(Thread.java:613)
> Exception in thread "main" java.lang.NullPointerException
> at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:721)
> at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1361)
> at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
> at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
> at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
> at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
> at com.aol.test.HttpTest$PoolingHttpConnector.doGet(HttpTest.java:47)
> at com.aol.test.HttpTest.main(HttpTest.java:17)
> It should throw a checked exception in main thread so caller can handle the error condition more gracefully.
> The test program is attached. This is caused by a race condition and it's not always reproducible. Running in debugger shows a different behavior.
> package com.aol.test;
> import java.io.IOException;
> import org.apache.commons.httpclient.HttpClient;
> import org.apache.commons.httpclient.HttpStatus;
> import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
> import org.apache.commons.httpclient.methods.GetMethod;
> import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
> public class HttpTest {
>
> public static void main(String[] args) {
> PoolingHttpConnector conn = new PoolingHttpConnector();
>
> try {
> String response = conn.doGet("http://www.aol.com:80001");
> System.out.println("Response='" + response + "'");
> } catch (IOException e) {
> e.printStackTrace();
> }
> }
> static class PoolingHttpConnector {
>
> public static final int MAX_TOTAL_CONNECTIONS = 16;
> public static final int MAX_CONNECTIONS_PER_HOST = 8;
> public static final int CONNECT_TIMEOUT = 5000;
> public static final int SOCKET_TIMEOUT = 5000;
> public static final boolean TCP_NO_DELAY = true;
>
> private static MultiThreadedHttpConnectionManager poolManager;
> private static HttpConnectionManagerParams httpParams;
> private static HttpClient httpClient;
> private static boolean initialized = false;
>
> public PoolingHttpConnector()
> {
> initialize();
> }
> public String doGet(String url) throws IOException {
> GetMethod method = new GetMethod(url);
>
> try {
> int status = httpClient.executeMethod(method);
> String response = new String(method.getResponseBody());
>
> if (status != HttpStatus.SC_OK)
> throw new IOException("HTTP error: " + response);
>
> return response;
>
> } finally {
> method.releaseConnection();
> }
> }
>
> private synchronized void initialize() {
> if (initialized)
> return;
>
> poolManager = new MultiThreadedHttpConnectionManager();
> httpParams = new HttpConnectionManagerParams();
>
> httpParams.setMaxTotalConnections(MAX_TOTAL_CONNECTIONS);
> httpParams.setDefaultMaxConnectionsPerHost(MAX_CONNECTIONS_PER_HOST);
> httpParams.setTcpNoDelay(TCP_NO_DELAY);
> httpParams.setSoTimeout(SOCKET_TIMEOUT);
> httpParams.setConnectionTimeout(CONNECT_TIMEOUT);
>
> poolManager.setParams(httpParams);
> httpClient = new HttpClient(poolManager);
> initialized = true;
> }
>
> }
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
[jira] Updated: (HTTPCLIENT-813) HttpClient throws NPE on Invalid
Port when used with MultiThreadedHttpConnectionManager
Posted by "Zhihong Zhang (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCLIENT-813?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Zhihong Zhang updated HTTPCLIENT-813:
-------------------------------------
Attachment: HttpTest.java
> HttpClient throws NPE on Invalid Port when used with MultiThreadedHttpConnectionManager
> ---------------------------------------------------------------------------------------
>
> Key: HTTPCLIENT-813
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-813
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Components: HttpClient
> Affects Versions: 3.1 Final
> Environment: Linux AS 3.1/Java 1.5
> Reporter: Zhihong Zhang
> Attachments: HttpTest.java
>
>
> The HttpClient throws NullPointerException in the main thread when an invalid port (like 80001) is used in the URL. An IllegalArgumentException is thrown in TimeoutGuard thread.
>
> Exception in thread "Timeout guard" java.lang.IllegalArgumentException: port out of range:80001
> at java.net.InetSocketAddress.<init>(InetSocketAddress.java:118)
> at java.net.Socket.<init>(Socket.java:240)
> at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:80)
> at org.apache.commons.httpclient.protocol.ControllerThreadSocketFactory$1.doit(ControllerThreadSocketFactory.java:91)
> at org.apache.commons.httpclient.protocol.ControllerThreadSocketFactory$SocketTask.run(ControllerThreadSocketFactory.java:158)
> at java.lang.Thread.run(Thread.java:613)
> Exception in thread "main" java.lang.NullPointerException
> at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:721)
> at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1361)
> at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
> at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
> at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
> at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
> at com.aol.test.HttpTest$PoolingHttpConnector.doGet(HttpTest.java:47)
> at com.aol.test.HttpTest.main(HttpTest.java:17)
> It should throw a checked exception in main thread so caller can handle the error condition more gracefully.
> The test program is attached. This is caused by a race condition and it's not always reproducible. Running in debugger shows a different behavior.
> package com.aol.test;
> import java.io.IOException;
> import org.apache.commons.httpclient.HttpClient;
> import org.apache.commons.httpclient.HttpStatus;
> import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
> import org.apache.commons.httpclient.methods.GetMethod;
> import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
> public class HttpTest {
>
> public static void main(String[] args) {
> PoolingHttpConnector conn = new PoolingHttpConnector();
>
> try {
> String response = conn.doGet("http://www.aol.com:80001");
> System.out.println("Response='" + response + "'");
> } catch (IOException e) {
> e.printStackTrace();
> }
> }
> static class PoolingHttpConnector {
>
> public static final int MAX_TOTAL_CONNECTIONS = 16;
> public static final int MAX_CONNECTIONS_PER_HOST = 8;
> public static final int CONNECT_TIMEOUT = 5000;
> public static final int SOCKET_TIMEOUT = 5000;
> public static final boolean TCP_NO_DELAY = true;
>
> private static MultiThreadedHttpConnectionManager poolManager;
> private static HttpConnectionManagerParams httpParams;
> private static HttpClient httpClient;
> private static boolean initialized = false;
>
> public PoolingHttpConnector()
> {
> initialize();
> }
> public String doGet(String url) throws IOException {
> GetMethod method = new GetMethod(url);
>
> try {
> int status = httpClient.executeMethod(method);
> String response = new String(method.getResponseBody());
>
> if (status != HttpStatus.SC_OK)
> throw new IOException("HTTP error: " + response);
>
> return response;
>
> } finally {
> method.releaseConnection();
> }
> }
>
> private synchronized void initialize() {
> if (initialized)
> return;
>
> poolManager = new MultiThreadedHttpConnectionManager();
> httpParams = new HttpConnectionManagerParams();
>
> httpParams.setMaxTotalConnections(MAX_TOTAL_CONNECTIONS);
> httpParams.setDefaultMaxConnectionsPerHost(MAX_CONNECTIONS_PER_HOST);
> httpParams.setTcpNoDelay(TCP_NO_DELAY);
> httpParams.setSoTimeout(SOCKET_TIMEOUT);
> httpParams.setConnectionTimeout(CONNECT_TIMEOUT);
>
> poolManager.setParams(httpParams);
> httpClient = new HttpClient(poolManager);
> initialized = true;
> }
>
> }
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
[jira] Resolved: (HTTPCLIENT-813) HttpClient throws NPE on Invalid
Port when used with MultiThreadedHttpConnectionManager
Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCLIENT-813?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Oleg Kalnichevski resolved HTTPCLIENT-813.
------------------------------------------
Resolution: Won't Fix
HttpClient 3.x is nearing end of life. There is no point fixing it (unless some one volunteers to provide a complete patch in udiff format including test coverage).
Oleg
> HttpClient throws NPE on Invalid Port when used with MultiThreadedHttpConnectionManager
> ---------------------------------------------------------------------------------------
>
> Key: HTTPCLIENT-813
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-813
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Components: HttpClient
> Affects Versions: 3.1 Final
> Environment: Linux AS 3.1/Java 1.5
> Reporter: Zhihong Zhang
> Attachments: HttpTest.java, HttpTest2.java
>
>
> The HttpClient throws NullPointerException in the main thread when an invalid port (like 80001) is used in the URL. An IllegalArgumentException is thrown in TimeoutGuard thread.
>
> Exception in thread "Timeout guard" java.lang.IllegalArgumentException: port out of range:80001
> at java.net.InetSocketAddress.<init>(InetSocketAddress.java:118)
> at java.net.Socket.<init>(Socket.java:240)
> at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:80)
> at org.apache.commons.httpclient.protocol.ControllerThreadSocketFactory$1.doit(ControllerThreadSocketFactory.java:91)
> at org.apache.commons.httpclient.protocol.ControllerThreadSocketFactory$SocketTask.run(ControllerThreadSocketFactory.java:158)
> at java.lang.Thread.run(Thread.java:613)
> Exception in thread "main" java.lang.NullPointerException
> at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:721)
> at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1361)
> at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
> at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
> at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
> at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
> at com.aol.test.HttpTest$PoolingHttpConnector.doGet(HttpTest.java:47)
> at com.aol.test.HttpTest.main(HttpTest.java:17)
> It should throw a checked exception in main thread so caller can handle the error condition more gracefully.
> The test program is attached. This is caused by a race condition and it's not always reproducible. Running in debugger shows a different behavior.
> package com.aol.test;
> import java.io.IOException;
> import org.apache.commons.httpclient.HttpClient;
> import org.apache.commons.httpclient.HttpStatus;
> import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
> import org.apache.commons.httpclient.methods.GetMethod;
> import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
> public class HttpTest {
>
> public static void main(String[] args) {
> PoolingHttpConnector conn = new PoolingHttpConnector();
>
> try {
> String response = conn.doGet("http://www.aol.com:80001");
> System.out.println("Response='" + response + "'");
> } catch (IOException e) {
> e.printStackTrace();
> }
> }
> static class PoolingHttpConnector {
>
> public static final int MAX_TOTAL_CONNECTIONS = 16;
> public static final int MAX_CONNECTIONS_PER_HOST = 8;
> public static final int CONNECT_TIMEOUT = 5000;
> public static final int SOCKET_TIMEOUT = 5000;
> public static final boolean TCP_NO_DELAY = true;
>
> private static MultiThreadedHttpConnectionManager poolManager;
> private static HttpConnectionManagerParams httpParams;
> private static HttpClient httpClient;
> private static boolean initialized = false;
>
> public PoolingHttpConnector()
> {
> initialize();
> }
> public String doGet(String url) throws IOException {
> GetMethod method = new GetMethod(url);
>
> try {
> int status = httpClient.executeMethod(method);
> String response = new String(method.getResponseBody());
>
> if (status != HttpStatus.SC_OK)
> throw new IOException("HTTP error: " + response);
>
> return response;
>
> } finally {
> method.releaseConnection();
> }
> }
>
> private synchronized void initialize() {
> if (initialized)
> return;
>
> poolManager = new MultiThreadedHttpConnectionManager();
> httpParams = new HttpConnectionManagerParams();
>
> httpParams.setMaxTotalConnections(MAX_TOTAL_CONNECTIONS);
> httpParams.setDefaultMaxConnectionsPerHost(MAX_CONNECTIONS_PER_HOST);
> httpParams.setTcpNoDelay(TCP_NO_DELAY);
> httpParams.setSoTimeout(SOCKET_TIMEOUT);
> httpParams.setConnectionTimeout(CONNECT_TIMEOUT);
>
> poolManager.setParams(httpParams);
> httpClient = new HttpClient(poolManager);
> initialized = true;
> }
>
> }
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
[jira] Resolved: (HTTPCLIENT-813) HttpClient throws NPE on Invalid
Port when used with MultiThreadedHttpConnectionManager
Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCLIENT-813?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Oleg Kalnichevski resolved HTTPCLIENT-813.
------------------------------------------
Resolution: Fixed
Fixed in SVN trunk. Please verify.
Oleg
> HttpClient throws NPE on Invalid Port when used with MultiThreadedHttpConnectionManager
> ---------------------------------------------------------------------------------------
>
> Key: HTTPCLIENT-813
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-813
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Components: HttpClient
> Affects Versions: 3.1 Final
> Environment: Linux AS 3.1/Java 1.5
> Reporter: Zhihong Zhang
> Fix For: 4.0 Beta 3
>
> Attachments: HttpTest.java, HttpTest2.java
>
>
> The HttpClient throws NullPointerException in the main thread when an invalid port (like 80001) is used in the URL. An IllegalArgumentException is thrown in TimeoutGuard thread.
>
> Exception in thread "Timeout guard" java.lang.IllegalArgumentException: port out of range:80001
> at java.net.InetSocketAddress.<init>(InetSocketAddress.java:118)
> at java.net.Socket.<init>(Socket.java:240)
> at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:80)
> at org.apache.commons.httpclient.protocol.ControllerThreadSocketFactory$1.doit(ControllerThreadSocketFactory.java:91)
> at org.apache.commons.httpclient.protocol.ControllerThreadSocketFactory$SocketTask.run(ControllerThreadSocketFactory.java:158)
> at java.lang.Thread.run(Thread.java:613)
> Exception in thread "main" java.lang.NullPointerException
> at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:721)
> at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1361)
> at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
> at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
> at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
> at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
> at com.aol.test.HttpTest$PoolingHttpConnector.doGet(HttpTest.java:47)
> at com.aol.test.HttpTest.main(HttpTest.java:17)
> It should throw a checked exception in main thread so caller can handle the error condition more gracefully.
> The test program is attached. This is caused by a race condition and it's not always reproducible. Running in debugger shows a different behavior.
> package com.aol.test;
> import java.io.IOException;
> import org.apache.commons.httpclient.HttpClient;
> import org.apache.commons.httpclient.HttpStatus;
> import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
> import org.apache.commons.httpclient.methods.GetMethod;
> import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
> public class HttpTest {
>
> public static void main(String[] args) {
> PoolingHttpConnector conn = new PoolingHttpConnector();
>
> try {
> String response = conn.doGet("http://www.aol.com:80001");
> System.out.println("Response='" + response + "'");
> } catch (IOException e) {
> e.printStackTrace();
> }
> }
> static class PoolingHttpConnector {
>
> public static final int MAX_TOTAL_CONNECTIONS = 16;
> public static final int MAX_CONNECTIONS_PER_HOST = 8;
> public static final int CONNECT_TIMEOUT = 5000;
> public static final int SOCKET_TIMEOUT = 5000;
> public static final boolean TCP_NO_DELAY = true;
>
> private static MultiThreadedHttpConnectionManager poolManager;
> private static HttpConnectionManagerParams httpParams;
> private static HttpClient httpClient;
> private static boolean initialized = false;
>
> public PoolingHttpConnector()
> {
> initialize();
> }
> public String doGet(String url) throws IOException {
> GetMethod method = new GetMethod(url);
>
> try {
> int status = httpClient.executeMethod(method);
> String response = new String(method.getResponseBody());
>
> if (status != HttpStatus.SC_OK)
> throw new IOException("HTTP error: " + response);
>
> return response;
>
> } finally {
> method.releaseConnection();
> }
> }
>
> private synchronized void initialize() {
> if (initialized)
> return;
>
> poolManager = new MultiThreadedHttpConnectionManager();
> httpParams = new HttpConnectionManagerParams();
>
> httpParams.setMaxTotalConnections(MAX_TOTAL_CONNECTIONS);
> httpParams.setDefaultMaxConnectionsPerHost(MAX_CONNECTIONS_PER_HOST);
> httpParams.setTcpNoDelay(TCP_NO_DELAY);
> httpParams.setSoTimeout(SOCKET_TIMEOUT);
> httpParams.setConnectionTimeout(CONNECT_TIMEOUT);
>
> poolManager.setParams(httpParams);
> httpClient = new HttpClient(poolManager);
> initialized = true;
> }
>
> }
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
[jira] Commented: (HTTPCLIENT-813) HttpClient throws NPE on Invalid
Port when used with MultiThreadedHttpConnectionManager
Posted by "Zhihong Zhang (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCLIENT-813?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12662021#action_12662021 ]
Zhihong Zhang commented on HTTPCLIENT-813:
------------------------------------------
You said 4.0 doesn't throw exception at all. That's not right behavior either. Since the input is invalid, it should throw a checked exception.
We want to switch to 4.0 but we have a policy not to use software in beta. Do you have an estimate on the official release?
Thanks for your quick response.
Zhihong
> HttpClient throws NPE on Invalid Port when used with MultiThreadedHttpConnectionManager
> ---------------------------------------------------------------------------------------
>
> Key: HTTPCLIENT-813
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-813
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Components: HttpClient
> Affects Versions: 3.1 Final
> Environment: Linux AS 3.1/Java 1.5
> Reporter: Zhihong Zhang
> Attachments: HttpTest.java, HttpTest2.java
>
>
> The HttpClient throws NullPointerException in the main thread when an invalid port (like 80001) is used in the URL. An IllegalArgumentException is thrown in TimeoutGuard thread.
>
> Exception in thread "Timeout guard" java.lang.IllegalArgumentException: port out of range:80001
> at java.net.InetSocketAddress.<init>(InetSocketAddress.java:118)
> at java.net.Socket.<init>(Socket.java:240)
> at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:80)
> at org.apache.commons.httpclient.protocol.ControllerThreadSocketFactory$1.doit(ControllerThreadSocketFactory.java:91)
> at org.apache.commons.httpclient.protocol.ControllerThreadSocketFactory$SocketTask.run(ControllerThreadSocketFactory.java:158)
> at java.lang.Thread.run(Thread.java:613)
> Exception in thread "main" java.lang.NullPointerException
> at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:721)
> at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1361)
> at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
> at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
> at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
> at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
> at com.aol.test.HttpTest$PoolingHttpConnector.doGet(HttpTest.java:47)
> at com.aol.test.HttpTest.main(HttpTest.java:17)
> It should throw a checked exception in main thread so caller can handle the error condition more gracefully.
> The test program is attached. This is caused by a race condition and it's not always reproducible. Running in debugger shows a different behavior.
> package com.aol.test;
> import java.io.IOException;
> import org.apache.commons.httpclient.HttpClient;
> import org.apache.commons.httpclient.HttpStatus;
> import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
> import org.apache.commons.httpclient.methods.GetMethod;
> import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
> public class HttpTest {
>
> public static void main(String[] args) {
> PoolingHttpConnector conn = new PoolingHttpConnector();
>
> try {
> String response = conn.doGet("http://www.aol.com:80001");
> System.out.println("Response='" + response + "'");
> } catch (IOException e) {
> e.printStackTrace();
> }
> }
> static class PoolingHttpConnector {
>
> public static final int MAX_TOTAL_CONNECTIONS = 16;
> public static final int MAX_CONNECTIONS_PER_HOST = 8;
> public static final int CONNECT_TIMEOUT = 5000;
> public static final int SOCKET_TIMEOUT = 5000;
> public static final boolean TCP_NO_DELAY = true;
>
> private static MultiThreadedHttpConnectionManager poolManager;
> private static HttpConnectionManagerParams httpParams;
> private static HttpClient httpClient;
> private static boolean initialized = false;
>
> public PoolingHttpConnector()
> {
> initialize();
> }
> public String doGet(String url) throws IOException {
> GetMethod method = new GetMethod(url);
>
> try {
> int status = httpClient.executeMethod(method);
> String response = new String(method.getResponseBody());
>
> if (status != HttpStatus.SC_OK)
> throw new IOException("HTTP error: " + response);
>
> return response;
>
> } finally {
> method.releaseConnection();
> }
> }
>
> private synchronized void initialize() {
> if (initialized)
> return;
>
> poolManager = new MultiThreadedHttpConnectionManager();
> httpParams = new HttpConnectionManagerParams();
>
> httpParams.setMaxTotalConnections(MAX_TOTAL_CONNECTIONS);
> httpParams.setDefaultMaxConnectionsPerHost(MAX_CONNECTIONS_PER_HOST);
> httpParams.setTcpNoDelay(TCP_NO_DELAY);
> httpParams.setSoTimeout(SOCKET_TIMEOUT);
> httpParams.setConnectionTimeout(CONNECT_TIMEOUT);
>
> poolManager.setParams(httpParams);
> httpClient = new HttpClient(poolManager);
> initialized = true;
> }
>
> }
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
[jira] Commented: (HTTPCLIENT-813) HttpClient throws NPE on Invalid
Port when used with MultiThreadedHttpConnectionManager
Posted by "Zhihong Zhang (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCLIENT-813?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12662391#action_12662391 ]
Zhihong Zhang commented on HTTPCLIENT-813:
------------------------------------------
Just tried 4.0. It replaces invalid port with default port in Scheme.resolvePort() without any errors. In my opinion, an exception should be thrown in this case.
> HttpClient throws NPE on Invalid Port when used with MultiThreadedHttpConnectionManager
> ---------------------------------------------------------------------------------------
>
> Key: HTTPCLIENT-813
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-813
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Components: HttpClient
> Affects Versions: 3.1 Final
> Environment: Linux AS 3.1/Java 1.5
> Reporter: Zhihong Zhang
> Attachments: HttpTest.java, HttpTest2.java
>
>
> The HttpClient throws NullPointerException in the main thread when an invalid port (like 80001) is used in the URL. An IllegalArgumentException is thrown in TimeoutGuard thread.
>
> Exception in thread "Timeout guard" java.lang.IllegalArgumentException: port out of range:80001
> at java.net.InetSocketAddress.<init>(InetSocketAddress.java:118)
> at java.net.Socket.<init>(Socket.java:240)
> at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:80)
> at org.apache.commons.httpclient.protocol.ControllerThreadSocketFactory$1.doit(ControllerThreadSocketFactory.java:91)
> at org.apache.commons.httpclient.protocol.ControllerThreadSocketFactory$SocketTask.run(ControllerThreadSocketFactory.java:158)
> at java.lang.Thread.run(Thread.java:613)
> Exception in thread "main" java.lang.NullPointerException
> at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:721)
> at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1361)
> at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
> at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
> at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
> at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
> at com.aol.test.HttpTest$PoolingHttpConnector.doGet(HttpTest.java:47)
> at com.aol.test.HttpTest.main(HttpTest.java:17)
> It should throw a checked exception in main thread so caller can handle the error condition more gracefully.
> The test program is attached. This is caused by a race condition and it's not always reproducible. Running in debugger shows a different behavior.
> package com.aol.test;
> import java.io.IOException;
> import org.apache.commons.httpclient.HttpClient;
> import org.apache.commons.httpclient.HttpStatus;
> import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
> import org.apache.commons.httpclient.methods.GetMethod;
> import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
> public class HttpTest {
>
> public static void main(String[] args) {
> PoolingHttpConnector conn = new PoolingHttpConnector();
>
> try {
> String response = conn.doGet("http://www.aol.com:80001");
> System.out.println("Response='" + response + "'");
> } catch (IOException e) {
> e.printStackTrace();
> }
> }
> static class PoolingHttpConnector {
>
> public static final int MAX_TOTAL_CONNECTIONS = 16;
> public static final int MAX_CONNECTIONS_PER_HOST = 8;
> public static final int CONNECT_TIMEOUT = 5000;
> public static final int SOCKET_TIMEOUT = 5000;
> public static final boolean TCP_NO_DELAY = true;
>
> private static MultiThreadedHttpConnectionManager poolManager;
> private static HttpConnectionManagerParams httpParams;
> private static HttpClient httpClient;
> private static boolean initialized = false;
>
> public PoolingHttpConnector()
> {
> initialize();
> }
> public String doGet(String url) throws IOException {
> GetMethod method = new GetMethod(url);
>
> try {
> int status = httpClient.executeMethod(method);
> String response = new String(method.getResponseBody());
>
> if (status != HttpStatus.SC_OK)
> throw new IOException("HTTP error: " + response);
>
> return response;
>
> } finally {
> method.releaseConnection();
> }
> }
>
> private synchronized void initialize() {
> if (initialized)
> return;
>
> poolManager = new MultiThreadedHttpConnectionManager();
> httpParams = new HttpConnectionManagerParams();
>
> httpParams.setMaxTotalConnections(MAX_TOTAL_CONNECTIONS);
> httpParams.setDefaultMaxConnectionsPerHost(MAX_CONNECTIONS_PER_HOST);
> httpParams.setTcpNoDelay(TCP_NO_DELAY);
> httpParams.setSoTimeout(SOCKET_TIMEOUT);
> httpParams.setConnectionTimeout(CONNECT_TIMEOUT);
>
> poolManager.setParams(httpParams);
> httpClient = new HttpClient(poolManager);
> initialized = true;
> }
>
> }
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
[jira] Updated: (HTTPCLIENT-813) HttpClient throws NPE on Invalid
Port when used with MultiThreadedHttpConnectionManager
Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCLIENT-813?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Oleg Kalnichevski updated HTTPCLIENT-813:
-----------------------------------------
Attachment: HttpTest2.java
I can reproduce the bug for HttpClient 3.x using the test case. However, the same code ported to 4.0 API seems to work for me without throwing any exception at all. See HttpTest2 attached.
The bug in HttpClient 3.x can be worked around by providing a better implementation of the ProtocolSocketFactory.
Oleg
> HttpClient throws NPE on Invalid Port when used with MultiThreadedHttpConnectionManager
> ---------------------------------------------------------------------------------------
>
> Key: HTTPCLIENT-813
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-813
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Components: HttpClient
> Affects Versions: 3.1 Final
> Environment: Linux AS 3.1/Java 1.5
> Reporter: Zhihong Zhang
> Attachments: HttpTest.java, HttpTest2.java
>
>
> The HttpClient throws NullPointerException in the main thread when an invalid port (like 80001) is used in the URL. An IllegalArgumentException is thrown in TimeoutGuard thread.
>
> Exception in thread "Timeout guard" java.lang.IllegalArgumentException: port out of range:80001
> at java.net.InetSocketAddress.<init>(InetSocketAddress.java:118)
> at java.net.Socket.<init>(Socket.java:240)
> at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:80)
> at org.apache.commons.httpclient.protocol.ControllerThreadSocketFactory$1.doit(ControllerThreadSocketFactory.java:91)
> at org.apache.commons.httpclient.protocol.ControllerThreadSocketFactory$SocketTask.run(ControllerThreadSocketFactory.java:158)
> at java.lang.Thread.run(Thread.java:613)
> Exception in thread "main" java.lang.NullPointerException
> at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:721)
> at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1361)
> at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
> at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
> at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
> at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
> at com.aol.test.HttpTest$PoolingHttpConnector.doGet(HttpTest.java:47)
> at com.aol.test.HttpTest.main(HttpTest.java:17)
> It should throw a checked exception in main thread so caller can handle the error condition more gracefully.
> The test program is attached. This is caused by a race condition and it's not always reproducible. Running in debugger shows a different behavior.
> package com.aol.test;
> import java.io.IOException;
> import org.apache.commons.httpclient.HttpClient;
> import org.apache.commons.httpclient.HttpStatus;
> import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
> import org.apache.commons.httpclient.methods.GetMethod;
> import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
> public class HttpTest {
>
> public static void main(String[] args) {
> PoolingHttpConnector conn = new PoolingHttpConnector();
>
> try {
> String response = conn.doGet("http://www.aol.com:80001");
> System.out.println("Response='" + response + "'");
> } catch (IOException e) {
> e.printStackTrace();
> }
> }
> static class PoolingHttpConnector {
>
> public static final int MAX_TOTAL_CONNECTIONS = 16;
> public static final int MAX_CONNECTIONS_PER_HOST = 8;
> public static final int CONNECT_TIMEOUT = 5000;
> public static final int SOCKET_TIMEOUT = 5000;
> public static final boolean TCP_NO_DELAY = true;
>
> private static MultiThreadedHttpConnectionManager poolManager;
> private static HttpConnectionManagerParams httpParams;
> private static HttpClient httpClient;
> private static boolean initialized = false;
>
> public PoolingHttpConnector()
> {
> initialize();
> }
> public String doGet(String url) throws IOException {
> GetMethod method = new GetMethod(url);
>
> try {
> int status = httpClient.executeMethod(method);
> String response = new String(method.getResponseBody());
>
> if (status != HttpStatus.SC_OK)
> throw new IOException("HTTP error: " + response);
>
> return response;
>
> } finally {
> method.releaseConnection();
> }
> }
>
> private synchronized void initialize() {
> if (initialized)
> return;
>
> poolManager = new MultiThreadedHttpConnectionManager();
> httpParams = new HttpConnectionManagerParams();
>
> httpParams.setMaxTotalConnections(MAX_TOTAL_CONNECTIONS);
> httpParams.setDefaultMaxConnectionsPerHost(MAX_CONNECTIONS_PER_HOST);
> httpParams.setTcpNoDelay(TCP_NO_DELAY);
> httpParams.setSoTimeout(SOCKET_TIMEOUT);
> httpParams.setConnectionTimeout(CONNECT_TIMEOUT);
>
> poolManager.setParams(httpParams);
> httpClient = new HttpClient(poolManager);
> initialized = true;
> }
>
> }
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
[jira] Reopened: (HTTPCLIENT-813) HttpClient throws NPE on Invalid
Port when used with MultiThreadedHttpConnectionManager
Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCLIENT-813?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Oleg Kalnichevski reopened HTTPCLIENT-813:
------------------------------------------
That's certainly wrong. Reopening the issue.
Oleg
> HttpClient throws NPE on Invalid Port when used with MultiThreadedHttpConnectionManager
> ---------------------------------------------------------------------------------------
>
> Key: HTTPCLIENT-813
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-813
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Components: HttpClient
> Affects Versions: 3.1 Final
> Environment: Linux AS 3.1/Java 1.5
> Reporter: Zhihong Zhang
> Attachments: HttpTest.java, HttpTest2.java
>
>
> The HttpClient throws NullPointerException in the main thread when an invalid port (like 80001) is used in the URL. An IllegalArgumentException is thrown in TimeoutGuard thread.
>
> Exception in thread "Timeout guard" java.lang.IllegalArgumentException: port out of range:80001
> at java.net.InetSocketAddress.<init>(InetSocketAddress.java:118)
> at java.net.Socket.<init>(Socket.java:240)
> at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:80)
> at org.apache.commons.httpclient.protocol.ControllerThreadSocketFactory$1.doit(ControllerThreadSocketFactory.java:91)
> at org.apache.commons.httpclient.protocol.ControllerThreadSocketFactory$SocketTask.run(ControllerThreadSocketFactory.java:158)
> at java.lang.Thread.run(Thread.java:613)
> Exception in thread "main" java.lang.NullPointerException
> at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:721)
> at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1361)
> at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
> at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
> at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
> at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
> at com.aol.test.HttpTest$PoolingHttpConnector.doGet(HttpTest.java:47)
> at com.aol.test.HttpTest.main(HttpTest.java:17)
> It should throw a checked exception in main thread so caller can handle the error condition more gracefully.
> The test program is attached. This is caused by a race condition and it's not always reproducible. Running in debugger shows a different behavior.
> package com.aol.test;
> import java.io.IOException;
> import org.apache.commons.httpclient.HttpClient;
> import org.apache.commons.httpclient.HttpStatus;
> import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
> import org.apache.commons.httpclient.methods.GetMethod;
> import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
> public class HttpTest {
>
> public static void main(String[] args) {
> PoolingHttpConnector conn = new PoolingHttpConnector();
>
> try {
> String response = conn.doGet("http://www.aol.com:80001");
> System.out.println("Response='" + response + "'");
> } catch (IOException e) {
> e.printStackTrace();
> }
> }
> static class PoolingHttpConnector {
>
> public static final int MAX_TOTAL_CONNECTIONS = 16;
> public static final int MAX_CONNECTIONS_PER_HOST = 8;
> public static final int CONNECT_TIMEOUT = 5000;
> public static final int SOCKET_TIMEOUT = 5000;
> public static final boolean TCP_NO_DELAY = true;
>
> private static MultiThreadedHttpConnectionManager poolManager;
> private static HttpConnectionManagerParams httpParams;
> private static HttpClient httpClient;
> private static boolean initialized = false;
>
> public PoolingHttpConnector()
> {
> initialize();
> }
> public String doGet(String url) throws IOException {
> GetMethod method = new GetMethod(url);
>
> try {
> int status = httpClient.executeMethod(method);
> String response = new String(method.getResponseBody());
>
> if (status != HttpStatus.SC_OK)
> throw new IOException("HTTP error: " + response);
>
> return response;
>
> } finally {
> method.releaseConnection();
> }
> }
>
> private synchronized void initialize() {
> if (initialized)
> return;
>
> poolManager = new MultiThreadedHttpConnectionManager();
> httpParams = new HttpConnectionManagerParams();
>
> httpParams.setMaxTotalConnections(MAX_TOTAL_CONNECTIONS);
> httpParams.setDefaultMaxConnectionsPerHost(MAX_CONNECTIONS_PER_HOST);
> httpParams.setTcpNoDelay(TCP_NO_DELAY);
> httpParams.setSoTimeout(SOCKET_TIMEOUT);
> httpParams.setConnectionTimeout(CONNECT_TIMEOUT);
>
> poolManager.setParams(httpParams);
> httpClient = new HttpClient(poolManager);
> initialized = true;
> }
>
> }
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org