Jai’s Weblog – Tech, Security & Fun…

Tech, Security & Fun…

  • Jaibeer Malik

    Jaibeer Malik
  • View Jaibeer Malik's profile on LinkedIn
  • Subscribe

  • Feedburner

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 3 other followers

  • Archives

  • Categories

  • Category Cloud

  • Stats

  • Blog Stats

    • 117,765
  • Live Traffic

Archive for the ‘Spring’ Category

Flex: Enterprise security implementation using Chimp, permission based filtering component

Posted by Jai on August 28, 2009

This post covers how you can implement enterprise security solution for flex applications. You can implement flex side security using Chimp which is permission based filtering of flex components using metadata and Spring Security on the server side and integrating the two.

This is part of the series of posts:

Flex then, now & tomorrow – From a java developer’s perspective
Flex: Cairngorm (MVC), SpringActionscript (IOC) and other Cairngorm Extensions
Flex: SpringActionscript (IOC) & SpringActionscript Cairngorm Extension Sample Code Examples
Flex: Cairngorm View Notifications Strategies, Responders from Command to View
Flex: Choosing the right flex data transfer strategy and designing the application accordingly
Flex Tips&Tricks

to cover different strategies in flex development using Cairngorm framework to solve different practical problems.

Consider an enterprise application where you need to have security on both flex side and server side. You want access control on flex side and depending on user roles you would like to create, remove, hide, enable particular view components in the application. Similarly, have access control on the server side that user having specific roles only would be able to use some service, package or call some particular methods.

There is very nice article by Ryan on Enterprise security for Flex which covers the spring security integration and flex side security implementation using chimp.

Read the rest of this entry »

Posted in Cairngorm, Flex, Security, Spring | Tagged: , , , , | 3 Comments »

Demo Application: JSR 286 Wicket Portlet Development on WebSphere Portal 6.1

Posted by Jai on June 5, 2009

This post share the demo application (source code, deployable war file and patched wicket jar) covering JSR 286 (The Eventing feature) Wicket Portlet development on WebSphere Portal 6.1.

Based on my previous posts JSR 286 Wicket Portlet Development on WebSphere Portal 6.1Wicket Portlet Development on WebSphere Portal – Lessons Learnt and few queries/comments, I have uploaded the working code.

The sample project: maven 2 based, RAD 7.5 project on WS Portal 6.1 and Wicket 1.4-rc2, Spring integration etc.

Download Location: http://www.mediafire.com/jaibeermalik

The portal-wicket folder contains three files.

JSR286WicketWSP61-src-full.zip : source code including patched wicket jar files
JSR286WicketWSP61-src-no-jars.zip : source code with out jar files
JSR286WicketWSP61.war : war file, try to directly deploy it. Configure portal server to work for filters and after deploying wire the portlets.

Read the rest of this entry »

Posted in Java, Spring, WebSphere Portal, Wicket | Tagged: , , , , , | Leave a Comment »

JSR 286 Wicket Portlet Development on WebSphere Portal 6.1

Posted by Jai on April 14, 2009

We will discussion here to get started with the JSR 286 Wicket portlet development on WebSpere Portal 6.1. Wicket release 1-4-rc2 has been updated to support the JSR 286: Upgrade Wicket Portlet Support to only use native Portlet API 2.0 . And have a look at later releases Upgrade wicket to fully support portlet 2.0 for more information. It seems to work fine in case of other portal containers like Liferay as mentioned steps Portal How To.

Lets have a look how to make it work for WS Portal. We will start with setting the environment first and will try to resolve the compatibility issues. Follow the below steps:

  • Update wicket release 1.4-rc2 with patch.
  • Configure WebSphere Portal to work with wicket filter
  • Develop JSR 286 eventing system based wicket portlet
  • Configure the portlet wiring in WS Portal

Update Wicket 1-4-rc2:

Have to look at wicket latest release 1-4-rc2 does not support IBM Websphere Portal Server 6.1 to understand the problem in case of WS Portal.

