Hi Robert,

1) To use the same JDBC Datasource, configure your Datasource in JNDI.
Once you have a JNDI-Based Datasource you can use it for both JackRabbit and 
your own Webapp.
See: http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html
And: 
http://wiki.magnolia-cms.com/display/WIKI/Database-Only+Repositories+with+JNDI+Datasources
(you don't need to go "database only", but the wiki-page still gives an example 
of using datasources with Jackrabbit).

Note however that using the same Datasource may not be such a good idea:
JackRabbit handles its own connection pooling, it isn't very 
"Datasource-friendly".
Your simple Webapp will presumably be more "normal" in its handling of Database 
connections.
In particular, JackRabbit should not have connection recovery configured, while 
your Webapp probably should.
So it might not be the best idea to use the same Datasource anyway.

2) From the way you describe your problem, it look to me like you don't really 
need a separate Webapp. Maybe I have misunderstood something.
But if the goal is to load something (survey questions or results) from an 
external Database, and display it using magnolia, then I think what you are 
looking for is more likely a "model class".
We have used patterns like this to integrate external data-sources already 
several times in our deployments:
- Create a factory class for handling the Database connections. This class will 
prepare a database connection, for example by acquiring it from your JNDI 
Datasource. It may also use MyBatis, Hibernate or something similar to provide 
a richer data-access layer.
- Create a model-class. If you are using STK your model class should extend 
STKTemplateModel. In your model class, create a method like
List<String> getMyResults()
This method can call the factory to obtain a database connection, load the data 
and write it into a List for returning the result.
- In your template definition, set the model class to use your model 
implementation. In the template script you can then write something like:
[#list model.myResults as result]
A result: ${result}
[/#list]

I think this way of proceeding will definitely work better than trying to load 
data in an external web-app or servlet, and then redirecting the request back 
to magnolia.

Regards from Vienna,

Richard

-----Ursprüngliche Nachricht-----
Von: [email protected] [mailto:[email protected]] 
Im Auftrag von Magnolia Forums (on behalf of Robert Bowen)
Gesendet: Freitag, 09. Dezember 2011 18:05
An: Magnolia User List
Betreff: [magnolia-user] Re: Integrate with small web app

Ok, so I made a small servlet that creates a connection and executes a SQL 
query against the database and all is good. I configured it in Configuration : 
Filters : Servlets to be called only with a certain path, and it prints the 
results of the query on the screen using HttpResponse.out.

Questions:

1. Is there a way to use the same JDBC connection (pool) that Magnolia is using?

2. How can I make this servlet part of the Magnolia "flow"? I mean, when you 
tell Magnolia that all requests like "survey/*" are handled by a custom 
servlet, you exit the Magnolia "flow". But I'd like to use a normal Magnolia 
template, just like all the other templates in my app - with the same header, 
footer, etc. - but that parses the data (a simple ArrayList<String>) stuck in 
the response. Is this possible?

-- 
Context is everything: 
http://forum.magnolia-cms.com/forum/thread.html?threadId=3f254fa9-4506-4830-8eee-44a5f18da5c4


----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------





----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------

Reply via email to