RESTXQ - access to InitParameters of ServletContext and/or ServletConfig
Monday, 15 December 2014 · 7 messages · last reply 16 Dec 2014
FE
Fabrice Etanchaud15 Dec 2014 17:02 #
Hi all BaseX users ,
Inside a RESTXQ function,
I would like to get InitParameters of the ServletContext or ServletConfig instances, I cannot find that in a module.
Did I miss something ?
Best regards,
Fabrice Etanchaud
CG
Christian Grün15 Dec 2014 20:25 #
Hi Fabrice,
Quoted text · Fabrice Etanchaud · 2 lines
> I would like to get InitParameters of the ServletContext or ServletConfig > instances,
The servlet init parameters are currently accessed by the BaseX itself [1,2], but there is no way to retrieve them from RESTXQ.
Well, that's only partially true. One way to reach the ServletContext init parrameters is to:
• Write a Java class that extends QueryModule [3]
• Access queryContext.http in that class (see e.g. [4])
• Call http.req.getServletContext().getInitParameterNames()
I am not sure, though, if that also works for the ServletConfig parameters (maybe you know?).
What do you want to do with that information? What parameters are you interested in?
Christian
[1] https://github.com/BaseXdb/basex/blob/master/basex-api/src/main/java/org/basex/http/BaseXServlet.java#L38 [2] https://github.com/BaseXdb/basex/blob/master/basex-api/src/main/java/org/basex/http/HTTPContext.java#L421 [3] http://docs.basex.org/wiki/Java_Bindings#Context-Awareness [4] https://github.com/BaseXdb/basex/blob/master/basex-api/src/main/java/org/basex/modules/Session.java#L142
FE
Fabrice Etanchaud16 Dec 2014 09:23 #
Dear Christian,
Thank you !
I use RESTXQ to easily transform RDBMS data into XML,
And am looking for a way to retrieve configuration parameters like jdbc url, username and password, for example.
How would you initialize persisting variables like a jdbc connection ?
Thank you again for your fantastic job.
Bien à vous,
Fabrice
-----Message d'origine-----
Quoted text · Christian Grün · 18 lines
De : Christian Grün [mailto:christian.gruen at gmail.com] Envoyé : lundi 15 décembre 2014 20:25 À : Fabrice Etanchaud Cc : basex-talk at mailman.uni-konstanz.de Objet : Re: [basex-talk] RESTXQ - access to InitParameters of ServletContext and/or ServletConfig Hi Fabrice, > I would like to get InitParameters of the ServletContext or > ServletConfig instances, The servlet init parameters are currently accessed by the BaseX itself [1,2], but there is no way to retrieve them from RESTXQ. Well, that's only partially true. One way to reach the ServletContext init parrameters is to: • Write a Java class that extends QueryModule [3] • Access queryContext.http in that class (see e.g. [4]) • Call http.req.getServletContext().getInitParameterNames() I am not sure, though, if that also works for the ServletConfig parameters (maybe you know?). What do you want to do with that information? What parameters are you interested in? Christian [1] https://github.com/BaseXdb/basex/blob/master/basex-api/src/main/java/org/basex/http/BaseXServlet.java#L38 [2] https://github.com/BaseXdb/basex/blob/master/basex-api/src/main/java/org/basex/http/HTTPContext.java#L421 [3] http://docs.basex.org/wiki/Java_Bindings#Context-Awareness [4] https://github.com/BaseXdb/basex/blob/master/basex-api/src/main/java/org/basex/modules/Session.java#L142
CG
Christian Grün16 Dec 2014 16:10 #
Hi Fabrice,
Quoted text · Fabrice Etanchaud · 1 line
> How would you initialize persisting variables like a jdbc connection ?
You could simply use the doc(...) function in XQuery and access the document from your web application directory. One more way would be to store the data in a database instance, but this is probably too much of an overhead in your case.
J'espère avoir pu t'aider,
Christian
Quoted text · Fabrice Etanchaud · 34 lines
> > Thank you again for your fantastic job. > > Bien à vous, > Fabrice > > > -----Message d'origine----- > De : Christian Grün [mailto:christian.gruen at gmail.com] > Envoyé : lundi 15 décembre 2014 20:25 > À : Fabrice Etanchaud > Cc : basex-talk at mailman.uni-konstanz.de > Objet : Re: [basex-talk] RESTXQ - access to InitParameters of ServletContext and/or ServletConfig > > Hi Fabrice, > >> I would like to get InitParameters of the ServletContext or >> ServletConfig instances, > > The servlet init parameters are currently accessed by the BaseX itself [1,2], but there is no way to retrieve them from RESTXQ. > > Well, that's only partially true. One way to reach the ServletContext init parrameters is to: > > • Write a Java class that extends QueryModule [3] • Access queryContext.http in that class (see e.g. [4]) • Call http.req.getServletContext().getInitParameterNames() > > I am not sure, though, if that also works for the ServletConfig parameters (maybe you know?). > > What do you want to do with that information? What parameters are you interested in? > Christian > > [1] https://github.com/BaseXdb/basex/blob/master/basex-api/src/main/java/org/basex/http/BaseXServlet.java#L38 > [2] https://github.com/BaseXdb/basex/blob/master/basex-api/src/main/java/org/basex/http/HTTPContext.java#L421 > [3] http://docs.basex.org/wiki/Java_Bindings#Context-Awareness > [4] https://github.com/BaseXdb/basex/blob/master/basex-api/src/main/java/org/basex/modules/Session.java#L142
FE
Fabrice Etanchaud16 Dec 2014 16:29 #
Merci Christian, I coded my first java module extending QueryModule, and installed it in the repository !
Sorry, I can't speak German, you know how French people are :-(
Best regards,
Fabrice
-----Message d'origine-----
Quoted text · Christian Grün · 53 lines
De : Christian Grün [mailto:christian.gruen at gmail.com] Envoyé : mardi 16 décembre 2014 16:10 À : Fabrice Etanchaud Cc : basex-talk at mailman.uni-konstanz.de Objet : Re: [basex-talk] RESTXQ - access to InitParameters of ServletContext and/or ServletConfig Hi Fabrice, > How would you initialize persisting variables like a jdbc connection ? You could simply use the doc(...) function in XQuery and access the document from your web application directory. One more way would be to store the data in a database instance, but this is probably too much of an overhead in your case. J'espère avoir pu t'aider, Christian > > Thank you again for your fantastic job. > > Bien à vous, > Fabrice > > > -----Message d'origine----- > De : Christian Grün [mailto:christian.gruen at gmail.com] > Envoyé : lundi 15 décembre 2014 20:25 > À : Fabrice Etanchaud > Cc : basex-talk at mailman.uni-konstanz.de > Objet : Re: [basex-talk] RESTXQ - access to InitParameters of > ServletContext and/or ServletConfig > > Hi Fabrice, > >> I would like to get InitParameters of the ServletContext or >> ServletConfig instances, > > The servlet init parameters are currently accessed by the BaseX itself [1,2], but there is no way to retrieve them from RESTXQ. > > Well, that's only partially true. One way to reach the ServletContext init parrameters is to: > > • Write a Java class that extends QueryModule [3] • Access > queryContext.http in that class (see e.g. [4]) • Call > http.req.getServletContext().getInitParameterNames() > > I am not sure, though, if that also works for the ServletConfig parameters (maybe you know?). > > What do you want to do with that information? What parameters are you interested in? > Christian > > [1] > https://github.com/BaseXdb/basex/blob/master/basex-api/src/main/java/o > rg/basex/http/BaseXServlet.java#L38 > [2] > https://github.com/BaseXdb/basex/blob/master/basex-api/src/main/java/o > rg/basex/http/HTTPContext.java#L421 > [3] http://docs.basex.org/wiki/Java_Bindings#Context-Awareness > [4] > https://github.com/BaseXdb/basex/blob/master/basex-api/src/main/java/o > rg/basex/modules/Session.java#L142
FE
Maybe it could help other BaseX users :
package questel.basex.modules;
import org.basex.http.HTTPContext;
import org.basex.query.*;
public class Parameter extends QueryModule { @Requires(Permission.NONE)
@Deterministic
@ContextDependent
public String get(String key) {
return ((HTTPContext) queryContext.http).req.getServletContext().getInitParameter(key); }
}
Don't forget to add the Main-Class: questel.basex.modules.Parameter line in the jar's MANIFEST. And finally install it in the repository : REPO INSTALL 'your jar filepath'
Best regards,
Fabrice
-----Message d'origine-----
Quoted text · Christian Grün · 53 lines
De : Christian Grün [mailto:christian.gruen at gmail.com] Envoyé : mardi 16 décembre 2014 16:10 À : Fabrice Etanchaud Cc : basex-talk at mailman.uni-konstanz.de Objet : Re: [basex-talk] RESTXQ - access to InitParameters of ServletContext and/or ServletConfig Hi Fabrice, > How would you initialize persisting variables like a jdbc connection ? You could simply use the doc(...) function in XQuery and access the document from your web application directory. One more way would be to store the data in a database instance, but this is probably too much of an overhead in your case. J'espère avoir pu t'aider, Christian > > Thank you again for your fantastic job. > > Bien à vous, > Fabrice > > > -----Message d'origine----- > De : Christian Grün [mailto:christian.gruen at gmail.com] > Envoyé : lundi 15 décembre 2014 20:25 > À : Fabrice Etanchaud > Cc : basex-talk at mailman.uni-konstanz.de > Objet : Re: [basex-talk] RESTXQ - access to InitParameters of > ServletContext and/or ServletConfig > > Hi Fabrice, > >> I would like to get InitParameters of the ServletContext or >> ServletConfig instances, > > The servlet init parameters are currently accessed by the BaseX itself [1,2], but there is no way to retrieve them from RESTXQ. > > Well, that's only partially true. One way to reach the ServletContext init parrameters is to: > > • Write a Java class that extends QueryModule [3] • Access > queryContext.http in that class (see e.g. [4]) • Call > http.req.getServletContext().getInitParameterNames() > > I am not sure, though, if that also works for the ServletConfig parameters (maybe you know?). > > What do you want to do with that information? What parameters are you interested in? > Christian > > [1] > https://github.com/BaseXdb/basex/blob/master/basex-api/src/main/java/o > rg/basex/http/BaseXServlet.java#L38 > [2] > https://github.com/BaseXdb/basex/blob/master/basex-api/src/main/java/o > rg/basex/http/HTTPContext.java#L421 > [3] http://docs.basex.org/wiki/Java_Bindings#Context-Awareness > [4] > https://github.com/BaseXdb/basex/blob/master/basex-api/src/main/java/o > rg/basex/modules/Session.java#L142
CG
Quoted text · Fabrice Etanchaud · 1 line
> Sorry, I can't speak German, you know how French people are :-(
But something must have gone wrong: Your English is pretty good ;)
Cheers,
Christian
Quoted text · Fabrice Etanchaud · 60 lines
> -----Message d'origine----- > De : Christian Grün [mailto:christian.gruen at gmail.com] > Envoyé : mardi 16 décembre 2014 16:10 > À : Fabrice Etanchaud > Cc : basex-talk at mailman.uni-konstanz.de > Objet : Re: [basex-talk] RESTXQ - access to InitParameters of ServletContext and/or ServletConfig > > Hi Fabrice, > >> How would you initialize persisting variables like a jdbc connection ? > > You could simply use the doc(...) function in XQuery and access the document from your web application directory. One more way would be to store the data in a database instance, but this is probably too much of an overhead in your case. > > J'espère avoir pu t'aider, > Christian > > >> >> Thank you again for your fantastic job. >> >> Bien à vous, >> Fabrice >> >> >> -----Message d'origine----- >> De : Christian Grün [mailto:christian.gruen at gmail.com] >> Envoyé : lundi 15 décembre 2014 20:25 >> À : Fabrice Etanchaud >> Cc : basex-talk at mailman.uni-konstanz.de >> Objet : Re: [basex-talk] RESTXQ - access to InitParameters of >> ServletContext and/or ServletConfig >> >> Hi Fabrice, >> >>> I would like to get InitParameters of the ServletContext or >>> ServletConfig instances, >> >> The servlet init parameters are currently accessed by the BaseX itself [1,2], but there is no way to retrieve them from RESTXQ. >> >> Well, that's only partially true. One way to reach the ServletContext init parrameters is to: >> >> • Write a Java class that extends QueryModule [3] • Access >> queryContext.http in that class (see e.g. [4]) • Call >> http.req.getServletContext().getInitParameterNames() >> >> I am not sure, though, if that also works for the ServletConfig parameters (maybe you know?). >> >> What do you want to do with that information? What parameters are you interested in? >> Christian >> >> [1] >> https://github.com/BaseXdb/basex/blob/master/basex-api/src/main/java/o >> rg/basex/http/BaseXServlet.java#L38 >> [2] >> https://github.com/BaseXdb/basex/blob/master/basex-api/src/main/java/o >> rg/basex/http/HTTPContext.java#L421 >> [3] http://docs.basex.org/wiki/Java_Bindings#Context-Awareness >> [4] >> https://github.com/BaseXdb/basex/blob/master/basex-api/src/main/java/o >> rg/basex/modules/Session.java#L142
Written for BaseX 7.9. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery