Discussion:
Question about HttP Core
COURTAULT Francois
2018-02-07 16:34:37 UTC
Permalink
Hello,

First I don't know if I use the appropriate mailing-list. If I look at http://hc.apache.org/mail.html , my understanding is that I can't use neither HttpComponents Commits list nor HttpComponents Dev list, right ?

I took a look at http://hc.apache.org/httpcomponents-core-4.4.x/examples.html and especially Synchronous HTTP file server.
I use this sample for my own purpose and I don't understand why some lines of code are not working.
Basically, I have:

SocketConfig socketConfig = SocketConfig.custom()
.setSoTimeout(15000)
.setTcpNoDelay(true)
.build();

final HttpServer server = ServerBootstrap.bootstrap()
.setListenerPort(80)
.setServerInfo("My Server/1.1")
.setSocketConfig(socketConfig)
.setExceptionLogger(new StdErrorExceptionLogger())
.registerHandler("/myurl", new MyURLHandler())
.create();


try {
server.start();
server.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
System.out.println("Simple HTTP server using Http Core started. Waiting for request ...");
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}

Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
server.shutdown(5, TimeUnit.SECONDS);
}
});

If I keep server.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);, I never saw Simple HTTP server using Http Core started. Waiting for request ... message.
Do you know why ?

Best Regards.
________________________________
This message and any attachments are intended solely for the addressees and may contain confidential information. Any unauthorized use or disclosure, either whole or partial, is prohibited.
E-mails are susceptible to alteration. Our company shall not be liable for the message if altered, changed or falsified. If you are not the intended recipient of this message, please delete it and notify the sender.
Although all reasonable efforts have been made to keep this transmission free from viruses, the sender will not be liable for damages caused by a transmitted virus.
Yossi Tamari
2018-02-07 16:56:51 UTC
Permalink
Hi Francois,

I believe the problem is that the implementation of awaitTermination in Java
requires that the amount of time in *nanoseconds* is no more than
Long.MAX_VALUE. This has nothing to do with HC.
To get the maximum possible delay, just do
server.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
(This gives you close to 300 years, I hope that's enough...)

Yossi.
-----Original Message-----
Sent: 07 February 2018 18:35
Subject: Question about HttP Core
Hello,
First I don't know if I use the appropriate mailing-list. If I look at
http://hc.apache.org/mail.html , my understanding is that I can't use
neither
HttpComponents Commits list nor HttpComponents Dev list, right ?
I took a look at http://hc.apache.org/httpcomponents-core-
4.4.x/examples.html and especially Synchronous HTTP file server.
I use this sample for my own purpose and I don't understand why some lines
of
code are not working.
SocketConfig socketConfig = SocketConfig.custom()
.setSoTimeout(15000)
.setTcpNoDelay(true)
.build();
final HttpServer server = ServerBootstrap.bootstrap()
.setListenerPort(80)
.setServerInfo("My Server/1.1")
.setSocketConfig(socketConfig)
.setExceptionLogger(new StdErrorExceptionLogger())
.registerHandler("/myurl", new MyURLHandler())
.create();
try {
server.start();
server.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
System.out.println("Simple HTTP server using Http Core started. Waiting
for
request ..."); } catch (IOException | InterruptedException e) {
e.printStackTrace();
}
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
server.shutdown(5, TimeUnit.SECONDS);
}
});
If I keep server.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);, I never
saw Simple HTTP server using Http Core started. Waiting for request ...
message.
Do you know why ?
Best Regards.
________________________________
This message and any attachments are intended solely for the addressees
and
may contain confidential information. Any unauthorized use or disclosure,
either
whole or partial, is prohibited.
E-mails are susceptible to alteration. Our company shall not be liable for
the
message if altered, changed or falsified. If you are not the intended
recipient of
this message, please delete it and notify the sender.
Although all reasonable efforts have been made to keep this transmission
free
from viruses, the sender will not be liable for damages caused by a
transmitted
virus.
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
COURTAULT Francois
2018-02-07 17:07:55 UTC
Permalink
Hello Yossi,

