+ All Categories
Home > Documents > © 2008 IBM Session ID: D19 Session Title: Annotated Portal Development with RAD and Spring...

© 2008 IBM Session ID: D19 Session Title: Annotated Portal Development with RAD and Spring...

Date post: 29-Dec-2015
Category:
Upload: olivia-powers
View: 219 times
Download: 1 times
Share this document with a friend
41
© 2008 IBM Session ID: D19 Session Title: Annotated Portal Development with RAD and Spring Speaker(s): Ken Sipe, Technology Director, Perficient Peter Blinstrubas, IBM Americas Portal Leader WebSphere Portal Technical Conference U.S. 2008
Transcript

© 2008 IBM

Session ID: D19Session Title: Annotated Portal Development

with RAD and Spring

Speaker(s): Ken Sipe, Technology Director, Perficient

Peter Blinstrubas, IBM Americas Portal Leader

WebSphere Portal Technical Conference U.S. 2008

STORY TITLE

WebSphere Portal Technical Conference U.S. 200822

Abstract

This session will show off the paradigm shift in portlet development which comes with Spring annotations.  

The session will also demonstrate how to unit test the portlets without a portal server running.  

This session is intended for developers already familiar with portlet development who want to improve their productivity and test their work

2

STORY TITLE

WebSphere Portal Technical Conference U.S. 200833

Agenda

Portlets

Anatomy of a Portlet Productivity Pain Points

Annotations

What are Annotations? Spring

What is Spring Spring 2.5 Annotations

Portlet + Spring Annotation Development

Better Development Paradigm Better Testing Paradigm

3

© 2008 IBM

Portal and Portlets

4

STORY TITLE

WebSphere Portal Technical Conference U.S. 200855

Portal Anatomy - External

5

Client Device

Portal Page

<Portlet D Content>

<Title>

<Portlet B Content>

<Title>

<Portlet A Content>

<Title>

<Portlet C Content>

<Title>

Portlet

Window

Portlet

Fragment

Portlet

Modes &

Controls

Portal Server

Portlet A

Portlet B

Portlet C

PortletContainer

Portlet D

Client Device

Portal Page

<Portlet D Content>

<Title>

<Portlet B Content>

<Title>

<Portlet A Content>

<Title>

<Portlet C Content>

<Title>

Portlet

Window

Portlet

Fragment

Portlet

Modes &

Controls

Portal Server

Portlet A

Portlet B

Portlet C

PortletContainer

Portlet D

STORY TITLE

WebSphere Portal Technical Conference U.S. 200866

Portlet Anatomy - Internal

These interfaces shape your role in the container and resources available from the container

Portlet PortletConfig PortletContext PortalContext

STORY TITLE

WebSphere Portal Technical Conference U.S. 200877

Portlet Interface

package javax.portlet;Public interface Portlet { void destroy(); void init(PortletConfig config); void processAction(ActionRequest req, ActionResponse res); void render(RenderRequest req, RenderResponse res);}

7

STORY TITLE

WebSphere Portal Technical Conference U.S. 200888

Portlet Functionality

Similar to Servlets

Managed by container Generate dynamic content Life-cycle managed

Differences from Servlets

Generate Markup fragments Not Directly addressable Persistence storage for preferences Request Processing Portlet Modes Window State

• Minimized, etc. User Information

8

STORY TITLE

WebSphere Portal Technical Conference U.S. 200899

Portlet Coding Difference 1: Request Processing

Request processing comes in two forms:

Action Requests

Render Requests

Each client request invokes at most one action request

Each client request may invoke any number of render requests, depending on layout, caching, and other factors

A portlet may be rendered many times between action requests

Unlike servlets, portlets are not bound to a logical location (URL)

STORY TITLE

WebSphere Portal Technical Conference U.S. 20081010

Portlet Modes

View mode

doView(…) Normal Display

Edit mode

