2

Hello I am trying to send http request using low level library chronicle wire. I was able to get this working with use of java sockets but I am curious about the diff with use of this lib. Bellow the calling code:

private static void call() throws IOException, TimeoutException {
        final String desc = "google.com";
        TCPRegistry.createServerSocketChannelFor(desc);

        EventLoop eg = new EventGroup(true);
        eg.start();
        TcpChannelHub tcpChannelHub = new TcpChannelHub(null, eg, WireType.TEXT, "",
                SocketAddressSupplier.uri(desc), false, null, HandlerPriority.HIGH, new FatalFailureConnectionStrategy(0, false));
        final long tid = tcpChannelHub.nextUniqueTransaction(System.currentTimeMillis());

        final Wire wire = new TextWire(Bytes.elasticByteBuffer());

        wire.writeDocument(true, w -> w.write("tid").int64(tid));
        wire.write("GET / HTTP/1.1\\r\\n");
        wire.write("Host google.com\\r\\n");
        tcpChannelHub.writeSocket(wire, false, false);
        tcpChannelHub.proxyReply(TimeUnit.SECONDS.toMillis(1), tid);
    }

I am getting the following error:

20:26:43.275 [main/TcpChannelHub-Reads--(none)] DEBUG net.openhft.chronicle.network.connection.TcpChannelHub - connected to remoteAddress=(none)
20:26:43.279 [main] DEBUG net.openhft.chronicle.network.connection.TcpChannelHub - tid=1606937203253 of client request
20:26:44.279 [main] WARN net.openhft.chronicle.network.connection.TcpChannelHub - 
java.util.concurrent.TimeoutException: timeoutTimeMs=1000
    at net.openhft.chronicle.network.connection.TcpChannelHub$TcpSocketConsumer.syncBlockingReadSocket(TcpChannelHub.java:1210)
    at net.openhft.chronicle.network.connection.TcpChannelHub.proxyReply(TcpChannelHub.java:685)
    at com.example.demo.DemoApplication.call(DemoApplication.java:115)
    at com.example.demo.DemoApplication.main(DemoApplication.java:31)
20:26:44.280 [main] DEBUG net.openhft.chronicle.network.connection.TcpChannelHub - closing
net.openhft.chronicle.core.StackTrace: only added for logging - please ignore ! on main
    at net.openhft.chronicle.network.connection.TcpChannelHub.closeSocket(TcpChannelHub.java:502)
    at net.openhft.chronicle.network.connection.TcpChannelHub.proxyReply(TcpChannelHub.java:693)
    at com.example.demo.DemoApplication.call(DemoApplication.java:115)
    at com.example.demo.DemoApplication.main(DemoApplication.java:31)
20:26:44.281 [main] DEBUG net.openhft.chronicle.network.connection.TcpChannelHub - disconnected to remoteAddress=(none)

Exception in thread "main" java.util.concurrent.TimeoutException: timeoutTimeMs=1000

1000ms should be enough so the problem is somewhere in the configuration.

filemonczyk
  • 1,613
  • 5
  • 26
  • 47

1 Answers1

0

While I am sure you could get this to work, it isn't a natural choice to use with HTTP.

However, if this is just an exercise, you should avoid writingDocument as this prepends a 32-bit length before the content which HTTP doesn't expect.

The createServerSocketChannelFor method is for generating a dummy server for testing purposes so it would prevent you from contacting the server you have in mind.

I suggest you get this working with a library designed for HTTP such as the one built into Java.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • 1
    thanks for answer. I was just curious how this is going to work. The problem also is on the fact that the server is using TLS so I'd have to handle that as well. Managed to do this with socket from java.net. – filemonczyk Dec 04 '20 at 09:38