Change to: server.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
But never see "Simple HTTP server using Http Core started. Waiting for request ..." message unfortunately :-(

Best Regards.

-----Original Message-----
From: Yossi Tamari [mailto:***@yossi.at]
Sent: mercredi 7 février 2018 17:57
To: 'HttpClient User Discussion' <httpclient-***@hc.apache.org>
Subject: RE: Question about HttP Core

Hi Francois,

I believe the problem is that the implementation of awaitTermination in Java requires that the amount of time in *nanoseconds* is no more than Long.MAX_VALUE. This has nothing to do with HC.
To get the maximum possible delay, just do server.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); (This gives you close to 300 years, I hope that's enough...)

Yossi.
-----Original Message-----
Sent: 07 February 2018 18:35
Subject: Question about HttP Core
Hello,
First I don't know if I use the appropriate mailing-list. If I look at
http://hc.apache.org/mail.html , my understanding is that I can't use
neither
HttpComponents Commits list nor HttpComponents Dev list, right ?
I took a look at http://hc.apache.org/httpcomponents-core-
4.4.x/examples.html and especially Synchronous HTTP file server.
I use this sample for my own purpose and I don't understand why some lines
of
code are not working.
SocketConfig socketConfig = SocketConfig.custom()
.setSoTimeout(15000)
.setTcpNoDelay(true)
.build();
final HttpServer server = ServerBootstrap.bootstrap()
.setListenerPort(80)
.setServerInfo("My Server/1.1")
.setSocketConfig(socketConfig)
.setExceptionLogger(new StdErrorExceptionLogger())
.registerHandler("/myurl", new MyURLHandler())
.create();
try {
server.start();
server.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
System.out.println("Simple HTTP server using Http Core started. Waiting
for
request ..."); } catch (IOException | InterruptedException e) {
e.printStackTrace();
}
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
server.shutdown(5, TimeUnit.SECONDS);
}
});
If I keep server.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);, I
never saw Simple HTTP server using Http Core started. Waiting for request ...
message.
Do you know why ?
Best Regards.
________________________________
This message and any attachments are intended solely for the
addressees
and
may contain confidential information. Any unauthorized use or
disclosure,
either
whole or partial, is prohibited.
E-mails are susceptible to alteration. Our company shall not be liable for
the
message if altered, changed or falsified. If you are not the intended
recipient of
this message, please delete it and notify the sender.
Although all reasonable efforts have been made to keep this
transmission
free
from viruses, the sender will not be liable for damages caused by a
transmitted
virus.
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org

________________________________
This message and any attachments are intended solely for the addressees and may contain confidential information. Any unauthorized use or disclosure, either whole or partial, is prohibited.
E-mails are susceptible to alteration. Our company shall not be liable for the message if altered, changed or falsified. If you are not the intended recipient of this message, please delete it and notify the sender.
Although all reasonable efforts have been made to keep this transmission free from viruses, the sender will not be liable for damages caused by a transmitted virus.

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Oleg Kalnichevski
2018-02-08 08:40:20 UTC
Permalink
Post by COURTAULT Francois
Hello Yossi,
Change to: server.awaitTermination(Long.MAX_VALUE,
TimeUnit.NANOSECONDS);
But never see "Simple HTTP server using Http Core started. Waiting
for request ..." message unfortunately :-(
Why do you expect to see those lines in the first place?

