Archive for the “Java” Category


Just before i left Accenture, i remembered i was surfing all the internal sites for java resources and there were lots of them. Amongst them, I found Spring Batch. At that time, i had just rolled off from an batch integration project and i was very interested in mass processing and automation. Before that, my knowledge of mass processing was simply bash scripts and i enjoyed doing processing of multiple csv files to produce a final output file.

Before i start to go off topic, the reason why Accenture had a relationship with Spring Batch is due to the fact that they had a vast experience in batch implementation for various industries. Combined with the SpringSource team, i feel Spring Batch has the potential to be a defacto for batch implementation for as many reasons why Spring is a highly recommended application framework.

Spring Batch is a lightweight, comprehensive batch framework designed to enable the development of robust batch applications vital for the daily operations of enterprise systems. Spring Batch builds upon the productivity, POJO-based development approach, and general ease of use capabilities people have come to know from the Spring Framework, while making it easy for developers to access and leverage more advance enterprise services when necessary.

Spring Batch (Introduction)

An advantage it will definitely bring to enterprise is reusability. That is also why we love Spring. You code once and reuse it however you want by using Spring’s IoC. With reusability, the eventual advantage is a shorter build lifespan. You probably can do more with less. I’ll blog how to go about using Spring Batch next. In the meantime, go visit the Spring Batch home page here.

Stay tuned for more..

Comments Comments

Today, there is only one API for creating production grade front end for RIA talking to Java. It’s called Adobe Flex. In 2010, JavaFX may become another alternative. But meanwhile, please stop bashing Java. Do not forget that many of these new popular programming languages exist because there is a J2EE application they need to connect to. Do not forget that Java puts bread on the tables of many people (including mine) around the world. Do not spit in the well you drink from.

Yakov Fain from Farata Systems » Flex is strong because of Java.

I can feel so much from what Yakov has written. I totally agree with him. Coming from an enterprise world, it is really where the big money pot is. No offense to the other languages, you can laugh all you want about Java but you are missing out on the potential Java can give to a Flex application. I am still a little skeptical about JavaFX. Let’s see what Sun can do with JavaFX.

Comments Comments

I am observing pretty bad performance when my BlazeDS services are configured with Apache and Tomcat on mod_jk. Not too sure whether it is because i used Cairngorm as my main application framework. Setting requestTimeouts on my remoteObjects didn’t help. It was until i tried hitting my BlazeDS endpoint directly with my browser that i realised it was Apache that had refused/restricted requests to my Tomcat.

Error message from Apache

Error message from Apache

What i see on the Apache Error log

Tue Jul 22 18:51:59 2008] [error] [client <ip address>] client denied by server configuration: amfsecure, referer: <url to my flex app>

but i do not see any request with the same timestamp on the Tomcat logs.

Performing tuning is the only way to go. However, my sys admin did hardened and tuned the mod_jk connector settings in the server.xml files. Still waiting for him to try to worker.properties file. Sys Administration is not my kind of work. =p

My guess is that unless you are expecting very low traffic, you should not use the mod_jk setup. I hope my sys admin ain’t gonna get hell from me to ask for a public-facing Tomcat. I sent a message onto the BlazeDS jira below to see if there is any advice on my situation.

References:

Comments Comments

Merapi is a bridge between applications written in Java and those running in and created for Adobe AIR™ (Adobe Integrated Runtime™).

Merapi has been designed to run on a user’s machine, along with an Adobe AIR™application and providea direct bridge between the Adobe AIR™ framework and Java, exposing the power and overall calabilities of the user’s operating system, including 3rd party hardware devices.

Introduction to Merapi

Got this from insideRIA.com and the moment i saw Java and AIr, it got me excited. First thing that comes to mind is “No more jfc/swing interfaces”. But visiting their sites, i see more potential in this. Adam Flater has created a demo which shows the interaction between the mac accelerometer and AIR. Check out the demos here!

I signed up for the alpha and hope to play with it asap.

Comments Comments

Time to talk about my experience on switching to Flex. It has been a month that i have been working with Flex. Being a Java developer, it has been really smooth. This article pretty much sums it all up.

Something about Flex that is worth mentioning is the amount of essential examples out there. Whenever i see examples on a website or blog, they are good examples.

