Data Exchange CFML-Java: Using Session and/or Application Variables

40 views
Skip to first unread message

verlsnake

unread,
Jun 7, 2011, 6:42:48 AM6/7/11
to Railo
I would like to have the capability to exchange data between UNRELATED
CFML and Java code; possibly using Session and/or Application
Variables ! Is there an approach for this provided by OpenBD ?

Along the following lines:
- In a .cfm file, do this:
- <cfset session["sharedSessionVar"] = "sharedSessionVarValue" />

- In a .java file, do this:
- String sharedSessionVar =
session.getAttribute("sharedSessionVar");
- The Java variable sharedSessionVar should have the value
"sharedSessionVarValue" then

Jay

unread,
Jun 7, 2011, 10:44:25 AM6/7/11
to ra...@googlegroups.com
you should probably start with getPageContext() -- then get a reference to the java Request object, and from there you can get a reference to the Session object.

if you'll do a dump on getPageContext() you will find the method signatures you want to use:
<cfdump var="#getPageContext()#" label="getPageContext()">


see also Java Servlet API at:

Michael Offner

unread,
Jun 8, 2011, 11:23:50 AM6/8/11
to ra...@googlegroups.com
Railo has a central entry point for interaction with Railo, the "CFMLEngine".
to get the CFML engine call the following static method:
railo.loader.engine.CFMLEngineFactory.getInstance();

Below you can find some examples of what the CFMLEngine provide, here you can find the Javadoc for it

/micha

some examples:

CFMLEngine engine = CFMLEngineFactory.getInstance();

 

  // using scopes/variables

  PageContext pc = engine.getThreadPageContext();// return the PageContext of the current thread (id there is a PC for this thread)

  pc.variablesScope();

  pc.sessionScope();

  pc.applicationScope();

  pc.requestScope();

  pc.setVariable("session.susi", "Susanne");

  pc.getVariable("session.susi");

 

  // create objects

  Creation creator = engine.getCreationUtil();

  creator.createArray();

  creator.createArray(1);

  creator.createQuery(new String[]{"firstname","lastname"}, 1, "fullname");

 

  // decision

  Decision decision = engine.getDecisionUtil();

  if(decision.isDate(obj,false) || decision.isStruct(obj));

 

  // operation

  Operation op = engine.getOperatonUtil();

  if(op.compare(left, right)); //cfml comparision rules

 

  // caster

  Cast caster = engine.getCastUtil();

  caster.toArray(obj);

  caster.toStruct(obj);

 

  // exception

  Excepton exp = engine.getExceptionUtil();

  if(cont)throw exp.createAbort();

  else throw exp.createApplicationException("this is wrong","you cannot ...");

 





2011/6/7 verlsnake <k...@kaitischler.de>

Jay

unread,
Jun 8, 2011, 12:00:10 PM6/8/11
to ra...@googlegroups.com
nice! :))

verlsnake

unread,
Jun 20, 2011, 9:18:49 AM6/20/11
to Railo
Thanks for this valuable input !

@Jay: Your hint allows me now to exchange data between Java and
CFML !

Concrete Code:
- In CFML:
getPageContext().getSession().setAttribute("attributeKey",
attributeValue);

- In Java:
Object attributeValue = session.getAttribute("attributeKey");



@Micha: My concrete Java Code at hand is an extension of a Servlet
Class; I have played around a little bit with the CFMLEngine approach:
- PageContext pc = engine.getThreadPageContext(): returns null
pointer, i.e. there is no PageContext in my use case
- I then tried to get a PageContext object via the following methods:
- CFMLFactory factory = engine.getCFMLFactory(...)
- PageContext pc = factory.getRailoPageContext(...)
- Both methods have signatures which I was obviously not able to cater
to ...
- I have the following two objects at my disposal:
- HttpServletRequest request
- HttpServletResponse response


Question: Is it possible to use the CFMLEngine approach in my use
case, too ? If yes: How could I get a valid PageContext object ?
Reply all
Reply to author
Forward
0 new messages