Tuesday, February 22, 2011

Parsing XML time value with java SimpleDateFormat

I have encountered a problem with parsing following string as a date object

2011-02-21T07:00:00.000+01:00

if the only interesting part is getting date and time following date time pattern is enough
yyyy-MM-dd'T'hh:mm:ss

assuming there is following xml node
<startTime>2011-02-23T08:00:00.000+01:00startTime>

//initialization with correct date time pattern
SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");

//timeParam is type of XMLElement

if (timeParam.getName().equals("startTime")) {
Date dateTime = dateTimeFormat .parse(timeParam.getContent());

//dateTime now can be used to set time for GregorianCalendar object
time.startTime = new GregorianCalendar();
time.startTime.setTime(dateTime );

Monday, February 21, 2011

Embedded mule ESB Java web services deployment and configuration to Tomcat server

Tomcat setup:

  1. Install Tomcat server (e.g. version 6.0 - requires Java 1.6 installed)

Deployment or upgrade of web services

  1. Place the war file (WebApplicaton_War_File_Name.war) file in Tomcat_Home\webapps 
  2. Start / Restart Tomcat

After starting tomcat web archive gets unpacked

Service url configuration

Service url (webserviceUrl) can be configured by making changes in mule-config.xml
(Tomcat_Home\webapps\WebApplicaton_War_File_Name\WEB-INF\classes\mule-config.xml)
by changing endpoint address value
 
-After configuration changes restart Tomcat server.

Testing if correctly deployed

Ensure that application runs correctly by navigating to:http://webserviceUrl?wsdl
e.g.http://localhost:8080/MyWebService?wsdl
WSDL sescription should be correctly displayed (NOTE: Chrome sometimes does not display wsdl file content- try in FireFox or IE)

Troubleshooting

In case of any problems log files can be found here:
Tomcat_Home\logs
Using war file greatly simplifies applications distribution, instead of many files there is only one file required, place it in correct place, start server, done. Simply great.

Resolving invalid target release error, java maven build

After running mvn install -DskipTests=true command
I got following error:

[INFO] Scanning for projects...
[INFO] -------------------------------------------------------------------------
---
[INFO] Building visitplanning
[INFO]    task-segment: [install]
[INFO] -------------------------------------------------------------------------
---
[INFO] Ignoring available plugin update: 2.3.2 as it requires Maven version 2.0.
9
[INFO] Ignoring available plugin update: 2.3.1 as it requires Maven version 2.0.
9
[INFO] Ignoring available plugin update: 2.3 as it requires Maven version 2.0.9
[INFO] Ignoring available plugin update: 2.2 as it requires Maven version 2.0.9
[INFO] Ignoring available plugin update: 2.1 as it requires Maven version 2.0.9
[INFO] Ignoring available plugin update: 2.7.2 as it requires Maven version 2.0.
9
[INFO] Ignoring available plugin update: 2.7.1 as it requires Maven version 2.0.
9
[INFO] Ignoring available plugin update: 2.7 as it requires Maven version 2.0.9
[INFO] Ignoring available plugin update: 2.6 as it requires Maven version 2.0.9
[INFO] Ignoring available plugin update: 2.5 as it requires Maven version 2.0.9
[INFO] [resources:resources]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\Workspace\XXXXXXXX\src\main\resourc
es
[INFO] [compiler:compile]
[INFO] Compiling 37 source files to D:\Workspace\XXXXXXXX\target\classes
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Compilation failure
Failure executing javac, but could not parse the error:
javac: invalid target release: 1.6

The solution was pretty simple. Maven uses JAVA_HOME environment variable and by changing it to point to JDK 1.6 the error was resolved.