---
server.start();
server.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
System.out.println("...
---

What that basically means is that the server starts and blocks in
#awaitTermination method until one two conditions takes place: the
server terminates or 2'147'483'647 days elapse. Only then the
System.out.println would be executed. You might not want to wait that
long and re-structure your application logic instead.


Oleg

PS: HttpCore does not have a separate user list. One should post
questions regarding HttpCore either to this list or the developer list.
Post by COURTAULT Francois
Best Regards.
-----Original Message-----
Sent: mercredi 7 février 2018 17:57
Subject: RE: Question about HttP Core
Hi Francois,
I believe the problem is that the implementation of awaitTermination
in Java requires that the amount of time in *nanoseconds* is no more
than Long.MAX_VALUE. This has nothing to do with HC.
To get the maximum possible delay, just do
server.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); (This
gives you close to 300 years, I hope that's enough...)
        Yossi.
-----Original Message-----
Sent: 07 February 2018 18:35
Subject: Question about HttP Core
Hello,
First I don't know if I use the appropriate mailing-list. If I look at
http://hc.apache.org/mail.html , my understanding is that I can't use
neither
HttpComponents Commits list nor HttpComponents Dev list, right ?
I took  a look at http://hc.apache.org/httpcomponents-core-
4.4.x/examples.html and especially Synchronous HTTP file server.
I use this sample for my own purpose and I don't understand why
some
lines
of
code are not working.
SocketConfig socketConfig = SocketConfig.custom()
    .setSoTimeout(15000)
    .setTcpNoDelay(true)
    .build();
final HttpServer server = ServerBootstrap.bootstrap()
    .setListenerPort(80)
    .setServerInfo("My Server/1.1")
    .setSocketConfig(socketConfig)
    .setExceptionLogger(new StdErrorExceptionLogger())
    .registerHandler("/myurl", new MyURLHandler())
    .create();
try {
  server.start();
  server.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
  System.out.println("Simple HTTP server using Http Core started.
Waiting
for
request ..."); } catch (IOException | InterruptedException e) {
  e.printStackTrace();
}
Runtime.getRuntime().addShutdownHook(new Thread() {
  public void run() {
    server.shutdown(5, TimeUnit.SECONDS);
  }
});
If I keep server.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);, I
never saw  Simple HTTP server using Http Core started. Waiting for
request ...
message.
Do you know why ?
Best Regards.
________________________________
This message and any attachments are intended solely for the
addressees
and
may contain confidential information. Any unauthorized use or disclosure,
either
whole or partial, is prohibited.
E-mails are susceptible to alteration. Our company shall not be
liable
for
the
message if altered, changed or falsified. If you are not the
intended
recipient of
this message, please delete it and notify the sender.
Although all reasonable efforts have been made to keep this
transmission
free
from viruses, the sender will not be liable for damages caused by a
transmitted
virus.
---------------------------------------------------------------------
________________________________
 This message and any attachments are intended solely for the
addressees and may contain confidential information. Any unauthorized
use or disclosure, either whole or partial, is prohibited.
E-mails are susceptible to alteration. Our company shall not be
liable for the message if altered, changed or falsified. If you are
not the intended recipient of this message, please delete it and
notify the sender.
Although all reasonable efforts have been made to keep this
transmission free from viruses, the sender will not be liable for
damages caused by a transmitted virus.
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
COURTAULT Francois
2018-02-09 10:27:08 UTC
Permalink
Hello Oleg,

Thanks a lot for your explanation. I think I have understood you.
This is not because we have server.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS) that the server can't accept several requests, right ?

BTW, is there a way to know when this kind of timeout has been reached in order to log something or to execute something ?

Best Regards.

-----Original Message-----
From: Oleg Kalnichevski [mailto:***@apache.org]
Sent: jeudi 8 février 2018 09:40
To: HttpClient User Discussion <httpclient-***@hc.apache.org>
Subject: Re: Question about HttP Core
Post by COURTAULT Francois
Hello Yossi,
Change to: server.awaitTermination(Long.MAX_VALUE,
TimeUnit.NANOSECONDS);
But never see "Simple HTTP server using Http Core started. Waiting for
request ..." message unfortunately :-(
Why do you expect to see those lines in the first place?