Sometimes, i make the mistake of mixing syntax when i switch over to work on some Java coding.

i:int = 0 instead of int i = 0

Comments Comments

Finally found the way to do the uploading via Flex to a Java backend. What i have used is the Spring Web MVC framework by making use of the example in the Spring Documentation on the multipart support #. The documentation does not include some of the necessary configuration such as the web.xml setup plus the controller and servlet configuration. It is pretty standard if you understand Spring.

The cool part about Spring’s multipart support is that we can simply extract the multipart file from the command object. Any multipart content will be identified by the multipartResolver which we will configure following the documentation.

So all the tricky part is left to be done on the Spring controller. And with a bit of java.io knowledge, our upload can be easily done in two hours. Yes two hours… i realised my mistake in using the file upload example in Spring Web Flow when i was testing with the Flex frontend upload example. At first, i thought it would be cool to make use of it but i guess i have to “Keep it sweet and simple”. So the spring dispatcher servlet approach. I am in love with Spring.

(Updated)References:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
 public class ImageUploadController extends SimpleFormController {
 
	protected String fileUploadLocation;
 
	protected ModelAndView onSubmit(
	        HttpServletRequest request,
	        HttpServletResponse response,
	        Object command,
 
	        BindException errors) throws Exception {
 
	         // cast the bean - POJO
	        FileUploadBean bean = (FileUploadBean) command;
 
	        // let's see if there's content there
	        MultipartFile imageFile = bean.getFile();
 
	        //Check upload file
	        if (imageFile.getSize() == 0) {
	             //the user did not upload anything
			throw new Exception("No file uploaded");
	        }
	        //Get image filename
	        String fileName = imageFile.getOriginalFilename();
 
	        int index = fileName.toLowerCase().indexOf("jpg");
	        String fileName = "test.jpg";
 
	        //Create new File Object
	        String fileSeparator = System.getProperty("file.separator");
	        File newFile = new File(assetsLocation + fileSeparator + fileUploadLocation + fileSeparator + fileName);
 
	        //check for file
			if (newFile.exists()) {
			    try {
			        // Create file if it does not exist
			        boolean success = newFile.createNewFile();
			        if (success) {
			            	// File did not exist and was created
					System.out.println("File created");
			        } else {
			            // File already exists
					System.out.println("File not created");
			        }
			    } catch (IOException e) {
				// Handle your exception
			    }
			}
		    imageFile.transferTo(newFile);
	        return super.onSubmit(request, response, command, errors);
	    }
}

Web.Xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<servlet>
	<servlet-name>profileImageUpload</servlet-name>
	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
	<servlet-name>profileImageUpload</servlet-name>
	<url-pattern>*.form</url-pattern>
</servlet-mapping>
 
imageUpload-servlet.xml
<pre lang="xml" line="1">
<?xml version="1.0" encoding="UTF-8"?>
 
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
	<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
		<!-- Limit uploads to small (5KB) files for this sample -->
		<property name="maxUploadSize" value="5120" />
	</bean>
 
	<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="location" value="/WEB-INF/test.properties"/>
	</bean>
	<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <props>
                <prop key="/upload.form">fileUploadController</prop>
            </props>
        </property>
    </bean>
 
    <bean id="fileUploadController" class="com.someclass.ImageUploadController">
        <property name="fileUploadLocation"><value>${fileuploadimage.location}</value></property>
        <property name="assetsLocation"><value>${fileuploadimage.assets}</value></property>
        <property name="commandClass"><value>com.someclass.FileUploadBean</value></property>
        <property name="successView"><value>confirmation.jsp</value></property>
    </bean>
</beans>

Flex codes with some modification from the example at http://blog.flexexamples.com/2007/09/21/uploading-files-in-flex-using-the-filereference-class/ (By request of Tamitutor)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
 
