You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Han Yainsun <Ya...@hotmail.com> on 2023/11/14 04:09:47 UTC

Jetty Component how to add additional steps after send http response back to the client

Dear Camel Community and Camel users,

Greetings to you!

Camel version: 3.20.4
Spring Boot version: 2.7.11
JDK: Amazon Corretto 17
Platform: Windows server 2019
IDE: IntelliJ IDEA 2021.3.2 (Community Edition)

I have an requirement that need calculate each message process time, incould total process time and backend process time. the route likes below, it seems that the jetty managed the http session and send the response  back to client automatically at the end of route.

Is it possible to explicitly inform jetty send the resonse at specific point?

Thansk in advance.

      from("jetty:http://0.0.0.0:8080/test")
      .process(exchange -> exchange.setProperty("inbound timestamp", System.currentTimeMillis()))
      .to("http://localhost/mockbackend")      
      .process(exchange -> exchange.setProperty("backend respond timestamp", System.currentTimeMillis()))
      .setBody(constant("hello"))
      // I expect jetty send response back to client here.
      .process(exchange -> exchange.setProperty("backend respond timestamp", System.currentTimeMillis()));


回复: Jetty Component how to add additional steps after send http response back to the client

Posted by Han Yainsun <ya...@hotmail.com>.
Dear all,

Does anyone have idea regarding this question? Or any workaroud?

I appreciate all the inputs.

Thanks in advance~
________________________________
发件人: Han Yainsun <Ya...@hotmail.com>
发送时间: 2023年11月14日 4:09
收件人: users@camel.apache.org <us...@camel.apache.org>
主题: Jetty Component how to add additional steps after send http response back to the client

Dear Camel Community and Camel users,

Greetings to you!

Camel version: 3.20.4
Spring Boot version: 2.7.11
JDK: Amazon Corretto 17
Platform: Windows server 2019
IDE: IntelliJ IDEA 2021.3.2 (Community Edition)

I have an requirement that need calculate each message process time, incould total process time and backend process time. the route likes below, it seems that the jetty managed the http session and send the response  back to client automatically at the end of route.

Is it possible to explicitly inform jetty send the resonse at specific point?

Thansk in advance.

      from("jetty:http://0.0.0.0:8080/test")
      .process(exchange -> exchange.setProperty("inbound timestamp", System.currentTimeMillis()))
      .to("http://localhost/mockbackend")      
      .process(exchange -> exchange.setProperty("backend respond timestamp", System.currentTimeMillis()))
      .setBody(constant("hello"))
      // I expect jetty send response back to client here.
      .process(exchange -> exchange.setProperty("backend respond timestamp", System.currentTimeMillis()));


Re: Jetty Component how to add additional steps after send http response back to the client

Posted by ski n <ra...@gmail.com>.
Or take a look at the wire tap pattern:

https://camel.apache.org/components/4.0.x/eips/wireTap-eip.html

Raymond

On Sun, Nov 19, 2023 at 2:05 PM Claus Ibsen <cl...@gmail.com> wrote:

