You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Paul Carter-Brown <pa...@jini.guru> on 2019/05/06 14:28:04 UTC

Re: Initiating httpservletrequest from inside Tomcat / TomEE

Hi John,

Thanks for your feedback.

The request I'm initiating should not or need not carry any context from
the originating code. There is also no session to worry about as its just
for rest calls. So basically I have the headers, path and body and need to
generate a http servlet request and get an http servlet response (or
similar) back. I have this working by calling into localhost but ideally
want to skip the trombone out and back in.

Have you got any basic code examples?

Paul

On Tue, Apr 30, 2019 at 5:27 PM John Dale <jc...@gmail.com> wrote:

> Another thought .. you can do some request dispatching, but without
> knowing more about the tools you're using, I can't say for sure if
> this is the direction you'll want to go.
>
> On 4/29/19, Paul Carter-Brown <pa...@jini.guru> wrote:
> > Hi
> >
> > I'm trying to design a Kafka consumer and producer that will run inside
> the
> > tomcat jvm and pick up messages off a Kafka topic and translate them
> into a
> > servlet request and pass it through tomcat and then when the response is
> > complete then translate it into a Kafka message and put it onto another
> > topic as a reply. This way I can reuse our existing jax-rs rest services
> > and expose them as an async api over Kafka. The idea is to make the Kafka
> > messages similar to http in that they would consist of headers and a
> body.
> > The body would be json.
> >
> > Now I know this could be done by calling localhost with an http call to
> > trombone the requests back into tomcat but I'd like to avoid the
> associated
> > latency and overhead. Is it possible to call tomcat directly in-process.
> > This does not need to be portable to other containers so can be
> > proprietary.
> >
> > I'm using tomcat 8. In fact its tomee 8 but guessed this is more a tomcat
> > question than tomee but have sent to both groups just in case.
> >
> > Thanks for any insights.
> >
> > Paul
> >
>

Re: Initiating httpservletrequest from inside Tomcat / TomEE

Posted by John Dale <jc...@gmail.com>.
Class loaders maintain isolation of contexts, so calling a method on a
different servlet can be tricky, but that is possible.  Although, take
into account that the container maintains pools of servlets, so
something like a static service method, assuming you can crack the
class loader nut, might work.

In the design of your service, you would need to define (possibly
static) methods that encapsulate the functionality you'd like to
execute (reuse).

Without doing something that would be considered a violation of
security principles in computing (SPECTR notwithstanding), I think
you'll have a very difficult time with this requirement.

The JVM may be doing some optimizations for localhost requests that
speed things up, but I can't confirm that at present (and my instincts
say it isn't).

This brings up the point about performance vs scalability.  When you
are proxying network requests like this, scalability can keep your
request/processing times normative (assuming you don't have a database
problem).  Assuming your baseline request/response times are
acceptable, using scalability techniques is generally preferred to
unrelenting performance optimizations not including memory leaks.

That said, I get your sentiment, and applaud your desire to make
things go fast.  Awesome!

On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
> I think we are completely missing each other. Forget sockets - that was
> just an example. I have code running in a Tomcat App server which is not
> managed by Tomcat and is not initiated by anything within Tomcat. That code
> now wants to call a servlet hosted in that very same JVM. Any way to do
> that without going out and back in on TCP?
>
>
> On Mon, May 6, 2019 at 5:14 PM John Dale <jc...@gmail.com> wrote:
>
>> Sockets are an implementation of TCP/UDP inherently.
>>
>> Perhaps a mountaintop signal fire?
>>
>> ;)
>>
>> John
>>
>>
>> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
>> > lol on the Semaphore Telegraph,
>> >
>> > I can't use a request dispatcher as the request is being initiated from
>> > code that has no context. I already have it working with HTTP using
>> > asynchttp library, but I want to avoid the overhead. E.g. lets say I
>> wrote
>> > my own server socket listener on port 10000 running in the Tomcat JVM
>> > and
>> > got some request in some propriatary protocol called X. Now I want to
>> call
>> > a Tomcat servlet in the current JVM with some info I got over X without
>> > going out on TCP and back in....
>> >
>> > On Mon, May 6, 2019 at 4:40 PM John Dale <jc...@gmail.com> wrote:
>> >
>> >> If you're wanting to forward control to another servlet deployed in
>> >> the same context:
>> >> https://www.javatpoint.com/requestdispatcher-in-servlet
>> >>
>> >> If you are okay going through TCP to facilitate some future or current
>> >> distribution of services, Use HTTPURLConnection (not sure what you're
>> >> wanting to do with the result of the request, if anything):
>> >>
>> >>
>> https://stackoverflow.com/questions/2793150/how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests
>> >>
>> >> If you need more sophisticated HTTP interactions, Apache maintains a
>> >> very useful library for that:  http://hc.apache.org/
>> >>
>> >> If these don't work-out for you, rather than using .NET, PHP, Python,
>> >> or some other Java facsimile at best, I recommend using the semaphore
>> >> telegraph:
>> >> https://en.wikipedia.org/wiki/Semaphore_telegraph
>> >>
>> >> Sincerely,
>> >>
>> >> John
>> >> DB2DOM
>> >>
>> >> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
>> >> > Hi John,
>> >> >
>> >> > Thanks for your feedback.
>> >> >
>> >> > The request I'm initiating should not or need not carry any context
>> >> > from
>> >> > the originating code. There is also no session to worry about as its
>> >> > just
>> >> > for rest calls. So basically I have the headers, path and body and
>> need
>> >> to
>> >> > generate a http servlet request and get an http servlet response (or
>> >> > similar) back. I have this working by calling into localhost but
>> >> > ideally
>> >> > want to skip the trombone out and back in.
>> >> >
>> >> > Have you got any basic code examples?
>> >> >
>> >> > Paul
>> >> >
>> >> > On Tue, Apr 30, 2019 at 5:27 PM John Dale <jc...@gmail.com> wrote:
>> >> >
>> >> >> Another thought .. you can do some request dispatching, but without
>> >> >> knowing more about the tools you're using, I can't say for sure if
>> >> >> this is the direction you'll want to go.
>> >> >>
>> >> >> On 4/29/19, Paul Carter-Brown <pa...@jini.guru> wrote:
>> >> >> > Hi
>> >> >> >
>> >> >> > I'm trying to design a Kafka consumer and producer that will run
>> >> inside
>> >> >> the
>> >> >> > tomcat jvm and pick up messages off a Kafka topic and translate
>> them
>> >> >> into a
>> >> >> > servlet request and pass it through tomcat and then when the
>> >> >> > response
>> >> >> > is
>> >> >> > complete then translate it into a Kafka message and put it onto
>> >> another
>> >> >> > topic as a reply. This way I can reuse our existing jax-rs rest
>> >> >> > services
>> >> >> > and expose them as an async api over Kafka. The idea is to make
>> >> >> > the
>> >> >> > Kafka
>> >> >> > messages similar to http in that they would consist of headers
>> >> >> > and
>> a
>> >> >> body.
>> >> >> > The body would be json.
>> >> >> >
>> >> >> > Now I know this could be done by calling localhost with an http
>> call
>> >> to
>> >> >> > trombone the requests back into tomcat but I'd like to avoid the
>> >> >> associated
>> >> >> > latency and overhead. Is it possible to call tomcat directly
>> >> >> > in-process.
>> >> >> > This does not need to be portable to other containers so can be
>> >> >> > proprietary.
>> >> >> >
>> >> >> > I'm using tomcat 8. In fact its tomee 8 but guessed this is more
>> >> >> > a
>> >> >> > tomcat
>> >> >> > question than tomee but have sent to both groups just in case.
>> >> >> >
>> >> >> > Thanks for any insights.
>> >> >> >
>> >> >> > Paul
>> >> >> >
>> >> >>
>> >> >
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> >> For additional commands, e-mail: users-help@tomcat.apache.org
>> >>
>> >>
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Initiating httpservletrequest from inside Tomcat / TomEE

Posted by John Dale <jc...@gmail.com>.
This was in the spirit of one of my suggestions and probably how I
would approach the problem to save them/me having to create a Tomcat
request harness .. encapsulate the service in a static method and call
that (cohesive).

Have a super day,

John


On 5/8/19, Christopher Schultz <ch...@christopherschultz.net> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
>
> Terence and Paul,
>
> On 5/6/19 14:36, Terence M. Bandoian wrote:
>> On 5/6/2019 10:45 AM, Paul Carter-Brown wrote: 2) Can the servlets
>> you want to use be refactored so that the underlying functionality
>> is exposed in a way that doesn't require any context?
>
> I think this is more likely to get you a satisfying solution.
>
> As much fun it is to watch you try to explain to John what you are
> trying to do (which seems straightforward, in principle, to me), I
> think you are barking up a tree which doesn't like dogs.
>
> Is it very important that your "work" actually be invoked via a
> servlet request/response mechanism? Or can you, as Terence suggests,
> call the "meat" of the service directly instead of invoking the "web
> service"?
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/
>
> iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAlzTavcACgkQHPApP6U8
> pFifog/+O2rgZGSHOSWYXq53NOXE6aN9byqVMfG2mj+Y2Ms8wvptgW6Dt5U4Slj5
> P+mD3tzBlaQlmDyl6aaLfk8cm2lSmphNUXDv8IKi5AMxMDRBrfAVPi0t0WXIfaDC
> odgE78Mnmztbb/wnCLDzeDEV+G2iDPc6Fy7n+4P1GtU82666vVBeE026Mtwi7PX/
> KwsQjwLSsNzkk0HlTXVPvC0lJeVdK4bCpk5sqhHZaDKaZvRvvR7guEXOG96ga+Xl
> RhTmz4Pe5s6BUImSdXI4ycT4Q9z9P2vZhcbOBBe/oCJivYaYshYgSkjgZ5scaMby
> DjP15t12SXtZiR5/K/OgCjXBFIX0ilc5Avn4bkIvBi2odf+vpaKif0z3XYujD6Ho
> PIauQhKORF5Rb8zOjb3ERnWOwtgv2S5s3zx22nIRV5IpgM9666p3p3mOU4Via4lh
> Eql/A+vT0nxLvoKmVXbw4eMh4c6UJKMk+e47sWbKTb9iwxLL9eyez2Co7YJLuwXr
> I+WeOet8naU6y+jfJ6Z7uuJw9FAeTAuUxHj315qYcovrBdiQWDHxMCFrV5TTZVJc
> oDKBkM86O82z477Ei/aSxxwF0qx9aFf8OtlzGIISkhOjIjzhY4l1ZKueMykAbEgb
> IkBqN7OMrvb5ekuV0c9U61vFTZ9zcmbJiaVidOHmFvRtuMohiIQ=
> =x7LQ
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Initiating httpservletrequest from inside Tomcat / TomEE

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Terence and Paul,

On 5/6/19 14:36, Terence M. Bandoian wrote:
> On 5/6/2019 10:45 AM, Paul Carter-Brown wrote: 2) Can the servlets
> you want to use be refactored so that the underlying functionality
> is exposed in a way that doesn't require any context?

I think this is more likely to get you a satisfying solution.

As much fun it is to watch you try to explain to John what you are
trying to do (which seems straightforward, in principle, to me), I
think you are barking up a tree which doesn't like dogs.

Is it very important that your "work" actually be invoked via a
servlet request/response mechanism? Or can you, as Terence suggests,
call the "meat" of the service directly instead of invoking the "web
service"?

- -chris
-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAlzTavcACgkQHPApP6U8
pFifog/+O2rgZGSHOSWYXq53NOXE6aN9byqVMfG2mj+Y2Ms8wvptgW6Dt5U4Slj5
P+mD3tzBlaQlmDyl6aaLfk8cm2lSmphNUXDv8IKi5AMxMDRBrfAVPi0t0WXIfaDC
odgE78Mnmztbb/wnCLDzeDEV+G2iDPc6Fy7n+4P1GtU82666vVBeE026Mtwi7PX/
KwsQjwLSsNzkk0HlTXVPvC0lJeVdK4bCpk5sqhHZaDKaZvRvvR7guEXOG96ga+Xl
RhTmz4Pe5s6BUImSdXI4ycT4Q9z9P2vZhcbOBBe/oCJivYaYshYgSkjgZ5scaMby
DjP15t12SXtZiR5/K/OgCjXBFIX0ilc5Avn4bkIvBi2odf+vpaKif0z3XYujD6Ho
PIauQhKORF5Rb8zOjb3ERnWOwtgv2S5s3zx22nIRV5IpgM9666p3p3mOU4Via4lh
Eql/A+vT0nxLvoKmVXbw4eMh4c6UJKMk+e47sWbKTb9iwxLL9eyez2Co7YJLuwXr
I+WeOet8naU6y+jfJ6Z7uuJw9FAeTAuUxHj315qYcovrBdiQWDHxMCFrV5TTZVJc
oDKBkM86O82z477Ei/aSxxwF0qx9aFf8OtlzGIISkhOjIjzhY4l1ZKueMykAbEgb
IkBqN7OMrvb5ekuV0c9U61vFTZ9zcmbJiaVidOHmFvRtuMohiIQ=
=x7LQ
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Initiating httpservletrequest from inside Tomcat / TomEE

Posted by "Terence M. Bandoian" <te...@tmbsw.com>.
On 5/6/2019 10:45 AM, Paul Carter-Brown wrote:
> Yea, but the issue is that only works when calling in the context of a
> current servlet call.
>
> Here is the kind of problem I want to solve:
>
> @WebServlet(name = "MyExample", urlPatterns = {"/example"}, loadOnStartup =
> 1)
> public class Example extends HttpServlet {
>
>      @PersistenceContext
>      private EntityManager em;
>
>      @Override
>      public void init(ServletConfig config) {
>          Thread t = new Thread(() -> {
>              while (true) {
>                  try {
>                      // Do a GET to /example/ and get the response without
> going out on localhost and back in....
>                      // We cant just call doGet as we want the request to
> flow through the servlet filters, do the entitymanager injection etc
>                      Thread.sleep(10000);
>                  } catch (Exception e) {
>                  }
>              }
>          });
>          t.start();
>
>      }
>
>      @Override
>      protected void doGet(HttpServletRequest req, HttpServletResponse resp)
> throws ServletException, IOException {
>          // do stuff like use em
>          resp.setStatus(200);
>          resp.getWriter().write("Hello World");
>      }
>
> }
>


If I understand the problem you're trying to solve, it seems like there 
could be two ways to approach it.

1) Can your service be initialized with the context information it needs 
to use the request dispatcher?
2) Can the servlets you want to use be refactored so that the underlying 
functionality is exposed in a way that doesn't require any context?

Hope that helps.

-Terence