---
server.start();
server.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS); System.out.println("...
---

What that basically means is that the server starts and blocks in #awaitTermination method until one two conditions takes place: the server terminates or 2'147'483'647 days elapse. Only then the System.out.println would be executed. You might not want to wait that long and re-structure your application logic instead.


Oleg

PS: HttpCore does not have a separate user list. One should post questions regarding HttpCore either to this list or the developer list.
Post by COURTAULT Francois
Best Regards.
-----Original Message-----
Sent: mercredi 7 février 2018 17:57
Subject: RE: Question about HttP Core
Hi Francois,
I believe the problem is that the implementation of awaitTermination
in Java requires that the amount of time in *nanoseconds* is no more
than Long.MAX_VALUE. This has nothing to do with HC.
To get the maximum possible delay, just do
server.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); (This
gives you close to 300 years, I hope that's enough...)
Yossi.
-----Original Message-----
Sent: 07 February 2018 18:35
Subject: Question about HttP Core
Hello,
First I don't know if I use the appropriate mailing-list. If I look
at http://hc.apache.org/mail.html , my understanding is that I can't
use
neither
HttpComponents Commits list nor HttpComponents Dev list, right ?
I took a look at http://hc.apache.org/httpcomponents-core-
4.4.x/examples.html and especially Synchronous HTTP file server.
I use this sample for my own purpose and I don't understand why some lines
of
code are not working.
SocketConfig socketConfig = SocketConfig.custom()
.setSoTimeout(15000)
.setTcpNoDelay(true)
.build();
final HttpServer server = ServerBootstrap.bootstrap()
.setListenerPort(80)
.setServerInfo("My Server/1.1")
.setSocketConfig(socketConfig)
.setExceptionLogger(new StdErrorExceptionLogger())
.registerHandler("/myurl", new MyURLHandler())
.create();
try {
server.start();
server.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
System.out.println("Simple HTTP server using Http Core started. Waiting
for
request ..."); } catch (IOException | InterruptedException e) {
e.printStackTrace();
}
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
server.shutdown(5, TimeUnit.SECONDS);
}
});
If I keep server.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);, I
never saw Simple HTTP server using Http Core started. Waiting for request ...
message.
Do you know why ?
Best Regards.
________________________________
This message and any attachments are intended solely for the
addressees
and
may contain confidential information. Any unauthorized use or disclosure,
either
whole or partial, is prohibited.
E-mails are susceptible to alteration. Our company shall not be liable for
the
message if altered, changed or falsified. If you are not the
intended
recipient of
this message, please delete it and notify the sender.
Although all reasonable efforts have been made to keep this
transmission
free
from viruses, the sender will not be liable for damages caused by a
transmitted
virus.
---------------------------------------------------------------------
________________________________
This message and any attachments are intended solely for the
addressees and may contain confidential information. Any unauthorized
use or disclosure, either whole or partial, is prohibited.
E-mails are susceptible to alteration. Our company shall not be liable
for the message if altered, changed or falsified. If you are not the
intended recipient of this message, please delete it and notify the
sender.
Although all reasonable efforts have been made to keep this
transmission free from viruses, the sender will not be liable for
damages caused by a transmitted virus.
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org

________________________________
This message and any attachments are intended solely for the addressees and may contain confidential information. Any unauthorized use or disclosure, either whole or partial, is prohibited.
E-mails are susceptible to alteration. Our company shall not be liable for the message if altered, changed or falsified. If you are not the intended recipient of this message, please delete it and notify the sender.
Although all reasonable efforts have been made to keep this transmission free from viruses, the sender will not be liable for damages caused by a transmitted virus.
B�KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKCB��[��X��ܚX�KK[XZ[��Y[� ]\�\��][��X��ܚX�P˘\X�K�ܙ�B��܈Y][ۘ[��[X[
Oleg Kalnichevski
2018-02-09 11:05:11 UTC
Permalink
Post by COURTAULT Francois
Hello Oleg,
Thanks a lot for your explanation. I think I have understood you.
This is not because we have server.awaitTermination(Long.MAX_VALUE,
TimeUnit.DAYS) that the server can't accept several requests, right ?
Correct.
Post by COURTAULT Francois
BTW, is there a way to know when this kind of timeout has been
reached in order to log something or to execute something ?
I am not sure I understand.

Oleg

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Loading...