> Hi
>
> You can also look at using onCompletion
> https://camel.apache.org/manual/oncompletion.html
>
> On Sat, Nov 18, 2023 at 8:36 PM Claus Ibsen <cl...@gmail.com> wrote:
>
> > Hi
> >
> > I would also add that HTTP servers like Tomcat, Jetty, JBoss etc have an
> > access log that logs how long time each request takes. And they often
> have
> > a API / plugin you can use to have your custom code triggered by the HTTP
> > server
> > so you can do any kind of "how long time it takes" you need.
> >
> >
> > On Sat, Nov 18, 2023 at 8:34 PM Claus Ibsen <cl...@gmail.com>
> wrote:
> >
> >> Hi
> >>
> >> Camel will send back the response at the end of the route in the
> >> consumer, so what you do in that route example will not work.
> >> However if you want to do some kind of custom logging of how long it
> >> takes, then Camel Jetty has send back the response to the client, when
> the
> >> UnitOfWork is done.
> >> So you can use Camel's UoW done to do any custom code for "backend
> >> response timestamp ...".
> >>
> >> See the docs for UnitOfWork or its also covered in the CiA2 book.
> >>
> >>
> >>
> >> On Tue, Nov 14, 2023 at 5:11 AM Han Yainsun <Ya...@hotmail.com>
> wrote:
> >>
> >>> Dear Camel Community and Camel users,
> >>>
> >>> Greetings to you!
> >>>
> >>> Camel version: 3.20.4
> >>> Spring Boot version: 2.7.11
> >>> JDK: Amazon Corretto 17
> >>> Platform: Windows server 2019
> >>> IDE: IntelliJ IDEA 2021.3.2 (Community Edition)
> >>>
> >>> I have an requirement that need calculate each message process time,
> >>> incould total process time and backend process time. the route likes
> below,
> >>> it seems that the jetty managed the http session and send the response
> >>> back to client automatically at the end of route.
> >>>
> >>> Is it possible to explicitly inform jetty send the resonse at specific
> >>> point?
> >>>
> >>> Thansk in advance.
> >>>
> >>> from("jetty:http://0.0.0.0:8080/test")
> >>> .process(exchange -> exchange.setProperty("inbound timestamp",
> >>> System.currentTimeMillis()))
> >>> .to("http://localhost/mockbackend")
> >>> .process(exchange -> exchange.setProperty("backend respond timestamp",
> >>> System.currentTimeMillis()))
> >>> .setBody(constant("hello"))
> >>> // I expect jetty send response back to client here.
> >>> .process(exchange -> exchange.setProperty("backend respond timestamp",
> >>> System.currentTimeMillis()));
> >>>
> >>>
> >>
> >> --
> >> Claus Ibsen
> >> -----------------
> >> @davsclaus
> >> Camel in Action 2: https://www.manning.com/ibsen2
> >>
> >
> >
> > --
> > Claus Ibsen
> > -----------------
> > @davsclaus
> > Camel in Action 2: https://www.manning.com/ibsen2
> >
>
>
> --
> Claus Ibsen
> -----------------
> @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2
>

Re: Jetty Component how to add additional steps after send http response back to the client

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

You can also look at using onCompletion
https://camel.apache.org/manual/oncompletion.html

On Sat, Nov 18, 2023 at 8:36 PM Claus Ibsen <cl...@gmail.com> wrote:

> Hi
>
> I would also add that HTTP servers like Tomcat, Jetty, JBoss etc have an
> access log that logs how long time each request takes. And they often have
> a API / plugin you can use to have your custom code triggered by the HTTP
> server
> so you can do any kind of "how long time it takes" you need.
>
>
> On Sat, Nov 18, 2023 at 8:34 PM Claus Ibsen <cl...@gmail.com> wrote:
>
>> Hi
>>
>> Camel will send back the response at the end of the route in the
>> consumer, so what you do in that route example will not work.
>> However if you want to do some kind of custom logging of how long it
>> takes, then Camel Jetty has send back the response to the client, when the
>> UnitOfWork is done.
>> So you can use Camel's UoW done to do any custom code for "backend
>> response timestamp ...".
>>
>> See the docs for UnitOfWork or its also covered in the CiA2 book.
>>
>>
>>
>> On Tue, Nov 14, 2023 at 5:11 AM Han Yainsun <Ya...@hotmail.com> wrote:
>>
>>> Dear Camel Community and Camel users,
>>>
>>> Greetings to you!
>>>
>>> Camel version: 3.20.4
>>> Spring Boot version: 2.7.11
>>> JDK: Amazon Corretto 17
>>> Platform: Windows server 2019
>>> IDE: IntelliJ IDEA 2021.3.2 (Community Edition)
>>>
>>> I have an requirement that need calculate each message process time,
>>> incould total process time and backend process time. the route likes below,
>>> it seems that the jetty managed the http session and send the response
>>> back to client automatically at the end of route.
>>>
>>> Is it possible to explicitly inform jetty send the resonse at specific
>>> point?
>>>
>>> Thansk in advance.
>>>
>>> from("jetty:http://0.0.0.0:8080/test")
>>> .process(exchange -> exchange.setProperty("inbound timestamp",
>>> System.currentTimeMillis()))
>>> .to("http://localhost/mockbackend")
>>> .process(exchange -> exchange.setProperty("backend respond timestamp",
>>> System.currentTimeMillis()))
>>> .setBody(constant("hello"))
>>> // I expect jetty send response back to client here.
>>> .process(exchange -> exchange.setProperty("backend respond timestamp",
>>> System.currentTimeMillis()));
>>>
>>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> @davsclaus
>> Camel in Action 2: https://www.manning.com/ibsen2
>>
>
>
> --
> Claus Ibsen
> -----------------
> @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2
>