doEdit(…) Configuration mode of the portlet

• Location details• Personal preferences

Help mode

doHelp(…)

© 2008 IBM

Simple HelloWorld Portlet Example

11

STORY TITLE

WebSphere Portal Technical Conference U.S. 20081212

Portal Tool Features v7.x

Streamlined Portlet Wizard

Co-operative Wizard Usability improvement.

Enhanced Credential Vault Support.

JSR 168 and JSR 286

STORY TITLE

WebSphere Portal Technical Conference U.S. 20081313

Hello World Portlet

public class HelloWorld extends GenericPortlet {

protected void doView(RenderRequest request,

RenderResponse response) throws

PortletException, IOException {

response.setContentType(“text/html”);

response.getWriter().println(“Hello Portlet”);

}

STORY TITLE

WebSphere Portal Technical Conference U.S. 20081414

Pain Points

Code Dependency on Portlet

Not POJO Management and Dependency on the View Technology

Execution Model

Action Request Render Request

Portlet Modes

View Edit Help

© 2008 IBM

Spring

Spring MVC Portal

15

STORY TITLE

WebSphere Portal Technical Conference U.S. 20081616

What is Spring?

IoC

Generic Bean Factory

Abstraction from other frameworks

Removes croft from developer code Provides typology freedom

• Develop on Tomcat, deploy to WebSphere Provides Testability

• No need for in the container testing• Framework ties are in the spring framework

16

STORY TITLE

WebSphere Portal Technical Conference U.S. 20081717

Heart of Spring MVC

DispatcherPortlet

Defined in the portlet.xml file Controller for portlet Multiple may be defined in a single portlet.xml file

Name of defined portlet is the key to the configuration file (by default)

springportlet-portlet.xml

STORY TITLE

WebSphere Portal Technical Conference U.S. 20081818

Spring Portlet XML File

Defines Controller and other Spring Beans

Maps Controller for each mode

STORY TITLE

WebSphere Portal Technical Conference U.S. 20081919

Spring Portlet Controller

import javax.portlet.RenderRequest;

import javax.portlet.RenderResponse;

import org.springframework.web.portlet.ModelAndView;

import org.springframework.web.portlet.mvc.AbstractController;

public class ViewController extends AbstractController {

protected ModelAndView handleRenderRequestInternal(RenderRequest request, RenderResponse response) throws Exception {

return new ModelAndView("View");

}

}

STORY TITLE

WebSphere Portal Technical Conference U.S. 20082020

Spring View Mapping

<bean id="viewResolver“ class=

"org.springframework.web.servlet.view.InternalResourceViewResolver">

<property name="viewClass">

<value>org.springframework.web.servlet.view.JstlView</value>

</property>

<property name="prefix">

<value>/WEB-INF/jsp/</value>

</property>

<property name="suffix">

<value>.jsp</value>

</property>

</bean>

STORY TITLE

WebSphere Portal Technical Conference U.S. 20082121

Changes to Web.xml

ContextLoaderListener

Listener to bootstap spring ViewRendererServlet

Front Controller for Spring Portlet MVC

STORY TITLE

WebSphere Portal Technical Conference U.S. 20082222

Spring applicationContent.xml

Required by ViewRendererServlet

Provides Shared Spring beans across portlets

STORY TITLE

WebSphere Portal Technical Conference U.S. 20082323

Spring Portlet MVC Setup

Jars: Spring

• Spring.jar, spring-webmvc-portlet.jar Logging

• Commons-logging.jar, log4j-1.2.14.jar Web

• Jstl.jar, standard.jar

Create portlet Configuration

Configure for Spring Portlet.xml with DispatcherPortlet Spring xml *-portlet.xml applicationContext.xml

Configure web.xml

Create Controller

Create Views

STORY TITLE

WebSphere Portal Technical Conference U.S. 20082424

Spring Portlet Benefits

Separates Portlet from View Technology

Spring Enables the Portlet

After Spring Wiring

Simple Code Model• Controller for multiple portlet modes• Controller for each portlet mode

24

© 2008 IBM

Spring 2.5 Annotations

25

STORY TITLE

WebSphere Portal Technical Conference U.S. 20082626

Java 5+ Annotations

Java 5 Introduces Annotations

New Type of Interface

Provides Metadata for: Compile time Runtime

Language Provides Built-in Annotations

• @Override

Ability to Define Custom Annotations

Annotation Creation

@Retention(RetentionPolicy.RUNTIME)public @interface Author { String name();}

Annotation Use

@Author ( name = "John Doe" )public class OrderDAO {// class code goes here}

26

STORY TITLE

WebSphere Portal Technical Conference U.S. 20082727

Spring 2.5 Annotations

JSR 250 - @PostConstruct, @Resource…

JAX-WS 2.0’s - @WebServiceRef

EJB 3.0 - @EJB

Test Enhancements - Junit 4.4 and TestNG

Stereotypes - @Component, @Controller…

Spring enhancements - @Autowired,

AOP - @Configurable

MVC annotations - @RequestParam, @RequestMapping…

27

STORY TITLE

WebSphere Portal Technical Conference U.S. 20082828

Spring 2.5 Context Annotations

@Scope

Indicates the scope to use for annotated class instances

Default == “singleton” Options:

• Singleton• Prototype

Web Options:• Request• Session• Global session

STORY TITLE

WebSphere Portal Technical Conference U.S. 20082929

Spring 2.5 Stereotypes

@Component **

Indicates that a class is a component Class is a candidate for auto-detection Custom component extensions

@Controller

Specialized Component Typically used with RequestMapping annotation Discussed in section on web mvc

@Repository

2.0 stereotype… previously mentioned Now an extension of @Component

@Service

Intended to be a business service facade

STORY TITLE

WebSphere Portal Technical Conference U.S. 20083030

Spring 2.5 Factory Annotations

@Autowired Marks a constructor, field, setter or config method for

injection. Fields are injected

• After construction• Before config methods

@Autowired(required=false) Config:

• AutowiredAnnotationBeanPostProcessor @Configurable

Marks class as being eligible for Spring-driven configuration

Used with AspectJ @Qualifier

Qualifies a bean for autowiring May be customized

@Required Marks a method as being injection required

© 2008 IBM

A World with No Editor Support

31

STORY TITLE

WebSphere Portal Technical Conference U.S. 20083232

Spring 2.5 MVC Annotations

@Controller

Stereotype used to “Controller” of MVC Scanned for RequestMappings

@RequestMapping

Annotates a handler method for a request Very flexible

@RequestParam

Annotates that a method parameter should be bound to a web request parameter

SessionAttributes

Marks session attributes that a handler uses

STORY TITLE

WebSphere Portal Technical Conference U.S. 20083333

@RequestMapping - Extreme Flexibility

Parameters can be Request / response / session WebRequest InputStream OutputStream @RequestParam +++

Return types ModelAndView Object Model Object Map for exposing model View Object String which is a view name Void… if method wrote the response content directly

STORY TITLE

WebSphere Portal Technical Conference U.S. 20083434

Spring 2.5 Controller Example

@Controllerpublic class ConfController { @Autowired private confDB confDB;

@RequestMapping("/sessionList") public String showSessionList(ModelMap model) { model.addAttribute("sessions", this.confDB.getSessions()); return "sessionList"; } @RequestMapping("speakerImage") public void streamSpeakerImage(@RequestParam("name") String name,

OutputStream outputStream) throws IOException { this.confDB.getSpeakerImage(name,outputStream); } @RequestMapping("/clearDatabase") public String clearDB() { this.confDB.clear(); return "redirect:sessionList"; }}

STORY TITLE

WebSphere Portal Technical Conference U.S. 20083535

Compare Controllers

Spring w/o annotations

Spring w/ annotations

STORY TITLE

WebSphere Portal Technical Conference U.S. 20083636

Testing – Here is your Portlet

Any Problems testing this code?

36

STORY TITLE

WebSphere Portal Technical Conference U.S. 20083737

Spring 3.X – What’s Coming?

JSR-286 Portlet Support

Java 5+ Only

Remove all pre-JDK 5 Dependencies

37

STORY TITLE

WebSphere Portal Technical Conference U.S. 20083838

Summary

IBM WebSphere Portal Server

#1 portal container in the enterprise Spring

#1 IoC container and glue of architecture Enables continuous integration

Future of Development

Annotations Code by convention instead of configuration

38

STORY TITLE

WebSphere Portal Technical Conference U.S. 20083939 39

Additional Information and Resources

WebSphere Portal – IBM Site

http://www-3.ibm.com/software/genservers/portal/

WebSphere Portal Business Solutions Catalog:

http://catalog.lotus.com/wps/portal/portal

Websphere Portal Developer’s Zone

http://www-106.ibm.com/developerworks/websphere/zones/portal/

Product Documentation and WebSphere Portal Wiki

http://www-3.ibm.com/software/genservers/portal/library/

http://www-10.lotus.com/ldd/portalwiki.nsf

http://springsource.com/

Education

http://www-3.ibm.com/software/genservers/portal/education/

WebSphere Portal 6.0 DemoNet

http://docs.dfw.ibm.com/wp6/?DDSPageRequest=/

STORY TITLE

WebSphere Portal Technical Conference U.S. 20084040 40

Session ID: D19

Session: Annotated Portal Development with RAD and Spring

Presenter(s): Ken Sipe, Technology Director, Perficient, Inc. Peter Blinstrubas, IBM Americas Portal Leader

Please take a few minutes to fill out the session survey. Thank you

Mark your calendars!Mark your calendars!

2009 U.S. WebSphere Portal Technical Conference2009 U.S. WebSphere Portal Technical ConferenceOctober 12-15, 2009, Sheraton San Diego Hotel and MarinaOctober 12-15, 2009, Sheraton San Diego Hotel and Marina

WebSphere Portal Technical Conference U.S. 2008

STORY TITLE

WebSphere Portal Technical Conference U.S. 20084141 41

© IBM Corporation 2008 All Rights Reserved.

The information contained in this publication is provided for informational purposes only. While efforts were made to verify the completeness and accuracy of the information contained in this publication, it is provided AS IS without warranty of any kind, express or implied. In addition, this information is based on IBM’s current product plans and strategy, which are subject to change by IBM without notice. IBM shall not be responsible for any damages arising out of the use of, or otherwise related to, this publication or any other materials. Nothing contained in this publication is intended to, nor shall have the effect of, creating any warranties or representations from IBM or its suppliers or licensors, or altering the terms and conditions of the applicable license agreement governing the use of IBM software.

References in this presentation to IBM products, programs, or services do not imply that they will be available in all countries in which IBM operates. Product release dates and/or capabilities referenced in this presentation may change at any time at IBM’s sole discretion based on market opportunities or other factors, and are not intended to be a commitment to future product or feature availability in any way. Nothing contained in these materials is intended to, nor shall have the effect of, stating or implying that any activities undertaken by you will result in any specific sales, revenue growth or other results.

All customer examples described are presented as illustrations of how those customers have used IBM products and the results they may have achieved. Actual environmental costs and performance characteristics may vary by customer.

IBM, the IBM logo, WebSphere, Lotus, Lotus Notes, Domino, Quickplace, Sametime, Workplace and Quickr are trademarks of International Business Machines Corporation in the United States, other countries, or both.

Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. in the United States, other countries, or both.

Microsoft and Windows 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.

All references to Renovations Inc. refer to a fictitious company and are used for illustration purposes only.


Recommended