>
>
> On Mon, May 6, 2019 at 5:35 PM John Dale <jc...@gmail.com> wrote:
>
>> For reference, I did find this after searching "calling a servlet
>> programmatically":
>> https://docs.oracle.com/cd/E19146-01/819-2634/abxbn/index.html
>>
>> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
>>> I think we are completely missing each other. Forget sockets - that was
>>> just an example. I have code running in a Tomcat App server which is not
>>> managed by Tomcat and is not initiated by anything within Tomcat. That
>> code
>>> now wants to call a servlet hosted in that very same JVM. Any way to do
>>> that without going out and back in on TCP?
>>>
>>>
>>> On Mon, May 6, 2019 at 5:14 PM John Dale <jc...@gmail.com> wrote:
>>>
>>>> Sockets are an implementation of TCP/UDP inherently.
>>>>
>>>> Perhaps a mountaintop signal fire?
>>>>
>>>> ;)
>>>>
>>>> John
>>>>
>>>>
>>>> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
>>>>> lol on the Semaphore Telegraph,
>>>>>
>>>>> I can't use a request dispatcher as the request is being initiated
>> from
>>>>> code that has no context. I already have it working with HTTP using
>>>>> asynchttp library, but I want to avoid the overhead. E.g. lets say I
>>>> wrote
>>>>> my own server socket listener on port 10000 running in the Tomcat JVM
>>>>> and
>>>>> got some request in some propriatary protocol called X. Now I want to
>>>> call
>>>>> a Tomcat servlet in the current JVM with some info I got over X
>> without
>>>>> going out on TCP and back in....
>>>>>
>>>>> On Mon, May 6, 2019 at 4:40 PM John Dale <jc...@gmail.com> wrote:
>>>>>
>>>>>> If you're wanting to forward control to another servlet deployed in
>>>>>> the same context:
>>>>>> https://www.javatpoint.com/requestdispatcher-in-servlet
>>>>>>
>>>>>> If you are okay going through TCP to facilitate some future or
>> current
>>>>>> distribution of services, Use HTTPURLConnection (not sure what you're
>>>>>> wanting to do with the result of the request, if anything):
>>>>>>
>>>>>>
>> https://stackoverflow.com/questions/2793150/how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests
>>>>>> If you need more sophisticated HTTP interactions, Apache maintains a
>>>>>> very useful library for that:  http://hc.apache.org/
>>>>>>
>>>>>> If these don't work-out for you, rather than using .NET, PHP, Python,
>>>>>> or some other Java facsimile at best, I recommend using the semaphore
>>>>>> telegraph:
>>>>>> https://en.wikipedia.org/wiki/Semaphore_telegraph
>>>>>>
>>>>>> Sincerely,
>>>>>>
>>>>>> John
>>>>>> DB2DOM
>>>>>>
>>>>>> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
>>>>>>> Hi John,
>>>>>>>
>>>>>>> Thanks for your feedback.
>>>>>>>
>>>>>>> The request I'm initiating should not or need not carry any context
>>>>>>> from
>>>>>>> the originating code. There is also no session to worry about as
>> its
>>>>>>> just
>>>>>>> for rest calls. So basically I have the headers, path and body and
>>>> need
>>>>>> to
>>>>>>> generate a http servlet request and get an http servlet response
>> (or
>>>>>>> similar) back. I have this working by calling into localhost but
>>>>>>> ideally
>>>>>>> want to skip the trombone out and back in.
>>>>>>>
>>>>>>> Have you got any basic code examples?
>>>>>>>
>>>>>>> Paul
>>>>>>>
>>>>>>> On Tue, Apr 30, 2019 at 5:27 PM John Dale <jc...@gmail.com>
>> wrote:
>>>>>>>> Another thought .. you can do some request dispatching, but
>> without
>>>>>>>> knowing more about the tools you're using, I can't say for sure if
>>>>>>>> this is the direction you'll want to go.
>>>>>>>>
>>>>>>>> On 4/29/19, Paul Carter-Brown <pa...@jini.guru>
>> wrote:
>>>>>>>>> Hi
>>>>>>>>>
>>>>>>>>> I'm trying to design a Kafka consumer and producer that will run
>>>>>> inside
>>>>>>>> the
>>>>>>>>> tomcat jvm and pick up messages off a Kafka topic and translate
>>>> them
>>>>>>>> into a
>>>>>>>>> servlet request and pass it through tomcat and then when the
>>>>>>>>> response
>>>>>>>>> is
>>>>>>>>> complete then translate it into a Kafka message and put it onto
>>>>>> another
>>>>>>>>> topic as a reply. This way I can reuse our existing jax-rs rest
>>>>>>>>> services
>>>>>>>>> and expose them as an async api over Kafka. The idea is to make
>>>>>>>>> the
>>>>>>>>> Kafka
>>>>>>>>> messages similar to http in that they would consist of headers
>>>>>>>>> and
>>>> a
>>>>>>>> body.
>>>>>>>>> The body would be json.
>>>>>>>>>
>>>>>>>>> Now I know this could be done by calling localhost with an http
>>>> call
>>>>>> to
>>>>>>>>> trombone the requests back into tomcat but I'd like to avoid the
>>>>>>>> associated
>>>>>>>>> latency and overhead. Is it possible to call tomcat directly
>>>>>>>>> in-process.
>>>>>>>>> This does not need to be portable to other containers so can be
>>>>>>>>> proprietary.
>>>>>>>>>
>>>>>>>>> I'm using tomcat 8. In fact its tomee 8 but guessed this is more
>>>>>>>>> a
>>>>>>>>> tomcat
>>>>>>>>> question than tomee but have sent to both groups just in case.
>>>>>>>>>
>>>>>>>>> Thanks for any insights.
>>>>>>>>>
>>>>>>>>> Paul
>>>>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>>>>
>>>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>>
>>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Initiating httpservletrequest from inside Tomcat / TomEE

Posted by John Dale <jc...@gmail.com>.
I would trace tomcat and recreate a servlet request .. see if I could
hack it in that way (assuming that localhost traffic isn't fast
enough).  Normalizing on HTTP/TCP will be more maintainable, though?

Can somebody suggest a good place for a breakpoint?

Any other suggestions?

John


On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
> Hi John,
>
> See original request. It's pretty much a Kafka/Servlet proxy/gateway:
>
> I'm trying to design a Kafka consumer and producer that will run inside the
> tomcat jvm and pick up messages off a Kafka topic and translate them into a
> servlet request and pass it through tomcat and then when the response is
> complete then translate it into a Kafka message and put it onto another
> topic as a reply. This way I can reuse our existing jax-rs rest services
> and expose them as an async api over Kafka. The idea is to make the Kafka
> messages similar to http in that they would consist of headers and a body.
> The body would be json.
>
>
> On Mon, May 6, 2019 at 6:13 PM John Dale <jc...@gmail.com> wrote:
>
>> You could try debugging the tomcat code and find out how, right after
>> it parses the TCP request, it invokes the servlet.  You can then
>> create your own harness for tomcat code after initializing the
>> appropriate context for the request to tomcat.  I don't know off hand
>> where in the tomcat code this cut point can be found.
>>
>> Is this a performance issue, or are you building a proxy?
>>
>> What is the problem you're trying to solve?
>>
>> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
>> > Yea, but the issue is that only works when calling in the context of a
>> > current servlet call.
>> >
>> > Here is the kind of problem I want to solve:
>> >
>> > @WebServlet(name = "MyExample", urlPatterns = {"/example"},
>> loadOnStartup =
>> > 1)
>> > public class Example extends HttpServlet {
>> >
>> >     @PersistenceContext
>> >     private EntityManager em;
>> >
>> >     @Override
>> >     public void init(ServletConfig config) {
>> >         Thread t = new Thread(() -> {
>> >             while (true) {
>> >                 try {
>> >                     // Do a GET to /example/ and get the response
>> > without
>> > going out on localhost and back in....
>> >                     // We cant just call doGet as we want the request
>> > to
>> > flow through the servlet filters, do the entitymanager injection etc
>> >                     Thread.sleep(10000);
>> >                 } catch (Exception e) {
>> >                 }
>> >             }
>> >         });
>> >         t.start();
>> >
>> >     }
>> >
>> >     @Override
>> >     protected void doGet(HttpServletRequest req, HttpServletResponse
>> resp)
>> > throws ServletException, IOException {
>> >         // do stuff like use em
>> >         resp.setStatus(200);
>> >         resp.getWriter().write("Hello World");
>> >     }
>> >
>> > }
>> >
>> >
>> >
>> >
>> > On Mon, May 6, 2019 at 5:35 PM John Dale <jc...@gmail.com> wrote:
>> >
>> >> For reference, I did find this after searching "calling a servlet
>> >> programmatically":
>> >> https://docs.oracle.com/cd/E19146-01/819-2634/abxbn/index.html
>> >>
>> >> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
>> >> > I think we are completely missing each other. Forget sockets - that
>> was
>> >> > just an example. I have code running in a Tomcat App server which is
>> >> > not
>> >> > managed by Tomcat and is not initiated by anything within Tomcat.
>> >> > That
>> >> code
>> >> > now wants to call a servlet hosted in that very same JVM. Any way to
>> do
>> >> > that without going out and back in on TCP?
>> >> >
>> >> >
>> >> > On Mon, May 6, 2019 at 5:14 PM John Dale <jc...@gmail.com> wrote:
>> >> >
>> >> >> Sockets are an implementation of TCP/UDP inherently.
>> >> >>
>> >> >> Perhaps a mountaintop signal fire?
>> >> >>
>> >> >> ;)
>> >> >>
>> >> >> John
>> >> >>
>> >> >>
>> >> >> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
>> >> >> > lol on the Semaphore Telegraph,
>> >> >> >
>> >> >> > I can't use a request dispatcher as the request is being
>> >> >> > initiated
>> >> from
>> >> >> > code that has no context. I already have it working with HTTP
>> >> >> > using
>> >> >> > asynchttp library, but I want to avoid the overhead. E.g. lets
>> >> >> > say
>> I
>> >> >> wrote
>> >> >> > my own server socket listener on port 10000 running in the Tomcat
>> >> >> > JVM
>> >> >> > and
>> >> >> > got some request in some propriatary protocol called X. Now I
>> >> >> > want
>> >> >> > to
>> >> >> call
>> >> >> > a Tomcat servlet in the current JVM with some info I got over X
>> >> without
>> >> >> > going out on TCP and back in....
>> >> >> >
>> >> >> > On Mon, May 6, 2019 at 4:40 PM John Dale <jc...@gmail.com>
>> wrote:
>> >> >> >
>> >> >> >> If you're wanting to forward control to another servlet deployed
>> in
>> >> >> >> the same context:
>> >> >> >> https://www.javatpoint.com/requestdispatcher-in-servlet
>> >> >> >>
>> >> >> >> If you are okay going through TCP to facilitate some future or
>> >> current
>> >> >> >> distribution of services, Use HTTPURLConnection (not sure what
>> >> >> >> you're
>> >> >> >> wanting to do with the result of the request, if anything):
>> >> >> >>
>> >> >> >>
>> >> >>
>> >>
>> https://stackoverflow.com/questions/2793150/how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests
>> >> >> >>
>> >> >> >> If you need more sophisticated HTTP interactions, Apache
>> >> >> >> maintains
>> >> >> >> a
>> >> >> >> very useful library for that:  http://hc.apache.org/
>> >> >> >>
>> >> >> >> If these don't work-out for you, rather than using .NET, PHP,
>> >> >> >> Python,
>> >> >> >> or some other Java facsimile at best, I recommend using the
>> >> >> >> semaphore
>> >> >> >> telegraph:
>> >> >> >> https://en.wikipedia.org/wiki/Semaphore_telegraph
>> >> >> >>
>> >> >> >> Sincerely,
>> >> >> >>
>> >> >> >> John
>> >> >> >> DB2DOM
>> >> >> >>
>> >> >> >> On 5/6/19, Paul Carter-Brown <pa...@jini.guru>
>> >> >> >> wrote:
>> >> >> >> > Hi John,
>> >> >> >> >
>> >> >> >> > Thanks for your feedback.
>> >> >> >> >
>> >> >> >> > The request I'm initiating should not or need not carry any
>> >> >> >> > context
>> >> >> >> > from
>> >> >> >> > the originating code. There is also no session to worry about
>> >> >> >> > as
>> >> its
>> >> >> >> > just
>> >> >> >> > for rest calls. So basically I have the headers, path and body
>> >> >> >> > and
>> >> >> need
>> >> >> >> to
>> >> >> >> > generate a http servlet request and get an http servlet
>> >> >> >> > response
>> >> (or
>> >> >> >> > similar) back. I have this working by calling into localhost
>> >> >> >> > but
>> >> >> >> > ideally
>> >> >> >> > want to skip the trombone out and back in.
>> >> >> >> >
>> >> >> >> > Have you got any basic code examples?
>> >> >> >> >
>> >> >> >> > Paul
>> >> >> >> >
>> >> >> >> > On Tue, Apr 30, 2019 at 5:27 PM John Dale <jc...@gmail.com>
>> >> wrote:
>> >> >> >> >
>> >> >> >> >> Another thought .. you can do some request dispatching, but
>> >> without
>> >> >> >> >> knowing more about the tools you're using, I can't say for
>> >> >> >> >> sure
>> >> >> >> >> if
>> >> >> >> >> this is the direction you'll want to go.
>> >> >> >> >>
>> >> >> >> >> On 4/29/19, Paul Carter-Brown <pa...@jini.guru>
>> >> wrote:
>> >> >> >> >> > Hi
>> >> >> >> >> >
>> >> >> >> >> > I'm trying to design a Kafka consumer and producer that
>> >> >> >> >> > will
>> >> >> >> >> > run
>> >> >> >> inside
>> >> >> >> >> the
>> >> >> >> >> > tomcat jvm and pick up messages off a Kafka topic and
>> >> >> >> >> > translate
>> >> >> them
>> >> >> >> >> into a
>> >> >> >> >> > servlet request and pass it through tomcat and then when
>> >> >> >> >> > the
>> >> >> >> >> > response
>> >> >> >> >> > is
>> >> >> >> >> > complete then translate it into a Kafka message and put it
>> >> >> >> >> > onto
>> >> >> >> another
>> >> >> >> >> > topic as a reply. This way I can reuse our existing jax-rs
>> >> >> >> >> > rest
>> >> >> >> >> > services
>> >> >> >> >> > and expose them as an async api over Kafka. The idea is to
>> >> >> >> >> > make
>> >> >> >> >> > the
>> >> >> >> >> > Kafka
>> >> >> >> >> > messages similar to http in that they would consist of
>> headers
>> >> >> >> >> > and
>> >> >> a
>> >> >> >> >> body.
>> >> >> >> >> > The body would be json.
>> >> >> >> >> >
>> >> >> >> >> > Now I know this could be done by calling localhost with an
>> >> >> >> >> > http
>> >> >> call
>> >> >> >> to
>> >> >> >> >> > trombone the requests back into tomcat but I'd like to
>> >> >> >> >> > avoid
>> >> >> >> >> > the
>> >> >> >> >> associated
>> >> >> >> >> > latency and overhead. Is it possible to call tomcat
>> >> >> >> >> > directly
>> >> >> >> >> > in-process.
>> >> >> >> >> > This does not need to be portable to other containers so
>> >> >> >> >> > can
>> >> >> >> >> > be
>> >> >> >> >> > proprietary.
>> >> >> >> >> >
>> >> >> >> >> > I'm using tomcat 8. In fact its tomee 8 but guessed this is
>> >> >> >> >> > more
>> >> >> >> >> > a
>> >> >> >> >> > tomcat
>> >> >> >> >> > question than tomee but have sent to both groups just in
>> case.
>> >> >> >> >> >
>> >> >> >> >> > Thanks for any insights.
>> >> >> >> >> >
>> >> >> >> >> > Paul
>> >> >> >> >> >
>> >> >> >> >>
>> >> >> >> >
>> >> >> >>
>> >> >> >>
>> ---------------------------------------------------------------------
>> >> >> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> >> >> >> For additional commands, e-mail: users-help@tomcat.apache.org
>> >> >> >>
>> >> >> >>
>> >> >> >
>> >> >>
>> >> >> ---------------------------------------------------------------------
>> >> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> >> >> For additional commands, e-mail: users-help@tomcat.apache.org
>> >> >>
>> >> >>
>> >> >
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> >> For additional commands, e-mail: users-help@tomcat.apache.org
>> >>
>> >>
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Initiating httpservletrequest from inside Tomcat / TomEE

