extending java from coldfusion - cfunited 2010
Post on 17-Jul-2015
141 Views
Preview:
TRANSCRIPT
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Rupesh Kumar July 25th 2010
http://www.rupeshk.org/ : rukumar
Extending Java with ColdFusion
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Agenda
Objective
Using Java from CFML
Leveraging ColdFusion Features from Java
Areas to watch out for
ColdFusion as a Service (CFaaS)
Q&A
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
ColdFusion is Java
3
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
ColdFusion is Java
ColdFusion applications are developed in CFML (and likely take
advantage of Java, XML, SOAP, and more).
At runtime ColdFusion applications are pure Java.
A J2EE server (internal or external)
… running a Java application (the ColdFusion engine)
… invoking Java code (CFML code compiled to Java bytecode).
CFML exists only at developer time, runtime is pure Java (and deployed
like any other Java application).
CFML source need not be present at runtime.
Applications may be packaged and deployed like any other Java
applications.
4
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
5
ColdFusion Leverages Underlying Java
Connectivity
Security
Management
Transactions
Directory
JEE ApplicationServer
Java App #1
ColdFusion
Java App #2
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 6
JEE Services
Java Runtime
Presentation(HTML, Reporting, PDF Generation, AJAX, Flash Forms)
Database
Connectivity
Document
ServicesPDF/Excel/P
PT/
Word
Network
Services(http, ftp, mail
–
smtp/pop/ima
p)
Enterprise
Services(Exchange,
Sharepoint)
SOA
connectivity(WebServices
FDS, Flash
Remoting)
Event
Gateways(IM, JMS
SMS)
ColdFusion Runtime
CFML Compiler
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
ColdFusion is Java…
ColdFusion Type Java Type
String String
Number Double
Boolean Boolean
Array List/Vector
Struct Map
Date Date
Query coldfusion.sql.QueryTable
7
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Why CF + Java?
ColdFusion and Java complement each other
ColdFusion Java
Take advantage of wide set of Java libraries available
Extend ColdFusion features
Functionalities that are not baked in ColdFusion could be available in Java
J2SDK APIs
There are tons of libraries shipped with ColdFusion – Apache POI, EhCache, Hibernate, iText, webchart etc
Other libraries -
Java ColdFusion
Productivity
Easy to learn.
Rapid development.
Huge number of Services available readymade.
Leverages standards and existing IT and training investments.
8
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 9
ColdFusion Integrated Services
Database connectivity
Full text searching (Verity and Solr)
Printing (PDF)
Document Services (PDF, Excel,
Word, PPT)
Reporting (PDF, FlashPaper, RTF,
Excel, HTML, XML)
Graphing and Charting
E-Mail (POP, IMAP and SMTP)
Exchange
XML manipulation
Including XSL and XPath
Imaging
Sharepoint
Flash Remoting
Server-side HTTP and FTP
LDAP client
Windows NT/AD authentication
Gateways
Socket
JMS
Instant messaging (including XMPP)
SMS
Asynchronous processing
S3 Storage Service
RSS Feed
Java, COM, .NET, CORBA client
… and more
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
ColdFusion Java
Java CFX Tags
JSP and Servlets
JSP Tag Libraries
Direct Invocation
10
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Direct Invocation
Object Creation
createObject(“java”, className)
<CFOBJECT type=“Java” class=“className” name=“variable”>
Method invocation
obj.foo(arg1, arg2,..)
Constructors – use init
<cfobject type=”java” class=”java.lang.StringBuffer” name=”buff”><cfset buff.init(“CFUnited”)>
Calling methods
<cfset buff.append(“2010”)>
Static method
no need to init() to call static method
integer = createObject(“Java”, “java.lang.Integer”);intval = integer.parseInt(“10”);
11
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Java Invocation – class loading ColdFusionJava
ColdFusion’s java invocation needs class to be loaded by ColdFusion
classloader
Classes need to be placed in a pre-defined directory
CF Classloader will pick up from <cf_root>/lib folder
Parent i.e web application classloader will pick up from <cf_root>/WEB-INF/lib
One might not have permission to do this
Classes cannot be changed at runtime.
Server must be restarted to pick up the change
They cannot be application specific
You cannot have multiple versions of the same library in the server
12
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
JavaLoader ColdFusionJava
Project by Mark Mandel :
http://www.compoundtheory.com/?action=javaloader.index
Dynamically loads java libraries using its own classloader
Create JavaLoader object
createObject("component","javaloader.JavaLoader").
init(loadPaths [,loadColdFusionClassPath]
[,parentClassLoader]);
Loadpaths : Array of jars or class directories
loadColdFusionClasspath : true|false whether ColdFusion classloader will be
the parent classloader
parentClassLoader : the parent classloader object
Create object
javaloader.create(className).init(arg1, arg2...);
13
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Java Invocation.. ColdFusionJava
Watch out for
Overloaded constructors and methods
Resolve ambiguity using javacast – javacast(“datatype”, data)
Java is case sensitive. Classname must be in the correct case
For method invocation, it is better to use the correct case.
14
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Demo
15
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Java ColdFusion
CFCProxy
TemplateProxy
Dynamic Proxy
WebServices (SOAP and REST)
CFC methods over HTTP
ColdFusion as a Service (CFaaS)
Event Gateway
16
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
CFC Proxy
Allows Java to directly invoke CFC methods
CFCProxy
new CFCProxy(“path to cfc");
invoke(String method, Object[] args)
Example
CFCProxy myCFC = new CFCProxy("C:\\test.cfc");
Object[] args = {"CFUnited"};
Object greeting = myCFC.invoke("greet", args);
ColdFusion classloader should be the context classloader
Works with cfc’s absolute path
17
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
TemplatePoxy
Use this when invoked from CF request
Works with cfc’s absolute path as well as cfc’s fully qualified name.
Create using TemplateProxyFactory
TemplateProxy proxy = TemplateProxyFactory.resolveFile(pageContext, file)
TemplateProxy proxy = TemplateProxyFactory.resolveName(cfcName,
pageContext)
Invoke
invoke(String method, Object[] args, PageContext ctx)
18
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Dynamic Proxy
Part of JavaLoader 1.0
Makes CFCs behave like Java classes or impl for Java interfaces
Allows java objects to call cfc methods seamlessly
Java Frameworks relying on certain contract can leverage CFC
DynamicProxy = javaloader.create(
"com.compoundtheory.coldfusion.cfc.CFCDynamicProxy");
DynamicProxy.createInstance(cfc, interfaces)
DynamicProxy.createInstance(pathToCFC, interfaces)
19
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
CFC methods over HTTP
A remote method can be invoked directly using http
Component
{
remote String function greet(arg)
{
return "Hello " & arg;
}
}
Invoke using url
http://localhost:8500/cfunited/hello.cfc?method=greet&a
rg=cfunited
20
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
WebService
CFC methods exposed as webservice
Component style="document" {remote String function greet(arg){
return "Hello " & arg;}
}
Generate the Java proxies from wsdl
Axis – Use WSDL2Java
java org.apache.axis.wsdl.WSDL2Java –p cfunited.hello http://localhost:8500/Hello.cfc?wsdl
HelloServiceLocator locator = new HelloServiceLocator(); cfunited.axis.hello.Hello helloCfc = locator.getHelloCfc();String msg = helloCfc.greet("CFUnited 2010");
Java SE6 now natively supports webservices
Wsimport
wsimport http://localhost:8500/cfunited/hello.cfc?wsdl -d c:\work\cfunitedemo\classes -s c:\Work\cfunitedemo\src\ -p cfunited.hello
HelloService helloService = new HelloService();Hello helloCfc = helloService.getHelloCfc();String msg = helloCfc.greet("CFUnited 2010");
21
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
ColdFusion as a Service
CFChart
CFDocument
CFImage
CFMail
CFPop
CFPdf
22
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Setup for CFaaS
Enable services in the admin
Define IPs for access
Admin>>security >> Allowed IP Address
Define users who have permission
Admin>> security >> User Manager >> add User >> Exposed Services
23
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 24
CFImage
• negative()
• rotate()
• blur()
• grayScale()
• scaletoFit()
• resize()
• overlay()
• flip()
• sharpen()
• shear()
• crop()
• addBorder()
• batchOperation()
getEXIFTAG()
getHeight()
getWidth()
info()
getIPTCTag()
getIPTCMetadata()
getEXIFMetaData()
http://localhost:8500/CFIDE/services/image.cfc?wsdl
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 25
CFPDF
protect()
thumbnail()
processDDX()
extractText()
extractImage()
setinfo()
mergeFiles()
addwatermark()
extractPages()
getinfo()
mergespecificpages()
deletepages()
removewatermark()
http://localhost:8500/CFIDE/services/pdf.cfc?wsdl
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Other Services
CFChart
http://localhost:8500/cfide/services/cfchart.cfc?wsdl
generate()
CFDocument
http://localhost:8500/cfide/services/document.cfc?wsdl
Generate()
CFMail
http://localhost:8500/cfide/services/mail.cfc?wsdl
Send()
CFPOP
http://localhost:8500/cfide/services/pop.cfc?wsdl
delete()
getAll()
getHeaderOnly()
26
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Summary
27
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Q & A
Q & A
rukumar@adobe.com
http://www.rupeshk.org
rukumar
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
top related