Java Code Examples for java.net.ConnectException#printStackTrace()

The following examples show how to use java.net.ConnectException#printStackTrace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProxyHttpTransparent.java    From PacketProxy with Apache License 2.0 4 votes vote down vote up
private void createHttpTransparentProxy(Socket client) throws Exception {
	InputStream ins = client.getInputStream();
	ByteArrayOutputStream bout = new ByteArrayOutputStream();
	HostPort hostPort = null;

	byte[] input_data = new byte[4096];
	int length = 0;
	while ((length = ins.read(input_data, 0, input_data.length)) != -1) {
		bout.write(input_data, 0, length);
		int accepted_input_size = 0;
		if (bout.size() > 0 && (accepted_input_size = Http.parseHttpDelimiter(bout.toByteArray())) > 0) {
			hostPort = parseHostName(ArrayUtils.subarray(bout.toByteArray(), 0, accepted_input_size));
			break;
		}
	}
	if (hostPort == null) {
		PacketProxyUtility.getInstance().packetProxyLogErr(new String(input_data));
		PacketProxyUtility.getInstance().packetProxyLogErr("bout length == " + bout.size());
		if(bout.size() == 0){
			PacketProxyUtility.getInstance().packetProxyLogErr("empty request!!");
			return;
		}
		PacketProxyUtility.getInstance().packetProxyLogErr("HTTP Host field is not found.");
		return ;
	}

	ByteArrayInputStream lookaheadBuffer = new ByteArrayInputStream(bout.toByteArray());

	try {
		Endpoint client_e = EndpointFactory.createClientEndpoint(client, lookaheadBuffer);
		Endpoint server_e = EndpointFactory.createServerEndpoint(hostPort.getInetSocketAddress());


		Server server = Servers.getInstance().queryByHostNameAndPort(hostPort.getHostName(), listen_info.getPort());
		createConnection(client_e, server_e, server);
	} 
	catch(ConnectException e) {
		InetSocketAddress addr = hostPort.getInetSocketAddress();
		PacketProxyUtility.getInstance().packetProxyLog("Connection Refused: " + addr.getHostName() + ":" + addr.getPort());
		e.printStackTrace();
	}
}
 
Example 2
Source File: RunToExit.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
    // find a free port
    ServerSocket ss = new ServerSocket(0);
    int port = ss.getLocalPort();
    ss.close();

    String address = String.valueOf(port);

    // launch the server debuggee
    Process process = launch(address, "Exit0");

    // attach to server debuggee and resume it so it can exit
    AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
    Map conn_args = conn.defaultArguments();
    Connector.IntegerArgument port_arg =
        (Connector.IntegerArgument)conn_args.get("port");
    port_arg.setValue(port);

    System.out.println("Connection arguments: " + conn_args);

    VirtualMachine vm = null;
    while (vm == null) {
        try {
            vm = conn.attach(conn_args);
        } catch (ConnectException e) {
            e.printStackTrace(System.out);
            System.out.println("--- Debugee not ready. Retrying in 500ms. ---");
            Thread.sleep(500);
        }
    }

    // The first event is always a VMStartEvent, and it is always in
    // an EventSet by itself.  Wait for it.
    EventSet evtSet = vm.eventQueue().remove();
    for (Event event: evtSet) {
        if (event instanceof VMStartEvent) {
            break;
        }
        throw new RuntimeException("Test failed - debuggee did not start properly");
    }
    vm.eventRequestManager().deleteAllBreakpoints();
    vm.resume();

    int exitCode = process.waitFor();

    // if the server debuggee ran cleanly, we assume we were clean
    if (exitCode == 0 && error_seen == 0) {
        System.out.println("Test passed - server debuggee cleanly terminated");
    } else {
        throw new RuntimeException("Test failed - server debuggee generated an error when it terminated, " +
            "exit code was " + exitCode + ", " + error_seen + " error(s) seen in debugee output.");
    }
}