Posted by Mark Thomas <ma...@apache.org>.
On 06/05/2019 17:47, Owen Rubel wrote:
> I didn't think that TomEE was Tomcat. Wasn't it it's own thing??? I mean
> TomEE is this separate project maintained by this up here in Seattle vs
> Tomcat which is an Apache Project.

Apache Tomcat are Apache TomEE are both Apache projects.

Apache TomEE spun out from Apache OpenEJB and is available in various
forms that each provide support for a different combination of
additional Java EE APIs.

Mark


> 
> Owen Rubel
> orubel@gmail.com
> 
> 
> On Mon, May 6, 2019 at 9:16 AM Paul Carter-Brown
> <pa...@jini.guru> wrote:
> 
>> Hi John,
>>
>> See original request. It's pretty much a Kafka/Servlet proxy/gateway:
>>
>> I'm trying to design a Kafka consumer and producer that will run inside the
>> tomcat jvm and pick up messages off a Kafka topic and translate them into a
>> servlet request and pass it through tomcat and then when the response is
>> complete then translate it into a Kafka message and put it onto another
>> topic as a reply. This way I can reuse our existing jax-rs rest services
>> and expose them as an async api over Kafka. The idea is to make the Kafka
>> messages similar to http in that they would consist of headers and a body.
>> The body would be json.
>>
>>
>> On Mon, May 6, 2019 at 6:13 PM John Dale <jc...@gmail.com> wrote:
>>
>>> You could try debugging the tomcat code and find out how, right after
>>> it parses the TCP request, it invokes the servlet.  You can then
>>> create your own harness for tomcat code after initializing the
>>> appropriate context for the request to tomcat.  I don't know off hand
>>> where in the tomcat code this cut point can be found.
>>>
>>> Is this a performance issue, or are you building a proxy?
>>>
>>> What is the problem you're trying to solve?
>>>
>>> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
>>>> Yea, but the issue is that only works when calling in the context of a
>>>> current servlet call.
>>>>
>>>> Here is the kind of problem I want to solve:
>>>>
>>>> @WebServlet(name = "MyExample", urlPatterns = {"/example"},
>>> loadOnStartup =
>>>> 1)
>>>> public class Example extends HttpServlet {
>>>>
>>>>     @PersistenceContext
>>>>     private EntityManager em;
>>>>
>>>>     @Override
>>>>     public void init(ServletConfig config) {
>>>>         Thread t = new Thread(() -> {
>>>>             while (true) {
>>>>                 try {
>>>>                     // Do a GET to /example/ and get the response
>> without
>>>> going out on localhost and back in....
>>>>                     // We cant just call doGet as we want the request
>> to
>>>> flow through the servlet filters, do the entitymanager injection etc
>>>>                     Thread.sleep(10000);
>>>>                 } catch (Exception e) {
>>>>                 }
>>>>             }
>>>>         });
>>>>         t.start();
>>>>
>>>>     }
>>>>
>>>>     @Override
>>>>     protected void doGet(HttpServletRequest req, HttpServletResponse
>>> resp)
>>>> throws ServletException, IOException {
>>>>         // do stuff like use em
>>>>         resp.setStatus(200);
>>>>         resp.getWriter().write("Hello World");
>>>>     }
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>>
>>>> On Mon, May 6, 2019 at 5:35 PM John Dale <jc...@gmail.com> wrote:
>>>>
>>>>> For reference, I did find this after searching "calling a servlet
>>>>> programmatically":
>>>>> https://docs.oracle.com/cd/E19146-01/819-2634/abxbn/index.html
>>>>>
>>>>> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
>>>>>> I think we are completely missing each other. Forget sockets - that
>>> was
>>>>>> just an example. I have code running in a Tomcat App server which is
>>>>>> not
>>>>>> managed by Tomcat and is not initiated by anything within Tomcat.
>> That
>>>>> code
>>>>>> now wants to call a servlet hosted in that very same JVM. Any way to
>>> do
>>>>>> that without going out and back in on TCP?
>>>>>>
>>>>>>
>>>>>> On Mon, May 6, 2019 at 5:14 PM John Dale <jc...@gmail.com> wrote:
>>>>>>
>>>>>>> Sockets are an implementation of TCP/UDP inherently.
>>>>>>>
>>>>>>> Perhaps a mountaintop signal fire?
>>>>>>>
>>>>>>> ;)
>>>>>>>
>>>>>>> John
>>>>>>>
>>>>>>>
>>>>>>> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
>>>>>>>> lol on the Semaphore Telegraph,
>>>>>>>>
>>>>>>>> I can't use a request dispatcher as the request is being
>> initiated
>>>>> from
>>>>>>>> code that has no context. I already have it working with HTTP
>> using
>>>>>>>> asynchttp library, but I want to avoid the overhead. E.g. lets
>> say
>>> I
>>>>>>> wrote
>>>>>>>> my own server socket listener on port 10000 running in the Tomcat
>>>>>>>> JVM
>>>>>>>> and
>>>>>>>> got some request in some propriatary protocol called X. Now I
>> want
>>>>>>>> to
>>>>>>> call
>>>>>>>> a Tomcat servlet in the current JVM with some info I got over X
>>>>> without
>>>>>>>> going out on TCP and back in....
>>>>>>>>
>>>>>>>> On Mon, May 6, 2019 at 4:40 PM John Dale <jc...@gmail.com>
>>> wrote:
>>>>>>>>
>>>>>>>>> If you're wanting to forward control to another servlet deployed
>>> in
>>>>>>>>> the same context:
>>>>>>>>> https://www.javatpoint.com/requestdispatcher-in-servlet
>>>>>>>>>
>>>>>>>>> If you are okay going through TCP to facilitate some future or
>>>>> current
>>>>>>>>> distribution of services, Use HTTPURLConnection (not sure what
>>>>>>>>> you're
>>>>>>>>> wanting to do with the result of the request, if anything):
>>>>>>>>>
>>>>>>>>>
>>>>>>>
>>>>>
>>>
>> https://stackoverflow.com/questions/2793150/how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests
>>>>>>>>>
>>>>>>>>> If you need more sophisticated HTTP interactions, Apache
>> maintains
>>>>>>>>> a
>>>>>>>>> very useful library for that:  http://hc.apache.org/
>>>>>>>>>
>>>>>>>>> If these don't work-out for you, rather than using .NET, PHP,
>>>>>>>>> Python,
>>>>>>>>> or some other Java facsimile at best, I recommend using the
>>>>>>>>> semaphore
>>>>>>>>> telegraph:
>>>>>>>>> https://en.wikipedia.org/wiki/Semaphore_telegraph
>>>>>>>>>
>>>>>>>>> Sincerely,
>>>>>>>>>
>>>>>>>>> John
>>>>>>>>> DB2DOM
>>>>>>>>>
>>>>>>>>> On 5/6/19, Paul Carter-Brown <pa...@jini.guru>
>> wrote:
>>>>>>>>>> Hi John,
>>>>>>>>>>
>>>>>>>>>> Thanks for your feedback.
>>>>>>>>>>
>>>>>>>>>> The request I'm initiating should not or need not carry any
>>>>>>>>>> context
>>>>>>>>>> from
>>>>>>>>>> the originating code. There is also no session to worry about
>> as
>>>>> its
>>>>>>>>>> just
>>>>>>>>>> for rest calls. So basically I have the headers, path and body
>>>>>>>>>> and
>>>>>>> need
>>>>>>>>> to
>>>>>>>>>> generate a http servlet request and get an http servlet
>> response
>>>>> (or
>>>>>>>>>> similar) back. I have this working by calling into localhost
>> but
>>>>>>>>>> ideally
>>>>>>>>>> want to skip the trombone out and back in.
>>>>>>>>>>
>>>>>>>>>> Have you got any basic code examples?
>>>>>>>>>>
>>>>>>>>>> Paul
>>>>>>>>>>
>>>>>>>>>> On Tue, Apr 30, 2019 at 5:27 PM John Dale <jc...@gmail.com>
>>>>> wrote:
>>>>>>>>>>
>>>>>>>>>>> Another thought .. you can do some request dispatching, but
>>>>> without
>>>>>>>>>>> knowing more about the tools you're using, I can't say for
>> sure
>>>>>>>>>>> if
>>>>>>>>>>> this is the direction you'll want to go.
>>>>>>>>>>>
>>>>>>>>>>> On 4/29/19, Paul Carter-Brown <pa...@jini.guru>
>>>>> wrote:
>>>>>>>>>>>> Hi
>>>>>>>>>>>>
>>>>>>>>>>>> I'm trying to design a Kafka consumer and producer that
>> will
>>>>>>>>>>>> run
>>>>>>>>> inside
>>>>>>>>>>> the
>>>>>>>>>>>> tomcat jvm and pick up messages off a Kafka topic and
>>>>>>>>>>>> translate
>>>>>>> them
>>>>>>>>>>> into a
>>>>>>>>>>>> servlet request and pass it through tomcat and then when
>> the
>>>>>>>>>>>> response
>>>>>>>>>>>> is
>>>>>>>>>>>> complete then translate it into a Kafka message and put it
>>>>>>>>>>>> onto
>>>>>>>>> another
>>>>>>>>>>>> topic as a reply. This way I can reuse our existing jax-rs
>>>>>>>>>>>> rest
>>>>>>>>>>>> services
>>>>>>>>>>>> and expose them as an async api over Kafka. The idea is to
>>>>>>>>>>>> make
>>>>>>>>>>>> the
>>>>>>>>>>>> Kafka
>>>>>>>>>>>> messages similar to http in that they would consist of
>>> headers
>>>>>>>>>>>> and
>>>>>>> a
>>>>>>>>>>> body.
>>>>>>>>>>>> The body would be json.
>>>>>>>>>>>>
>>>>>>>>>>>> Now I know this could be done by calling localhost with an
>>>>>>>>>>>> http
>>>>>>> call
>>>>>>>>> to
>>>>>>>>>>>> trombone the requests back into tomcat but I'd like to
>> avoid
>>>>>>>>>>>> the
>>>>>>>>>>> associated
>>>>>>>>>>>> latency and overhead. Is it possible to call tomcat
>> directly
>>>>>>>>>>>> in-process.
>>>>>>>>>>>> This does not need to be portable to other containers so
>> can
>>>>>>>>>>>> be
>>>>>>>>>>>> proprietary.
>>>>>>>>>>>>
>>>>>>>>>>>> I'm using tomcat 8. In fact its tomee 8 but guessed this is
>>>>>>>>>>>> more
>>>>>>>>>>>> a
>>>>>>>>>>>> tomcat
>>>>>>>>>>>> question than tomee but have sent to both groups just in
>>> case.
>>>>>>>>>>>>
>>>>>>>>>>>> Thanks for any insights.
>>>>>>>>>>>>
>>>>>>>>>>>> Paul
>>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>> ---------------------------------------------------------------------
>>>>>>>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>>>>>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>>>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>>>
>>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>
>>>
>>
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Initiating httpservletrequest from inside Tomcat / TomEE

Posted by Owen Rubel <or...@gmail.com>.
I didn't think that TomEE was Tomcat. Wasn't it it's own thing??? I mean
TomEE is this separate project maintained by this up here in Seattle vs
Tomcat which is an Apache Project.

Owen Rubel
orubel@gmail.com


On Mon, May 6, 2019 at 9:16 AM Paul Carter-Brown
<pa...@jini.guru> wrote:

> Hi John,
>
> See original request. It's pretty much a Kafka/Servlet proxy/gateway:
>
> I'm trying to design a Kafka consumer and producer that will run inside the
> tomcat jvm and pick up messages off a Kafka topic and translate them into a
> servlet request and pass it through tomcat and then when the response is
> complete then translate it into a Kafka message and put it onto another
> topic as a reply. This way I can reuse our existing jax-rs rest services
> and expose them as an async api over Kafka. The idea is to make the Kafka
> messages similar to http in that they would consist of headers and a body.
> The body would be json.
>
>
> On Mon, May 6, 2019 at 6:13 PM John Dale <jc...@gmail.com> wrote:
>
> > You could try debugging the tomcat code and find out how, right after
> > it parses the TCP request, it invokes the servlet.  You can then
> > create your own harness for tomcat code after initializing the
> > appropriate context for the request to tomcat.  I don't know off hand
> > where in the tomcat code this cut point can be found.
> >
> > Is this a performance issue, or are you building a proxy?
> >
> > What is the problem you're trying to solve?
> >
> > On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
> > > Yea, but the issue is that only works when calling in the context of a
> > > current servlet call.
> > >
> > > Here is the kind of problem I want to solve:
> > >
> > > @WebServlet(name = "MyExample", urlPatterns = {"/example"},
> > loadOnStartup =
> > > 1)
> > > public class Example extends HttpServlet {
> > >
> > >     @PersistenceContext
> > >     private EntityManager em;
> > >
> > >     @Override
> > >     public void init(ServletConfig config) {
> > >         Thread t = new Thread(() -> {
> > >             while (true) {
> > >                 try {
> > >                     // Do a GET to /example/ and get the response
> without
> > > going out on localhost and back in....
> > >                     // We cant just call doGet as we want the request
> to
> > > flow through the servlet filters, do the entitymanager injection etc
> > >                     Thread.sleep(10000);
> > >                 } catch (Exception e) {
> > >                 }
> > >             }
> > >         });
> > >         t.start();
> > >
> > >     }
> > >
> > >     @Override
> > >     protected void doGet(HttpServletRequest req, HttpServletResponse
> > resp)
> > > throws ServletException, IOException {
> > >         // do stuff like use em
> > >         resp.setStatus(200);
> > >         resp.getWriter().write("Hello World");
> > >     }
> > >
> > > }
> > >
> > >
> > >
> > >
> > > On Mon, May 6, 2019 at 5:35 PM John Dale <jc...@gmail.com> wrote:
> > >
> > >> For reference, I did find this after searching "calling a servlet
> > >> programmatically":
> > >> https://docs.oracle.com/cd/E19146-01/819-2634/abxbn/index.html
> > >>
> > >> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
> > >> > I think we are completely missing each other. Forget sockets - that
> > was
> > >> > just an example. I have code running in a Tomcat App server which is
> > >> > not
> > >> > managed by Tomcat and is not initiated by anything within Tomcat.
> That
> > >> code
> > >> > now wants to call a servlet hosted in that very same JVM. Any way to
> > do
> > >> > that without going out and back in on TCP?
> > >> >
> > >> >
> > >> > On Mon, May 6, 2019 at 5:14 PM John Dale <jc...@gmail.com> wrote:
> > >> >
> > >> >> Sockets are an implementation of TCP/UDP inherently.
> > >> >>
> > >> >> Perhaps a mountaintop signal fire?
> > >> >>
> > >> >> ;)
> > >> >>
> > >> >> John
> > >> >>
> > >> >>
> > >> >> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
> > >> >> > lol on the Semaphore Telegraph,
> > >> >> >
> > >> >> > I can't use a request dispatcher as the request is being
> initiated
> > >> from
> > >> >> > code that has no context. I already have it working with HTTP
> using
> > >> >> > asynchttp library, but I want to avoid the overhead. E.g. lets
> say
> > I
> > >> >> wrote
> > >> >> > my own server socket listener on port 10000 running in the Tomcat
> > >> >> > JVM
> > >> >> > and
> > >> >> > got some request in some propriatary protocol called X. Now I
> want
> > >> >> > to
> > >> >> call
> > >> >> > a Tomcat servlet in the current JVM with some info I got over X
> > >> without
> > >> >> > going out on TCP and back in....
> > >> >> >
> > >> >> > On Mon, May 6, 2019 at 4:40 PM John Dale <jc...@gmail.com>
> > wrote:
> > >> >> >
> > >> >> >> If you're wanting to forward control to another servlet deployed
> > in
> > >> >> >> the same context:
> > >> >> >> https://www.javatpoint.com/requestdispatcher-in-servlet
> > >> >> >>
> > >> >> >> If you are okay going through TCP to facilitate some future or
> > >> current
> > >> >> >> distribution of services, Use HTTPURLConnection (not sure what
> > >> >> >> you're
> > >> >> >> wanting to do with the result of the request, if anything):
> > >> >> >>
> > >> >> >>
> > >> >>
> > >>
> >
> https://stackoverflow.com/questions/2793150/how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests
> > >> >> >>
> > >> >> >> If you need more sophisticated HTTP interactions, Apache
> maintains
> > >> >> >> a
> > >> >> >> very useful library for that:  http://hc.apache.org/
> > >> >> >>
> > >> >> >> If these don't work-out for you, rather than using .NET, PHP,
> > >> >> >> Python,
> > >> >> >> or some other Java facsimile at best, I recommend using the
> > >> >> >> semaphore
> > >> >> >> telegraph:
> > >> >> >> https://en.wikipedia.org/wiki/Semaphore_telegraph
> > >> >> >>
> > >> >> >> Sincerely,
> > >> >> >>
> > >> >> >> John
> > >> >> >> DB2DOM
> > >> >> >>
> > >> >> >> On 5/6/19, Paul Carter-Brown <pa...@jini.guru>
> wrote:
> > >> >> >> > Hi John,
> > >> >> >> >
> > >> >> >> > Thanks for your feedback.
> > >> >> >> >
> > >> >> >> > The request I'm initiating should not or need not carry any
> > >> >> >> > context
> > >> >> >> > from
> > >> >> >> > the originating code. There is also no session to worry about
> as
> > >> its
> > >> >> >> > just
> > >> >> >> > for rest calls. So basically I have the headers, path and body
> > >> >> >> > and
> > >> >> need
> > >> >> >> to
> > >> >> >> > generate a http servlet request and get an http servlet
> response
> > >> (or
> > >> >> >> > similar) back. I have this working by calling into localhost
> but
> > >> >> >> > ideally
> > >> >> >> > want to skip the trombone out and back in.
> > >> >> >> >
> > >> >> >> > Have you got any basic code examples?
> > >> >> >> >
> > >> >> >> > Paul
> > >> >> >> >
> > >> >> >> > On Tue, Apr 30, 2019 at 5:27 PM John Dale <jc...@gmail.com>
> > >> wrote:
> > >> >> >> >
> > >> >> >> >> Another thought .. you can do some request dispatching, but
> > >> without
> > >> >> >> >> knowing more about the tools you're using, I can't say for
> sure
> > >> >> >> >> if
> > >> >> >> >> this is the direction you'll want to go.
> > >> >> >> >>
> > >> >> >> >> On 4/29/19, Paul Carter-Brown <pa...@jini.guru>
> > >> wrote:
> > >> >> >> >> > Hi
> > >> >> >> >> >
> > >> >> >> >> > I'm trying to design a Kafka consumer and producer that
> will
> > >> >> >> >> > run
> > >> >> >> inside
> > >> >> >> >> the
> > >> >> >> >> > tomcat jvm and pick up messages off a Kafka topic and
> > >> >> >> >> > translate
> > >> >> them
> > >> >> >> >> into a
> > >> >> >> >> > servlet request and pass it through tomcat and then when
> the
> > >> >> >> >> > response
> > >> >> >> >> > is
> > >> >> >> >> > complete then translate it into a Kafka message and put it
> > >> >> >> >> > onto
> > >> >> >> another
> > >> >> >> >> > topic as a reply. This way I can reuse our existing jax-rs
> > >> >> >> >> > rest
> > >> >> >> >> > services
> > >> >> >> >> > and expose them as an async api over Kafka. The idea is to
> > >> >> >> >> > make
> > >> >> >> >> > the
> > >> >> >> >> > Kafka
> > >> >> >> >> > messages similar to http in that they would consist of
> > headers
> > >> >> >> >> > and
> > >> >> a
> > >> >> >> >> body.
> > >> >> >> >> > The body would be json.
> > >> >> >> >> >
> > >> >> >> >> > Now I know this could be done by calling localhost with an
> > >> >> >> >> > http
> > >> >> call
> > >> >> >> to
> > >> >> >> >> > trombone the requests back into tomcat but I'd like to
> avoid
> > >> >> >> >> > the
> > >> >> >> >> associated
> > >> >> >> >> > latency and overhead. Is it possible to call tomcat
> directly
> > >> >> >> >> > in-process.
> > >> >> >> >> > This does not need to be portable to other containers so
> can
> > >> >> >> >> > be
> > >> >> >> >> > proprietary.
> > >> >> >> >> >
> > >> >> >> >> > I'm using tomcat 8. In fact its tomee 8 but guessed this is
> > >> >> >> >> > more
> > >> >> >> >> > a
> > >> >> >> >> > tomcat
> > >> >> >> >> > question than tomee but have sent to both groups just in
> > case.
> > >> >> >> >> >
> > >> >> >> >> > Thanks for any insights.
> > >> >> >> >> >
> > >> >> >> >> > Paul
> > >> >> >> >> >
> > >> >> >> >>
> > >> >> >> >
> > >> >> >>
> > >> >> >>
> > ---------------------------------------------------------------------
> > >> >> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > >> >> >> For additional commands, e-mail: users-help@tomcat.apache.org
> > >> >> >>
> > >> >> >>
> > >> >> >
> > >> >>
> > >> >>
> ---------------------------------------------------------------------
> > >> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > >> >> For additional commands, e-mail: users-help@tomcat.apache.org
> > >> >>
> > >> >>
> > >> >
> > >>
> > >> ---------------------------------------------------------------------
> > >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > >> For additional commands, e-mail: users-help@tomcat.apache.org
> > >>
> > >>
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: users-help@tomcat.apache.org
> >
> >
>

Re: Initiating httpservletrequest from inside Tomcat / TomEE

Posted by Paul Carter-Brown <pa...@jini.guru>.
Hi John,

See original request. It's pretty much a Kafka/Servlet proxy/gateway:

I'm trying to design a Kafka consumer and producer that will run inside the
tomcat jvm and pick up messages off a Kafka topic and translate them into a
servlet request and pass it through tomcat and then when the response is
complete then translate it into a Kafka message and put it onto another
topic as a reply. This way I can reuse our existing jax-rs rest services
and expose them as an async api over Kafka. The idea is to make the Kafka
messages similar to http in that they would consist of headers and a body.
The body would be json.


On Mon, May 6, 2019 at 6:13 PM John Dale <jc...@gmail.com> wrote:

> You could try debugging the tomcat code and find out how, right after
> it parses the TCP request, it invokes the servlet.  You can then
> create your own harness for tomcat code after initializing the
> appropriate context for the request to tomcat.  I don't know off hand
> where in the tomcat code this cut point can be found.
>
> Is this a performance issue, or are you building a proxy?
>
> What is the problem you're trying to solve?
>
> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
> > Yea, but the issue is that only works when calling in the context of a
> > current servlet call.
> >
> > Here is the kind of problem I want to solve:
> >
> > @WebServlet(name = "MyExample", urlPatterns = {"/example"},
> loadOnStartup =
> > 1)
> > public class Example extends HttpServlet {
> >
> >     @PersistenceContext
> >     private EntityManager em;
> >
> >     @Override
> >     public void init(ServletConfig config) {
> >         Thread t = new Thread(() -> {
> >             while (true) {
> >                 try {
> >                     // Do a GET to /example/ and get the response without
> > going out on localhost and back in....
> >                     // We cant just call doGet as we want the request to
> > flow through the servlet filters, do the entitymanager injection etc
> >                     Thread.sleep(10000);
> >                 } catch (Exception e) {
> >                 }
> >             }
> >         });
> >         t.start();
> >
> >     }
> >
> >     @Override
> >     protected void doGet(HttpServletRequest req, HttpServletResponse
> resp)
> > throws ServletException, IOException {
> >         // do stuff like use em
> >         resp.setStatus(200);
> >         resp.getWriter().write("Hello World");
> >     }
> >
> > }
> >
> >
> >
> >
> > On Mon, May 6, 2019 at 5:35 PM John Dale <jc...@gmail.com> wrote:
> >
> >> For reference, I did find this after searching "calling a servlet
> >> programmatically":
> >> https://docs.oracle.com/cd/E19146-01/819-2634/abxbn/index.html
> >>
> >> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
> >> > I think we are completely missing each other. Forget sockets - that
> was
> >> > just an example. I have code running in a Tomcat App server which is
> >> > not
> >> > managed by Tomcat and is not initiated by anything within Tomcat. That
> >> code
> >> > now wants to call a servlet hosted in that very same JVM. Any way to
> do
> >> > that without going out and back in on TCP?
> >> >
> >> >
> >> > On Mon, May 6, 2019 at 5:14 PM John Dale <jc...@gmail.com> wrote:
> >> >
> >> >> Sockets are an implementation of TCP/UDP inherently.
> >> >>
> >> >> Perhaps a mountaintop signal fire?
> >> >>
> >> >> ;)
> >> >>
> >> >> John
> >> >>
> >> >>
> >> >> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
> >> >> > lol on the Semaphore Telegraph,
> >> >> >
> >> >> > I can't use a request dispatcher as the request is being initiated
> >> from
> >> >> > code that has no context. I already have it working with HTTP using
> >> >> > asynchttp library, but I want to avoid the overhead. E.g. lets say
> I
> >> >> wrote
> >> >> > my own server socket listener on port 10000 running in the Tomcat
> >> >> > JVM
> >> >> > and
> >> >> > got some request in some propriatary protocol called X. Now I want
> >> >> > to
> >> >> call
> >> >> > a Tomcat servlet in the current JVM with some info I got over X
> >> without
> >> >> > going out on TCP and back in....
> >> >> >
> >> >> > On Mon, May 6, 2019 at 4:40 PM John Dale <jc...@gmail.com>
> wrote:
> >> >> >
> >> >> >> If you're wanting to forward control to another servlet deployed
> in
> >> >> >> the same context:
> >> >> >> https://www.javatpoint.com/requestdispatcher-in-servlet
> >> >> >>
> >> >> >> If you are okay going through TCP to facilitate some future or
> >> current
> >> >> >> distribution of services, Use HTTPURLConnection (not sure what
> >> >> >> you're
> >> >> >> wanting to do with the result of the request, if anything):
> >> >> >>
> >> >> >>
> >> >>
> >>
> https://stackoverflow.com/questions/2793150/how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests
> >> >> >>
> >> >> >> If you need more sophisticated HTTP interactions, Apache maintains
> >> >> >> a
> >> >> >> very useful library for that:  http://hc.apache.org/
> >> >> >>
> >> >> >> If these don't work-out for you, rather than using .NET, PHP,
> >> >> >> Python,
> >> >> >> or some other Java facsimile at best, I recommend using the
> >> >> >> semaphore
> >> >> >> telegraph:
> >> >> >> https://en.wikipedia.org/wiki/Semaphore_telegraph
> >> >> >>
> >> >> >> Sincerely,
> >> >> >>
> >> >> >> John
> >> >> >> DB2DOM
> >> >> >>
> >> >> >> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
> >> >> >> > Hi John,
> >> >> >> >
> >> >> >> > Thanks for your feedback.
> >> >> >> >
> >> >> >> > The request I'm initiating should not or need not carry any
> >> >> >> > context
> >> >> >> > from
> >> >> >> > the originating code. There is also no session to worry about as
> >> its
> >> >> >> > just
> >> >> >> > for rest calls. So basically I have the headers, path and body
> >> >> >> > and
> >> >> need
> >> >> >> to
> >> >> >> > generate a http servlet request and get an http servlet response
> >> (or
> >> >> >> > similar) back. I have this working by calling into localhost but
> >> >> >> > ideally
> >> >> >> > want to skip the trombone out and back in.
> >> >> >> >
> >> >> >> > Have you got any basic code examples?
> >> >> >> >
> >> >> >> > Paul
> >> >> >> >
> >> >> >> > On Tue, Apr 30, 2019 at 5:27 PM John Dale <jc...@gmail.com>
> >> wrote:
> >> >> >> >
> >> >> >> >> Another thought .. you can do some request dispatching, but
> >> without
> >> >> >> >> knowing more about the tools you're using, I can't say for sure
> >> >> >> >> if
> >> >> >> >> this is the direction you'll want to go.
> >> >> >> >>
> >> >> >> >> On 4/29/19, Paul Carter-Brown <pa...@jini.guru>
> >> wrote:
> >> >> >> >> > Hi
> >> >> >> >> >
> >> >> >> >> > I'm trying to design a Kafka consumer and producer that will
> >> >> >> >> > run
> >> >> >> inside
> >> >> >> >> the
> >> >> >> >> > tomcat jvm and pick up messages off a Kafka topic and
> >> >> >> >> > translate
> >> >> them
> >> >> >> >> into a
> >> >> >> >> > servlet request and pass it through tomcat and then when the
> >> >> >> >> > response
> >> >> >> >> > is
> >> >> >> >> > complete then translate it into a Kafka message and put it
> >> >> >> >> > onto
> >> >> >> another
> >> >> >> >> > topic as a reply. This way I can reuse our existing jax-rs
> >> >> >> >> > rest
> >> >> >> >> > services
> >> >> >> >> > and expose them as an async api over Kafka. The idea is to
> >> >> >> >> > make
> >> >> >> >> > the
> >> >> >> >> > Kafka
> >> >> >> >> > messages similar to http in that they would consist of
> headers
> >> >> >> >> > and
> >> >> a
> >> >> >> >> body.
> >> >> >> >> > The body would be json.
> >> >> >> >> >
> >> >> >> >> > Now I know this could be done by calling localhost with an
> >> >> >> >> > http
> >> >> call
> >> >> >> to
> >> >> >> >> > trombone the requests back into tomcat but I'd like to avoid
> >> >> >> >> > the
> >> >> >> >> associated
> >> >> >> >> > latency and overhead. Is it possible to call tomcat directly
> >> >> >> >> > in-process.
> >> >> >> >> > This does not need to be portable to other containers so can
> >> >> >> >> > be
> >> >> >> >> > proprietary.
> >> >> >> >> >
> >> >> >> >> > I'm using tomcat 8. In fact its tomee 8 but guessed this is
> >> >> >> >> > more
> >> >> >> >> > a
> >> >> >> >> > tomcat
> >> >> >> >> > question than tomee but have sent to both groups just in
> case.
> >> >> >> >> >
> >> >> >> >> > Thanks for any insights.
> >> >> >> >> >
> >> >> >> >> > Paul
> >> >> >> >> >
> >> >> >> >>
> >> >> >> >
> >> >> >>
> >> >> >>
> ---------------------------------------------------------------------
> >> >> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >> >> >> For additional commands, e-mail: users-help@tomcat.apache.org
> >> >> >>
> >> >> >>
> >> >> >
> >> >>
> >> >> ---------------------------------------------------------------------
> >> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >> >> For additional commands, e-mail: users-help@tomcat.apache.org
> >> >>
> >> >>
> >> >
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >> For additional commands, e-mail: users-help@tomcat.apache.org
> >>
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: Initiating httpservletrequest from inside Tomcat / TomEE