-- 
Claus Ibsen
-----------------
@davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: Jetty Component how to add additional steps after send http response back to the client

Posted by Han Yainsun <ya...@hotmail.com>.
Dear Claus lbsen,

Thanks so much for your suggestions, I will try both.

Thanks again for your kind help. Have a nice day. :)

________________________________
From: Claus Ibsen <cl...@gmail.com>
Sent: Sunday, November 19, 2023 3:36:23 AM
To: users@camel.apache.org <us...@camel.apache.org>
Subject: Re: Jetty Component how to add additional steps after send http response back to the client

Hi

I would also add that HTTP servers like Tomcat, Jetty, JBoss etc have an
access log that logs how long time each request takes. And they often have
a API / plugin you can use to have your custom code triggered by the HTTP
server
so you can do any kind of "how long time it takes" you need.


On Sat, Nov 18, 2023 at 8:34 PM Claus Ibsen <cl...@gmail.com> wrote:

> Hi
>
> Camel will send back the response at the end of the route in the consumer,
> so what you do in that route example will not work.
> However if you want to do some kind of custom logging of how long it
> takes, then Camel Jetty has send back the response to the client, when the
> UnitOfWork is done.
> So you can use Camel's UoW done to do any custom code for "backend
> response timestamp ...".
>
> See the docs for UnitOfWork or its also covered in the CiA2 book.
>
>
>
> On Tue, Nov 14, 2023 at 5:11 AM Han Yainsun <Ya...@hotmail.com> wrote:
>
>> Dear Camel Community and Camel users,
>>
>> Greetings to you!
>>
>> Camel version: 3.20.4
>> Spring Boot version: 2.7.11
>> JDK: Amazon Corretto 17
>> Platform: Windows server 2019
>> IDE: IntelliJ IDEA 2021.3.2 (Community Edition)
>>
>> I have an requirement that need calculate each message process time,
>> incould total process time and backend process time. the route likes below,
>> it seems that the jetty managed the http session and send the response
>> back to client automatically at the end of route.
>>
>> Is it possible to explicitly inform jetty send the resonse at specific
>> point?
>>
>> Thansk in advance.
>>
>> from("jetty:http://0.0.0.0:8080/test")
>> .process(exchange -> exchange.setProperty("inbound timestamp",
>> System.currentTimeMillis()))
>> .to("http://localhost/mockbackend")
>> .process(exchange -> exchange.setProperty("backend respond timestamp",
>> System.currentTimeMillis()))
>> .setBody(constant("hello"))
>> // I expect jetty send response back to client here.
>> .process(exchange -> exchange.setProperty("backend respond timestamp",
>> System.currentTimeMillis()));
>>
>>
>
> --
> Claus Ibsen
> -----------------
> @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2
>


--
Claus Ibsen
-----------------
@davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: Jetty Component how to add additional steps after send http response back to the client

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

