You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Diego Ribeiro de Souza <ri...@gmail.com> on 2012/04/03 21:18:16 UTC

Is possible to send a request through 3G moden and a network adapter?

Hi there,

I don´t have much experience with HttpClient and I´m afraid of doing
something wrong. I´m trying to send a request through a 3G moden and
another through my Network Adapter. I manage to send a request individually
but whem I tried to send one request through de 3G modem and another
through the network adapter only the the 3G Modem works, whem the
HttpClient try to send the request through the network adapter this happens:

Response: HTTP/1.1 200 OK with the IP: /187.27.12.199
03/04/2012 13:50:59 org.apache.http.impl.client.DefaultRequestDirector
tryConnect
INFO: I/O exception (java.net.SocketException) caught when connecting to
the target host: Network is unreachable: connect
03/04/2012 13:50:59 org.apache.http.impl.client.DefaultRequestDirector
tryConnect
INFO: Retrying connect
03/04/2012 13:50:59 org.apache.http.impl.client.DefaultRequestDirector
tryConnect
INFO: I/O exception (java.net.SocketException) caught when connecting to
the target host: Network is unreachable: connect
03/04/2012 13:50:59 org.apache.http.impl.client.DefaultRequestDirector
tryConnect
INFO: Retrying connect
03/04/2012 13:50:59 org.apache.http.impl.client.DefaultRequestDirector
tryConnect
INFO: I/O exception (java.net.SocketException) caught when connecting to
the target host: Network is unreachable: connect
03/04/2012 13:50:59 org.apache.http.impl.client.DefaultRequestDirector
tryConnect
INFO: Retrying connect
Exception in thread "main" java.net.SocketException: Network is
unreachable: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
    at java.net.Socket.connect(Socket.java:529)
    at
org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:120)
    at
org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:177)
    at
org.apache.http.conn.scheme.SchemeSocketFactoryAdaptor.connectSocket(SchemeSocketFactoryAdaptor.java:62)
    at
org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:148)
    at
org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:149)
    at
org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:121)
    at
org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:562)
    at
org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:415)
    at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
    at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
    at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)
    at br.com.fiveware.Main.main(Main.java:40)

The first line shows that the request went fine through the 3G, but the log
and the exception shows that it wasn´t possible to find a connection
through the network adapter.

The code that a wrote is this:

package org.test.httpclient;

import java.io.*;
import java.net.*;
import java.util.*;

import org.apache.http.*;
import org.apache.http.client.*;
import org.apache.http.client.methods.*;
import org.apache.http.conn.params.*;
import org.apache.http.conn.scheme.*;
import org.apache.http.impl.client.*;
import org.apache.http.impl.conn.tsccm.*;

public class Main {

    private static final int HTTP_PORT = 80;

    @SuppressWarnings("deprecation")
    public static void main(String[] args) throws ClientProtocolException,
IOException, UnhandledException {
        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http",
PlainSocketFactory.getSocketFactory(), HTTP_PORT));

        ThreadSafeClientConnManager connectionManager = new
ThreadSafeClientConnManager();

        DefaultHttpClient client = new DefaultHttpClient(connectionManager);

        List<InetAddress> ips = new ArrayList<InetAddress>();
        ips.add(InetAddress.getByName("187.27.12.199"));
        ips.add(InetAddress.getByName("192.168.1.172"));

        for (int i = 0; i < ips.size(); i++) {
            HttpGet get = new HttpGet("http://www.apache.org/");
            get.getParams().setParameter(ConnRouteParams.LOCAL_ADDRESS,
ips.get(i));
            HttpResponse response = client.execute(get);
            InetAddress ip = (InetAddress)
response.getParams().getParameter(ConnRouteParams.LOCAL_ADDRESS);
            System.out.println("Response: " + response.getStatusLine() + "
with the IP: " + ip);
        }

    }

}


Is this a OS problem or there is a way of making this work?

Thanks,
Diego.