From users-return-267497-archive-asf-public=cust-asf.ponee.io@tomcat.apache.org Mon May 6 16:48:59 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 1DBB718060F for ; Mon, 6 May 2019 18:48:59 +0200 (CEST) Received: (qmail 16911 invoked by uid 500); 6 May 2019 16:48:47 -0000 Mailing-List: contact users-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Users List" Delivered-To: mailing list users@tomcat.apache.org Received: (qmail 16900 invoked by uid 99); 6 May 2019 16:48:47 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 May 2019 16:48:47 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id DED4FC691D for ; Mon, 6 May 2019 16:48:46 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.724 X-Spam-Level: * X-Spam-Status: No, score=1.724 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FROM_LOCAL_NOVOWEL=0.5, HK_RANDOM_ENVFROM=0.626, KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd1-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id k-5z0N9abEnh for ; Mon, 6 May 2019 16:48:43 +0000 (UTC) Received: from mail-it1-f193.google.com (mail-it1-f193.google.com [209.85.166.193]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id 3822361276 for ; Mon, 6 May 2019 16:40:32 +0000 (UTC) Received: by mail-it1-f193.google.com with SMTP id q132so6117177itc.5 for ; Mon, 06 May 2019 09:40:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=EkFnsJ8QerJQ+/1eT0MM8SCHePEFJrO5DUXcMopw3j0=; b=gsMUQDQljrqBb0b76+yADEGEKhs0byFX7Hps8fvPxRX/odJ4qzrZ4yh37DNAjxzy6a txAg0pqGRIMTdRtovKYjNCv4r6ZbuPs+p4K1KAN1S8ETiQKAZybDSdBx4PX/Ye+xaLte ujSZ2HUkB0dmuP+kRUBr7ZTDK1BG8VVlTteaAk1GZ7C8theNM7ogS7D2xzBoXc5O/I47 een6tRgdIhw1SfQWDqtutEMf6c/mVNkd3cXOG3a7QEzg14v2AbcOVEg88sPFv6z8E/3o WTvSisSejOxijqaNzb1vd6Ciyytdn+NXSZF7DcBRQmPT3oTA4tN4XNWoMiwiodZmjUGH +5sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=EkFnsJ8QerJQ+/1eT0MM8SCHePEFJrO5DUXcMopw3j0=; b=QzQKUNeDAgBgO5qj4IwYzjSIMhbg3dva7NlgH5zASdcaEgzLVxkzMdF7TOuaiaIxgh kwSyXDfVzM1nqsLkyIbmjHzKldG67gPoI+GbGYHd89DF7iYB9KXykp/sCwb6qYitrbhR m/MoRiu7TQ0oRtARrKujBpTACg9Wmt6Ow+7cqvdD3Q5Qn8Yl+tn5PhmeLSTEwZxswH7r fRsTi0OXukFRwRl5QgUKVN1x4kpSz0z2hKxL26+Ij8i1FRY7bmqt67UWCBeXoGfmr5xj fg7mBGyThM9GzEfKzQX9L6U6R4s0ftTslFMxxoAEja8FF6F0fDgl4x+iDYKz3N5MuS43 0PhQ== X-Gm-Message-State: APjAAAU7Gvn0ysdRjF60+B0fOFB5X6e0qHdc5XkC+f7WW3JE7o7TtTVg yZVRWh9AdcBIhDLWZYdG3qX1gRYVUfLt9H17FwVfgw== X-Google-Smtp-Source: APXvYqw76aQHpb9FjjhEHgFgknf/Cyzb0w0yh68uArWpFeqWxjQAh1b7KkEymrRiLxCSVhkIC4wB5+Qa9XoB9jqhH9M= X-Received: by 2002:a05:660c:4d0:: with SMTP id v16mr6678886itk.62.1557160831403; Mon, 06 May 2019 09:40:31 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a4f:aa46:0:0:0:0:0 with HTTP; Mon, 6 May 2019 09:40:30 -0700 (PDT) In-Reply-To: References: From: John Dale Date: Mon, 6 May 2019 10:40:30 -0600 Message-ID: Subject: Re: Initiating httpservletrequest from inside Tomcat / TomEE To: Tomcat Users List Cc: users@tomee.apache.org Content-Type: text/plain; charset="UTF-8" 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 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 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 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 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 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 wrote: >> >> > >> >> >> Sockets are an implementation of TCP/UDP inherently. >> >> >> >> >> >> Perhaps a mountaintop signal fire? >> >> >> >> >> >> ;) >> >> >> >> >> >> John >> >> >> >> >> >> >> >> >> On 5/6/19, Paul Carter-Brown 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 >> 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 >> >> >> >> 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 >> >> 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 >> >> 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