3

I need to access WEB-INF files content in Lotus Notes database by using Java or Lotus Script: WebContent\WEB-INF\jdbc\DB2Connect.jdbc

XPages are using these properties to connect DB2 database. But I need a Java agent that would use same properties in DB2Connect.jdbc file (user name/password) to connect DB2 and do some routine task.

enter image description here

VladP
  • 881
  • 2
  • 13
  • 37
  • Could you use a file resource instead which would be accessible from both? – Steve Zavocki Feb 10 '15 at 18:10
  • How can I use file resource to declare DB2 connection for XPage? I would use WEB-INF source. – VladP Feb 10 '15 at 18:15
  • See http://stackoverflow.com/questions/4340653/file-path-to-resource-in-our-war-web-inf-folder/4342095#4342095 – Berin Loritsch Feb 10 '15 at 18:16
  • I am only suggesting that it is possible, I have never done this. For XPages only web-inf is best, but if you need to share the file then something inside the NSF will be accessible to the agent. I am guessing that you can write similar java (as your agent) to read the file and write the values to a scoped variable for XPages use. – Steve Zavocki Feb 10 '15 at 18:24

1 Answers1

1

You can't access files within the nsf from an Java agent.

An Java agent lives in it's own "world". It has included all Java classes, Java archives, Java libraries and all resources.

You could probably access the file via http.

It might be easier though to just copy this one file into the agent's resource folder with "Import / Resource". You would access the file with

 InputStream is = this.getClass().getResourceAsStream("/DB2connect.jdbc");
Knut Herrmann
  • 30,880
  • 4
  • 31
  • 67
  • but how xPages access these files in WEB-INF directory? Assume java agents can access them as well – VladP Feb 11 '15 at 02:44
  • DB2Connect.jdbc file is used in XPages SSJS with `@JdbcInsert("DB2Connect", ...` , `@JdbcUpdate("DB2Connect", ...` and `@JdbcDelete("DB2Connect", ...`. Have a look at this tutorial about integrating DB2 in XPages http://johnjardin.ukuvuma.co.za/2012/02/29/tutorial-integrating-xpages-with-db2-part-1/ – Knut Herrmann Feb 11 '15 at 06:36
  • Sorry.. I meant xPages can access it.. but why I cannot access it by Java? – VladP Feb 11 '15 at 14:10
  • Because Java agent runs in its own environment. You can use Sven's hack with undocumented methods OR try to access file with http OR just copy it into the Java agent. The latter would be my prefered way as it is just one little file. – Knut Herrmann Feb 11 '15 at 14:47
  • I want this file be used by both xPages and Java agent.. So this is why I put all info into WEB-INF folder.. especially for xPages.. – VladP Feb 11 '15 at 15:15