To fix it, update the jar with the patch:

Configuring WebSphere Portal Server:

It seems like WebSphere doesn’t handle the servlet filters porperly and you may get this error while deploying the wicket portlets on WebSphere 6.1:  Error 404: SRVE0190E: File not found:

Setting the com.ibm.ws.webcontainer.invokefilterscompatibility” property to true in Servers > Server > Web Container Settings > Web Container > Custom Properties, may help solve the issue.

Developing JSR 286 Wicket Portlets:

We will take JSR 86 eventing system as an example to work for wicket portlets.

Lets develop two portlets say TestPortlet and TestDetailsPortlet to publish and process events and spring integration for bean management.

Update deployment descriptor web.xml:


<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext.xml</param-value>
</context-param>

<context-param>
<param-name>org.apache.wicket.detectPortletContext</param-name>
<param-value>true</param-value>
</context-param>

<filter>
	<filter-name>wicket.testPortlet</filter-name>
	<filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
	<init-param>
<param-name>applicationClassName</param-name>
<param-value>com.test.portlet.testproject.TestPortletApplication</param-value>
	</init-param>
</filter>

<filter-mapping>
        <filter-name>wicket.testPortlet </filter-name>
	<url-pattern>/testPortlet/*</url-pattern>
	<dispatcher>REQUEST</dispatcher>
	<dispatcher>INCLUDE</dispatcher>
</filter-mapping>

<filter>
	<filter-name>wicket.testPortletDetails</filter-name>
	<filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
	<init-param>
<param-name>applicationClassName</param-name>
<param-value>com.test.portlet.testproject.TestPortletDetailsApplication</param-value>
	</init-param>
</filter>

<filter-mapping>
	<filter-name>wicket.testPortletDetails </filter-name>
	<url-pattern>/testDetailsPortlet/*</url-pattern>
	<dispatcher>REQUEST</dispatcher>
	<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
	<listener>
	<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

Now configure the portlet.xml :

<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" xmlns:test="http://www.test.com/portlets/testing" ...

<portlet>
	<description>Test Portlet</description>
<portlet-name>TestPortlet</portlet-name>
	<display-name>TestPortlet</display-name>
<portlet-class>com.test.portlet.test.TestPortlet</portlet-class>
	<init-param>
		<name>wicketFilterPath</name>
		<value>/testPortlet</value>
	</init-param>
	<supports>
		<mime-type>*/*</mime-type>
<portlet-mode>VIEW</portlet-mode>
	</supports>
<portlet-info>
		<title>Test Portlet</title>
	</portlet-info>
	<supported-publishing-event>
		<qname>test:test_selected</qname>
	</supported-publishing-event>
</portlet>
<portlet>
	<description>Test Details Portlet</description>
<portlet-name>TestDetailsPortlet</portlet-name>
	<display-name>TestDetailsPortlet</display-name>