I would also add that HTTP servers like Tomcat, Jetty, JBoss etc have an
access log that logs how long time each request takes. And they often have
a API / plugin you can use to have your custom code triggered by the HTTP
server
so you can do any kind of "how long time it takes" you need.


On Sat, Nov 18, 2023 at 8:34 PM Claus Ibsen <cl...@gmail.com> wrote:

> Hi
>
> Camel will send back the response at the end of the route in the consumer,
> so what you do in that route example will not work.
> However if you want to do some kind of custom logging of how long it
> takes, then Camel Jetty has send back the response to the client, when the
> UnitOfWork is done.
> So you can use Camel's UoW done to do any custom code for "backend
> response timestamp ...".
>
> See the docs for UnitOfWork or its also covered in the CiA2 book.
>
>
>
> On Tue, Nov 14, 2023 at 5:11 AM Han Yainsun <Ya...@hotmail.com> wrote:
>
>> Dear Camel Community and Camel users,
>>
>> Greetings to you!
>>
>> Camel version: 3.20.4
>> Spring Boot version: 2.7.11
>> JDK: Amazon Corretto 17
>> Platform: Windows server 2019
>> IDE: IntelliJ IDEA 2021.3.2 (Community Edition)
>>
>> I have an requirement that need calculate each message process time,
>> incould total process time and backend process time. the route likes below,
>> it seems that the jetty managed the http session and send the response
>> back to client automatically at the end of route.
>>
>> Is it possible to explicitly inform jetty send the resonse at specific
>> point?
>>
>> Thansk in advance.
>>
>> from("jetty:http://0.0.0.0:8080/test")
>> .process(exchange -> exchange.setProperty("inbound timestamp",
>> System.currentTimeMillis()))
>> .to("http://localhost/mockbackend")
>> .process(exchange -> exchange.setProperty("backend respond timestamp",
>> System.currentTimeMillis()))
>> .setBody(constant("hello"))
>> // I expect jetty send response back to client here.
>> .process(exchange -> exchange.setProperty("backend respond timestamp",
>> System.currentTimeMillis()));
>>
>>
>
> --
> Claus Ibsen
> -----------------
> @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2
>


-- 
Claus Ibsen
-----------------
@davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: Jetty Component how to add additional steps after send http response back to the client

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Camel will send back the response at the end of the route in the consumer,
so what you do in that route example will not work.
However if you want to do some kind of custom logging of how long it takes,
then Camel Jetty has send back the response to the client, when the
UnitOfWork is done.
So you can use Camel's UoW done to do any custom code for "backend response
timestamp ...".

See the docs for UnitOfWork or its also covered in the CiA2 book.



On Tue, Nov 14, 2023 at 5:11 AM Han Yainsun <Ya...@hotmail.com> wrote:

> Dear Camel Community and Camel users,
>
> Greetings to you!
>
> Camel version: 3.20.4
> Spring Boot version: 2.7.11
> JDK: Amazon Corretto 17
> Platform: Windows server 2019
> IDE: IntelliJ IDEA 2021.3.2 (Community Edition)
>
> I have an requirement that need calculate each message process time,
> incould total process time and backend process time. the route likes below,
> it seems that the jetty managed the http session and send the response
> back to client automatically at the end of route.
>
> Is it possible to explicitly inform jetty send the resonse at specific
> point?
>
> Thansk in advance.
>
> from("jetty:http://0.0.0.0:8080/test")
> .process(exchange -> exchange.setProperty("inbound timestamp",
> System.currentTimeMillis()))
> .to("http://localhost/mockbackend")
> .process(exchange -> exchange.setProperty("backend respond timestamp",
> System.currentTimeMillis()))
> .setBody(constant("hello"))
> // I expect jetty send response back to client here.
> .process(exchange -> exchange.setProperty("backend respond timestamp",
> System.currentTimeMillis()));
>
>

-- 
Claus Ibsen
-----------------
@davsclaus
Camel in Action 2: https://www.manning.com/ibsen2