You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Shinan Kassam <sh...@gmail.com> on 2010/04/20 15:00:31 UTC
Is it possible to connect to a different database based on the URL?
I am using:
BlazeDS Turnkey:
Tomcat 6.0.14
I am building only AMF type services
I currently have custom authentication working using JDBCRealm. Hence, I
have some database parameters in server.xml as well as my application. Is it
possible to use a portion of the URL as a parameter to connect to a
different database.
For example, currently I use the following URL:
http://localhost:8400/samples/messagebroker/amf
If the URL was something like:
http://localhost:8400/samples/messagebroker/<customer>/amf
I would like to connect to the database for <customer>.
Would it be best to pull the portion of the url for the customer and
dynamically create the database connection programatically? OR just have
different applications for different customers.
Alternative:
http://localhost:8400/<customer>/messagebroker/amf
So each customer would physically have different folders and different
applications with different database configurations.
Thanks In Advance.
--
Shinan S. Kassam
Re: Is it possible to connect to a different database based on the
URL?
Posted by Pid <pi...@pidster.com>.
On 20/04/2010 14:00, Shinan Kassam wrote:
> I am using:
> BlazeDS Turnkey:
> Tomcat 6.0.14
Old: 6.0.26 is the latest, you should plan to upgrade asap.
> I am building only AMF type services
>
> I currently have custom authentication working using JDBCRealm. Hence, I
> have some database parameters in server.xml as well as my application. Is it
> possible to use a portion of the URL as a parameter to connect to a
> different database.
Use the DataSourceRealm, JDBCRealm is slow & not recommended for production.
> For example, currently I use the following URL:
> http://localhost:8400/samples/messagebroker/amf
>
> If the URL was something like:
> http://localhost:8400/samples/messagebroker/<customer>/amf
> I would like to connect to the database for <customer>.
Is anything stopping you from using that information as part of your
custom authentication?
> Would it be best to pull the portion of the url for the customer and
> dynamically create the database connection programatically?
Would be slow to do that every time.
> OR just have different applications for different customers.
>
> Alternative:
> http://localhost:8400/<customer>/messagebroker/amf
> So each customer would physically have different folders and different
> applications with different database configurations.
It's a little extra work during the build process, but having
independent apps is the route I'd take.
p
Re: Is it possible to connect to a different database based on the
URL?
Posted by Gregor Schneider <rc...@googlemail.com>.
On Tue, Apr 20, 2010 at 3:00 PM, Shinan Kassam <sh...@gmail.com> wrote:
>
> I currently have custom authentication working using JDBCRealm. Hence, I
> have some database parameters in server.xml as well as my application. Is it
> possible to use a portion of the URL as a parameter to connect to a
> different database.
>
shot from the hip:
- specify all databases available inside your context.xml-file
- from the url, read a parameter (such as "&customer=scrooge")
- depending on the parameter, create the datasource:
try {
Context env = (Context) new InitialContext().lookup("java:comp/env");
dbDS = (DataSource) env.lookup(customer);
if (dbDS == null) {
logger.error("seems that '" + dataSourceName + "' is an unknown
DataSource");
throw new ServletException("'" + dataSourceName + "' is an
unknown DataSource");
}
} catch (NamingException e) {
logger.error("Exception caught:", e);
throw new ServletException(e);
}
hth
gregor
--
just because you're paranoid, don't mean they're not after you...
gpgp-fp: 79A84FA526807026795E4209D3B3FE028B3170B2
gpgp-key available
@ http://pgpkeys.pca.dfn.de:11371
@ http://pgp.mit.edu:11371/
skype:rc46fi
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org