Ad Widget

Collapse

org.apache.http.ConnectionClosedException: Connection closed exception

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hound
    Junior Member
    • Aug 2015
    • 9

    #1

    org.apache.http.ConnectionClosedException: Connection closed exception

    When I am making API calls to zabbix 3.0 through Java, i am getting a org.apache.http.ConnectionClosedException: Connection closed exception.
    But with zabbix 2.4 it works just fine. Here is the code

    import javax.net.ssl.*;
    import org.apache.http.client.methods.*;
    import org.apache.http.conn.ssl.*;
    import org.apache.http.impl.client.*;
    import org.apache.http.impl.nio.client.*;
    import org.apache.http.nio.conn.ssl.SSLIOSessionStrategy;
    import org.apache.http.*;
    import org.apache.http.entity.StringEntity;
    import org.apache.http.ssl.SSLContexts;
    import org.apache.http.HttpHost;
    import org.apache.http.client.config.RequestConfig;
    import java.util.concurrent.Future;
    import org.apache.http.HttpResponse;
    import org.apache.http.client.methods.HttpUriRequest;
    import org.apache.http.impl.nio.client.CloseableHttpAsync Client;
    import org.apache.http.util.EntityUtils;


    public class asynctest {


    public static void main(String[] args){

    SSLContext sslContext =null;
    try {
    sslContext = SSLContext.getDefault();
    } catch(Exception e) {

    }

    String[] prots = new String[2];
    prots[0] = "TLSv1";
    prots[1] = "SSLv3";


    SSLIOSessionStrategy sslSessionStrategy = new SSLIOSessionStrategy(
    sslContext,
    prots,
    null,
    SSLIOSessionStrategy.ALLOW_ALL_HOSTNAME_VERIFIER);
    // SSLIOSessionStrategy sslSessionStrategy = new SSLIOSessionStrategy(sslContext);

    HttpHost proxy = new HttpHost("myproxy.com", 8080);
    HttpAsyncClientBuilder builder = HttpAsyncClients.custom();
    builder.setSSLStrategy(sslSessionStrategy);
    builder.setProxy(proxy);
    CloseableHttpAsyncClient client = builder.build();


    client.start();

    String requestBodyJson = "{\"jsonrpc\": \"2.0\",\"method\": \"user.login\",\"params\": {\"user\": \"###\",\"password\": \"###\"},\"id\" : 1}";

    //"Content-Type" -> "application/json-rpc"


    HttpPost request = new HttpPost("myzabbix.com/api_jsonrpc.php");

    StringEntity entity = null;

    try {
    entity = new StringEntity(requestBodyJson);
    } catch(Exception e) {}

    request.setEntity(entity);
    request.addHeader("Content-Type","application/json");
    System.out.println("\nStarting!");
    Future<HttpResponse> response = client.execute(request, null);
    System.out.println("\nReturned!");
    if(response == null) {
    System.out.println("Failed!");
    } else {
    try {
    System.out.println("\n\nResponse: " + response.get().getStatusLine().getStatusCode());
    System.out.println("\n\nResponse: " + EntityUtils.toString(response.get().getEntity()));
    //} catch(Exception e) { e.printStackTrace(); }
    } catch(Exception e) { System.out.println("Exception! " + e.getMessage()); }
    }

    }

    }

    Any help will be appreciated
  • burn1024
    Member
    • Jun 2012
    • 52

    #2
    check web server logs

    Comment

    Working...