Posted by Paul Carter-Brown <pa...@jini.guru>.
Hi John,

See original request. It's pretty much a Kafka/Servlet proxy/gateway:

I'm trying to design a Kafka consumer and producer that will run inside the
tomcat jvm and pick up messages off a Kafka topic and translate them into a
servlet request and pass it through tomcat and then when the response is
complete then translate it into a Kafka message and put it onto another
topic as a reply. This way I can reuse our existing jax-rs rest services
and expose them as an async api over Kafka. The idea is to make the Kafka
messages similar to http in that they would consist of headers and a body.
The body would be json.


On Mon, May 6, 2019 at 6:13 PM John Dale <jc...@gmail.com> wrote:

> You could try debugging the tomcat code and find out how, right after
> it parses the TCP request, it invokes the servlet.  You can then
> create your own harness for tomcat code after initializing the
> appropriate context for the request to tomcat.  I don't know off hand
> where in the tomcat code this cut point can be found.
>
> Is this a performance issue, or are you building a proxy?
>
> What is the problem you're trying to solve?
>
> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
> > Yea, but the issue is that only works when calling in the context of a
> > current servlet call.
> >
> > Here is the kind of problem I want to solve:
> >
> > @WebServlet(name = "MyExample", urlPatterns = {"/example"},
> loadOnStartup =
> > 1)
> > public class Example extends HttpServlet {
> >
> >     @PersistenceContext
> >     private EntityManager em;
> >
> >     @Override
> >     public void init(ServletConfig config) {
> >         Thread t = new Thread(() -> {
> >             while (true) {
> >                 try {
> >                     // Do a GET to /example/ and get the response without
> > going out on localhost and back in....
> >                     // We cant just call doGet as we want the request to
> > flow through the servlet filters, do the entitymanager injection etc
> >                     Thread.sleep(10000);
> >                 } catch (Exception e) {
> >                 }
> >             }
> >         });
> >         t.start();
> >
> >     }
> >
> >     @Override
> >     protected void doGet(HttpServletRequest req, HttpServletResponse
> resp)
> > throws ServletException, IOException {
> >         // do stuff like use em
> >         resp.setStatus(200);
> >         resp.getWriter().write("Hello World");
> >     }
> >
> > }
> >
> >
> >
> >
> > On Mon, May 6, 2019 at 5:35 PM John Dale <jc...@gmail.com> wrote:
> >
> >> For reference, I did find this after searching "calling a servlet
> >> programmatically":
> >> https://docs.oracle.com/cd/E19146-01/819-2634/abxbn/index.html
> >>
> >> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
> >> > I think we are completely missing each other. Forget sockets - that
> was
> >> > just an example. I have code running in a Tomcat App server which is
> >> > not
> >> > managed by Tomcat and is not initiated by anything within Tomcat. That
> >> code
> >> > now wants to call a servlet hosted in that very same JVM. Any way to
> do
> >> > that without going out and back in on TCP?
> >> >
> >> >
> >> > On Mon, May 6, 2019 at 5:14 PM John Dale <jc...@gmail.com> wrote:
> >> >
> >> >> Sockets are an implementation of TCP/UDP inherently.
> >> >>
> >> >> Perhaps a mountaintop signal fire?
> >> >>
> >> >> ;)
> >> >>
> >> >> John
> >> >>
> >> >>
> >> >> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
> >> >> > lol on the Semaphore Telegraph,
> >> >> >
> >> >> > I can't use a request dispatcher as the request is being initiated
> >> from
> >> >> > code that has no context. I already have it working with HTTP using
> >> >> > asynchttp library, but I want to avoid the overhead. E.g. lets say
> I
> >> >> wrote
> >> >> > my own server socket listener on port 10000 running in the Tomcat
> >> >> > JVM
> >> >> > and
> >> >> > got some request in some propriatary protocol called X. Now I want
> >> >> > to
> >> >> call
> >> >> > a Tomcat servlet in the current JVM with some info I got over X
> >> without
> >> >> > going out on TCP and back in....
> >> >> >
> >> >> > On Mon, May 6, 2019 at 4:40 PM John Dale <jc...@gmail.com>
> wrote:
> >> >> >
> >> >> >> If you're wanting to forward control to another servlet deployed
> in
> >> >> >> the same context:
> >> >> >> https://www.javatpoint.com/requestdispatcher-in-servlet
> >> >> >>
> >> >> >> If you are okay going through TCP to facilitate some future or
> >> current
> >> >> >> distribution of services, Use HTTPURLConnection (not sure what
> >> >> >> you're
> >> >> >> wanting to do with the result of the request, if anything):
> >> >> >>
> >> >> >>
> >> >>
> >>
> https://stackoverflow.com/questions/2793150/how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests
> >> >> >>
> >> >> >> If you need more sophisticated HTTP interactions, Apache maintains
> >> >> >> a
> >> >> >> very useful library for that:  http://hc.apache.org/
> >> >> >>
> >> >> >> If these don't work-out for you, rather than using .NET, PHP,
> >> >> >> Python,
> >> >> >> or some other Java facsimile at best, I recommend using the
> >> >> >> semaphore
> >> >> >> telegraph:
> >> >> >> https://en.wikipedia.org/wiki/Semaphore_telegraph
> >> >> >>
> >> >> >> Sincerely,
> >> >> >>
> >> >> >> John
> >> >> >> DB2DOM
> >> >> >>
> >> >> >> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
> >> >> >> > Hi John,
> >> >> >> >
> >> >> >> > Thanks for your feedback.
> >> >> >> >
> >> >> >> > The request I'm initiating should not or need not carry any
> >> >> >> > context
> >> >> >> > from
> >> >> >> > the originating code. There is also no session to worry about as
> >> its
> >> >> >> > just
> >> >> >> > for rest calls. So basically I have the headers, path and body
> >> >> >> > and
> >> >> need
> >> >> >> to
> >> >> >> > generate a http servlet request and get an http servlet response
> >> (or
> >> >> >> > similar) back. I have this working by calling into localhost but
> >> >> >> > ideally
> >> >> >> > want to skip the trombone out and back in.
> >> >> >> >
> >> >> >> > Have you got any basic code examples?
> >> >> >> >
> >> >> >> > Paul
> >> >> >> >
> >> >> >> > On Tue, Apr 30, 2019 at 5:27 PM John Dale <jc...@gmail.com>
> >> wrote:
> >> >> >> >
> >> >> >> >> Another thought .. you can do some request dispatching, but
> >> without
> >> >> >> >> knowing more about the tools you're using, I can't say for sure
> >> >> >> >> if
> >> >> >> >> this is the direction you'll want to go.
> >> >> >> >>
> >> >> >> >> On 4/29/19, Paul Carter-Brown <pa...@jini.guru>
> >> wrote:
> >> >> >> >> > Hi
> >> >> >> >> >
> >> >> >> >> > I'm trying to design a Kafka consumer and producer that will
> >> >> >> >> > run
> >> >> >> inside
> >> >> >> >> the
> >> >> >> >> > tomcat jvm and pick up messages off a Kafka topic and
> >> >> >> >> > translate
> >> >> them
> >> >> >> >> into a
> >> >> >> >> > servlet request and pass it through tomcat and then when the
> >> >> >> >> > response
> >> >> >> >> > is
> >> >> >> >> > complete then translate it into a Kafka message and put it
> >> >> >> >> > onto
> >> >> >> another
> >> >> >> >> > topic as a reply. This way I can reuse our existing jax-rs
> >> >> >> >> > rest
> >> >> >> >> > services
> >> >> >> >> > and expose them as an async api over Kafka. The idea is to
> >> >> >> >> > make
> >> >> >> >> > the
> >> >> >> >> > Kafka
> >> >> >> >> > messages similar to http in that they would consist of
> headers
> >> >> >> >> > and
> >> >> a
> >> >> >> >> body.
> >> >> >> >> > The body would be json.
> >> >> >> >> >
> >> >> >> >> > Now I know this could be done by calling localhost with an
> >> >> >> >> > http
> >> >> call
> >> >> >> to
> >> >> >> >> > trombone the requests back into tomcat but I'd like to avoid
> >> >> >> >> > the
> >> >> >> >> associated
> >> >> >> >> > latency and overhead. Is it possible to call tomcat directly
> >> >> >> >> > in-process.
> >> >> >> >> > This does not need to be portable to other containers so can
> >> >> >> >> > be
> >> >> >> >> > proprietary.
> >> >> >> >> >
> >> >> >> >> > I'm using tomcat 8. In fact its tomee 8 but guessed this is
> >> >> >> >> > more
> >> >> >> >> > a
> >> >> >> >> > tomcat
> >> >> >> >> > question than tomee but have sent to both groups just in
> case.
> >> >> >> >> >
> >> >> >> >> > Thanks for any insights.
> >> >> >> >> >
> >> >> >> >> > Paul
> >> >> >> >> >
> >> >> >> >>
> >> >> >> >
> >> >> >>
> >> >> >>
> ---------------------------------------------------------------------
> >> >> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >> >> >> For additional commands, e-mail: users-help@tomcat.apache.org
> >> >> >>
> >> >> >>
> >> >> >
> >> >>
> >> >> ---------------------------------------------------------------------
> >> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >> >> For additional commands, e-mail: users-help@tomcat.apache.org
> >> >>
> >> >>
> >> >
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >> For additional commands, e-mail: users-help@tomcat.apache.org
> >>
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: Initiating httpservletrequest from inside Tomcat / TomEE

Posted by John Dale <jc...@gmail.com>.
You could try debugging the tomcat code and find out how, right after
it parses the TCP request, it invokes the servlet.  You can then
create your own harness for tomcat code after initializing the
appropriate context for the request to tomcat.  I don't know off hand
where in the tomcat code this cut point can be found.

Is this a performance issue, or are you building a proxy?

What is the problem you're trying to solve?

On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
> Yea, but the issue is that only works when calling in the context of a
> current servlet call.
>
> Here is the kind of problem I want to solve:
>
> @WebServlet(name = "MyExample", urlPatterns = {"/example"}, loadOnStartup =
> 1)
> public class Example extends HttpServlet {
>
>     @PersistenceContext
>     private EntityManager em;
>
>     @Override
>     public void init(ServletConfig config) {
>         Thread t = new Thread(() -> {
>             while (true) {
>                 try {
>                     // Do a GET to /example/ and get the response without
> going out on localhost and back in....
>                     // We cant just call doGet as we want the request to
> flow through the servlet filters, do the entitymanager injection etc
>                     Thread.sleep(10000);
>                 } catch (Exception e) {
>                 }
>             }
>         });
>         t.start();
>
>     }
>
>     @Override
>     protected void doGet(HttpServletRequest req, HttpServletResponse resp)
> throws ServletException, IOException {
>         // do stuff like use em
>         resp.setStatus(200);
>         resp.getWriter().write("Hello World");
>     }
>
> }
>
>
>
>
> On Mon, May 6, 2019 at 5:35 PM John Dale <jc...@gmail.com> wrote:
>
>> For reference, I did find this after searching "calling a servlet
>> programmatically":
>> https://docs.oracle.com/cd/E19146-01/819-2634/abxbn/index.html
>>
>> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
>> > I think we are completely missing each other. Forget sockets - that was
>> > just an example. I have code running in a Tomcat App server which is
>> > not
>> > managed by Tomcat and is not initiated by anything within Tomcat. That
>> code
>> > now wants to call a servlet hosted in that very same JVM. Any way to do
>> > that without going out and back in on TCP?
>> >
>> >
>> > On Mon, May 6, 2019 at 5:14 PM John Dale <jc...@gmail.com> wrote:
>> >
>> >> Sockets are an implementation of TCP/UDP inherently.
>> >>
>> >> Perhaps a mountaintop signal fire?
>> >>
>> >> ;)
>> >>
>> >> John
>> >>
>> >>
>> >> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
>> >> > lol on the Semaphore Telegraph,
>> >> >
>> >> > I can't use a request dispatcher as the request is being initiated
>> from
>> >> > code that has no context. I already have it working with HTTP using
>> >> > asynchttp library, but I want to avoid the overhead. E.g. lets say I
>> >> wrote
>> >> > my own server socket listener on port 10000 running in the Tomcat
>> >> > JVM
>> >> > and
>> >> > got some request in some propriatary protocol called X. Now I want
>> >> > to
>> >> call
>> >> > a Tomcat servlet in the current JVM with some info I got over X
>> without
>> >> > going out on TCP and back in....
>> >> >
>> >> > On Mon, May 6, 2019 at 4:40 PM John Dale <jc...@gmail.com> wrote:
>> >> >
>> >> >> If you're wanting to forward control to another servlet deployed in
>> >> >> the same context:
>> >> >> https://www.javatpoint.com/requestdispatcher-in-servlet
>> >> >>
>> >> >> If you are okay going through TCP to facilitate some future or
>> current
>> >> >> distribution of services, Use HTTPURLConnection (not sure what
>> >> >> you're
>> >> >> wanting to do with the result of the request, if anything):
>> >> >>
>> >> >>
>> >>
>> https://stackoverflow.com/questions/2793150/how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests
>> >> >>
>> >> >> If you need more sophisticated HTTP interactions, Apache maintains
>> >> >> a
>> >> >> very useful library for that:  http://hc.apache.org/
>> >> >>
>> >> >> If these don't work-out for you, rather than using .NET, PHP,
>> >> >> Python,
>> >> >> or some other Java facsimile at best, I recommend using the
>> >> >> semaphore
>> >> >> telegraph:
>> >> >> https://en.wikipedia.org/wiki/Semaphore_telegraph
>> >> >>
>> >> >> Sincerely,
>> >> >>
>> >> >> John
>> >> >> DB2DOM
>> >> >>
>> >> >> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
>> >> >> > Hi John,
>> >> >> >
>> >> >> > Thanks for your feedback.
>> >> >> >
>> >> >> > The request I'm initiating should not or need not carry any
>> >> >> > context
>> >> >> > from
>> >> >> > the originating code. There is also no session to worry about as
>> its
>> >> >> > just
>> >> >> > for rest calls. So basically I have the headers, path and body
>> >> >> > and
>> >> need
>> >> >> to
>> >> >> > generate a http servlet request and get an http servlet response
>> (or
>> >> >> > similar) back. I have this working by calling into localhost but
>> >> >> > ideally
>> >> >> > want to skip the trombone out and back in.
>> >> >> >
>> >> >> > Have you got any basic code examples?
>> >> >> >
>> >> >> > Paul
>> >> >> >
>> >> >> > On Tue, Apr 30, 2019 at 5:27 PM John Dale <jc...@gmail.com>
>> wrote:
>> >> >> >
>> >> >> >> Another thought .. you can do some request dispatching, but
>> without
>> >> >> >> knowing more about the tools you're using, I can't say for sure
>> >> >> >> if
>> >> >> >> this is the direction you'll want to go.
>> >> >> >>
>> >> >> >> On 4/29/19, Paul Carter-Brown <pa...@jini.guru>
>> wrote:
>> >> >> >> > Hi
>> >> >> >> >
>> >> >> >> > I'm trying to design a Kafka consumer and producer that will
>> >> >> >> > run
>> >> >> inside
>> >> >> >> the
>> >> >> >> > tomcat jvm and pick up messages off a Kafka topic and
>> >> >> >> > translate
>> >> them
>> >> >> >> into a
>> >> >> >> > servlet request and pass it through tomcat and then when the
>> >> >> >> > response
>> >> >> >> > is
>> >> >> >> > complete then translate it into a Kafka message and put it
>> >> >> >> > onto
>> >> >> another
>> >> >> >> > topic as a reply. This way I can reuse our existing jax-rs
>> >> >> >> > rest
>> >> >> >> > services
>> >> >> >> > and expose them as an async api over Kafka. The idea is to
>> >> >> >> > make
>> >> >> >> > the
>> >> >> >> > Kafka
>> >> >> >> > messages similar to http in that they would consist of headers
>> >> >> >> > and
>> >> a
>> >> >> >> body.
>> >> >> >> > The body would be json.
>> >> >> >> >
>> >> >> >> > Now I know this could be done by calling localhost with an
>> >> >> >> > http
>> >> call
>> >> >> to
>> >> >> >> > trombone the requests back into tomcat but I'd like to avoid
>> >> >> >> > the
>> >> >> >> associated
>> >> >> >> > latency and overhead. Is it possible to call tomcat directly
>> >> >> >> > in-process.
>> >> >> >> > This does not need to be portable to other containers so can
>> >> >> >> > be
>> >> >> >> > proprietary.
>> >> >> >> >
>> >> >> >> > I'm using tomcat 8. In fact its tomee 8 but guessed this is
>> >> >> >> > more
>> >> >> >> > a
>> >> >> >> > tomcat
>> >> >> >> > question than tomee but have sent to both groups just in case.
>> >> >> >> >
>> >> >> >> > Thanks for any insights.
>> >> >> >> >
>> >> >> >> > Paul
>> >> >> >> >
>> >> >> >>
>> >> >> >
>> >> >>
>> >> >> ---------------------------------------------------------------------
>> >> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> >> >> For additional commands, e-mail: users-help@tomcat.apache.org
>> >> >>
>> >> >>
>> >> >
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> >> For additional commands, e-mail: users-help@tomcat.apache.org
>> >>
>> >>
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Initiating httpservletrequest from inside Tomcat / TomEE

