Re: Tomcat 8 Connection Pooling

2017-07-18 Thread Avinash Krishnan
Hello Riccardo,

When I try using the pool properties(Without JNDI ) it gives me URL Cannot
Be null error. What I have understood is that, when we make the data source
as a static variable or a member variable of another class and try to use
it another class's function it throws error. If I instantiate and use Data
Souce on same function it is working.

I am wondering how to use the JNDI based Tomcat JDBC Connection Pool.
If I use Context variable and instantiate DataSouce object,the object
should be of type javax.sql.datasource and we don't get the
latest  org.apache.tomcat.jdbc.pool.DataSource;.

Any idea find the exact way to implement JNDI usage of
new  org.apache.tomcat.jdbc.pool.DataSource; ?

On Tue, Jul 18, 2017 at 9:02 PM, Riccardo Cohen 
wrote:

> Can you see any info in the log : login incorrect, database not found etc.
> ?
> (There are many logs in tomcat : localhost log, catalina log, manager log,
> host manager log, localhost access log)
>
>
> On 18/07/2017 13:55, Avinash Krishnan wrote:
>
>> Hello Riccardo ,
>>
>> Thanks for the response. This didn't work for me. Connections are not
>> getting initated and I am seeing java.lang.NullPointerException on
>> accessing getConnection.
>>
>> I  am refering to http://tomcat.apache.org/tomcat-8.0-doc/jdbc-pool.html
>>
>> The pool properties is also not working.
>>
>> On Tue, Jul 18, 2017 at 4:18 PM, Riccardo Cohen <
>> riccardo.co...@e5group.fr>
>> wrote:
>>
>> Hello Avinash
>>>
>>> I'm not expert but this is rather simple :
>>> in web/META-INF/context.xml write something like :
>>>
>>> 
>>>   >> type="javax.sql.DataSource"
>>> username="root"
>>> password="pass"
>>> driverClassName="com.mysql.jdbc.Driver"
>>>
>>> url="jdbc:mysql://localhost:3306/databasename?useSSL=false&
>>> amp;zeroDateTimeBehavior=convertToNulljdbcCompliantTrun
>>> cation=falsecharacterEncoding=utf8"
>>>   />
>>> 
>>>
>>> in web/WEB-INF/web.xml add in  tag :
>>>   
>>> 
>>>   jdbc/tomcattest
>>> 
>>> 
>>>   javax.sql.DataSource
>>> 
>>>   
>>>
>>> and in a java class add this :
>>>
>>> public class T3Servlet extends HttpServlet
>>> {
>>>   @Resource(name="jdbc/tomcattest")
>>>   public DataSource ds;
>>>
>>>
>>> You will normally have a data source in your class, by injection, using
>>> tomcat database pool.
>>>
>>>
>>> On 18/07/2017 12:26, Avinash Krishnan wrote:
>>>
>>> I am trying to implement Apache Tomcat 8.5.15  "Tomcat JDBC Connection
 Pool" using the steps mentioned in the guide.

 Can some one help me to understand how this connection pooling has to be
 done.

 Is the Plain Java Method,by implementing Pool Properties is an
 alternative
 to the JNDI lookup based pooling ? When I implement using Pool
 Properties,
 there isn't any provision to set up the Factory to
 org.apache.tomcat.jdbc.pool.DataSourceFactory"
 and I always get invalid arguments in call.

 On a different note, I tried by adding to context.xml . And implementing
 JNDI lookup from context. But that time,I get
 "org.apache.tomcat.dbcp.dbcp2.BasicDataSource cannot be cast to
 org.apache.tomcat.jdbc.pool.DataSource" even after setting factory to
 DataSourceFactory.


 --
>>> Riccardo Cohen
>>> +33 6 09 83 64 49
>>> E5Group
>>> http://www.5flow.com
>>>
>>>
>>> -
>>> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
>>> For additional commands, e-mail: users-h...@tomcat.apache.org
>>>
>>>
>>>
>>
>>
> --
> Riccardo Cohen
> +33 6 09 83 64 49
> E5Group
> http://www.5flow.com
>
>
> -
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>
>


-- 
Regards,
Avinash K
+91 9497359324


Re: Getting user role membership without context

2017-07-18 Thread Mark Thomas
On 18/07/17 23:21, Alex O'Ree wrote:
> Nice, any idea which method I need to call?

You already have the Context so you want

Context.findChildren()

for a list of all the Wrappers (and it is the wrapper object you need) or

Context.findChild(String)

for a specific Wrapper if you know the name. The name should be the name
used in web.xml to define the Servlet.

Mark


> 
> On Jul 18, 2017 3:54 PM, "Mark Thomas"  wrote:
> 
>> On 18/07/17 17:41, Alex O'Ree wrote:
>>> Alright, quick update on this.
>>>
>>> At this point, I have servlet context and a username running off the
>>> main tomcat http threads (quartz job)
>>>
 StandardContext tomcat;load from reflection from ApplicationContext
>> from ServletContext as ApplicationContextFacade
 Realm realm = tomcat.getRealm()
>>>
>>> At this point, realm is a LockoutRealm that contains two child realms,
>>> the JNDI Realm and the standard UserDatabaseRealm
>>>
 Principal user = realm.authenticate(username);
>>>
>>> At this point, the user object is populated and appears to have the
>>> roles attached to it (they are listed in the to String method).
>>>
 realm.hasRole(new StandardWrapper(), user, role);
>>>
>>> This part returns false, if and only if the ldap membership matches
>>> exactly. Mapped roles via servlet/security-role-ref/role-link and
>>> role-name do not appear to be effect.
>>>
>>> I think this may have something to do with the Principal object not
>>> having a login context. Normally, this is available via a servlet, but
>>> this it is not.
>>>
>>> I think the root cause might be this line.
>>> https://github.com/apache/tomcat/blob/TOMCAT_7_0_42/
>> java/org/apache/catalina/realm/RealmBase.java#L933
>>>
>>> Which probably does the translation from the LDAP defined group or
>>> role into what the application is expecting. Am I on the right path
>>> here?
>>
>> Yes. If you check auth outside of a Servlet, the role mappings for the
>> Servlet won't apply. If you know which servlet to use for the role
>> mappings you can get that from the Context (Wrappers represent Servlets
>> and are children of the Context).
>>
>> Mark
>>
>> -
>> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
>> For additional commands, e-mail: users-h...@tomcat.apache.org
>>
>>
> 


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



Re: Getting user role membership without context

2017-07-18 Thread Alex O'Ree
Nice, any idea which method I need to call?

On Jul 18, 2017 3:54 PM, "Mark Thomas"  wrote:

> On 18/07/17 17:41, Alex O'Ree wrote:
> > Alright, quick update on this.
> >
> > At this point, I have servlet context and a username running off the
> > main tomcat http threads (quartz job)
> >
> >> StandardContext tomcat;load from reflection from ApplicationContext
> from ServletContext as ApplicationContextFacade
> >> Realm realm = tomcat.getRealm()
> >
> > At this point, realm is a LockoutRealm that contains two child realms,
> > the JNDI Realm and the standard UserDatabaseRealm
> >
> >> Principal user = realm.authenticate(username);
> >
> > At this point, the user object is populated and appears to have the
> > roles attached to it (they are listed in the to String method).
> >
> >> realm.hasRole(new StandardWrapper(), user, role);
> >
> > This part returns false, if and only if the ldap membership matches
> > exactly. Mapped roles via servlet/security-role-ref/role-link and
> > role-name do not appear to be effect.
> >
> > I think this may have something to do with the Principal object not
> > having a login context. Normally, this is available via a servlet, but
> > this it is not.
> >
> > I think the root cause might be this line.
> > https://github.com/apache/tomcat/blob/TOMCAT_7_0_42/
> java/org/apache/catalina/realm/RealmBase.java#L933
> >
> > Which probably does the translation from the LDAP defined group or
> > role into what the application is expecting. Am I on the right path
> > here?
>
> Yes. If you check auth outside of a Servlet, the role mappings for the
> Servlet won't apply. If you know which servlet to use for the role
> mappings you can get that from the Context (Wrappers represent Servlets
> and are children of the Context).
>
> Mark
>
> -
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>
>


Re: run thread from servlet

2017-07-18 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

Lance,

On 7/18/17 9:56 AM, Campbell, Lance wrote:
> Tomcat 8.0.x Question: I am wanting to know the proper way to start
> a thread from a servlet.
> 
> Use Case: A batch process will call a URL that is a servlet.  The
> servlet will call a processes that will trigger a thread to run to
> do a particular job.  The thread will run for a while.  The servlet
> will not wait on the thread to finish running.  Also the thread
> that is started is running a processes that requires there to only
> be one of these processes running at any given time.
> 
> What I have done: I created a class I call EmailProcess.  I have a
> static Boolean flag in the class called isWorking that indicates if
> the process is running.  The class extends Runnable.  The class
> also has a static method to start the thread if isWorking flag is
> false.  I have a servlet that will call the static method in
> EmailProcess to start the thread if possible.
> 
> Note: If the Tomcat container decides to clean up the servlet that
> is called that triggers the thread I don't want it to mess with the
> thread.  I want it to keep on running.

You want an ExecutorService (provided by the Java standard library),
and you can limit the number of simultaneous jobs to 1. Submit the
jobs to the service as they arrive, and then make sure you call
service.shutdown() when the servlet (or better yet, context) is being
taken out of service. You might want to provide a way to cancel
in-process jobs, otherwise you may stall container shutdown which
might be inconvenient for you.

- -chris
-BEGIN PGP SIGNATURE-
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBCAAGBQJZbn3uAAoJEBzwKT+lPKRYCTUP/1Ho+5z49FntCBrEevVxnYiO
He331XbbPN7x6XLzO8nqf82pZcjnH1DGPtZXhPdZ2DKOjqPKmSeoI3az1+s1gu6X
Igff6xoHpARdyWdVElIxHYO93QOJdIa0DtuaSgaO4HXwpZYgwxs/QwbuN9VWLK5f
4afXp0gE5VaUxZoLHb9TTVIV8t0IABXdq+m9tuKZtrihfVwyc79w0HTwDCzqHlYH
39p70KQEagzhj/ZNqUHZENvFZ+2vMHD8zGcnWtAoVzOaseNth0FtZY5aqO+2WThl
k1VpcCGIK6hsytcBXuYAtfp/H6o2ircpwa66+O1nbNuP3OLT9x4IHqe5I0KoG/zG
hPOA/ydauaTps4xoYVLPjIVfVLx4D3+Rcrsti2tlo80hRK4Mv3SEeZu5eH1Zxz/N
W1MSLrVa5QOdWQ1rLMUbfWyNFXbm3xT8DrlQ3WvsAlMsRCrHkBIPqihnN7cPdRKp
m7QsQGYk/QNJ4U45ZeF/n5e/P62Dw34dHEbsefXNozvAOzykRSmwSG+6guCVXiiL
tfxC72zOiPxHUFMO8+mfXUrbsODNUjAUQA8O5dphwHGkTIni9xAL3/38dxkyaVy3
1jU2CFGaou5rdvjeL/Ixwqs4LzsY4Li0DrA5MwJVjEJG62MGK9x65NcpQ/3AtvZ4
T6lRQ5ZjJH99h9b2/ijL
=SVOd
-END PGP SIGNATURE-

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



Re: run thread from servlet

2017-07-18 Thread Mark Thomas
On 18/07/17 18:07, Campbell, Lance wrote:
> Also if tomcat is shut down and a thread is running how does tomcat 
> communicate with my software to end a thread?

It can't. The thread will either just stop if it is a Daemon thread or
the Java process won't exit until your thread does.

>  Is this where you were referring to the servlet context listener? 

Yes. That is a good way to start/stop threads.

> 
> -Original Message-
> From: Campbell, Lance [mailto:la...@illinois.edu] 
> Sent: Tuesday, July 18, 2017 12:00 PM
> To: Tomcat Users List 
> Subject: RE: run thread from servlet
> 
> Basically I have batch jobs that I need to run on many different web 
> applications.  The batch jobs call servlets that then create threads to do 
> whatever task I need done behind the scenes.  The servlets immediately return 
> a message after starting the batch threaded job.However my understanding 
> is that there can be issues with Tomcat detecting memory leaks if you have a 
> thread spawned by a servlet.  So I was wondering if there was a better way to 
> trigger a thread.

Memory leaks are likely because the Thread will almost certainly load
classes from the web application.

A (possibly single threaded) Executor started and stopped via a
ServletContextListener is the solution that springs to mind.

Mark


> 
> -Original Message-
> From: Pradip Bhattacharya [mailto:pradip.bhattacha...@gmail.com] 
> Sent: Tuesday, July 18, 2017 9:10 AM
> To: Tomcat Users List 
> Subject: Re: run thread from servlet
> 
> Hello,
> I hope I understood the requirement correctly. I believe you can start 
> EmailProcess thread by the context listener. This thread can wait on an 
> object. And the servlet can enque the data in a concurrent queue, and then 
> notify the object, on which EmailProcess thread is waiting.
> Is this EmailProcess is an asynchronous service to send emails ?
> Regards
> Pradip.B
> 
> On Jul 18, 2017 7:27 PM, "Campbell, Lance"  wrote:
> 
> Tomcat 8.0.x
> Question:
> I am wanting to know the proper way to start a thread from a servlet.
> 
> Use Case:
> A batch process will call a URL that is a servlet.  The servlet will call a 
> processes that will trigger a thread to run to do a particular job.  The 
> thread will run for a while.  The servlet will not wait on the thread to 
> finish running.  Also the thread that is started is running a processes that 
> requires there to only be one of these processes running at any given time.
> 
> What I have done:
> I created a class I call EmailProcess.  I have a static Boolean flag in the 
> class called isWorking that indicates if the process is running.  The class 
> extends Runnable.  The class also has a static method to start the thread if 
> isWorking flag is false.  I have a servlet that will call the static method 
> in EmailProcess to start the thread if possible.
> 
> Note: If the Tomcat container decides to clean up the servlet that is called 
> that triggers the thread I don't want it to mess with the thread.  I want it 
> to keep on running.
> 
> Thanks for your advice.
> 
> Lance
> 
> -
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
> 


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



Re: Getting user role membership without context

2017-07-18 Thread Mark Thomas
On 18/07/17 17:41, Alex O'Ree wrote:
> Alright, quick update on this.
> 
> At this point, I have servlet context and a username running off the
> main tomcat http threads (quartz job)
> 
>> StandardContext tomcat;load from reflection from ApplicationContext from 
>> ServletContext as ApplicationContextFacade
>> Realm realm = tomcat.getRealm()
> 
> At this point, realm is a LockoutRealm that contains two child realms,
> the JNDI Realm and the standard UserDatabaseRealm
> 
>> Principal user = realm.authenticate(username);
> 
> At this point, the user object is populated and appears to have the
> roles attached to it (they are listed in the to String method).
> 
>> realm.hasRole(new StandardWrapper(), user, role);
> 
> This part returns false, if and only if the ldap membership matches
> exactly. Mapped roles via servlet/security-role-ref/role-link and
> role-name do not appear to be effect.
> 
> I think this may have something to do with the Principal object not
> having a login context. Normally, this is available via a servlet, but
> this it is not.
> 
> I think the root cause might be this line.
> https://github.com/apache/tomcat/blob/TOMCAT_7_0_42/java/org/apache/catalina/realm/RealmBase.java#L933
> 
> Which probably does the translation from the LDAP defined group or
> role into what the application is expecting. Am I on the right path
> here?

Yes. If you check auth outside of a Servlet, the role mappings for the
Servlet won't apply. If you know which servlet to use for the role
mappings you can get that from the Context (Wrappers represent Servlets
and are children of the Context).

Mark

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



RE: run thread from servlet

2017-07-18 Thread Campbell, Lance
Also if tomcat is shut down and a thread is running how does tomcat communicate 
with my software to end a thread?  Is this where you were referring to the 
servlet context listener? 

-Original Message-
From: Campbell, Lance [mailto:la...@illinois.edu] 
Sent: Tuesday, July 18, 2017 12:00 PM
To: Tomcat Users List 
Subject: RE: run thread from servlet

Basically I have batch jobs that I need to run on many different web 
applications.  The batch jobs call servlets that then create threads to do 
whatever task I need done behind the scenes.  The servlets immediately return a 
message after starting the batch threaded job.However my understanding is 
that there can be issues with Tomcat detecting memory leaks if you have a 
thread spawned by a servlet.  So I was wondering if there was a better way to 
trigger a thread.  

-Original Message-
From: Pradip Bhattacharya [mailto:pradip.bhattacha...@gmail.com] 
Sent: Tuesday, July 18, 2017 9:10 AM
To: Tomcat Users List 
Subject: Re: run thread from servlet

Hello,
I hope I understood the requirement correctly. I believe you can start 
EmailProcess thread by the context listener. This thread can wait on an object. 
And the servlet can enque the data in a concurrent queue, and then notify the 
object, on which EmailProcess thread is waiting.
Is this EmailProcess is an asynchronous service to send emails ?
Regards
Pradip.B

On Jul 18, 2017 7:27 PM, "Campbell, Lance"  wrote:

Tomcat 8.0.x
Question:
I am wanting to know the proper way to start a thread from a servlet.

Use Case:
A batch process will call a URL that is a servlet.  The servlet will call a 
processes that will trigger a thread to run to do a particular job.  The thread 
will run for a while.  The servlet will not wait on the thread to finish 
running.  Also the thread that is started is running a processes that requires 
there to only be one of these processes running at any given time.

What I have done:
I created a class I call EmailProcess.  I have a static Boolean flag in the 
class called isWorking that indicates if the process is running.  The class 
extends Runnable.  The class also has a static method to start the thread if 
isWorking flag is false.  I have a servlet that will call the static method in 
EmailProcess to start the thread if possible.

Note: If the Tomcat container decides to clean up the servlet that is called 
that triggers the thread I don't want it to mess with the thread.  I want it to 
keep on running.

Thanks for your advice.

Lance


RE: run thread from servlet

2017-07-18 Thread Campbell, Lance
Basically I have batch jobs that I need to run on many different web 
applications.  The batch jobs call servlets that then create threads to do 
whatever task I need done behind the scenes.  The servlets immediately return a 
message after starting the batch threaded job.However my understanding is 
that there can be issues with Tomcat detecting memory leaks if you have a 
thread spawned by a servlet.  So I was wondering if there was a better way to 
trigger a thread.  

-Original Message-
From: Pradip Bhattacharya [mailto:pradip.bhattacha...@gmail.com] 
Sent: Tuesday, July 18, 2017 9:10 AM
To: Tomcat Users List 
Subject: Re: run thread from servlet

Hello,
I hope I understood the requirement correctly. I believe you can start 
EmailProcess thread by the context listener. This thread can wait on an object. 
And the servlet can enque the data in a concurrent queue, and then notify the 
object, on which EmailProcess thread is waiting.
Is this EmailProcess is an asynchronous service to send emails ?
Regards
Pradip.B

On Jul 18, 2017 7:27 PM, "Campbell, Lance"  wrote:

Tomcat 8.0.x
Question:
I am wanting to know the proper way to start a thread from a servlet.

Use Case:
A batch process will call a URL that is a servlet.  The servlet will call a 
processes that will trigger a thread to run to do a particular job.  The thread 
will run for a while.  The servlet will not wait on the thread to finish 
running.  Also the thread that is started is running a processes that requires 
there to only be one of these processes running at any given time.

What I have done:
I created a class I call EmailProcess.  I have a static Boolean flag in the 
class called isWorking that indicates if the process is running.  The class 
extends Runnable.  The class also has a static method to start the thread if 
isWorking flag is false.  I have a servlet that will call the static method in 
EmailProcess to start the thread if possible.

Note: If the Tomcat container decides to clean up the servlet that is called 
that triggers the thread I don't want it to mess with the thread.  I want it to 
keep on running.

Thanks for your advice.

Lance


Re: Tomcat 8.5.16 - APR version mismatch error upon startup

2017-07-18 Thread M. Manna
Thanks Konstantin

1) Our %CATALINA_HOME% and %CATALINA_BASE% are both pointing to the root of
the binary folder - as described by the Reading.txt
2) We have never set anything for java.library.path - and it has always
worked because %CATALINA_HOME%\bin is part of the search path.


