building server-side eclipse based web applications
TRANSCRIPT
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license1
Building Server-Side Eclipse based web applications
Tutorial
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license
The authors
Jochen HillerDeutsche Telekom AG, [email protected]
Simon KaegiIBM Rational Software, [email protected], E4 Committer
Gunnar WagenknechtAGETO, [email protected] Committer
2
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license
Overview
• Introduction to Server-Side Eclipse
• Developing Server-Side Eclipse applications
• Deploying Server-Side Eclipse applications
• Monitoring and Debugging Server-Side Eclipse applications
• Summary
3
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license
What is Server-Side Eclipse (SSE)?• Recognition… that many of the features that have made RCP successful are
equally applicable in server-side contexts.Standardized component model (OSGi)Pervasive extensibility – Extension RegistryRuntime provisioning
• Integration... with existing server-side infrastructure and technologiesJ2EE Application ServersServlets and JSPsApplication Frameworks…
• Jeff McAffer stated at EclipseCon 2007, Equinox BOF:Server-Side Eclipse is a concept, a marketing name, to illustrate possible usage scenarios (like RCP).
• The new top level project Eclipse Runtime is an umbrella project for a lot of server-related projects
4
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license
What motivates developers to use SSE?
JavaTM EEapplication
RCPapplication
+ component model+ use 3rd party plug-ins
Web developer
+ server support+ re-use plugins+ distributed
applications
RCP developer
applicationframework
+ component model• modular• flexible• dynamic
Infrastructure developer
5
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license
SSE Based Web Applications
• Component based (Bundles)
• Use the OSGi HttpService (Servlet API)Explicitly (code) or declaratively (extension registry)
• Consistent development story independent of deployment constraints
Support for an embedded HttpServiceSupport for running embedded in Application Servers
6
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license
Overview
• Introduction to Server-Side Eclipse
• Developing Server-Side Eclipse applications
• Deploying Server-Side Eclipse applications
• Monitoring and Debugging Server-Side Eclipse applications
• Summary
7
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license
Integrating Java EE with the OSGi HttpService
• Replaces web deploy descriptor (e.g. “web.xml”)• URL mapping differences• Servlet API support
ServletContext / HttpContext differencesDoes not provide “direct” support for Filters, Listeners.
• Dynamic Registrationvoid registerResources(String alias, String name, HttpContext context) void registerServlet(String alias, Servlet servlet, Dictionary initparams, HttpContext context)void unregister(String alias)
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license
URL Mapping Differencesvoid registerResources(String alias, String name, HttpContext context)
• “alias” roughly equivalent to <url-mapping>alias of “/myContent” is equivalent to <url-mapping>
/myContent/*</url-mapping>
• “name” provides a base path when looking up resources in the HttpContext.
• No support for extension mappings
• No implicit welcome file supporteg. mapping “/” to “/index.html”
Supported in Equinox
Syntax is:{path}/*.jsp
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license
HttpContext• Maps 1-1 to a ServletContext
• Allows implementation of custom HttpContext
• MIME type retrieval • resource retrieval• authentication
• Does not directly support:getNamedDispatchergetResourcePathsgetInitParameters (*)“Context Path” (*)
Method Summary
String getMimeType(String name)
URL getResource(String name)
boolean handleSecurity(HttpServletRequest request, HttpServletResponse response)
Supported in Equinox (via Reflection)
Set getResourcePaths(String path)
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license
Servlets and FiltersWhat’s missing…
• Filter (*)
• HttpSessionListener• HttpSessionAttributeListener• HttpSessionActivationListener
• ServletContextListener (*)• ServletContextAttributeListener
• ServletRequestListener• ServletRequestAttributeListener
(*) = Workarounds Available:
• Technique is to wrap-and-adapt your Servlet or Resource.
Servlet wrapped = new ContextListenerServletAdaptor(
myServlet, myListener);registerServlet(“/myPath”, wrapped, params, myHttpContext);
• See org.eclipse.equinox.http.helper[s]in the Equinox-Incubator CVS
• not currently API but supported
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license
Dynamic RegistrationTwo main techniques:• Code-based
Lifecycle: tied to Bundle START and STOPMore Complex but provides greater control
• Extension Registry (org.eclipse.equinox.http.registry)Lifecycle: tied to Bundle RESOLVED and UNRESOLVEDSimpler in most cases
• Declarative Services / Spring
URL Space is also dynamic and shared across all registrationsNo more than one registration per “alias”Worth planning – useful techniques with relative URLs
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license
JSP Support
• Provided by:org.eclipse.equinox.jsp.jasper.JspServlet
<< public JspServlet(Bundle bundle, String bundleResourcePath, String alias) >>
• No default constructor
• Requires compilation / runtime context from “bundle”• JSP lookup consistent with OSGi HttpService resource
registration.
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license
JSP Support – Extension Registry• Extension Registry Support provided by:
org.eclipse.equinox.jsp.jasper.registry.JspFactory• ExecutableExtensionFactory
<!--* © Copyright 2007 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corp.; All rights reserved. This source code is made available under the terms of the Eclipse Public License, v1.0. -->
<extensionpoint="org.eclipse.equinox.http.registry.servlets">
<servletalias="/myPath/*.jsp“class="org.eclipse.equinox.jsp.jasper.registry.JSPFactory:/bundlePath">
</servlet></extension>
• Use “{path}/*.jsp” style alias for JSPs.Allows a “{path}” resource registration to support more efficiently serving static resources without an alias namespace collision.
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license
Exercises
• Start Eclipse & configure target platform• Hello Servlet• Hello JSP• Hello Servlet Registry• Hello JSP Registry
15
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license
Overview
• Introduction to Server-Side Eclipse
• Developing Server-Side Eclipse applications
• Deploying Server-Side Eclipse applications
• Monitoring and Debugging Server-Side Eclipse applications
• Summary
16
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license
Recommended deployment scenarios
Deployment depends on target infrastructure:
• Standalone Equinox server applicationEmbedded HttpServiceLightweight solution – good choice for developmentDistribute like Eclipse RCP application
• Run application in External Application ServerRecommended as production solutionDeploy as standard WAR application (scripts provided)
17
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license
Equinox embedding an HttpService• Run Equinox as standalone application• Multiple processes isolated• Embedded HttpService (e.g. Jetty)• Application functionality based on bundles, Servlets, JSPs, ...• Add web services as bundle• Server management based on bundles
Source: Jeff McAffer, Eclipse Summit Europe, Server-Side Symposium, Oct 12nd 2006
18
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license
Deploying standalone Equinox server
• Choose target platform• Add platform specific launchers if required• Add common services and bundles (see Eclipse Orbit!)• Add application plug-ins• Group bundles / plug-ins as features
Application plug-ins
Common services(see Orbit)
Server-Side EclipseEquinox
Operating System
Jetty
Servlet JSP
Jasper
Bundles
commons-logging, ...
...
3rdParty UpdateConfigurator
...
Laun
cher
19
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license
Deploying Standalone Equinox server• Deploy like an RCP application
Plugins / Feature / Product based exportYou have to include SSE related pluginsMaintain config.ini for starting bundles
• Important config.ini settings:osgi.console=true # start an OSGi consoleosgi.noShutdown=true # do NOT shutdown OSGieclipse.ignoreApp=true # do NOT start an Eclipse application
• Or use commandline arguments when using Eclipse starter:-console # enable OSGi console-noExit # same as osgi.noShutdown=true-application <id> # start application with <id>
20
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license
Deploy Standard Equinox – Running the Server
•Start Equinox serverjava –Dorg.osgi.service.http.port=8080 \
–jar plugins\org.eclipse.equinox.launcher_<version>.jar \–console -noExit
21
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license
Application Server running an embedded Equinox
• Launch Equinox in traditional application server• Isolation between multiple web applications/Equinox instances• Forwarding (Lite) HttpService exposes application server
capabilities• Application functionality based on bundles, Servlets, JSPs, ...• Bridging aspect is referred to as the Servletbridge
22
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license
What is the Servletbridge?
Servlet - side• Eclipse framework launcher• Bridge Servlet with a call-back
registration point
OSGi - side• Proxy Servlet that registers with
Bridge Servlet• OSGi HttpService
Servlet OSGi
… a bridge between the servlet and OSGi world
Framework Launcher HttpService
Proxy ServletBridge Servlet1
2
3
4
5
23
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license
What is the Servletbridge?
Servletbridge
Servlet OSGi
Incoming Request Registered Request Handler
OSGi HttpServiceregisterResource(…)
registerServlet(…)
Incoming requests are “proxied” through the Servletbridge to registered request handlers.
24
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license
Deploying Equinox Inside an Application Server
• Deploy similar to an RCP application but in a Web Archive/WEB-INF
/web.xml (with one servlet entry assigning all incoming requests to the BridgeServlet) /lib/servletbridge.jar (the classes associated with the equinox.servletbridge) /eclipse (the eclipse platform directory)
launch.ini (contains framework properties that will allow override of any eclipse specific System Properties)
/configuration (contains config.ini which lists the bundles you want to have available at startup)
/features /plugins
• org.eclipse.equinox.servletbridge Project/scripts/webappBuilder.xml (Ant Script for building WAR file)/templates (contains the WAR directory structure)
25
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license
Deploying Equinox inside Application Server
• Online Demo
26
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license
Exercises
• Create feature for build/export• Export standalone server using product export• Create & deploy WAR file using Servlet bridge
27
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license
Overview
• Introduction to Server-Side Eclipse
• Developing Server-Side Eclipse applications
• Deploying Server-Side Eclipse applications
• Monitoring and Debugging Server-Side Eclipse applications
• Summary
28
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license
Logging in Equinox Jetty 6 Integration
• Jetty logging now controllable in 3.5
• -Dorg.eclipse.equinox.http.jetty.log.stderr.threshold=<level>
"debug", "info", "warn", "error", and "off“Default is “warn”
• Log will happen to STDERR only (for now)
• Outlook: deeper integration with Extended Equinox Log Service (3.6)
29
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license
Debugging: Where to hook in
•Hook either inOSGi worldServetBridge
•Startup problems:FrameworkLauncher
•Central access: ProxyServlet
Hook in processAlias
30
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license
Servlet Bridge Management Commands
“web.xml” allows configuration of initial parameters:• commandline Allows all non-VM command line parameterizations of Eclipse.
The default value is "-console“ which should be cleared for production.• enableFrameworkControls (true / false) - Controls whether or not the sp_* control URLs are
accessiblesp_deploy - Copies the contents of /platform to the install area (the servlet context tempdir is used -parameterizable someday) sp_undeploy - Removes the copy of Eclipse from the install area sp_redeploy - Resets the platform (e.g. stops, undeploys, deploys, starts) sp_start - Starts a deployed platform sp_stop - Stops the platform sp_test - Provides a sanity check and determines if an OSGi based servlet is ready to accept requests
• frameworkLauncherClass – allows customization of the launcher• extendedFrameworkExports – additional java package exports from the web application.
Servlet API is automatically exported.
31
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license
Knopflerfish HTTP Console
• Provides convenient way to manage bundles at runtime
• Works within Servlet Bridge
32
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license
Overview
• Introduction to Server-Side Eclipse
• Developing Server-Side Eclipse applications
• Deploying Server-Side Eclipse applications
• Monitoring and Debugging Server-Side Eclipse applications
• Summary
33
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license
Summary - Looking forward...• Eclipse >3.3 supports building OSGi based web applications for:
Equinox based RCP and headless applicationsEquinox embedded in an application server
• Outlook for Eclipse 3.5Jetty 6
• Jetty joined Eclipse much tigther integration expected
• Outlook for OSGi Spec workEnterprise Expert GroupHttp Service according 2.5 Spec“WebContainer” alike support, but with OSGi dynamics
34
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license
For more information...
Project hub:http://www.eclipse.org/equinox/server
Newsgroup:news://news.eclipse.org/eclipse.technology.equinox
Dev Mailing List:[email protected]
Thank-you
35
Building Server-Side Eclipse based web applications | Tutorial© Copyright 2007, 2008, 2009 Jochen Hiller, Simon Kaegi, Gunnar Wagenknecht, IBM Corporation; Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license
Legal Notices• Java and all Java-based trademarks are trademarks of Sun
Microsystems, Inc. in the United States, other countries, or both
• Microsoft, Windows, Windows NT, and the Windows logo are trademarks of Microsoft Corporation in the United States, other countries, or both.
• Linux is a registered trademark of Linus Torvalds in the United States, other countries, or both.
• Other company, product, or service names may be trademarks or service marks of others
36