Posted by Paul Carter-Brown <pa...@jini.guru>.
Yea, but the issue is that only works when calling in the context of a
current servlet call.

Here is the kind of problem I want to solve:

@WebServlet(name = "MyExample", urlPatterns = {"/example"}, loadOnStartup =
1)
public class Example extends HttpServlet {

    @PersistenceContext
    private EntityManager em;

    @Override
    public void init(ServletConfig config) {
        Thread t = new Thread(() -> {
            while (true) {
                try {
                    // Do a GET to /example/ and get the response without
going out on localhost and back in....
                    // We cant just call doGet as we want the request to
flow through the servlet filters, do the entitymanager injection etc
                    Thread.sleep(10000);
                } catch (Exception e) {
                }
            }
        });
        t.start();

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
        // do stuff like use em
        resp.setStatus(200);
        resp.getWriter().write("Hello World");
    }

}




On Mon, May 6, 2019 at 5:35 PM John Dale <jc...@gmail.com> wrote:

> For reference, I did find this after searching "calling a servlet
> programmatically":
> https://docs.oracle.com/cd/E19146-01/819-2634/abxbn/index.html
>
> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
> > I think we are completely missing each other. Forget sockets - that was
> > just an example. I have code running in a Tomcat App server which is not
> > managed by Tomcat and is not initiated by anything within Tomcat. That
> code
> > now wants to call a servlet hosted in that very same JVM. Any way to do
> > that without going out and back in on TCP?
> >
> >
> > On Mon, May 6, 2019 at 5:14 PM John Dale <jc...@gmail.com> wrote:
> >
> >> Sockets are an implementation of TCP/UDP inherently.
> >>
> >> Perhaps a mountaintop signal fire?
> >>
> >> ;)
> >>
> >> John
> >>
> >>
> >> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
> >> > lol on the Semaphore Telegraph,
> >> >
> >> > I can't use a request dispatcher as the request is being initiated
> from
> >> > code that has no context. I already have it working with HTTP using
> >> > asynchttp library, but I want to avoid the overhead. E.g. lets say I
> >> wrote
> >> > my own server socket listener on port 10000 running in the Tomcat JVM
> >> > and
> >> > got some request in some propriatary protocol called X. Now I want to
> >> call
> >> > a Tomcat servlet in the current JVM with some info I got over X
> without
> >> > going out on TCP and back in....
> >> >
> >> > On Mon, May 6, 2019 at 4:40 PM John Dale <jc...@gmail.com> wrote:
> >> >
> >> >> If you're wanting to forward control to another servlet deployed in
> >> >> the same context:
> >> >> https://www.javatpoint.com/requestdispatcher-in-servlet
> >> >>
> >> >> If you are okay going through TCP to facilitate some future or
> current
> >> >> distribution of services, Use HTTPURLConnection (not sure what you're
> >> >> wanting to do with the result of the request, if anything):
> >> >>
> >> >>
> >>
> https://stackoverflow.com/questions/2793150/how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests
> >> >>
> >> >> If you need more sophisticated HTTP interactions, Apache maintains a
> >> >> very useful library for that:  http://hc.apache.org/
> >> >>
> >> >> If these don't work-out for you, rather than using .NET, PHP, Python,
> >> >> or some other Java facsimile at best, I recommend using the semaphore
> >> >> telegraph:
> >> >> https://en.wikipedia.org/wiki/Semaphore_telegraph
> >> >>
> >> >> Sincerely,
> >> >>
> >> >> John
> >> >> DB2DOM
> >> >>
> >> >> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
> >> >> > Hi John,
> >> >> >
> >> >> > Thanks for your feedback.
> >> >> >
> >> >> > The request I'm initiating should not or need not carry any context
> >> >> > from
> >> >> > the originating code. There is also no session to worry about as
> its
> >> >> > just
> >> >> > for rest calls. So basically I have the headers, path and body and
> >> need
> >> >> to
> >> >> > generate a http servlet request and get an http servlet response
> (or
> >> >> > similar) back. I have this working by calling into localhost but
> >> >> > ideally
> >> >> > want to skip the trombone out and back in.
> >> >> >
> >> >> > Have you got any basic code examples?
> >> >> >
> >> >> > Paul
> >> >> >
> >> >> > On Tue, Apr 30, 2019 at 5:27 PM John Dale <jc...@gmail.com>
> wrote:
> >> >> >
> >> >> >> Another thought .. you can do some request dispatching, but
> without
> >> >> >> knowing more about the tools you're using, I can't say for sure if
> >> >> >> this is the direction you'll want to go.
> >> >> >>
> >> >> >> On 4/29/19, Paul Carter-Brown <pa...@jini.guru>
> wrote:
> >> >> >> > Hi
> >> >> >> >
> >> >> >> > I'm trying to design a Kafka consumer and producer that will run
> >> >> inside
> >> >> >> the
> >> >> >> > tomcat jvm and pick up messages off a Kafka topic and translate
> >> them
> >> >> >> into a
> >> >> >> > servlet request and pass it through tomcat and then when the
> >> >> >> > response
> >> >> >> > is
> >> >> >> > complete then translate it into a Kafka message and put it onto
> >> >> another
> >> >> >> > topic as a reply. This way I can reuse our existing jax-rs rest
> >> >> >> > services
> >> >> >> > and expose them as an async api over Kafka. The idea is to make
> >> >> >> > the
> >> >> >> > Kafka
> >> >> >> > messages similar to http in that they would consist of headers
> >> >> >> > and
> >> a
> >> >> >> body.
> >> >> >> > The body would be json.
> >> >> >> >
> >> >> >> > Now I know this could be done by calling localhost with an http
> >> call
> >> >> to
> >> >> >> > trombone the requests back into tomcat but I'd like to avoid the
> >> >> >> associated
> >> >> >> > latency and overhead. Is it possible to call tomcat directly
> >> >> >> > in-process.
> >> >> >> > This does not need to be portable to other containers so can be
> >> >> >> > proprietary.
> >> >> >> >
> >> >> >> > I'm using tomcat 8. In fact its tomee 8 but guessed this is more
> >> >> >> > a
> >> >> >> > tomcat
> >> >> >> > question than tomee but have sent to both groups just in case.
> >> >> >> >
> >> >> >> > Thanks for any insights.
> >> >> >> >
> >> >> >> > Paul
> >> >> >> >
> >> >> >>
> >> >> >
> >> >>
> >> >> ---------------------------------------------------------------------
> >> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >> >> For additional commands, e-mail: users-help@tomcat.apache.org
> >> >>
> >> >>
> >> >
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >> For additional commands, e-mail: users-help@tomcat.apache.org
> >>
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: Initiating httpservletrequest from inside Tomcat / TomEE

Posted by Paul Carter-Brown <pa...@jini.guru>.
Yea, but the issue is that only works when calling in the context of a
current servlet call.

Here is the kind of problem I want to solve:

@WebServlet(name = "MyExample", urlPatterns = {"/example"}, loadOnStartup =
1)
public class Example extends HttpServlet {

    @PersistenceContext
    private EntityManager em;

    @Override
    public void init(ServletConfig config) {
        Thread t = new Thread(() -> {
            while (true) {
                try {
                    // Do a GET to /example/ and get the response without
going out on localhost and back in....
                    // We cant just call doGet as we want the request to
flow through the servlet filters, do the entitymanager injection etc
                    Thread.sleep(10000);
                } catch (Exception e) {
                }
            }
        });
        t.start();

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
        // do stuff like use em
        resp.setStatus(200);
        resp.getWriter().write("Hello World");
    }

}




On Mon, May 6, 2019 at 5:35 PM John Dale <jc...@gmail.com> wrote:

> For reference, I did find this after searching "calling a servlet
> programmatically":
> https://docs.oracle.com/cd/E19146-01/819-2634/abxbn/index.html
>
> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
> > I think we are completely missing each other. Forget sockets - that was
> > just an example. I have code running in a Tomcat App server which is not
> > managed by Tomcat and is not initiated by anything within Tomcat. That
> code
> > now wants to call a servlet hosted in that very same JVM. Any way to do
> > that without going out and back in on TCP?
> >
> >
> > On Mon, May 6, 2019 at 5:14 PM John Dale <jc...@gmail.com> wrote:
> >
> >> Sockets are an implementation of TCP/UDP inherently.
> >>
> >> Perhaps a mountaintop signal fire?
> >>
> >> ;)
> >>
> >> John
> >>
> >>
> >> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
> >> > lol on the Semaphore Telegraph,
> >> >
> >> > I can't use a request dispatcher as the request is being initiated
> from
> >> > code that has no context. I already have it working with HTTP using
> >> > asynchttp library, but I want to avoid the overhead. E.g. lets say I
> >> wrote
> >> > my own server socket listener on port 10000 running in the Tomcat JVM
> >> > and
> >> > got some request in some propriatary protocol called X. Now I want to
> >> call
> >> > a Tomcat servlet in the current JVM with some info I got over X
> without
> >> > going out on TCP and back in....
> >> >
> >> > On Mon, May 6, 2019 at 4:40 PM John Dale <jc...@gmail.com> wrote:
> >> >
> >> >> If you're wanting to forward control to another servlet deployed in
> >> >> the same context:
> >> >> https://www.javatpoint.com/requestdispatcher-in-servlet
> >> >>
> >> >> If you are okay going through TCP to facilitate some future or
> current
> >> >> distribution of services, Use HTTPURLConnection (not sure what you're
> >> >> wanting to do with the result of the request, if anything):
> >> >>
> >> >>
> >>
> https://stackoverflow.com/questions/2793150/how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests
> >> >>
> >> >> If you need more sophisticated HTTP interactions, Apache maintains a
> >> >> very useful library for that:  http://hc.apache.org/
> >> >>
> >> >> If these don't work-out for you, rather than using .NET, PHP, Python,
> >> >> or some other Java facsimile at best, I recommend using the semaphore
> >> >> telegraph:
> >> >> https://en.wikipedia.org/wiki/Semaphore_telegraph
> >> >>
> >> >> Sincerely,
> >> >>
> >> >> John
> >> >> DB2DOM
> >> >>
> >> >> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
> >> >> > Hi John,
> >> >> >
> >> >> > Thanks for your feedback.
> >> >> >
> >> >> > The request I'm initiating should not or need not carry any context
> >> >> > from
> >> >> > the originating code. There is also no session to worry about as
> its
> >> >> > just
> >> >> > for rest calls. So basically I have the headers, path and body and
> >> need
> >> >> to
> >> >> > generate a http servlet request and get an http servlet response
> (or
> >> >> > similar) back. I have this working by calling into localhost but
> >> >> > ideally
> >> >> > want to skip the trombone out and back in.
> >> >> >
> >> >> > Have you got any basic code examples?
> >> >> >
> >> >> > Paul
> >> >> >
> >> >> > On Tue, Apr 30, 2019 at 5:27 PM John Dale <jc...@gmail.com>
> wrote:
> >> >> >
> >> >> >> Another thought .. you can do some request dispatching, but
> without
> >> >> >> knowing more about the tools you're using, I can't say for sure if
> >> >> >> this is the direction you'll want to go.
> >> >> >>
> >> >> >> On 4/29/19, Paul Carter-Brown <pa...@jini.guru>
> wrote:
> >> >> >> > Hi
> >> >> >> >
> >> >> >> > I'm trying to design a Kafka consumer and producer that will run
> >> >> inside
> >> >> >> the
> >> >> >> > tomcat jvm and pick up messages off a Kafka topic and translate
> >> them
> >> >> >> into a
> >> >> >> > servlet request and pass it through tomcat and then when the
> >> >> >> > response
> >> >> >> > is
> >> >> >> > complete then translate it into a Kafka message and put it onto
> >> >> another
> >> >> >> > topic as a reply. This way I can reuse our existing jax-rs rest
> >> >> >> > services
> >> >> >> > and expose them as an async api over Kafka. The idea is to make
> >> >> >> > the
> >> >> >> > Kafka
> >> >> >> > messages similar to http in that they would consist of headers
> >> >> >> > and
> >> a
> >> >> >> body.
> >> >> >> > The body would be json.
> >> >> >> >
> >> >> >> > Now I know this could be done by calling localhost with an http
> >> call
> >> >> to
> >> >> >> > trombone the requests back into tomcat but I'd like to avoid the
> >> >> >> associated
> >> >> >> > latency and overhead. Is it possible to call tomcat directly
> >> >> >> > in-process.
> >> >> >> > This does not need to be portable to other containers so can be
> >> >> >> > proprietary.
> >> >> >> >
> >> >> >> > I'm using tomcat 8. In fact its tomee 8 but guessed this is more
> >> >> >> > a
> >> >> >> > tomcat
> >> >> >> > question than tomee but have sent to both groups just in case.
> >> >> >> >
> >> >> >> > Thanks for any insights.
> >> >> >> >
> >> >> >> > Paul
> >> >> >> >
> >> >> >>
> >> >> >
> >> >>
> >> >> ---------------------------------------------------------------------
> >> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >> >> For additional commands, e-mail: users-help@tomcat.apache.org
> >> >>
> >> >>
> >> >
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >> For additional commands, e-mail: users-help@tomcat.apache.org
> >>
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: Initiating httpservletrequest from inside Tomcat / TomEE

Posted by John Dale <jc...@gmail.com>.
For reference, I did find this after searching "calling a servlet
programmatically":
https://docs.oracle.com/cd/E19146-01/819-2634/abxbn/index.html