<portlet-class>com.test.portlet.testdetails.TestDetailsPortlet</portlet-class>
	<init-param>
		<name>wicketFilterPath</name>
		<value>/testDetailsPortlet</value>
	</init-param>
	<supports>
		<mime-type>*/*</mime-type>
<portlet-mode>VIEW</portlet-mode>
	</supports>
<portlet-info>
		<title>Test Details Portlet</title>
	</portlet-info>
	<supported-processing-event>
	        <qname>test:test_selected</qname>
	</supported-processing-event>
</portlet>
<event-definition>
	<qname>test:test_selected</qname>
	<value-type>java.lang.String</value-type>
</event-definition>

Note: Put the event-definition entries in the end after all the portlet entries, cross check with portlet 2 xsd for validation.

For each portlet, we will be specifying separate application class (eg. TestPortletApplication and TestDetailsPortletApplication) where each one will have different home page (eg. TestPage and TestDetailsPage).

TestPortletApplication:

    public class TestPortletApplication extends WebApplication {

        @Override
	protected void init() {
		super.init();
		addComponentInstantiationListener(new SpringComponentInjector(this));
	}

	@Override
	public Class<? extends Page> getHomePage() {
		return TestPage.class;
	}
    }

TestDetailsPortletApplication:

    public class TestDetailsPortletApplication extends WebApplication {    

        @Override
	protected void init() {
		super.init();
		addComponentInstantiationListener(new SpringComponentInjector(this));
	}

	@Override
	public Class<? extends Page> getHomePage() {
		return TestDetailsPage.class;
	}
    }

TestPage:

Lets say this wicket WebPage submits some value on selection/click. Here lets say
it submits some parameter “test_value” which we are using to set the event value.

TestDetailsPage:


public class TestDetailsPage extends WebPage {

 @SpringBean(name = "testService")
 private TestService testService;
 ...
 public TestDetailsPage() {
     //Get parameter value set by the process event and use in the wicket page
     String testSelectedValue = getRequest().getParameter("test_selected_value");
     ....
     //Do whatever you need to do, find or store.
     testService.findTestDetails(testSelectedValue);
  }

 ...

}

Update TestPortlet to publish the event:


public class TestPortlet extends WicketPortlet {

 @Override
 public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException {
        super.processAction(request, response);
        //set the event and value, here we are getting value from request and setting as event value.
        QName name = new QName("http://www.test.com/portlets/testing","test_selected");
        response.setEvent(name, request.getParameter(“test_value”));
 }
}

Qname is same which you mentioned in the portlet definition file for the test-selected event. And “test_value” is the parameter value which you want to pass to this event. Here in this example we will use only string values to pass otherwise it can be any serialized object.

Update TestDetailsPortlet to procees the event:

public class TestPortlet extends WicketPortlet {

 @ProcessEvent(qname = "{http://www.test.com/portlets/testing}test_selected")
 public void processTestSelectedEvent(EventRequest request, EventResponse response) throws PortletException, IOException {
       //Do whatever you want to do with the event handling part.
       response.setRenderParameter("test_selected_value", request.getEvent().getValue().toString());
 }
}

Configuring Portlet Wiring:

Once you are done with the deployment, you need to wire the two portlet otherwise you will get the error:

“EJPKB0991E: The propertybroker encountered a problem finding a communication source with name…”.

Have a look at Using portlet wires for WS Portal 6.1.

To access the wiring Tool portlet, proceed as follows:
1.Access the Manage Pages portlet.
2.Locate the page for which you want to add wires.
3.Click the Edit Page Layout icon for that page. This takes you to the Edit Layout panel.
4.Click the Wires tab. You can now start working with wires.

The same example of Developing Inter Portlet communication (IPC) portlets can be achieved using the JSR 268 Public Render Parameters also but this example demonstrates how it works using the JSR 268 eventing support.

Hope this will help you to get things started on WebSphere Portal. Feel free to share your experiences and lets hope it gets fixed either by Wicket or IBM in future.

Posted in Java, Spring, WebSphere Portal, Wicket | Tagged: , , , | 6 Comments »

Handling semi-transactional cases in spring programmatically

Posted by Jai on June 7, 2008

Consider a case in which you are updating information in local database and need to publish the same information some where on the remote application over network. You don’t have control over the transactional behavior of the remote application but some how get to know that the publishing/operation is not successful.

There can be scenarios when the remote operation is successful but you local database update fails, in such a situation you must be aware of what reverse operation should be done on remote application to revert it. The following cases can arise in semi-transaction cases:

Local operation Remote Operation Transaction Behavior Remote App-State
Successful Failure Rollback Remote App will handle it
Failure Failure Rollback Remote App will handle it
Failure Successful Rollback Revert call to be send
Successful Successful Commit Successful

Now how to handle such kind of scenarios and reverse transaction programmatically. I will walk you through small example to handle it.

Interface ReverseTransactionCallback:

***************

public interface ReverseTransactionCallback {

void executeTransaction();

void executeReverseTransaction();

}
****************

This interface contains two methods to execute in transaction or if the transaction fails then this is called to rollback stuff on remote application.

Reverse Transaction Template – ReversableTransactionTemplate:

**************

public class ReversableTransactionTemplate {

private PlatformTransactionManager transactionManager;

protected void executeReverseTransactionCallback(ReverseTransactionCallback callback) {
TransactionStatus transaction = transactionManager.getTransaction(new DefaultTransactionDefinition(
TransactionDefinition.PROPAGATION_REQUIRES_NEW));
try {
callback.executeTransaction();
} catch (RuntimeException ex) {
rollbackOnException(transaction, ex);
throw ex;
} catch (Error err) {
rollbackOnException(transaction, err);
throw err;
}
try {
transactionManager.commit(transaction);
} catch (TransactionException e) {
try {
callback.executeReverseTransaction();
} catch (RuntimeException ex) {
LOG.error(“Commit exception overridden by rollback exception”, e);
throw ex;
} catch (Error err) {
LOG.error(“Commit exception overridden by rollback exception”, e);
throw err;
}
throw e;
}
}

private void rollbackOnException(TransactionStatus status, Throwable ex) throws TransactionException {
LOG.debug(“Initiating transaction rollback on application exception”, ex);
try {
this.transactionManager.rollback(status);
} catch (RuntimeException ex2) {
LOG.error(“Application exception overridden by rollback exception”, ex);
throw ex2;
} catch (Error err) {
LOG.error(“Application exception overridden by rollback error”, ex);
throw err;
}
}

…..

}
****************

This is the template which handles commit/rollback of the stuff using org.springframework.transaction.PlatformTransactionManager and does the exception handling also.

Local operation and remote operation Service – UpdateLocalDBAndPostToService:

********************

public class UpdateLocalDBAndPostToService extends ReversableTransactionTemplate {

public void doOperation() {
try {
executeReverseTransactionCallback(new ReverseTransactionCallback() {
public void executeTransaction() {
localOperationService.storeData(data);
httpPostClient.publishData(data);
}

public void executeReverseTransaction() {
httpPostClient.publishDataReverse(data);
}
});
} catch (Exception e) {
LOG.error(“Failed to update.”, e);
}
}

….

….

}

***************************

Look at the implementation of executeTransaction() method which will update local database and will publish to remote application. Lets go through each scenario in case of exception:

Local operation fails before commit: Local operation is done first, so in case of exception the rollback will be done on local side and no communication with remote app.

Local operation successful but Remote operation fails: the transaction is rolled back on local side.

Local operation successful and remote operation successful but the commit fails: the transaction is rolled back on local side and executeReverseTransaction() method is called for reversal command on remote application. This is the only scenario where we need to send reversal call to remote application.

All Successful : Enjoy…job is done. All well if it ends well.

Posted in Spring | Tagged: , , | Leave a Comment »

SpringSource Tool Suite Analysis

Posted by Jai on June 4, 2008

SpringSource recently released the beta version of tool suite and being a developer working on Spring for long enough I thought to give it a try and here is what i think of it.

About SpringSource:

Formerly known as Interface21. SpringSource created and sustains the development of the Spring Framework.
SpringSource Tool Suite:

  • Goal – most sophisticated development tools for doing enterprise development with the Spring Portfolio on the Eclipse platform.
  • Eclipse Mylyn and Spring IDE as a core component.
  • Pre-integrated issue tracking support and code quality analysis tools.

Experience/Expectations:

  • From Spring Training – how much can you automate it, just on a click.
  • During development process – what expectation do you have from spring tool.
  • As new to Spring – how fast and easy can you make me to get it started to work on spring.
  • As member of Spring community – how can you help or get help from the spring community.

Feature List:

  • Spring Development Tools
  • Mylyn’s Task-Focused User Interface for Java, Resources and Spring application blueprints
  • Task-Focused Tutorials (Spring, OSGi concepts, Equinox and Spring Dynamic Modules)‏
  • Runtime Error Analysis
  • Best Practice and Architecture Review tools

I am waiting for the enterprise edition.

Posted in Spring | Tagged: | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.