Wednesday, August 25, 2010

FileUpload Streaming

I use Apache Commons FileUpload to upload files. I was doing it in the "traditional" way, using DiskFileItemFactory. One requirement I have is that I need to convert the stream to DataHandler, because it will then be passed to call web services with MTOM. This works perfectly fine with DiskFileItermFactory. However, with DiskFileItemFactory, you still need to setup a temp folder to save the file and also FileCleaningTracker to clean up. So I decided to give the streaming API a try.

I had to create FileItemStreamDataSource to wrap FileItemSteam for the purpose of creating a DataHandler.
package com.myapp.fileupload;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.activation.DataSource;

import org.apache.commons.fileupload.FileItemStream;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class FileItemStreamDataSource implements DataSource {
/**
* log.
*/
private Log log = LogFactory.getLog(getClass());

private FileItemStream stream;

public FileItemStreamDataSource(final FileItemStream stream) {
this.stream = stream;
}

@Override
public String getContentType() {
return stream.getContentType();
}

@Override
public InputStream getInputStream() throws IOException {
log.info("******** open stream **********");
return stream.openStream();
}

@Override
public String getName() {
return stream.getName();
}

@Override
public OutputStream getOutputStream() throws IOException {
throw new IOException();
}

}



There was no error in tests. However, when trying to open the file on the other end of web service, I found the content was either corrupted or empty (only 1KB). I wonder if this is because the stream was not read in full somehow. Maybe it is the same as the discussion here? Could it be that the stream is not kept open in web service calls? Anyway, I did not have enough time to get it work now and will need to revisit it later.

Friday, August 13, 2010

Enable Oracle SSO for an application

Assuming that SSO is enabled for OAS. (This requires a conf file generated from the SSO provided and installed in C:\product\10.1.3.1\OracleAS_1\Apache\Apache\conf\osso on your OAS)

After deploying your application (myapp), add the following to your "mod_osso.conf" file C:\product\10.1.3.1\OracleAS_1\Apache\Apache\conf\mod_osso.conf.

    <Location /myapp> 
require valid-user
AuthType Basic
</Location>

Wednesday, August 11, 2010

Spring AOP Interception

According to this post, most important - proxy-based AOP only works from "outside". Internal method calls are never intercepted.

This means that only the methods of your Spring beans can be intercepted. If this is not a problem, then here is an example.

Java
package com.my.aop;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.aop.ThrowsAdvice;

/**
* A Spring AOP advice to log service exception.
*/
@Aspect
public final class LoggingAdvice implements ThrowsAdvice {

/**
* Log.
*/
private Log log = LogFactory.getLog(this.getClass());

/**
* Log AxisFault detail after it is thrown.
*
* @param method calling method
* @param args method arguments
* @param target target
* @param ex AxisFault
* @throws Throwable throwable
*/
@AfterThrowing(pointcut="execution(* com.my.service.MyService.*(..))", throwing="ex")
public void afterThrowing(final Throwable ex) {
log.error(System.getProperty("line.separator") + "*****" + ex.getMessage());
}
}


Spring applicationContext.xml
<aop:aspectj-autoproxy/>
<bean id="loggingAdvice" class="my.com.aop.LoggingAdvice" />

Thursday, July 29, 2010

On enterprise architect

Quote from The Role of the Enterprise Architect.

one of the fundamental requirements for being a successful EA is the ability to lead without actually owning anything: If you don't have good leadership skills, the rest of it fundamentally doesn’t matter... If you do not lead and do not take the risk to lead, the transformation won’t occur. One of the barriers for the profession today is that many architects are not prepared to take the risk of leadership.

The authority of an architect ultimately comes from their ability to articulate a compelling value proposition for architecture in general, for specific architect in a specific situation... This is probably one of the biggest problems that architects coming from a technical background have. They'll tell you about features and functions but never get around talking about benefits.

Wednesday, May 5, 2010

Missing Maven dependencies when deployed in Eclipse

I created a dynamic web project in Eclipse with Maven structure. I have Maven Eclipse Plugin so I enabled it. Everything seemed fine but the app wouldn't run in Tomcat within Eclipse. It turned out that the maven dependencies did not get copied to WEB-INF/lib when I browsed to "wtpwebapps" folder where the app was deployed.

To enable it, go to Project > properties > Java EE Module Dependencies, and check "Maven Dependencies" for this project. And it worked like a charm.

Friday, April 30, 2010

Quote from Skype architect

Technical skills are a hygiene factor for architects. You need to have them to be accepted for the job. But emotional intelligence and ability to understand organizations are the skills that define how good you really are.

Here
is the complete original post.

Saturday, April 24, 2010

Create a template project with gwt-maven-plugin archetype

I wanted to use maven for my GWT project. In the beginning, I ran archetype to create a project template with gwt-maven-plugin.

mvn archetype:generate -DarchetypeRepository=http://repository.codehaus.org -DarchetypeGroupId=org.codehaus.mojo -DarchetypeArtifactId=gwt-maven-plugin -DarchetypeVersion=1.2 -DgroupId=myGroupId -DartifactId=myArtifactId