On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
> I think we are completely missing each other. Forget sockets - that was
> just an example. I have code running in a Tomcat App server which is not
> managed by Tomcat and is not initiated by anything within Tomcat. That code
> now wants to call a servlet hosted in that very same JVM. Any way to do
> that without going out and back in on TCP?
>
>
> On Mon, May 6, 2019 at 5:14 PM John Dale <jc...@gmail.com> wrote:
>
>> Sockets are an implementation of TCP/UDP inherently.
>>
>> Perhaps a mountaintop signal fire?
>>
>> ;)
>>
>> John
>>
>>
>> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
>> > lol on the Semaphore Telegraph,
>> >
>> > I can't use a request dispatcher as the request is being initiated from
>> > code that has no context. I already have it working with HTTP using
>> > asynchttp library, but I want to avoid the overhead. E.g. lets say I
>> wrote
>> > my own server socket listener on port 10000 running in the Tomcat JVM
>> > and
>> > got some request in some propriatary protocol called X. Now I want to
>> call
>> > a Tomcat servlet in the current JVM with some info I got over X without
>> > going out on TCP and back in....
>> >
>> > On Mon, May 6, 2019 at 4:40 PM John Dale <jc...@gmail.com> wrote:
>> >
>> >> If you're wanting to forward control to another servlet deployed in
>> >> the same context:
>> >> https://www.javatpoint.com/requestdispatcher-in-servlet
>> >>
>> >> If you are okay going through TCP to facilitate some future or current
>> >> distribution of services, Use HTTPURLConnection (not sure what you're
>> >> wanting to do with the result of the request, if anything):
>> >>
>> >>
>> https://stackoverflow.com/questions/2793150/how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests
>> >>
>> >> If you need more sophisticated HTTP interactions, Apache maintains a
>> >> very useful library for that:  http://hc.apache.org/
>> >>
>> >> If these don't work-out for you, rather than using .NET, PHP, Python,
>> >> or some other Java facsimile at best, I recommend using the semaphore
>> >> telegraph:
>> >> https://en.wikipedia.org/wiki/Semaphore_telegraph
>> >>
>> >> Sincerely,
>> >>
>> >> John
>> >> DB2DOM
>> >>
>> >> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
>> >> > Hi John,
>> >> >
>> >> > Thanks for your feedback.
>> >> >
>> >> > The request I'm initiating should not or need not carry any context
>> >> > from
>> >> > the originating code. There is also no session to worry about as its
>> >> > just
>> >> > for rest calls. So basically I have the headers, path and body and
>> need
>> >> to
>> >> > generate a http servlet request and get an http servlet response (or
>> >> > similar) back. I have this working by calling into localhost but
>> >> > ideally
>> >> > want to skip the trombone out and back in.
>> >> >
>> >> > Have you got any basic code examples?
>> >> >
>> >> > Paul
>> >> >
>> >> > On Tue, Apr 30, 2019 at 5:27 PM John Dale <jc...@gmail.com> wrote:
>> >> >
>> >> >> Another thought .. you can do some request dispatching, but without
>> >> >> knowing more about the tools you're using, I can't say for sure if
>> >> >> this is the direction you'll want to go.
>> >> >>
>> >> >> On 4/29/19, Paul Carter-Brown <pa...@jini.guru> wrote:
>> >> >> > Hi
>> >> >> >
>> >> >> > I'm trying to design a Kafka consumer and producer that will run
>> >> inside
>> >> >> the
>> >> >> > tomcat jvm and pick up messages off a Kafka topic and translate
>> them
>> >> >> into a
>> >> >> > servlet request and pass it through tomcat and then when the
>> >> >> > response
>> >> >> > is
>> >> >> > complete then translate it into a Kafka message and put it onto
>> >> another
>> >> >> > topic as a reply. This way I can reuse our existing jax-rs rest
>> >> >> > services
>> >> >> > and expose them as an async api over Kafka. The idea is to make
>> >> >> > the
>> >> >> > Kafka
>> >> >> > messages similar to http in that they would consist of headers
>> >> >> > and
>> a
>> >> >> body.
>> >> >> > The body would be json.
>> >> >> >
>> >> >> > Now I know this could be done by calling localhost with an http
>> call
>> >> to
>> >> >> > trombone the requests back into tomcat but I'd like to avoid the
>> >> >> associated
>> >> >> > latency and overhead. Is it possible to call tomcat directly
>> >> >> > in-process.
>> >> >> > This does not need to be portable to other containers so can be
>> >> >> > proprietary.
>> >> >> >
>> >> >> > I'm using tomcat 8. In fact its tomee 8 but guessed this is more
>> >> >> > a
>> >> >> > tomcat
>> >> >> > question than tomee but have sent to both groups just in case.
>> >> >> >
>> >> >> > Thanks for any insights.
>> >> >> >
>> >> >> > Paul
>> >> >> >
>> >> >>
>> >> >
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> >> For additional commands, e-mail: users-help@tomcat.apache.org
>> >>
>> >>
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Initiating httpservletrequest from inside Tomcat / TomEE

Posted by Paul Carter-Brown <pa...@jini.guru>.
I think we are completely missing each other. Forget sockets - that was
just an example. I have code running in a Tomcat App server which is not
managed by Tomcat and is not initiated by anything within Tomcat. That code
now wants to call a servlet hosted in that very same JVM. Any way to do
that without going out and back in on TCP?


On Mon, May 6, 2019 at 5:14 PM John Dale <jc...@gmail.com> wrote:

> Sockets are an implementation of TCP/UDP inherently.
>
> Perhaps a mountaintop signal fire?
>
> ;)
>
> John
>
>
> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
> > lol on the Semaphore Telegraph,
> >
> > I can't use a request dispatcher as the request is being initiated from
> > code that has no context. I already have it working with HTTP using
> > asynchttp library, but I want to avoid the overhead. E.g. lets say I
> wrote
> > my own server socket listener on port 10000 running in the Tomcat JVM and
> > got some request in some propriatary protocol called X. Now I want to
> call
> > a Tomcat servlet in the current JVM with some info I got over X without
> > going out on TCP and back in....
> >
> > On Mon, May 6, 2019 at 4:40 PM John Dale <jc...@gmail.com> wrote:
> >
> >> If you're wanting to forward control to another servlet deployed in
> >> the same context:
> >> https://www.javatpoint.com/requestdispatcher-in-servlet
> >>
> >> If you are okay going through TCP to facilitate some future or current
> >> distribution of services, Use HTTPURLConnection (not sure what you're
> >> wanting to do with the result of the request, if anything):
> >>
> >>
> https://stackoverflow.com/questions/2793150/how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests
> >>
> >> If you need more sophisticated HTTP interactions, Apache maintains a
> >> very useful library for that:  http://hc.apache.org/
> >>
> >> If these don't work-out for you, rather than using .NET, PHP, Python,
> >> or some other Java facsimile at best, I recommend using the semaphore
> >> telegraph:
> >> https://en.wikipedia.org/wiki/Semaphore_telegraph
> >>
> >> Sincerely,
> >>
> >> John
> >> DB2DOM
> >>
> >> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
> >> > Hi John,
> >> >
> >> > Thanks for your feedback.
> >> >
> >> > The request I'm initiating should not or need not carry any context
> >> > from
> >> > the originating code. There is also no session to worry about as its
> >> > just
> >> > for rest calls. So basically I have the headers, path and body and
> need
> >> to
> >> > generate a http servlet request and get an http servlet response (or
> >> > similar) back. I have this working by calling into localhost but
> >> > ideally
> >> > want to skip the trombone out and back in.
> >> >
> >> > Have you got any basic code examples?
> >> >
> >> > Paul
> >> >
> >> > On Tue, Apr 30, 2019 at 5:27 PM John Dale <jc...@gmail.com> wrote:
> >> >
> >> >> Another thought .. you can do some request dispatching, but without
> >> >> knowing more about the tools you're using, I can't say for sure if
> >> >> this is the direction you'll want to go.
> >> >>
> >> >> On 4/29/19, Paul Carter-Brown <pa...@jini.guru> wrote:
> >> >> > Hi
> >> >> >
> >> >> > I'm trying to design a Kafka consumer and producer that will run
> >> inside
> >> >> the
> >> >> > tomcat jvm and pick up messages off a Kafka topic and translate
> them
> >> >> into a
> >> >> > servlet request and pass it through tomcat and then when the
> >> >> > response
> >> >> > is
> >> >> > complete then translate it into a Kafka message and put it onto
> >> another
> >> >> > topic as a reply. This way I can reuse our existing jax-rs rest
> >> >> > services
> >> >> > and expose them as an async api over Kafka. The idea is to make the
> >> >> > Kafka
> >> >> > messages similar to http in that they would consist of headers and
> a
> >> >> body.
> >> >> > The body would be json.
> >> >> >
> >> >> > Now I know this could be done by calling localhost with an http
> call
> >> to
> >> >> > trombone the requests back into tomcat but I'd like to avoid the
> >> >> associated
> >> >> > latency and overhead. Is it possible to call tomcat directly
> >> >> > in-process.
> >> >> > This does not need to be portable to other containers so can be
> >> >> > proprietary.
> >> >> >
> >> >> > I'm using tomcat 8. In fact its tomee 8 but guessed this is more a
> >> >> > tomcat
> >> >> > question than tomee but have sent to both groups just in case.
> >> >> >
> >> >> > Thanks for any insights.
> >> >> >
> >> >> > Paul
> >> >> >
> >> >>
> >> >
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >> For additional commands, e-mail: users-help@tomcat.apache.org
> >>
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: Initiating httpservletrequest from inside Tomcat / TomEE

Posted by Paul Carter-Brown <pa...@jini.guru>.
I think we are completely missing each other. Forget sockets - that was
just an example. I have code running in a Tomcat App server which is not
managed by Tomcat and is not initiated by anything within Tomcat. That code
now wants to call a servlet hosted in that very same JVM. Any way to do
that without going out and back in on TCP?


On Mon, May 6, 2019 at 5:14 PM John Dale <jc...@gmail.com> wrote:

> Sockets are an implementation of TCP/UDP inherently.
>
> Perhaps a mountaintop signal fire?
>
> ;)
>
> John
>
>
> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
> > lol on the Semaphore Telegraph,
> >
> > I can't use a request dispatcher as the request is being initiated from
> > code that has no context. I already have it working with HTTP using
> > asynchttp library, but I want to avoid the overhead. E.g. lets say I
> wrote
> > my own server socket listener on port 10000 running in the Tomcat JVM and
> > got some request in some propriatary protocol called X. Now I want to
> call
> > a Tomcat servlet in the current JVM with some info I got over X without
> > going out on TCP and back in....
> >
> > On Mon, May 6, 2019 at 4:40 PM John Dale <jc...@gmail.com> wrote:
> >
> >> If you're wanting to forward control to another servlet deployed in
> >> the same context:
> >> https://www.javatpoint.com/requestdispatcher-in-servlet
> >>
> >> If you are okay going through TCP to facilitate some future or current
> >> distribution of services, Use HTTPURLConnection (not sure what you're
> >> wanting to do with the result of the request, if anything):
> >>
> >>
> https://stackoverflow.com/questions/2793150/how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests
> >>
> >> If you need more sophisticated HTTP interactions, Apache maintains a
> >> very useful library for that:  http://hc.apache.org/
> >>
> >> If these don't work-out for you, rather than using .NET, PHP, Python,
> >> or some other Java facsimile at best, I recommend using the semaphore
> >> telegraph:
> >> https://en.wikipedia.org/wiki/Semaphore_telegraph
> >>
> >> Sincerely,
> >>
> >> John
> >> DB2DOM
> >>
> >> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
> >> > Hi John,
> >> >
> >> > Thanks for your feedback.
> >> >
> >> > The request I'm initiating should not or need not carry any context
> >> > from
> >> > the originating code. There is also no session to worry about as its
> >> > just
> >> > for rest calls. So basically I have the headers, path and body and
> need
> >> to
> >> > generate a http servlet request and get an http servlet response (or
> >> > similar) back. I have this working by calling into localhost but
> >> > ideally
> >> > want to skip the trombone out and back in.
> >> >
> >> > Have you got any basic code examples?
> >> >
> >> > Paul
> >> >
> >> > On Tue, Apr 30, 2019 at 5:27 PM John Dale <jc...@gmail.com> wrote:
> >> >
> >> >> Another thought .. you can do some request dispatching, but without
> >> >> knowing more about the tools you're using, I can't say for sure if
> >> >> this is the direction you'll want to go.
> >> >>
> >> >> On 4/29/19, Paul Carter-Brown <pa...@jini.guru> wrote:
> >> >> > Hi
> >> >> >
> >> >> > I'm trying to design a Kafka consumer and producer that will run
> >> inside
> >> >> the
> >> >> > tomcat jvm and pick up messages off a Kafka topic and translate
> them
> >> >> into a
> >> >> > servlet request and pass it through tomcat and then when the
> >> >> > response
> >> >> > is
> >> >> > complete then translate it into a Kafka message and put it onto
> >> another
> >> >> > topic as a reply. This way I can reuse our existing jax-rs rest
> >> >> > services
> >> >> > and expose them as an async api over Kafka. The idea is to make the
> >> >> > Kafka
> >> >> > messages similar to http in that they would consist of headers and
> a
> >> >> body.
> >> >> > The body would be json.
> >> >> >
> >> >> > Now I know this could be done by calling localhost with an http
> call
> >> to
> >> >> > trombone the requests back into tomcat but I'd like to avoid the
> >> >> associated
> >> >> > latency and overhead. Is it possible to call tomcat directly
> >> >> > in-process.
> >> >> > This does not need to be portable to other containers so can be
> >> >> > proprietary.
> >> >> >
> >> >> > I'm using tomcat 8. In fact its tomee 8 but guessed this is more a
> >> >> > tomcat
> >> >> > question than tomee but have sent to both groups just in case.
> >> >> >
> >> >> > Thanks for any insights.
> >> >> >
> >> >> > Paul
> >> >> >
> >> >>
> >> >
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >> For additional commands, e-mail: users-help@tomcat.apache.org
> >>
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: Initiating httpservletrequest from inside Tomcat / TomEE

Posted by John Dale <jc...@gmail.com>.
Sockets are an implementation of TCP/UDP inherently.

Perhaps a mountaintop signal fire?

;)

John