<?xml version="1.0" encoding="utf-8"?>
 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        creationComplete="init();">
 
    <mx:Script>
        <![CDATA[
            [Bindable]
            private var fileRef:FileReference;
 
            private const FILE_UPLOAD_URL:String = "http://localhost:8080/demo/upload.form";
 
            private function init():void {
                fileRef = new FileReference();
                fileRef.addEventListener(Event.SELECT, fileRef_select);
                fileRef.addEventListener(ProgressEvent.PROGRESS, progressHandler);
                fileRef.addEventListener(Event.COMPLETE, fileRef_complete);
            }
 
            private function browseAndUpload():void {
                fileRef.browse();
                message.text = "";
            }
 
            private function fileRef_select(evt:Event):void {
                try {
                    message.text = "size (bytes): " + numberFormatter.format(fileRef.size);
                    var request:URLRequest = new URLRequest(FILE_UPLOAD_URL);
                    request.method = URLRequestMethod.POST;
                    var uploaderReqVars:URLVariables = new URLVariables("var=samevalue");
                    request.data = uploaderReqVars;
                    fileRef.upload(request, "file");
                } catch (err:Error) {
                    message.text = "ERROR: zero-byte file";
                }
            }
 
            private function fileRef_progress(evt:ProgressEvent):void {
                progressBar.setProgress(Number(evt.bytesLoaded), Number(evt.bytesTotal));
            }
 
            private function progressHandler(event:ProgressEvent):void {
            var file:FileReference = FileReference(event.target);
            progressBar.setProgress( Number(event.bytesLoaded), Number(event.bytesTotal));
        }
 
            private function fileRef_complete(evt:Event):void {
                message.text += " (complete)";
            }
        ]]>
    </mx:Script>
<mx:NumberFormatter id="numberFormatter" />
	<mx:ApplicationControlBar>
 
 
	    <mx:Button label="Upload file"
	            click="browseAndUpload();" />
	    <mx:Label id="message" />
	    <mx:ProgressBar id="progressBar" mode="manual"
	            visible="true" />
	</mx:ApplicationControlBar>
 
 
</mx:Application>

Comments Comments

Had some problems when trying to get Flex to invoke my Xfire Web Service. The culprit <xsd:any>. I don’t have the exact reason but i think Flex will try read the WSDL and attempt to decipher each soap message structure. <xsd:any> becomes a null. I get the error “No such property null… on com.myCustomObject”.

By default, Xfire will not generate the <xsd:any> in the WSDL but i have a complexType of a ValueObject in another ValueObject type. Strangely, it generates the <xsd:any>. My only clue is on the Xfire jira. The solution is there but i think i should let everyone know that the fix for the bug #295 only works for a normal valueObject. For my case, it doesn’t work.

My saviour: the extensibleElements, and extensibleAttributes flags.(Source) There should be some mention about this on the Xfire website.

Example codes:

import org.codehaus.xfire.aegis.type.java5.XmlElement ;
import org.codehaus.xfire.aegis.type.java5.XmlType;
@XmlType(name="A", extensibleElements=false, extensibleAttributes=false)
public class A {
	public int var1;

	@XmlElement(name="Var1")
	public int getVar1() {

		return var1;

	}

	public void setVar1(int var1) {

		this.var1 = var1;
	}

}

Generated WSDL:

<xsd:complexType name=”A>

<xsd:element minOccurs=”0 name=”Var1 nillable=”true type=”xsd:int />

</xsd:sequence>
</xsd:complexType >

Comments Comments

It is really cool to hear Sun is making noise in the RIA domain.

JavaFX is a new family of Java technology-based products that will help content providers create and deploy rich Internet applications (RIA).

JavaFX has two releases: JavaFX Script and JavaFX Mobile.

JavaFX Script is a new script language that allows Java developer the capability to create content-rich applications. It is supported on various clients, including mobile devices, set-top boxes, desktops, even Blu-ray discs. Advantages? Simplicity

JavaFX Mobile is like J2EE of mobile devices. It is available via OEM licenses to carriers, handset manufacturers, and other companies that want to simplify and accelerate the development of a powerful standardized software system that can be leveraged across a wide range of consumer devices.

  • Allows content creators to create rich media content without relying on developers, including drag and drop of desktop and mobile content to the desktop, something that is not possible in any other RIA.
  • Offers a close integration with other Java components (applications and infrastructure) running on server and client platforms, enabling a rich end-to-end experience for developers and users.
  • Takes advantage of the Java security model so consumers can securely access assets (e.g., pictures, music files, word documents) on their desktop.

Another new thing to try out… Great stuff…

Comments Comments