Our application doesn't have any other duplicate tcnative-1.dll but I will
keep checking.

KR,


On 18 July 2017 at 16:44, Konstantin Kolinko  wrote:

> 2017-07-18 17:42 GMT+03:00 M. Manna :
> > Hello,
> >
> > We have recently upgraded our tomcat from 8.0.29 to 8.5.16. As part of
> > standard upgrade we have cleaned up all our bin/conf/lib folder contents
> > and removed any older jars (e.g. ecj jars).
> >
> > Upon startup - we are getting the following error:
> >
> > Listening for transport dt_socket at address: 5005
> >
> > Jul 18, 2017 5:53:14 PM org.apache.catalina.core.AprLifecycleListener
> init
> >
> > SEVERE: An incompatible version [1.1.33] of the APR based Apache Tomcat
> > Native library is installed, while Tomcat requires version [1.2.6]
> >
> [...]
>
> > We copied and pasted the tcnative-1.dll into JDK ext folder and the
> problem
> > seems to have gone away. But in the past with all the tomcats, we never
> had
> > to do it. Is this something new we have to take care of?
> >
> > We also tried running tomcat standalone by downloading it from apache
> sites
> > and they work fine - is this some new classpath settings we need to do?
>
> The tcnative-1.dll library is loaded via a java.lang.System.loadLibrary()
> call.
> It searches directories listed by "java.library.path" system property.
>
> Print the value of that property and it should give you a clue where
> to look for a duplicate copy of the library.
>
> http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/java/org/
> apache/tomcat/jni/Library.java?revision=1734771=markup#l42
>
> Placing the dll into JDK ext folder is an unusual way to configure it.
> The usual location is the same directory where service wrapper is
> (Tomcat85.exe).
>
> Best regards,
> Konstantin Kolinko
>
> -
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>
>