On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
> lol on the Semaphore Telegraph,
>
> I can't use a request dispatcher as the request is being initiated from
> code that has no context. I already have it working with HTTP using
> asynchttp library, but I want to avoid the overhead. E.g. lets say I wrote
> my own server socket listener on port 10000 running in the Tomcat JVM and
> got some request in some propriatary protocol called X. Now I want to call
> a Tomcat servlet in the current JVM with some info I got over X without
> going out on TCP and back in....
>
> On Mon, May 6, 2019 at 4:40 PM John Dale <jc...@gmail.com> wrote:
>
>> If you're wanting to forward control to another servlet deployed in
>> the same context:
>> https://www.javatpoint.com/requestdispatcher-in-servlet
>>
>> If you are okay going through TCP to facilitate some future or current
>> distribution of services, Use HTTPURLConnection (not sure what you're
>> wanting to do with the result of the request, if anything):
>>
>> https://stackoverflow.com/questions/2793150/how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests
>>
>> If you need more sophisticated HTTP interactions, Apache maintains a
>> very useful library for that:  http://hc.apache.org/
>>
>> If these don't work-out for you, rather than using .NET, PHP, Python,
>> or some other Java facsimile at best, I recommend using the semaphore
>> telegraph:
>> https://en.wikipedia.org/wiki/Semaphore_telegraph
>>
>> Sincerely,
>>
>> John
>> DB2DOM
>>
>> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
>> > Hi John,
>> >
>> > Thanks for your feedback.
>> >
>> > The request I'm initiating should not or need not carry any context
>> > from
>> > the originating code. There is also no session to worry about as its
>> > just
>> > for rest calls. So basically I have the headers, path and body and need
>> to
>> > generate a http servlet request and get an http servlet response (or
>> > similar) back. I have this working by calling into localhost but
>> > ideally
>> > want to skip the trombone out and back in.
>> >
>> > Have you got any basic code examples?
>> >
>> > Paul
>> >
>> > On Tue, Apr 30, 2019 at 5:27 PM John Dale <jc...@gmail.com> wrote:
>> >
>> >> Another thought .. you can do some request dispatching, but without
>> >> knowing more about the tools you're using, I can't say for sure if
>> >> this is the direction you'll want to go.
>> >>
>> >> On 4/29/19, Paul Carter-Brown <pa...@jini.guru> wrote:
>> >> > Hi
>> >> >
>> >> > I'm trying to design a Kafka consumer and producer that will run
>> inside
>> >> the
>> >> > tomcat jvm and pick up messages off a Kafka topic and translate them
>> >> into a
>> >> > servlet request and pass it through tomcat and then when the
>> >> > response
>> >> > is
>> >> > complete then translate it into a Kafka message and put it onto
>> another
>> >> > topic as a reply. This way I can reuse our existing jax-rs rest
>> >> > services
>> >> > and expose them as an async api over Kafka. The idea is to make the
>> >> > Kafka
>> >> > messages similar to http in that they would consist of headers and a
>> >> body.
>> >> > The body would be json.
>> >> >
>> >> > Now I know this could be done by calling localhost with an http call
>> to
>> >> > trombone the requests back into tomcat but I'd like to avoid the
>> >> associated
>> >> > latency and overhead. Is it possible to call tomcat directly
>> >> > in-process.
>> >> > This does not need to be portable to other containers so can be
>> >> > proprietary.
>> >> >
>> >> > I'm using tomcat 8. In fact its tomee 8 but guessed this is more a
>> >> > tomcat
>> >> > question than tomee but have sent to both groups just in case.
>> >> >
>> >> > Thanks for any insights.
>> >> >
>> >> > Paul
>> >> >
>> >>
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Initiating httpservletrequest from inside Tomcat / TomEE

Posted by John Dale <jc...@gmail.com>.
Another thought is that servlets maintain contextual information and
resources .. that's nice, saves a lot of time.  As soon as you need a
database resource or an extension of your pruned-back HTTP
implementation on the server socket, you'll be rebuilding what Tomcat
has already done?


On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
> lol on the Semaphore Telegraph,
>
> I can't use a request dispatcher as the request is being initiated from
> code that has no context. I already have it working with HTTP using
> asynchttp library, but I want to avoid the overhead. E.g. lets say I wrote
> my own server socket listener on port 10000 running in the Tomcat JVM and
> got some request in some propriatary protocol called X. Now I want to call
> a Tomcat servlet in the current JVM with some info I got over X without
> going out on TCP and back in....
>
> On Mon, May 6, 2019 at 4:40 PM John Dale <jc...@gmail.com> wrote:
>
>> If you're wanting to forward control to another servlet deployed in
>> the same context:
>> https://www.javatpoint.com/requestdispatcher-in-servlet
>>
>> If you are okay going through TCP to facilitate some future or current
>> distribution of services, Use HTTPURLConnection (not sure what you're
>> wanting to do with the result of the request, if anything):
>>
>> https://stackoverflow.com/questions/2793150/how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests
>>
>> If you need more sophisticated HTTP interactions, Apache maintains a
>> very useful library for that:  http://hc.apache.org/
>>
>> If these don't work-out for you, rather than using .NET, PHP, Python,
>> or some other Java facsimile at best, I recommend using the semaphore
>> telegraph:
>> https://en.wikipedia.org/wiki/Semaphore_telegraph
>>
>> Sincerely,
>>
>> John
>> DB2DOM
>>
>> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
>> > Hi John,
>> >
>> > Thanks for your feedback.
>> >
>> > The request I'm initiating should not or need not carry any context
>> > from
>> > the originating code. There is also no session to worry about as its
>> > just
>> > for rest calls. So basically I have the headers, path and body and need
>> to
>> > generate a http servlet request and get an http servlet response (or
>> > similar) back. I have this working by calling into localhost but
>> > ideally
>> > want to skip the trombone out and back in.
>> >
>> > Have you got any basic code examples?
>> >
>> > Paul
>> >
>> > On Tue, Apr 30, 2019 at 5:27 PM John Dale <jc...@gmail.com> wrote:
>> >
>> >> Another thought .. you can do some request dispatching, but without
>> >> knowing more about the tools you're using, I can't say for sure if
>> >> this is the direction you'll want to go.
>> >>
>> >> On 4/29/19, Paul Carter-Brown <pa...@jini.guru> wrote:
>> >> > Hi
>> >> >
>> >> > I'm trying to design a Kafka consumer and producer that will run
>> inside
>> >> the
>> >> > tomcat jvm and pick up messages off a Kafka topic and translate them
>> >> into a
>> >> > servlet request and pass it through tomcat and then when the
>> >> > response
>> >> > is
>> >> > complete then translate it into a Kafka message and put it onto
>> another
>> >> > topic as a reply. This way I can reuse our existing jax-rs rest
>> >> > services
>> >> > and expose them as an async api over Kafka. The idea is to make the
>> >> > Kafka
>> >> > messages similar to http in that they would consist of headers and a
>> >> body.
>> >> > The body would be json.
>> >> >
>> >> > Now I know this could be done by calling localhost with an http call
>> to
>> >> > trombone the requests back into tomcat but I'd like to avoid the
>> >> associated
>> >> > latency and overhead. Is it possible to call tomcat directly
>> >> > in-process.
>> >> > This does not need to be portable to other containers so can be
>> >> > proprietary.
>> >> >
>> >> > I'm using tomcat 8. In fact its tomee 8 but guessed this is more a
>> >> > tomcat
>> >> > question than tomee but have sent to both groups just in case.
>> >> >
>> >> > Thanks for any insights.
>> >> >
>> >> > Paul
>> >> >
>> >>
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Initiating httpservletrequest from inside Tomcat / TomEE

Posted by Paul Carter-Brown <pa...@jini.guru>.
lol on the Semaphore Telegraph,

I can't use a request dispatcher as the request is being initiated from
code that has no context. I already have it working with HTTP using
asynchttp library, but I want to avoid the overhead. E.g. lets say I wrote
my own server socket listener on port 10000 running in the Tomcat JVM and
got some request in some propriatary protocol called X. Now I want to call
a Tomcat servlet in the current JVM with some info I got over X without
going out on TCP and back in....

On Mon, May 6, 2019 at 4:40 PM John Dale <jc...@gmail.com> wrote:

> If you're wanting to forward control to another servlet deployed in
> the same context:
> https://www.javatpoint.com/requestdispatcher-in-servlet
>
> If you are okay going through TCP to facilitate some future or current
> distribution of services, Use HTTPURLConnection (not sure what you're
> wanting to do with the result of the request, if anything):
>
> https://stackoverflow.com/questions/2793150/how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests
>
> If you need more sophisticated HTTP interactions, Apache maintains a
> very useful library for that:  http://hc.apache.org/
>
> If these don't work-out for you, rather than using .NET, PHP, Python,
> or some other Java facsimile at best, I recommend using the semaphore
> telegraph:
> https://en.wikipedia.org/wiki/Semaphore_telegraph
>
> Sincerely,
>
> John
> DB2DOM
>
> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
> > Hi John,
> >
> > Thanks for your feedback.
> >
> > The request I'm initiating should not or need not carry any context from
> > the originating code. There is also no session to worry about as its just
> > for rest calls. So basically I have the headers, path and body and need
> to
> > generate a http servlet request and get an http servlet response (or
> > similar) back. I have this working by calling into localhost but ideally
> > want to skip the trombone out and back in.
> >
> > Have you got any basic code examples?
> >
> > Paul
> >
> > On Tue, Apr 30, 2019 at 5:27 PM John Dale <jc...@gmail.com> wrote:
> >
> >> Another thought .. you can do some request dispatching, but without
> >> knowing more about the tools you're using, I can't say for sure if
> >> this is the direction you'll want to go.
> >>
> >> On 4/29/19, Paul Carter-Brown <pa...@jini.guru> wrote:
> >> > Hi
> >> >
> >> > I'm trying to design a Kafka consumer and producer that will run
> inside
> >> the
> >> > tomcat jvm and pick up messages off a Kafka topic and translate them
> >> into a
> >> > servlet request and pass it through tomcat and then when the response
> >> > is
> >> > complete then translate it into a Kafka message and put it onto
> another
> >> > topic as a reply. This way I can reuse our existing jax-rs rest
> >> > services
> >> > and expose them as an async api over Kafka. The idea is to make the
> >> > Kafka
> >> > messages similar to http in that they would consist of headers and a
> >> body.
> >> > The body would be json.
> >> >
> >> > Now I know this could be done by calling localhost with an http call
> to
> >> > trombone the requests back into tomcat but I'd like to avoid the
> >> associated
> >> > latency and overhead. Is it possible to call tomcat directly
> >> > in-process.
> >> > This does not need to be portable to other containers so can be
> >> > proprietary.
> >> >
> >> > I'm using tomcat 8. In fact its tomee 8 but guessed this is more a
> >> > tomcat
> >> > question than tomee but have sent to both groups just in case.
> >> >
> >> > Thanks for any insights.
> >> >
> >> > Paul
> >> >
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: Initiating httpservletrequest from inside Tomcat / TomEE

Posted by Paul Carter-Brown <pa...@jini.guru>.
lol on the Semaphore Telegraph,

I can't use a request dispatcher as the request is being initiated from
code that has no context. I already have it working with HTTP using
asynchttp library, but I want to avoid the overhead. E.g. lets say I wrote
my own server socket listener on port 10000 running in the Tomcat JVM and
got some request in some propriatary protocol called X. Now I want to call
a Tomcat servlet in the current JVM with some info I got over X without
going out on TCP and back in....

On Mon, May 6, 2019 at 4:40 PM John Dale <jc...@gmail.com> wrote:

> If you're wanting to forward control to another servlet deployed in
> the same context:
> https://www.javatpoint.com/requestdispatcher-in-servlet
>
> If you are okay going through TCP to facilitate some future or current
> distribution of services, Use HTTPURLConnection (not sure what you're
> wanting to do with the result of the request, if anything):
>
> https://stackoverflow.com/questions/2793150/how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests
>
> If you need more sophisticated HTTP interactions, Apache maintains a
> very useful library for that:  http://hc.apache.org/
>
> If these don't work-out for you, rather than using .NET, PHP, Python,
> or some other Java facsimile at best, I recommend using the semaphore
> telegraph:
> https://en.wikipedia.org/wiki/Semaphore_telegraph
>
> Sincerely,
>
> John
> DB2DOM
>
> On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
> > Hi John,
> >
> > Thanks for your feedback.
> >
> > The request I'm initiating should not or need not carry any context from
> > the originating code. There is also no session to worry about as its just
> > for rest calls. So basically I have the headers, path and body and need
> to
> > generate a http servlet request and get an http servlet response (or
> > similar) back. I have this working by calling into localhost but ideally
> > want to skip the trombone out and back in.
> >
> > Have you got any basic code examples?
> >
> > Paul
> >
> > On Tue, Apr 30, 2019 at 5:27 PM John Dale <jc...@gmail.com> wrote:
> >
> >> Another thought .. you can do some request dispatching, but without
> >> knowing more about the tools you're using, I can't say for sure if
> >> this is the direction you'll want to go.
> >>
> >> On 4/29/19, Paul Carter-Brown <pa...@jini.guru> wrote:
> >> > Hi
> >> >
> >> > I'm trying to design a Kafka consumer and producer that will run
> inside
> >> the
> >> > tomcat jvm and pick up messages off a Kafka topic and translate them
> >> into a
> >> > servlet request and pass it through tomcat and then when the response
> >> > is
> >> > complete then translate it into a Kafka message and put it onto
> another
> >> > topic as a reply. This way I can reuse our existing jax-rs rest
> >> > services
> >> > and expose them as an async api over Kafka. The idea is to make the
> >> > Kafka
> >> > messages similar to http in that they would consist of headers and a
> >> body.
> >> > The body would be json.
> >> >
> >> > Now I know this could be done by calling localhost with an http call
> to
> >> > trombone the requests back into tomcat but I'd like to avoid the
> >> associated
> >> > latency and overhead. Is it possible to call tomcat directly
> >> > in-process.
> >> > This does not need to be portable to other containers so can be
> >> > proprietary.
> >> >
> >> > I'm using tomcat 8. In fact its tomee 8 but guessed this is more a
> >> > tomcat
> >> > question than tomee but have sent to both groups just in case.
> >> >
> >> > Thanks for any insights.
> >> >
> >> > Paul
> >> >
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: Initiating httpservletrequest from inside Tomcat / TomEE

Posted by John Dale <jc...@gmail.com>.
If you're wanting to forward control to another servlet deployed in
the same context:
https://www.javatpoint.com/requestdispatcher-in-servlet

If you are okay going through TCP to facilitate some future or current
distribution of services, Use HTTPURLConnection (not sure what you're
wanting to do with the result of the request, if anything):
https://stackoverflow.com/questions/2793150/how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests

If you need more sophisticated HTTP interactions, Apache maintains a
very useful library for that:  http://hc.apache.org/

If these don't work-out for you, rather than using .NET, PHP, Python,
or some other Java facsimile at best, I recommend using the semaphore
telegraph:
https://en.wikipedia.org/wiki/Semaphore_telegraph

Sincerely,

John
DB2DOM

On 5/6/19, Paul Carter-Brown <pa...@jini.guru> wrote:
> Hi John,
>
> Thanks for your feedback.
>
> The request I'm initiating should not or need not carry any context from
> the originating code. There is also no session to worry about as its just
> for rest calls. So basically I have the headers, path and body and need to
> generate a http servlet request and get an http servlet response (or
> similar) back. I have this working by calling into localhost but ideally
> want to skip the trombone out and back in.
>
> Have you got any basic code examples?
>
> Paul
>
> On Tue, Apr 30, 2019 at 5:27 PM John Dale <jc...@gmail.com> wrote:
>
>> Another thought .. you can do some request dispatching, but without
>> knowing more about the tools you're using, I can't say for sure if
>> this is the direction you'll want to go.
>>
>> On 4/29/19, Paul Carter-Brown <pa...@jini.guru> wrote:
>> > Hi
>> >
>> > I'm trying to design a Kafka consumer and producer that will run inside
>> the
>> > tomcat jvm and pick up messages off a Kafka topic and translate them
>> into a
>> > servlet request and pass it through tomcat and then when the response
>> > is
>> > complete then translate it into a Kafka message and put it onto another
>> > topic as a reply. This way I can reuse our existing jax-rs rest
>> > services
>> > and expose them as an async api over Kafka. The idea is to make the
>> > Kafka
>> > messages similar to http in that they would consist of headers and a
>> body.
>> > The body would be json.
>> >
>> > Now I know this could be done by calling localhost with an http call to
>> > trombone the requests back into tomcat but I'd like to avoid the
>> associated
>> > latency and overhead. Is it possible to call tomcat directly
>> > in-process.
>> > This does not need to be portable to other containers so can be
>> > proprietary.
>> >
>> > I'm using tomcat 8. In fact its tomee 8 but guessed this is more a
>> > tomcat
>> > question than tomee but have sent to both groups just in case.
>> >
>> > Thanks for any insights.
>> >
>> > Paul
>> >
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org