Re: Reverse proxy support in Tomcat

2017-07-18 Thread Igal @ Lucee.org

On 7/18/2017 6:29 AM, Mark Thomas wrote:

Note: Passing on the host header can require explicit configuration. In
the proxy. e.g. for httpd:

ProxyPreserveHost On


The best tool that I found to set up reverse proxy is Tomcat's 
RemoteIpFilter --

https://tomcat.apache.org/tomcat-8.5-doc/api/org/apache/catalina/filters/RemoteIpFilter.html
which I configure like so in the web descriptor:

| RemoteIpFilter 
org.apache.catalina.filters.RemoteIpFilter 
 internalProxies 
127\.0\.0\.1   
remoteIpHeader 
x-forwarded-for   
remoteIpProxiesHeader 
x-forwarded-by   
protocolHeader 
x-forwarded-proto   
 RemoteIpFilter 
/* REQUEST 
|



Then in the web server I pass the following headers from the web server 
to Tomcat (example shows nginx as web server, but they all work the 
same, the only difference is the variable names in the web server):



|proxy_set_header Host $host; ## CGI.HTTP_HOST|


See https://gist.github.com/isapir/8a70ed85b3a7a6e92908191f938d7a1a for 
more.



Igal Sapir

Lucee Core Developer
Lucee.org 



Re: Getting user role membership without context

2017-07-18 Thread Alex O'Ree
Alright, quick update on this.

At this point, I have servlet context and a username running off the
main tomcat http threads (quartz job)

> StandardContext tomcat;load from reflection from ApplicationContext from 
> ServletContext as ApplicationContextFacade
> Realm realm = tomcat.getRealm()

At this point, realm is a LockoutRealm that contains two child realms,
the JNDI Realm and the standard UserDatabaseRealm

> Principal user = realm.authenticate(username);

At this point, the user object is populated and appears to have the
roles attached to it (they are listed in the to String method).

> realm.hasRole(new StandardWrapper(), user, role);

This part returns false, if and only if the ldap membership matches
exactly. Mapped roles via servlet/security-role-ref/role-link and
role-name do not appear to be effect.

I think this may have something to do with the Principal object not
having a login context. Normally, this is available via a servlet, but
this it is not.

I think the root cause might be this line.
https://github.com/apache/tomcat/blob/TOMCAT_7_0_42/java/org/apache/catalina/realm/RealmBase.java#L933

Which probably does the translation from the LDAP defined group or
role into what the application is expecting. Am I on the right path
here?


On Sun, Jul 16, 2017 at 6:18 PM, Alex O'Ree  wrote:
> bugger, this time replying with the correct reply address. Not sure
> if the previous reply went through.
>
> Awesome thanks for the pointer.
>
> For the reflection mechanism. I think i have a working solution, so
> long as the tomcat dev's don't change the name of the private context
> variables in ApplicationContextFacade and ApplicationContext
>
> I'll also further investigate the JMX/Mbean method with JNDI as it
> will probably be more sustainable in the long run
>
> On Sun, Jul 16, 2017 at 3:55 PM, Mark Thomas  wrote:
>> On 16/07/17 15:31, Alex O'Ree wrote:
>>> Thanks for the clarification. To add to my description
>>>
>>> I'm running a task on the users behalf on a background thread with a
>>> task scheduler.  I need to get the roles when the task is ran in case
>>> of a change in role membership between the time the task is scheduled
>>> and when it is executed.
>>
>> Assuming that that thread is started by a web application, a better
>> route might be:
>>
>> ServletContext -> ApplicationContext -> Context -> Realm
>>
>> but that requires casting to Tomcat specific classes and some reflection
>> trickery since Tomcat deliberately tries to stop apps accessing its
>> internals.
>>
>>
>>> It looks like the Digester class loads server.xml and creates the
>>> realms but it looks like it's almost entirely done with dynamic class
>>> loading. I couldn't narrow down the point in code where Realms are
>>> created. Perhaps there's a way to get a reference to the realm via
>>> some static reference? I went through the code but could not find a
>>> solution. I also tried extending the UserDatabaseRealm but was unable
>>> to get it to fire up (new instance) due to the lack of the calling
>>> infrastructure and requisite calls from higher up in the tomcat code
>>> base.
>>
>> Not any more. It used to be possible the static reference essentially
>> prevented multiple Tomcat instances from being embedded in the same
>> application (a rare but valid use case) so we removed it.
>>
>>> Moving on, I was also poking around in JMX and found that the all
>>> users are listed (and clear text passwords are available? not sure if
>>> this is the case for digested or encrypt file stores).
>>
>> You have access to the UserDatabase (if configured) via JMX. It isn't
>> intended for production use but even it it were, the passwords are not
>> considered a security issue. JMX access is the equivalent of root access
>> as far as Tomcat is concerned. Whatever is in the tomcat-users.xml file
>> (clear text passwords, digested passwords, etc.) is also visible via JMX.
>>
>> Other Realms expose a lot less via JMX.
>>
>>> From this
>>> approach, i was able to parse the output and eventually found
>>> attributes that list all roles a given user account has (success!).
>>> What isn't clear is if this approach will work for LDAP (JNDI)
>>> connections or kerberos setups, SSO setups, etc. It may also be
>>> version specific to tomcat (running 7.0.76 at the moment). I'd
>>> appreciate any feedback on this.
>>
>> It will only work for the UserDatabaseRealm. It will work for any
>> currently supported Tomcat version.
>>
>> JMX may be your best option here. If you search for objects that have
>> "type=Realm" you'll be able to enumerate the Realms and hopefully find
>> the one you need.
>>
>> Mark
>>
>> -
>> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
>> For additional commands, e-mail: users-h...@tomcat.apache.org
>>

-
To unsubscribe, e-mail: 

Re: Tomcat 8.5.16 - APR version mismatch error upon startup

2017-07-18 Thread Konstantin Kolinko
2017-07-18 17:42 GMT+03:00 M. Manna :
> Hello,
>
> We have recently upgraded our tomcat from 8.0.29 to 8.5.16. As part of
> standard upgrade we have cleaned up all our bin/conf/lib folder contents
> and removed any older jars (e.g. ecj jars).
>
> Upon startup - we are getting the following error:
>
> Listening for transport dt_socket at address: 5005
>
> Jul 18, 2017 5:53:14 PM org.apache.catalina.core.AprLifecycleListener init
>
> SEVERE: An incompatible version [1.1.33] of the APR based Apache Tomcat
> Native library is installed, while Tomcat requires version [1.2.6]
>
[...]

> We copied and pasted the tcnative-1.dll into JDK ext folder and the problem
> seems to have gone away. But in the past with all the tomcats, we never had
> to do it. Is this something new we have to take care of?
>
> We also tried running tomcat standalone by downloading it from apache sites
> and they work fine - is this some new classpath settings we need to do?

The tcnative-1.dll library is loaded via a java.lang.System.loadLibrary() call.
It searches directories listed by "java.library.path" system property.

Print the value of that property and it should give you a clue where
to look for a duplicate copy of the library.

http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/java/org/apache/tomcat/jni/Library.java?revision=1734771=markup#l42

Placing the dll into JDK ext folder is an unusual way to configure it.
The usual location is the same directory where service wrapper is
(Tomcat85.exe).

Best regards,
Konstantin Kolinko

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



Re: Tomcat 8 Connection Pooling

2017-07-18 Thread Riccardo Cohen

Can you see any info in the log : login incorrect, database not found etc. ?
(There are many logs in tomcat : localhost log, catalina log, manager 
log, host manager log, localhost access log)


On 18/07/2017 13:55, Avinash Krishnan wrote:

Hello Riccardo ,

Thanks for the response. This didn't work for me. Connections are not
getting initated and I am seeing java.lang.NullPointerException on
accessing getConnection.

I  am refering to http://tomcat.apache.org/tomcat-8.0-doc/jdbc-pool.html

The pool properties is also not working.

On Tue, Jul 18, 2017 at 4:18 PM, Riccardo Cohen 
wrote:


Hello Avinash

I'm not expert but this is rather simple :
in web/META-INF/context.xml write something like :


  


in web/WEB-INF/web.xml add in  tag :
  

  jdbc/tomcattest


  javax.sql.DataSource

  

and in a java class add this :

public class T3Servlet extends HttpServlet
{
  @Resource(name="jdbc/tomcattest")
  public DataSource ds;


You will normally have a data source in your class, by injection, using
tomcat database pool.


On 18/07/2017 12:26, Avinash Krishnan wrote:


I am trying to implement Apache Tomcat 8.5.15  "Tomcat JDBC Connection
Pool" using the steps mentioned in the guide.

Can some one help me to understand how this connection pooling has to be
done.

Is the Plain Java Method,by implementing Pool Properties is an alternative
to the JNDI lookup based pooling ? When I implement using Pool Properties,
there isn't any provision to set up the Factory to
org.apache.tomcat.jdbc.pool.DataSourceFactory"
and I always get invalid arguments in call.

On a different note, I tried by adding to context.xml . And implementing
JNDI lookup from context. But that time,I get
"org.apache.tomcat.dbcp.dbcp2.BasicDataSource cannot be cast to
org.apache.tomcat.jdbc.pool.DataSource" even after setting factory to
DataSourceFactory.



--
Riccardo Cohen
+33 6 09 83 64 49
E5Group
http://www.5flow.com


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







--
Riccardo Cohen
+33 6 09 83 64 49
E5Group
http://www.5flow.com


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



Re: Tomcat 8.5.16 - APR version mismatch error upon startup

2017-07-18 Thread Mark Thomas
On 18/07/17 15:42, M. Manna wrote:
> Hello,
> 
> We have recently upgraded our tomcat from 8.0.29 to 8.5.16. As part of
> standard upgrade we have cleaned up all our bin/conf/lib folder contents
> and removed any older jars (e.g. ecj jars).

That sounds like you have been installing new versions on top of old
ones. That is probably the cause of the behaviour you have seen.



> We copied and pasted the tcnative-1.dll into JDK ext folder and the problem
> seems to have gone away. But in the past with all the tomcats, we never had
> to do it. Is this something new we have to take care of?

That should not have been necessary. It sounds like you had an old
version of the library somewhere on the path.

> We also tried running tomcat standalone by downloading it from apache sites
> and they work fine - is this some new classpath settings we need to do?
> 
> 
> Any suggestions ?

Review your upgrade process and adjust as necessary. Take a look at the
information on separating CATALINA_HOME and CATALINA_BASE in RUNNING.txt
- that might give you some ideas.

Mark

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



Tomcat 8.5.16 - APR version mismatch error upon startup

2017-07-18 Thread M. Manna
Hello,

We have recently upgraded our tomcat from 8.0.29 to 8.5.16. As part of
standard upgrade we have cleaned up all our bin/conf/lib folder contents
and removed any older jars (e.g. ecj jars).

Upon startup - we are getting the following error:

Listening for transport dt_socket at address: 5005

Jul 18, 2017 5:53:14 PM org.apache.catalina.core.AprLifecycleListener init

SEVERE: An incompatible version [1.1.33] of the APR based Apache Tomcat
Native library is installed, while Tomcat requires version [1.2.6]

Jul 18, 2017 5:53:14 PM org.apache.catalina.core.AprLifecycleListener init

SEVERE: An incompatible version [1.1.33] of the APR based Apache Tomcat
Native library is installed, while Tomcat requires version [1.2.6]

Jul 18, 2017 5:53:14 PM org.apache.catalina.core.AprLifecycleListener init

SEVERE: An incompatible version [1.1.33] of the APR based Apache Tomcat
Native library is installed, while Tomcat requires version [1.2.6]

Jul 18, 2017 5:53:14 PM org.apache.catalina.core.AprLifecycleListener init

SEVERE: An incompatible version [1.1.33] of the APR based Apache Tomcat
Native library is installed, while Tomcat requires version [1.2.6]

Jul 18, 2017 5:53:14 PM org.apache.catalina.core.AprLifecycleListener init

SEVERE: An incompatible version [1.1.33] of the APR based Apache Tomcat
Native library is installed, while Tomcat requires version [1.2.6]

Jul 18, 2017 5:53:15 PM org.apache.catalina.core.AprLifecycleListener init

SEVERE: An incompatible version [1.1.33] of the APR based Apache Tomcat
Native library is installed, while Tomcat requires version [1.2.6]

Jul 18, 2017 5:53:15 PM org.apache.catalina.core.StandardService
initInternal

SEVERE: Failed to initialize connector
[Connector[org.apache.coyote.http11.Http11AprProtocol-80]]

org.apache.catalina.LifecycleException: Failed to initialize component
[Connector[org.apache.coyote.http11.Http11AprProtocol-80]]

at
org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:112)

at
org.apache.catalina.core.StandardService.initInternal(StandardService.java:549)

at
org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:107)

at
org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:875)

at
org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:107)

at org.apache.catalina.startup.Catalina.load(Catalina.java:607)

at org.apache.catalina.startup.Catalina.load(Catalina.java:630)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:497)

at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:311)

at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:494)

Caused by: org.apache.catalina.LifecycleException: The configured protocol
[org.apache.coyote.http11.Http11AprProtocol] requires the APR/native
library which is not available

at
org.apache.catalina.connector.Connector.initInternal(Connector.java:981)

at
org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:107)

... 12 more



Jul 18, 2017 5:53:15 PM org.apache.catalina.core.AprLifecycleListener init

SEVERE: An incompatible version [1.1.33] of the APR based Apache Tomcat
Native library is installed, while Tomcat requires version [1.2.6]



We copied and pasted the tcnative-1.dll into JDK ext folder and the problem
seems to have gone away. But in the past with all the tomcats, we never had
to do it. Is this something new we have to take care of?

We also tried running tomcat standalone by downloading it from apache sites
and they work fine - is this some new classpath settings we need to do?


Any suggestions ?

KR,


RE: run thread from servlet

2017-07-18 Thread Tran, Dung Minh
Hello Pradip,
   Thanks for the comments. Could you please clarify the statement "the servlet 
can enque the data in a concurrent queue, and then
notify the object " ? Would you assume that there would be two threads in the 
servlet ? One is context listener thread, and the other is enqueue data thread ?
Thanks,
Tom

From: Pradip Bhattacharya [pradip.bhattacha...@gmail.com]
Sent: Tuesday, July 18, 2017 10:09 AM
To: Tomcat Users List
Subject: Re: run thread from servlet

Hello,
I hope I understood the requirement correctly. I believe you can start
EmailProcess thread by the context listener. This thread can wait on an
object. And the servlet can enque the data in a concurrent queue, and then
notify the object, on which EmailProcess thread is waiting.
Is this EmailProcess is an asynchronous service to send emails ?
Regards
Pradip.B

On Jul 18, 2017 7:27 PM, "Campbell, Lance"  wrote:

Tomcat 8.0.x
Question:
I am wanting to know the proper way to start a thread from a servlet.

Use Case:
A batch process will call a URL that is a servlet.  The servlet will call a
processes that will trigger a thread to run to do a particular job.  The
thread will run for a while.  The servlet will not wait on the thread to
finish running.  Also the thread that is started is running a processes
that requires there to only be one of these processes running at any given
time.

What I have done:
I created a class I call EmailProcess.  I have a static Boolean flag in the
class called isWorking that indicates if the process is running.  The class
extends Runnable.  The class also has a static method to start the thread
if isWorking flag is false.  I have a servlet that will call the static
method in EmailProcess to start the thread if possible.

Note: If the Tomcat container decides to clean up the servlet that is
called that triggers the thread I don't want it to mess with the thread.  I
want it to keep on running.

Thanks for your advice.

Lance



This e-mail message (including any attachments) is for the sole use of
the intended recipient(s) and may contain confidential and privileged
information. If the reader of this message is not the intended
recipient, you are hereby notified that any dissemination, distribution
or copying of this message (including any attachments) is strictly
prohibited.

If you have received this message in error, please contact
the sender by reply e-mail message and destroy all copies of the
original message (including attachments).

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



Re: run thread from servlet

2017-07-18 Thread Pradip Bhattacharya
Hello,
I hope I understood the requirement correctly. I believe you can start
EmailProcess thread by the context listener. This thread can wait on an
object. And the servlet can enque the data in a concurrent queue, and then
notify the object, on which EmailProcess thread is waiting.
Is this EmailProcess is an asynchronous service to send emails ?
Regards
Pradip.B

On Jul 18, 2017 7:27 PM, "Campbell, Lance"  wrote:

Tomcat 8.0.x
Question:
I am wanting to know the proper way to start a thread from a servlet.

Use Case:
A batch process will call a URL that is a servlet.  The servlet will call a
processes that will trigger a thread to run to do a particular job.  The
thread will run for a while.  The servlet will not wait on the thread to
finish running.  Also the thread that is started is running a processes
that requires there to only be one of these processes running at any given
time.

What I have done:
I created a class I call EmailProcess.  I have a static Boolean flag in the
class called isWorking that indicates if the process is running.  The class
extends Runnable.  The class also has a static method to start the thread
if isWorking flag is false.  I have a servlet that will call the static
method in EmailProcess to start the thread if possible.

Note: If the Tomcat container decides to clean up the servlet that is
called that triggers the thread I don't want it to mess with the thread.  I
want it to keep on running.

Thanks for your advice.

Lance


run thread from servlet

2017-07-18 Thread Campbell, Lance
Tomcat 8.0.x
Question:
I am wanting to know the proper way to start a thread from a servlet.

Use Case:
A batch process will call a URL that is a servlet.  The servlet will call a 
processes that will trigger a thread to run to do a particular job.  The thread 
will run for a while.  The servlet will not wait on the thread to finish 
running.  Also the thread that is started is running a processes that requires 
there to only be one of these processes running at any given time.

What I have done:
I created a class I call EmailProcess.  I have a static Boolean flag in the 
class called isWorking that indicates if the process is running.  The class 
extends Runnable.  The class also has a static method to start the thread if 
isWorking flag is false.  I have a servlet that will call the static method in 
EmailProcess to start the thread if possible.

Note: If the Tomcat container decides to clean up the servlet that is called 
that triggers the thread I don't want it to mess with the thread.  I want it to 
keep on running.

Thanks for your advice.

Lance



Re: Reverse proxy support in Tomcat

2017-07-18 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

André,

On 7/18/17 8:29 AM, André Warnier (tomcat) wrote:
> Hi.
> 
> On 18.07.2017 14:09, Jan Hlavatý wrote:
>> Hello,
>> 
>> I can't seem to figure out the proper setup for the situation
>> where I have multiple webhosts behind a reverse proxy server
>> being forwarded to Tomcat.
>> 
>> There can be only one proxyHost and proxyPort on a Connector but
>> I have multiple Hosts and Aliases.
>> 
>> How am I supposed to do that? Make multiple Connectors one per
>> hostname, on different local ports, sharing on Executor to avoid
>> multiplying threads, and have the proxy forward to different
>> ports based on hostname?
>> 
> 
> No to all that. All you need is multiple  entries in the
> tomcat server.xml config. A single  (and port) will do
> for all.  is optional, and indeed relates to optimising
> the usage of threads.
> 
> Other than that, I don't really know at what level to begin
> explaining why. Let's try this :
> 
> In HTTP 1.1 and above, when a browser sends a request to a server,
> it adds a header line to each request : Host: some.server.com
> 
> The receiving HTTP server reads this header, and that is what tells
> it to which of it's "hosts" this request is adressed.
> 
> If you have a front-end reverse proxy, and say 10 virtual hosts,
> then each of these virtual host names is configured in the DNS to
> resolve to the IP address of your proxy. So the front-end proxy
> receives all requests directed to any of these hosts. It then
> belongs to the proxy, to forward all these requests to the single
> back-end Tomcat server, and include the original "Host:" header in
> the requests that it proxies so.
> 
> The single Tomcat Connector will receive all these requests, and
> will dispatch them to each individual  in function of that
> same "Host:" header.

+1

See point 5 in: https://tomcat.apache.org/tomcat-8.0-doc/proxy-howto.htm
l

Also see the list of bullet points under
https://tomcat.apache.org/connectors-doc/common_howto/proxy.html,
specifically this one:

"
* local name: getLocalName(). This is also equal to getServerName(),
unless a Host header is contained in the request. In this case the
server name is taken from that header.
"

So, basically, if you simply don't configure any proxyHost or
proxyPort at all, I think you'll get the behavior you desire.

- -chris
-BEGIN PGP SIGNATURE-
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAlluDf4ACgkQHPApP6U8
pFiboQ/+Po/u6b4OwC0Nsel1sbN3TA8cIyrASDy4NmYjlNLw3DSTBMo38VVK1Rqm
+L4sLFBBdJ/01eH6ahEHmJGE9Cifg72i/ldsqFfrLD9kglSOa8Y4iJtRkMyq8qgr
ElkzLY+phBDNVk45ePQ0dSEW97i/HJI3/DSaRGLxmiI2a7FDSQEM7Y1E5ZEvQ1nQ
q+A0zrr0+yxJmKEjx1u0q1ehiAqcK1P3QpcSsBOGEIliDoalCdSMIZgYnl0ok9sR
LeKnc5+2Xz3QWwpRRPhUFb+2AXLe7MBG2YKwJxCJraRn+ets12MV5NrpNg0NHUOz
knlJL6auc2m1vaU1fOjN5tzS4O9pBmT/eM7f35gNz9A9ggmOcwOnyd9hZ7NZh20h
7vEkvBKMA0C+8aO2w4cICm+25b2Oy6ut5mGHCZz68MY2s8dfEGo614nFIdlQtklu
QmhlTCj4cw8kNdGZ9ayfvSOaLD3O/lz6azpLWGHP0qGUvtTB4TqMI3CqNtuDxwWO
vzU8jXKaTFxnCMphgpMxwLOxUlbEjOEfWJeIARasNKJswgHEHFEe9XGNyfMXP6zC
7RTACy5nvX6FWm0U0RtzXrF0zKbqTaeRtNoI+wmkhrsDbEuVqMPUoG/UhBP1NEmZ
QkHCEoJaAxmFU/qC5FIyU88sM8Y8rhiRqkhT6E8oNriv8VtT+Xw=
=vjQ7
-END PGP SIGNATURE-

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



Re: Reverse proxy support in Tomcat

2017-07-18 Thread Mark Thomas
On 18/07/17 13:29, André Warnier (tomcat) wrote:
> Hi.
> 
> On 18.07.2017 14:09, Jan Hlavatý wrote:
>> Hello,
>>
>> I can't seem to figure out the proper setup for the situation where I
>> have multiple webhosts behind a reverse proxy server being forwarded to
>> Tomcat.
>>
>> There can be only one proxyHost and proxyPort on a Connector but I have
>> multiple Hosts and Aliases.
>>
>> How am I supposed to do that? Make multiple Connectors one per hostname,
>> on different local ports, sharing on Executor to avoid multiplying
>> threads, and have the proxy forward to different ports based on hostname?
>>
> 
> No to all that. All you need is multiple  entries in the tomcat
> server.xml config.
> A single  (and port) will do for all.  is optional,
> and indeed relates to optimising the usage of threads.
> 
> Other than that, I don't really know at what level to begin explaining why.
> Let's try this :
> 
> In HTTP 1.1 and above, when a browser sends a request to a server, it
> adds a header line to each request :
> Host: some.server.com
> 
> The receiving HTTP server reads this header, and that is what tells it
> to which of it's "hosts" this request is adressed.
> 
> If you have a front-end reverse proxy, and say 10 virtual hosts, then
> each of these virtual host names is configured in the DNS to resolve to
> the IP address of your proxy.
> So the front-end proxy receives all requests directed to any of these
> hosts.
> It then belongs to the proxy, to forward all these requests to the
> single back-end Tomcat server, and include the original "Host:" header
> in the requests that it proxies so.

Note: Passing on the host header can require explicit configuration. In
the proxy. e.g. for httpd:

ProxyPreserveHost On


> The single Tomcat Connector will receive all these requests, and will
> dispatch them to each individual  in function of that same "Host:"
> header.
> 
> Clear ?

One tip. Don't try and change the context path in the reverse proxy. It
creates all sorts of potential for things to go wrong. In httpd config
syntax:

ProxyPass /foo http://localhost:8080/foo

is good

ProxyPass /foo http://localhost:8080/bar

is likely to be a lot of work to get working correctly. In the past I
have spent days on-site with one customer getting one application to
work in this configuration because they didn't want to change the
back-end context path.

And finally, if the reverse proxy handles HTTP and HTTPS
and you are proxying to Tomcat over HTTP, use a separate Tomcat
connector for each of the HTTP and HTTPS traffic - it makes correct,
secure configuration a lot simpler.

Mark

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



Re: Reverse proxy support in Tomcat

2017-07-18 Thread tomcat

Hi.

On 18.07.2017 14:09, Jan Hlavatý wrote:

Hello,

I can't seem to figure out the proper setup for the situation where I
have multiple webhosts behind a reverse proxy server being forwarded to
Tomcat.

There can be only one proxyHost and proxyPort on a Connector but I have
multiple Hosts and Aliases.

How am I supposed to do that? Make multiple Connectors one per hostname,
on different local ports, sharing on Executor to avoid multiplying
threads, and have the proxy forward to different ports based on hostname?



No to all that. All you need is multiple  entries in the tomcat 
server.xml config.
A single  (and port) will do for all.  is optional, and indeed 
relates to optimising the usage of threads.


Other than that, I don't really know at what level to begin explaining why.
Let's try this :

In HTTP 1.1 and above, when a browser sends a request to a server, it adds a header line 
to each request :

Host: some.server.com

The receiving HTTP server reads this header, and that is what tells it to which of it's 
"hosts" this request is adressed.


If you have a front-end reverse proxy, and say 10 virtual hosts, then each of these 
virtual host names is configured in the DNS to resolve to the IP address of your proxy.

So the front-end proxy receives all requests directed to any of these hosts.
It then belongs to the proxy, to forward all these requests to the single back-end Tomcat 
server, and include the original "Host:" header in the requests that it proxies so.


The single Tomcat Connector will receive all these requests, and will dispatch them to 
each individual  in function of that same "Host:" header.


Clear ?



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



Reverse proxy support in Tomcat

2017-07-18 Thread Jan Hlavatý
Hello,

I can't seem to figure out the proper setup for the situation where I
have multiple webhosts behind a reverse proxy server being forwarded to
Tomcat.

There can be only one proxyHost and proxyPort on a Connector but I have
multiple Hosts and Aliases.

How am I supposed to do that? Make multiple Connectors one per hostname,
on different local ports, sharing on Executor to avoid multiplying
threads, and have the proxy forward to different ports based on hostname?

Jan



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



Re: Tomcat 8 Connection Pooling

2017-07-18 Thread Avinash Krishnan
Hello Riccardo ,

Thanks for the response. This didn't work for me. Connections are not
getting initated and I am seeing java.lang.NullPointerException on
accessing getConnection.

I  am refering to http://tomcat.apache.org/tomcat-8.0-doc/jdbc-pool.html

The pool properties is also not working.

On Tue, Jul 18, 2017 at 4:18 PM, Riccardo Cohen 
wrote:

> Hello Avinash
>
> I'm not expert but this is rather simple :
> in web/META-INF/context.xml write something like :
>
> 
>type="javax.sql.DataSource"
> username="root"
> password="pass"
> driverClassName="com.mysql.jdbc.Driver"
>
> url="jdbc:mysql://localhost:3306/databasename?useSSL=false&
> amp;zeroDateTimeBehavior=convertToNulljdbcCompliantTrun
> cation=falsecharacterEncoding=utf8"
>   />
> 
>
> in web/WEB-INF/web.xml add in  tag :
>   
> 
>   jdbc/tomcattest
> 
> 
>   javax.sql.DataSource
> 
>   
>
> and in a java class add this :
>
> public class T3Servlet extends HttpServlet
> {
>   @Resource(name="jdbc/tomcattest")
>   public DataSource ds;
>
>
> You will normally have a data source in your class, by injection, using
> tomcat database pool.
>
>
> On 18/07/2017 12:26, Avinash Krishnan wrote:
>
>> I am trying to implement Apache Tomcat 8.5.15  "Tomcat JDBC Connection
>> Pool" using the steps mentioned in the guide.
>>
>> Can some one help me to understand how this connection pooling has to be
>> done.
>>
>> Is the Plain Java Method,by implementing Pool Properties is an alternative
>> to the JNDI lookup based pooling ? When I implement using Pool Properties,
>> there isn't any provision to set up the Factory to
>> org.apache.tomcat.jdbc.pool.DataSourceFactory"
>> and I always get invalid arguments in call.
>>
>> On a different note, I tried by adding to context.xml . And implementing
>> JNDI lookup from context. But that time,I get
>> "org.apache.tomcat.dbcp.dbcp2.BasicDataSource cannot be cast to
>> org.apache.tomcat.jdbc.pool.DataSource" even after setting factory to
>> DataSourceFactory.
>>
>>
> --
> Riccardo Cohen
> +33 6 09 83 64 49
> E5Group
> http://www.5flow.com
>
>
> -
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>
>


-- 
Regards,
Avinash K
+91 9497359324


Re: Tomcat 8 Connection Pooling

2017-07-18 Thread Riccardo Cohen

Hello Avinash

I'm not expert but this is rather simple :
in web/META-INF/context.xml write something like :


  


in web/WEB-INF/web.xml add in  tag :
  

  jdbc/tomcattest


  javax.sql.DataSource

  

and in a java class add this :

public class T3Servlet extends HttpServlet
{
  @Resource(name="jdbc/tomcattest")
  public DataSource ds;


You will normally have a data source in your class, by injection, using 
tomcat database pool.



On 18/07/2017 12:26, Avinash Krishnan wrote:

I am trying to implement Apache Tomcat 8.5.15  "Tomcat JDBC Connection
Pool" using the steps mentioned in the guide.

Can some one help me to understand how this connection pooling has to be
done.

Is the Plain Java Method,by implementing Pool Properties is an alternative
to the JNDI lookup based pooling ? When I implement using Pool Properties,
there isn't any provision to set up the Factory to
org.apache.tomcat.jdbc.pool.DataSourceFactory"
and I always get invalid arguments in call.

On a different note, I tried by adding to context.xml . And implementing
JNDI lookup from context. But that time,I get
"org.apache.tomcat.dbcp.dbcp2.BasicDataSource cannot be cast to
org.apache.tomcat.jdbc.pool.DataSource" even after setting factory to
DataSourceFactory.



--
Riccardo Cohen
+33 6 09 83 64 49
E5Group
http://www.5flow.com


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



Tomcat 8 Connection Pooling

2017-07-18 Thread Avinash Krishnan
I am trying to implement Apache Tomcat 8.5.15  "Tomcat JDBC Connection
Pool" using the steps mentioned in the guide.

Can some one help me to understand how this connection pooling has to be
done.

Is the Plain Java Method,by implementing Pool Properties is an alternative
to the JNDI lookup based pooling ? When I implement using Pool Properties,
there isn't any provision to set up the Factory to
org.apache.tomcat.jdbc.pool.DataSourceFactory"
and I always get invalid arguments in call.

On a different note, I tried by adding to context.xml . And implementing
JNDI lookup from context. But that time,I get
"org.apache.tomcat.dbcp.dbcp2.BasicDataSource cannot be cast to
org.apache.tomcat.jdbc.pool.DataSource" even after setting factory to
DataSourceFactory.

-- 
Regards,
Avinash K