<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Bandos&#039; Arcade &#187; Java</title>
	<atom:link href="http://www.nuwanbando.com/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nuwanbando.com</link>
	<description>&#34;It&#039;s not about how it is, but how I see it &#34; - Stranger Than Fiction</description>
	<lastBuildDate>Thu, 02 Feb 2012 08:52:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Sharing HTTPS, HTTP sessions in tomcat hosted web-apps</title>
		<link>http://www.nuwanbando.com/2010/05/sharing-https-http-sessions-in-tomcat/</link>
		<comments>http://www.nuwanbando.com/2010/05/sharing-https-http-sessions-in-tomcat/#comments</comments>
		<pubDate>Thu, 06 May 2010 19:33:06 +0000</pubDate>
		<dc:creator>Nuwan Bandara</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Apache Tomcat]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Jsp]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Servlet]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[HTTPS]]></category>

		<guid isPermaLink="false">http://www.nuwanbando.com/?p=440</guid>
		<description><![CDATA[The requirement is to only serve the login page securely and once the user is authenticated (s)he should be redirected to non-secure http mode. I was struggling to do this quite some time back, and just thought of documenting about it. The idea I had was; &#8220;It should be quite simple&#8221;, Facebook does that, Google [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.nuwanbando.com%2F2010%2F05%2Fsharing-https-http-sessions-in-tomcat%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.nuwanbando.com%2F2010%2F05%2Fsharing-https-http-sessions-in-tomcat%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>The requirement is to only serve the login page securely and once the user is authenticated (s)he should be redirected to non-secure http mode. I was struggling to do this quite some time back, and just thought of documenting about it.</p>
<div id="attachment_441" class="wp-caption alignleft" style="width: 366px"><a href="http://www.nuwanbando.com/wp-content/uploads/2010/05/req.jpg"><img class="size-full wp-image-441 " title="req" src="http://www.nuwanbando.com/wp-content/uploads/2010/05/req.jpg" alt="" width="356" height="179" /></a><p class="wp-caption-text">The requirement </p></div>
<p>The idea I had was; &#8220;It should be quite simple&#8221;, Facebook does that, Google does that and why is it still not well documented ?, However the almost all Google search results for my queries were about simply redirecting HTTP traffic to HTTPS for certain URLs, some were using <a href="http://httpd.apache.org/docs/2.0/misc/rewriteguide.html" target="_blank">URL rewriting</a> (mod_rewrite), and some have used server configuration via Tomcat&#8217;s server.xml.</p>
<p>What I really wanted to achieve is to preserve the state between the protocol switch. After some considerable amount of searching I found out this is not achievable (in a very clean manner) with tomcat or rather it is a conflict between security and state management in the servlet spec itself, hence there only exist a <a href="http://www.mail-archive.com/tomcat-user@jakarta.apache.org/msg151759.html" target="_blank">dirty hack</a> (not sure if this works) to get it done, but even that hack couldn&#8217;t be applied to my scenario.</p>
<p>So after some thinking I came up with my own hack (I think its even dirtier <img src='http://www.nuwanbando.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  ) to solve the issue; Its quite simple, and involves cookie manipulation. My approach was simply read the HTTPS cookie and set it as the HTTP cookie, what I need was one jsp which is served with HTTPS and few lines of Java code.</p>
<div id="attachment_454" class="wp-caption alignleft" style="width: 470px"><a href="http://www.nuwanbando.com/wp-content/uploads/2010/05/sol1.jpg"><img class="size-full wp-image-454" title="sol" src="http://www.nuwanbando.com/wp-content/uploads/2010/05/sol1.jpg" alt="The solution" width="460" height="437" /></a><p class="wp-caption-text">The solution</p></div>
<p>True enough it certainly looks like a hack, but security wise its as same as the Tomcat user group has suggested. so until the new servlet specification answers this question we have to live with this. the code of converting the cookies are as follows.</p>
<div>
<pre class="java" name="code" style="width: 55%;">
    Cookie[] cookies = request.getCookies();
    String sessionId;
    if (cookies != null) {
        for (Cookie c : cookies) {
            if (c.getName().equals("JSESSIONID")) {
                sessionId = c.getValue();
            }
        }
    }

    Cookie k = new Cookie("JSESSIONID", sessionId);
    k.setPath(request.getContextPath());
    response.addCookie(k);
</pre>
</div>
<p>Basically what the code does is, reading the secure cookies while inside the middle.jsp and setting them without security (k.setSecure() is not mentioned hence by default its false), and that&#8217;s about it, once this is done you can simply redirect to the HTTP page.</p>
<div>
<pre class="java" name="code" style="width: 55%;">
response.sendRedirect("http://foo.com:8080/index.jsp");
</pre>
</div>
<p>and now the cookie which originally set via HTTPS is accessible to the HTTP requests, hence the session is shared.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nuwanbando.com/2010/05/sharing-https-http-sessions-in-tomcat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mashing up RDF data with WSO2 Mashup Server</title>
		<link>http://www.nuwanbando.com/2010/04/mashing-up-rdf-data-with-wso2-mashup-server/</link>
		<comments>http://www.nuwanbando.com/2010/04/mashing-up-rdf-data-with-wso2-mashup-server/#comments</comments>
		<pubDate>Tue, 13 Apr 2010 20:27:21 +0000</pubDate>
		<dc:creator>Nuwan Bandara</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[RDF]]></category>
		<category><![CDATA[Semantic web]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[SPARQL]]></category>
		<category><![CDATA[WSO2]]></category>
		<category><![CDATA[WSO2 Gadget Server]]></category>
		<category><![CDATA[Mashup]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[WSO2 Mashup Server]]></category>

		<guid isPermaLink="false">http://www.nuwanbando.com/?p=341</guid>
		<description><![CDATA[Okey so this is the fun part that I promised to write about . I managed to cook up a use-case to demonstrate RDF querying and making use of the semantic data. The data that I am using for querying, is the rdf data sources available in the UK data.gov site. With some analysis I [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.nuwanbando.com%2F2010%2F04%2Fmashing-up-rdf-data-with-wso2-mashup-server%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.nuwanbando.com%2F2010%2F04%2Fmashing-up-rdf-data-with-wso2-mashup-server%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Okey so this is the fun part that I promised to write about <img src='http://www.nuwanbando.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> . I managed to cook up a use-case to demonstrate RDF querying and making use of the semantic data. The data that I am using for querying, is the rdf data sources available in the UK data.gov site. With some analysis I figured out that this task can be fundamentally archived using the combination of Mashup and Gadget Technologies. My choice of tools were <a href="http://wso2.com/products/mashup-server/">WSO2 Mashup Server</a> and <a href="http://wso2.com/products/gadget-server/">WSO2 Gadget Server</a> for their great flexibility and of cause for other obvious reasons <img src='http://www.nuwanbando.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> . However the Mashup Server does not natively support RDF data retrieval, hence I had to do some work to get such functionality integrated. The great fact about the mashup server is its extensibility, the <a href="http://en.wikipedia.org/wiki/WSO2_Mashup_Server">concept of host objects</a> and the ability to write custom host objects and its pluggable nature comes handy in such cases. The high level architecture of what I am trying to achieve is as follows.</p>
<div id="attachment_348" class="wp-caption aligncenter" style="width: 850px"><a href="http://www.nuwanbando.com/wp-content/uploads/2010/04/rdf.png"><img class="size-full wp-image-348" style="background-color: #ffffff;" title="rdf" src="http://www.nuwanbando.com/wp-content/uploads/2010/04/rdf.png" alt="" width="840" height="262" /></a><p class="wp-caption-text">RDF data retrival with WSO2 Mashup server / WSO2 Gadget Server</p></div>
<p style="text-align: left;">To implement the above architecture with the tools at hand I created a <a href="http://wso2.org/library/tutorials/writing-custom-hostobjectttp://" target="_blank">custom host object</a> that can be plugged to the Mashup Server. When dealing with semantic web related tasks and RDF data handling HP&#8217;s <a href="http://jena.sourceforge.net/" target="_blank">Jena</a> java library comes in handy. With the use of <a href="http://openjena.org/ARQ/">Jena-ARQ</a> (for <a href="http://en.wikipedia.org/wiki/SPARQL" target="_blank">SPARQL</a>) api I managed to get the host object working with few lines of code.</p>
<p style="text-align: left;">
<pre name="code" class="java">.....
            Dataset dataSet = DatasetFactory.create(sparqlObject.rdfDataSource);
            // Create a new query form a given user query
            String queryString = sparqlObject.spaqrlQuery;
            Query query = QueryFactory.create(queryString);
            QueryExecution qe = QueryExecutionFactory.create(query, dataSet);
            ResultSet results = qe.execSelect();
.....
           resultString = ResultSetFormatter.asXMLString(results);
..... OR.....
           ByteArrayOutputStream bos = new ByteArrayOutputStream();
           ResultSetFormatter.outputAsJSON(bos, results);
</pre>
<p style="text-align: left;">With the host object in place, the next task was to create a Mashup in-order to query the rdf data with a given source (EndPoint or data source). The javascript service (Mashup) is created to serve this purpose, where the consumer can specify the RDF endpoint or the data source with the SPARQL query and retrieve the dataset in XML or JSON.</p>
<pre name="code" class="js">.....
function RdfDocQueryService(rdfDataSource, rdfQuery, resultType) {
   var sparqlObj = new SparqlHostObject();
   sparqlObj.rdfDataSource = rdfDataSource;
   sparqlObj.spaqrlQuery = rdfQuery;
   sparqlObj.resultType = resultType;
   return new XML(sparqlObj.getDataFromRdfSource());
}
</pre>
<p>Finally to bind everything together, lets try querying some data. My example usecase is to use the query at <a href="http://blogs.talis.com/n2/archives/836" target="_blank">N2 blog</a> to retrieve traffic monitoring points in UK roads. The query to retrieve the data set as follows,</p>
<pre name="code" class="sql">#List the uri, latitude and longitude for road traffic monitoring points on the M5
PREFIX road:
PREFIX rdf:
PREFIX geo:
PREFIX wgs84:
PREFIX xsd:
SELECT ?point ?lat ?long WHERE {
  ?x a road:Road.
  ?x road:number "A4"^^xsd:NCName.
  ?x geo:point ?point.
  ?point wgs84:lat ?lat.
  ?point wgs84:long ?long.
}
</pre>
<p>To visualize these points I have created a gadget with the aid of Google Maps api. This gadget can be hosted in the Gadget Server, where it can dynamically retrieve traffic monitoring points for each road in the UK and display them in the map as follows.</p>
<p style="text-align: center;">
<div id="attachment_362" class="wp-caption aligncenter" style="width: 841px"><a href="http://www.nuwanbando.com/wp-content/uploads/2010/04/WSO2-Gadget-Server_1271189245784.png"><img class="size-full wp-image-362" title="WSO2 Gadget Server_1271189245784" src="http://www.nuwanbando.com/wp-content/uploads/2010/04/WSO2-Gadget-Server_1271189245784.png" alt="" width="831" height="414" /></a><p class="wp-caption-text">Traffic points in A4 road, UK</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.nuwanbando.com/2010/04/mashing-up-rdf-data-with-wso2-mashup-server/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Convert from HTML to XML with HTML Tidy</title>
		<link>http://www.nuwanbando.com/2009/09/convert-from-html-to-xml-with-html-tidy/</link>
		<comments>http://www.nuwanbando.com/2009/09/convert-from-html-to-xml-with-html-tidy/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 06:37:18 +0000</pubDate>
		<dc:creator>Nuwan Bandara</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[Tidy]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.nuwanbando.com/?p=199</guid>
		<description><![CDATA[For few days I was involved with WSO2 Mashup Server 2.0 release documentation, giving a hand to the mashup team. Documentation is a painful task, but when comes to open source what matters mostly is documentation . Last night I had to convert a bunch of html files (some Java Api Docs) to xml in-order [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.nuwanbando.com%2F2009%2F09%2Fconvert-from-html-to-xml-with-html-tidy%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.nuwanbando.com%2F2009%2F09%2Fconvert-from-html-to-xml-with-html-tidy%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>For few days I was involved with <a href="http://wso2.org/projects/mashup">WSO2 Mashup Server</a> 2.0 release documentation, giving a hand to the mashup team. Documentation is a painful task, but when comes to open source what matters mostly is documentation <img src='http://www.nuwanbando.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> .<br />
Last night I had to convert a bunch of html files (some Java Api Docs) to xml in-order to port into maven site. Formatting 30+ html files to xml !@#$%^&amp;*@% <img src='http://www.nuwanbando.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> . So I was googleing for a tool to automate the task. With few clicks here and there I found a nice article in <a href="http://www.ibm.com">Big Blue</a>&#8216;s developer works site, a tool called &#8220;<a href="http://tidy.sourceforge.net/">Tidy</a>&#8220;. When I tried to download and use I figure out that you can straight away apt-get the package and use. So,</p>
<pre name="code" class="xml">sudo apt-get install tidy</pre>
<p>and your box is now equiped with the tool, and can be accessed via the shell.</p>
<pre name="code" class="xml">tidy -asxhtml -numeric < index.html > index.xml</pre>
<p>but who wants to convert file by file when you have such a nice tool, so I spent few minutes in writing a tiny shell script to get the job done, the snippet is, </p>
<pre name="code" class="xml">
#!/bin/bash
for file in $(find $1 -type f -iname '*.html'); do
	myf=`echo $file | sed 's/html/xml/g'`
	tidy -asxhtml -numeric < $file > $myf
done
</pre>
<p>All looked good, worked fine. However in my Api Docs I had, had few special tags, custom to our Mashup Apis (&lt;imconfig&gt;, &lt;yahoo&gt;, &lt;mail:config&gt;). Tidy gave error for these files since the tags are not recognized. </p>
<p>In such a case you can train Tidy for new tags, by adding few lines to the tidy configuration file. (/etc/tidy.config &#8211; You can also give your own config file at the prompt)</p>
<pre name="code" class="xml">new-pre-tags: imconfig, yahoo, msn, aim, icq, jabber, username, password</pre>
<p>There are whole bunch of tweeks you can do with tidy, [<a href="http://www.ibm.com/developerworks/library/x-tiptidy.html">1</a>], [<a href="http://tidy.sourceforge.net/">2</a>] and [<a href="http://tidy.sourceforge.net/docs/tidy_man.html">3</a>] are some useful links that you can read up when using the tool.</p>
<p>[1] : <a href="http://www.ibm.com/developerworks/library/x-tiptidy.html">http://www.ibm.com/developerworks/library/x-tiptidy.html</a><br />
[2] : <a href="http://tidy.sourceforge.net/">http://tidy.sourceforge.net/</a><br />
[3] : <a href="http://tidy.sourceforge.net/docs/tidy_man.html">http://tidy.sourceforge.net/docs/tidy_man.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nuwanbando.com/2009/09/convert-from-html-to-xml-with-html-tidy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Writing custom queries to retrieve data from WSO2 Governance Registry</title>
		<link>http://www.nuwanbando.com/2009/08/custom-queries-to-retrieve-data-from-wso2-governance-registry/</link>
		<comments>http://www.nuwanbando.com/2009/08/custom-queries-to-retrieve-data-from-wso2-governance-registry/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 11:58:55 +0000</pubDate>
		<dc:creator>Nuwan Bandara</dc:creator>
				<category><![CDATA[FOSS]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[WSO2]]></category>
		<category><![CDATA[G-reg]]></category>

		<guid isPermaLink="false">http://www.nuwanbando.com/?p=176</guid>
		<description><![CDATA[WSO2 Governance Registry is a big part of wso2 governance product stack. Even though it is primarily aimed at managing, versioning, rating, and commenting on SOA artifacts it can also be used as a simple data store. with the 3.0 version the G-Reg gave support to custom query execution from the client side. This feature [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.nuwanbando.com%2F2009%2F08%2Fcustom-queries-to-retrieve-data-from-wso2-governance-registry%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.nuwanbando.com%2F2009%2F08%2Fcustom-queries-to-retrieve-data-from-wso2-governance-registry%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><a href="http://wso2.org/projects/governance-registry">WSO2 Governance Registry</a> is a big part of wso2 governance product stack. Even though it is primarily aimed at managing, versioning, rating, and commenting on SOA artifacts it can also be used as a simple data store. with the 3.0 version the G-Reg gave support to custom query execution from the client side. This feature helps immensely when you use the registry for non-standard tasks. For me I had to do some pagination work for the comments that belongs to a particular resource, hence my approach was to write few custom quires to get the job done. The code is as follows.</p>
<pre name="code" class="java">
	/**
	 * Returns a chunk of comments
	 *
	 * @param resPath	Path to the comment
	 * @param start		The beginning index
	 * @param size		Size of the chunk
	 * @return			an array of comments
	 */
 public Comment[] getCommentSet(String resPath, int start, int size) {
		Registry registry = null;
		try {
			registry = ; // get an instance of the registry 

			Resource comQuery = registry.newResource();

                        // The Sql Statement
			String sql = "SELECT REG_COMMENT_ID FROM REG_RESOURCE_COMMENT RC, REG_RESOURCE R, REG_PATH P WHERE "
					+ "RC.REG_VERSION=R.REG_VERSION AND "
					+ "R.REG_NAME=? AND "
					+ "P.REG_PATH_VALUE=? AND "
					+ "P.REG_PATH_ID=R.REG_PATH_ID LIMIT ?, ?";

			// Set SQL statement as the resource content
                        comQuery.setContent(sql);

                       // Setting the media type and properties
			comQuery.setMediaType(RegistryConstants.SQL_QUERY_MEDIA_TYPE);
			comQuery.addProperty(RegistryConstants.RESULT_TYPE_PROPERTY_NAME, RegistryConstants.COMMENTS_RESULT_TYPE);

			registry.put("system/myQueries/query", comQuery);
                 String resourceName = "testResource";
                 String pathToResource = "/system/myResources"

			Map<String, String> params = new HashMap<String, String>();

                        //Setting the parameters
			params.put("1", resourceName);
			params.put("2", pathToResource);
			params.put("3", start);
			params.put("4", size);

                       // Executing the SQL statement
			Collection qResults = registry.executeQuery("system/myQueries/query", params);

			String[] qPaths = (String[]) qResults.getContent();

			Comment[] comments = new Comment[qPaths.length];
                        // Loading the comment data to comment object array
			for (int i = 0; i < qPaths.length; i++) {
				if (registry.resourceExists(qPaths[i])) {
					comments[i] = (Comment) registry.get(qPaths[i]);
				}
			}

			return comments;

		} catch (Exception e) {
			String errorMsg = "Backend server error - could not get comment set";
			log.error(new MyTestException(errorMsg, e));
			return null;
		}

	}
</pre>
<p>Yeah simple as that you get your resources set without much effort. A big thank goes to <a href="http://www.dimuthu.org/">Dimuthu</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nuwanbando.com/2009/08/custom-queries-to-retrieve-data-from-wso2-governance-registry/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>YUI file upload with jsp backend</title>
		<link>http://www.nuwanbando.com/2009/07/yui-file-upload-with-jsp-backend/</link>
		<comments>http://www.nuwanbando.com/2009/07/yui-file-upload-with-jsp-backend/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 16:51:29 +0000</pubDate>
		<dc:creator>Nuwan Bandara</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://www.nuwanbando.com/?p=147</guid>
		<description><![CDATA[For last two weeks I was working on some user interface logic and happened to use Yahoo UI library (YUI). The task was to upload an image using Ajax. Since I was new to YUI, I was looking here and there over the net for some references. There were some good ones but thats for [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.nuwanbando.com%2F2009%2F07%2Fyui-file-upload-with-jsp-backend%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.nuwanbando.com%2F2009%2F07%2Fyui-file-upload-with-jsp-backend%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>For last two weeks I was working on some user interface logic and happened to use Yahoo UI library (<a href="http://developer.yahoo.com/yui/" target="_blank">YUI</a>). The task was to upload an image using Ajax. Since I was new to YUI, I was looking here and there over the net for some references. There were some good ones but thats for PHP back-ends, but mine was a jsp back-end and i didn&#8217;t know how to read the object thrown out from the YUI side.</p>
<p>with some more digging I came across nice file handling library in Apache commons (<a href="http://commons.apache.org/fileupload/using.html" target="_blank">Commons File Upload</a>) and took use of it to do the task. the code is as follows.</p>
<pre name="code" class="html">
<html>
<head>

<script type="text/javascript" src="[PATH_TO_YUI]/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="[PATH_TO_YUI]/connection/connection-min.js"></script>
<script type="text/javascript">
function init(){
  var onUploadButtonClick = function(e){
    //the second argument of setForm is crucial,
    //which tells Connection Manager this is a file upload form
    YAHOO.util.Connect.setForm('testForm', true);

    var uploadHandler = {
      upload: function(o) {
        alert(o.responseText);
      }
    };
  YAHOO.util.Connect.asyncRequest('POST', 'upload.php', uploadHandler);
  };
  YAHOO.util.Event.on('uploadButton', 'click', onUploadButtonClick);
}

YAHOO.util.Event.on(window, 'load', init);
</script>
</head>
<body>
<form action="upload.php" enctype="multipart/form-data" method="post" id="testForm">
<input type="text" id="test"/>
<input type="text" id="test-2"/>
<input type="text" id="test-3"/>
<input type="file" name="testFile"/>
<input type="button" id="uploadButton" value="Upload"/>
</form>

</body>
</html>
</pre>
<p>I took the above code segment directly from a <a href="http://thecodecentral.com/2007/09/04/asynchronous-file-upload-yuis-approach">YUI file upload tutorial</a> hence the credit goes to the author. The jsp back-end using apache commons file upload is as follows.<br />
<span id="more-147"></span></p>
<pre name="code" class="java">
if (ServletFileUpload.isMultipartContent(request)) {
	FileItemFactory factory = new DiskFileItemFactory();

	ServletFileUpload servletFileUpload = new ServletFileUpload(
					factory);
	List fileItemsList = servletFileUpload
					.parseRequest(request);

	String optionalFileName = "";
	FileItem fileItem = null;

	Iterator it = fileItemsList.iterator();

	while (it.hasNext()) {
		FileItem item = (FileItem) it.next();
		if (item.isFormField()) {
		//Other form values
			if (item.getFieldName().equals("test"))
				gName = item.getString();
			if (item.getFieldName().equals("test-2"))
				gUrl = item.getString();
			if (item.getFieldName().equals("test-3"))
				gDesc = item.getString();
		} else {
			contentType = item.getContentType();
			itemSizeInBytes = item.getSize();
			//any operation with the file goes here
		}

	}

}
</pre>
<p>So thats how it goes <img src='http://www.nuwanbando.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.nuwanbando.com/2009/07/yui-file-upload-with-jsp-backend/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JSF, Spring together with apache CXF</title>
		<link>http://www.nuwanbando.com/2009/01/jsf-spring-together-with-apache-cxf/</link>
		<comments>http://www.nuwanbando.com/2009/01/jsf-spring-together-with-apache-cxf/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 09:43:23 +0000</pubDate>
		<dc:creator>Nuwan Bandara</dc:creator>
				<category><![CDATA[FOSS]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[CXF]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://www.nuwanbando.com/?p=113</guid>
		<description><![CDATA[Good tutorials and resources on Apache CXF How Tos are not easy to digg. I had to spend hours searching and reading to make my small application up and running, Integrating Spring with JSF was pretty straightforward, but when it comes to integrating those two with JSF i got stuck. So this post is about [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.nuwanbando.com%2F2009%2F01%2Fjsf-spring-together-with-apache-cxf%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.nuwanbando.com%2F2009%2F01%2Fjsf-spring-together-with-apache-cxf%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Good tutorials and resources on Apache CXF How Tos are not easy to digg. I had to spend hours searching and reading to make my small application up and running, Integrating Spring with JSF was pretty straightforward, but when it comes to integrating those two with JSF i got stuck.</p>
<p>So this post is about <strong>exposing a web service</strong> as a web project using <strong>JSF front end / Spring backed and CXF</strong> for service invocation</p>
<p>before starting I should mention few valuable resource around the net.</p>
<ul>
<li><a href="http://cwiki.apache.org/CXF20DOC/index.html" target="_blank">The CXF documentation (Hope it will be completed soon)</a></li>
<li><a href="http://wheelersoftware.com/articles/spring-cxf-consuming-web-services.html" target="_blank">Make Web Services Transparent with Spring 2.5 and Apache CXF 2.0 by Willie Wheeler</a></li>
<li><a href="http://www.ibm.com/developerworks/webservices/library/ws-pojo-springcxf/index.html?S_TACT=105AGX04&amp;S_CMP=EDU">Introduction to Web services creation using CXF and Spring by Rajeev Hathi and Naveen Balani</a></li>
<li><a href="http://www.netbeans.org/kb/60/websvc/client.html">Developing JAX-WS Web Service Clients &#8211; netbeans</a></li>
<li><a href="http://weblogs.java.net/blog/caroljmcdonald/archive/2007/09/sample_applicat_3.html" target="_blank">Sample Application using JAX-WS, JSF, Spring, and Java by Carol Mcdonal</a></li>
</ul>
<p>The web service u used was the publicly available spelling checker which is used in the <a href="http://www.netbeans.org/kb/60/websvc/client.html">netbeans tutorial.</a></p>
<p><strong>The Step by step guide as follows &gt;&gt;</strong></p>
<p><strong>Step 1 : </strong></p>
<p>Create the classes from the WSDL you can use netbeans for this task or WSDL2JAVA command (wsdl2java [URL]) in the shell.</p>
<p><span id="more-113"></span></p>
<p><strong>Step2 :</strong></p>
<p>Put the generated classes to your WEB-INF/classes directory and simply write a java class to bind to the JSF front and to expose the web service. I was too lazy to iterate the whole list when showing the incorrect words. so please bare with me <img src='http://www.nuwanbando.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Example :</p>
<blockquote><p>package demo;</p>
<p>import com.cdyne.ws.CheckSoap;<br />
import com.cdyne.ws.Words;<br />
import java.util.List;</p>
<p>public class SpellChecker {</p>
<p>private CheckSoap service;<br />
private String textArea;<br />
private String wrongWord;</p>
<p>public void setWrongWord(String wrongWord) {<br />
this.wrongWord = wrongWord;<br />
}</p>
<p>public String getWrongWord() {<br />
return wrongWord;<br />
}</p>
<p>public void setTextArea(String textArea) {<br />
this.textArea = textArea;<br />
}</p>
<p>public String getTextArea() {<br />
return textArea;<br />
}</p>
<p>//the spring context sets the service using cxf dynamic proxy</p>
<p><strong>public void setService(CheckSoap service) {<br />
this.service = service;<br />
}</strong></p>
<p>public void checkSpelling() {<br />
try{<br />
System.out.println(&#8220;Checking spelli&#8230;&#8221;);<br />
com.cdyne.ws.DocumentSummary doc = service.checkTextBody(textArea, &#8220;&#8221;);<br />
List allwrongwords = doc.getMisspelledWord();<br />
wrongWord = ((Words) allwrongwords.get(0)).getWord();<br />
}catch (Exception e){<br />
e.printStackTrace();<br />
}</p>
<p>}</p>
<p>}</p></blockquote>
<p><strong>Step 3:</strong></p>
<p>Write a small JSF form to display and for use inputs,</p>
<p>Some thing like,</p>
<blockquote><p>&lt;h:form id=&#8221;spellingForm&#8221;&gt;<br />
&lt;h:outputLabel id=&#8221;label1&#8243; value=&#8221;ENTER you text : &#8221; /&gt;<br />
&lt;br /&gt;<br />
&lt;h:inputTextarea id=&#8221;textarea1&#8243; value=&#8221;#{spellingBean.textArea}&#8221; /&gt;<br />
&lt;br /&gt;<br />
&lt;h:commandButton id=&#8221;cmd1&#8243; value=&#8221;check&#8221; action=&#8221;#{spellingBean.checkSpelling}&#8221; /&gt;<br />
&lt;br /&gt;<br />
&lt;h:outputLabel id=&#8221;lab2&#8243; value=&#8221;The misspelled word is : &#8221; /&gt;<br />
&lt;h:outputText id=&#8221;text2&#8243; value=&#8221;#{spellingBean.wrongWord}&#8221; /&gt;<br />
&lt;/h:form&gt;</p></blockquote>
<p><strong>Step 4:</strong></p>
<p>Here comes the good stuff <img src='http://www.nuwanbando.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Write a Spring Context file for me it was spellapp-servlet.xml</p>
<blockquote><p>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;UTF-8&#8243;?&gt;<br />
&lt;beans xmlns=&#8221;http://www.springframework.org/schema/beans&#8221;<br />
xmlns:xsi=&#8221;http://www.w3.org/2001/XMLSchema-instance&#8221;<br />
xmlns:context=&#8221;http://www.springframework.org/schema/context&#8221;<br />
xsi:schemaLocation=&#8221;http://www.springframework.org/schema/beans</p>
<p>http://www.springframework.org/schema/beans/spring-beans-2.5.xsd</p>
<p>http://www.springframework.org/schema/context</p>
<p>http://www.springframework.org/schema/context/spring-context-2.5.xsd&#8221;&gt;</p>
<p><strong>&lt;bean id=&#8221;client&#8221; class=&#8221;com.cdyne.ws.CheckSoap&#8221;<br />
factory-bean=&#8221;clientFactory&#8221; factory-method=&#8221;create&#8221;/&gt;</strong></p>
<p><strong>&lt;bean id=&#8221;clientFactory&#8221; class=&#8221;org.apache.cxf.jaxws.JaxWsProxyFactoryBean&#8221;&gt;<br />
&lt;property name=&#8221;serviceClass&#8221; value=&#8221;com.cdyne.ws.CheckSoap&#8221;/&gt;<br />
&lt;property name=&#8221;address&#8221; value=&#8221;http://ws.cdyne.com/SpellChecker/check.asmx?WSDL&#8221;/&gt;<br />
&lt;/bean&gt;</strong></p>
<p>&lt;/beans&gt;</p></blockquote>
<p><strong>Step 5: </strong></p>
<p>The Faces config (faces-config.xml)</p>
<blockquote><p>&lt;faces-config version=&#8221;1.2&#8243;<br />
xmlns=&#8221;http://java.sun.com/xml/ns/javaee&#8221;<br />
xmlns:xsi=&#8221;http://www.w3.org/2001/XMLSchema-instance&#8221;<br />
xsi:schemaLocation=&#8221;http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd&#8221;&gt;<br />
&lt;application&gt;<br />
&lt;variable-resolver&gt;org.springframework.web.jsf.DelegatingVariableResolver&lt;/variable-resolver&gt;<br />
&lt;/application&gt;</p>
<p>&lt;managed-bean&gt;<br />
&lt;managed-bean-name&gt;spellingBean&lt;/managed-bean-name&gt;<br />
&lt;managed-bean-class&gt;<br />
demo.SpellChecker<br />
&lt;/managed-bean-class&gt;<br />
&lt;managed-bean-scope&gt;session&lt;/managed-bean-scope&gt;<br />
<strong>&lt;managed-property&gt;<br />
&lt;property-name&gt;service&lt;/property-name&gt;<br />
&lt;value&gt;#{client}&lt;/value&gt;<br />
&lt;/managed-property&gt;</strong></p>
<p>&lt;/managed-bean&gt;</p>
<p>&lt;/faces-config&gt;</p></blockquote>
<p><strong>Step 6:</strong></p>
<p>The web.xml</p>
<blockquote><p>&lt;web-app version=&#8221;2.5&#8243; xmlns=&#8221;http://java.sun.com/xml/ns/javaee&#8221; xmlns:xsi=&#8221;http://www.w3.org/2001/XMLSchema-instance&#8221; xsi:schemaLocation=&#8221;http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&#8221;&gt;<br />
&lt;!&#8211; Spring Application Context configuration &#8211;&gt;<br />
<strong>&lt;context-param&gt;<br />
&lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;<br />
&lt;param-value&gt;</strong><br />
<strong>/WEB-INF/spellapp-servlet.xml<br />
&lt;/param-value&gt;</strong><br />
&lt;/context-param&gt;<br />
&lt;context-param&gt;<br />
&lt;param-name&gt;javax.faces.CONFIG_FILES&lt;/param-name&gt;<br />
&lt;param-value&gt;/WEB-INF/faces-config.xml&lt;/param-value&gt;<br />
&lt;/context-param&gt;</p>
<p>&lt;context-param&gt;<br />
&lt;param-name&gt;javax.faces.STATE_SAVING_METHOD&lt;/param-name&gt;<br />
&lt;param-value&gt;server&lt;/param-value&gt;<br />
&lt;/context-param&gt;<br />
&lt;listener&gt;<br />
<strong>&lt;listener-class&gt;<br />
org.springframework.web.context.request.RequestContextListener<br />
&lt;/listener-class&gt;</strong><br />
&lt;/listener&gt;<br />
&lt;context-param&gt;<br />
&lt;param-name&gt;com.sun.faces.verifyObjects&lt;/param-name&gt;<br />
&lt;param-value&gt;false&lt;/param-value&gt;<br />
&lt;/context-param&gt;<br />
&lt;context-param&gt;<br />
&lt;param-name&gt;com.sun.faces.validateXml&lt;/param-name&gt;<br />
&lt;param-value&gt;true&lt;/param-value&gt;<br />
&lt;/context-param&gt;<br />
<strong>&lt;listener&gt;<br />
&lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;<br />
&lt;/listener&gt;</strong><br />
&lt;servlet&gt;<br />
&lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;<br />
&lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;<br />
&lt;load-on-startup&gt;3&lt;/load-on-startup&gt;<br />
&lt;/servlet&gt;<br />
&lt;servlet&gt;<br />
&lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;<br />
&lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;<br />
&lt;load-on-startup&gt;2&lt;/load-on-startup&gt;<br />
&lt;/servlet&gt;<br />
&lt;servlet-mapping&gt;<br />
&lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;<br />
&lt;url-pattern&gt;*.htm&lt;/url-pattern&gt;<br />
&lt;/servlet-mapping&gt;<br />
&lt;servlet-mapping&gt;<br />
&lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;<br />
&lt;url-pattern&gt;/faces/*&lt;/url-pattern&gt;<br />
&lt;/servlet-mapping&gt;<br />
&lt;session-config&gt;<br />
&lt;session-timeout&gt;<br />
30<br />
&lt;/session-timeout&gt;<br />
&lt;/session-config&gt;<br />
&lt;welcome-file-list&gt;<br />
&lt;welcome-file&gt;redirect.jsp&lt;/welcome-file&gt;<br />
&lt;/welcome-file-list&gt;<br />
&lt;/web-app&gt;<br />
<strong><br />
</strong></p></blockquote>
<p><strong>Step 7:</strong></p>
<p>That&#8217;s It Build it deploy it. Have fun <img src='http://www.nuwanbando.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> <strong><br />
</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nuwanbando.com/2009/01/jsf-spring-together-with-apache-cxf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>English &#8211; Sinhala Unicode Translator (ඉංග්‍රිසි &#8211; සිංහල භාෂා පරිවර්තකය)</title>
		<link>http://www.nuwanbando.com/2008/08/english-sinhala-unicode-translator-%e0%b6%89%e0%b6%82%e0%b6%9c%e0%b7%8a%e0%b6%bb%e0%b7%93%e0%b7%83%e0%b7%92-%e0%b7%83%e0%b7%92%e0%b6%82%e0%b7%84%e0%b6%bd-%e0%b6%b7%e0%b7%8f%e0%b7%82%e0%b7%8f/</link>
		<comments>http://www.nuwanbando.com/2008/08/english-sinhala-unicode-translator-%e0%b6%89%e0%b6%82%e0%b6%9c%e0%b7%8a%e0%b6%bb%e0%b7%93%e0%b7%83%e0%b7%92-%e0%b7%83%e0%b7%92%e0%b6%82%e0%b7%84%e0%b6%bd-%e0%b6%b7%e0%b7%8f%e0%b7%82%e0%b7%8f/#comments</comments>
		<pubDate>Sat, 02 Aug 2008 11:58:07 +0000</pubDate>
		<dc:creator>Nuwan Bandara</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Sinhala]]></category>
		<category><![CDATA[Unicode]]></category>

		<guid isPermaLink="false">http://www.nuwanbando.com/?p=90</guid>
		<description><![CDATA[Lat few days i was stuck with some web dev work for archmage. For the 1st time i had to localize a website in sinhala. Hence i had a longing desire to do something on sinhala i was glad. (Also getting payed for it definitely a chance. ) so yeah the site is www.technology.lk still [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.nuwanbando.com%2F2008%2F08%2Fenglish-sinhala-unicode-translator-%25e0%25b6%2589%25e0%25b6%2582%25e0%25b6%259c%25e0%25b7%258a%25e0%25b6%25bb%25e0%25b7%2593%25e0%25b7%2583%25e0%25b7%2592-%25e0%25b7%2583%25e0%25b7%2592%25e0%25b6%2582%25e0%25b7%2584%25e0%25b6%25bd-%25e0%25b6%25b7%25e0%25b7%258f%25e0%25b7%2582%25e0%25b7%258f%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.nuwanbando.com%2F2008%2F08%2Fenglish-sinhala-unicode-translator-%25e0%25b6%2589%25e0%25b6%2582%25e0%25b6%259c%25e0%25b7%258a%25e0%25b6%25bb%25e0%25b7%2593%25e0%25b7%2583%25e0%25b7%2592-%25e0%25b7%2583%25e0%25b7%2592%25e0%25b6%2582%25e0%25b7%2584%25e0%25b6%25bd-%25e0%25b6%25b7%25e0%25b7%258f%25e0%25b7%2582%25e0%25b7%258f%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Lat few days i was stuck with some web dev work for <a href="http://www.archmage.lk" target="_blank">archmage</a>. For the 1st time i had to localize a website in sinhala. Hence i had a longing desire to do something on sinhala i was glad. (Also getting payed for it <img src='http://www.nuwanbando.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  definitely a chance. )  so yeah the site is <a href="http://www.technology.lk" target="_blank">www.technology.lk</a> still under construction. The site back-end is powered by Joomla CMS and the famous Ecom component virtuemart. I had to prepare a language pack (Sinhala) for virtuemart, not a hard task, yet translating about 200+ words to sinhala is a boring task, so i was googling for an English-Sinhala Translator tool, Found <a href="http://www.maduraonline.com/" target="_blank">Madura Dictionary</a>. Unfortunately the sinhala words given in madura is not in Unicode. so it was impossible to copy and paste in my language pack php script.</p>
<dl id="attachment_95" class="wp-caption alignnone" style="width: 310px;"> </dl>
<p>After having a chat with my dear friend <a href="http://www.sandaru1.com" target="_blank">sanda</a>, he suggested a <a href="http://www.ucsc.cmb.ac.lk/ltrl/projects/EnSiTip/" target="_blank">FireFox plug-in</a> which was developed by the University of Colombo (<a href="http://www.ucsc.cmb.ac.lk/" target="_blank">UCSC</a>) which does a similar task. the plug-in came with a sqlite database which consisted nearly 50,000 English to sinhala translation words, and in Unicode. I was thrilled to see this. So for my personal satisfaction I just put to gather a small translator tool where you can type an English word and it gives some Sinhala suggestions (in Unicode).</p>
<div id="attachment_95" class="wp-caption alignnone" style="width: 310px"><a href="http://www.nuwanbando.com/wp-content/uploads/2008/08/dict.jpg"><img class="size-medium wp-image-95" title="dict" src="http://www.nuwanbando.com/wp-content/uploads/2008/08/dict-300x249.jpg" alt="En-Si Trans" width="300" height="249" /></a><p class="wp-caption-text"> </p></div>
<p>Made it in Java, also wanted to test this new swing look and feel called <a href="https://substance.dev.java.net/" target="_blank">Substance</a> which did work smoothly. so yeah you can <a href="http://www.nuwanbando.com/wp-content/uploads/2008/08/ensitranslator.rar">download</a></p>
<p>this tool and use it, modify it or what ever <img src='http://www.nuwanbando.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  .</p>
<p>have fun,</p>
<p>p.s. : I will publish the Virtuemart Sinhala language pack in my next post.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nuwanbando.com/2008/08/english-sinhala-unicode-translator-%e0%b6%89%e0%b6%82%e0%b6%9c%e0%b7%8a%e0%b6%bb%e0%b7%93%e0%b7%83%e0%b7%92-%e0%b7%83%e0%b7%92%e0%b6%82%e0%b7%84%e0%b6%bd-%e0%b6%b7%e0%b7%8f%e0%b7%82%e0%b7%8f/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Select Many Problem : JSF</title>
		<link>http://www.nuwanbando.com/2008/02/select-many-problem-jsf/</link>
		<comments>http://www.nuwanbando.com/2008/02/select-many-problem-jsf/#comments</comments>
		<pubDate>Wed, 06 Feb 2008 09:59:06 +0000</pubDate>
		<dc:creator>Nuwan Bandara</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web Designing & Development]]></category>
		<category><![CDATA[JSF]]></category>

		<guid isPermaLink="false">http://nuwanbando.com/?p=76</guid>
		<description><![CDATA[After few days, got some time to write a post&#8230; well as i promised in my earlier post.. I thought of writing about the Annoying problem anybody will face while using selectMany component in JSF. At 1st with out any experience what any one would do is writing both assessor and mutator methods to return [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.nuwanbando.com%2F2008%2F02%2Fselect-many-problem-jsf%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.nuwanbando.com%2F2008%2F02%2Fselect-many-problem-jsf%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>After few days, got some time to write a post&#8230; well as i promised in my earlier post.. I thought of writing about the Annoying problem anybody will face while using selectMany component in JSF.</p>
<p>At 1st with out any experience what any one would do is writing both assessor and mutator methods to return and set A LIST of selected objects. some thing like</p>
<blockquote><p>private List&lt;myClass&gt; selectList;</p>
<p>public List&lt;myClass&gt; getSelectList() {<br />
return selectList;<br />
}</p>
<p>public void setSelectList(List&lt;myClass&gt; selectList) {<br />
this.selectList =  selectList;<br />
}</p></blockquote>
<p>Even though this is the straight forward way, For some reason JSF implementation does not support it. In many places over the NET and in JSF forums, people have advised to use String Arrays, Saying you cannot use Java Collections in this scenario.</p>
<p>But Use of String Arrays are very much annoying and makes your work very messy. After some testing and trying I found this work around to take the selected objects as it is, not just the label string, Its pretty simple. Instead of using String arrays, Just use an array of your own class. Something like this</p>
<blockquote><p>private myClass[] selectList;</p>
<p>public myClass[] getSelectList() {<br />
return selectList;<br />
}</p>
<p>public void setSelectList(myClass[] selectList) {<br />
this.selectList =  selectList;<br />
}</p></blockquote>
<p>Of-cause you have to use a converter in this case but not difference out there its just a normal converter for your class. So hope this tip will help</p>
<p>cheers !!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nuwanbando.com/2008/02/select-many-problem-jsf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8220;Validation Error: Value is not valid&#8221; famous validation error, when using custom converters in JSF.</title>
		<link>http://www.nuwanbando.com/2008/01/validation-error-value-is-not-valid-famous-validation-error-when-using-custom-converters-in-jsf/</link>
		<comments>http://www.nuwanbando.com/2008/01/validation-error-value-is-not-valid-famous-validation-error-when-using-custom-converters-in-jsf/#comments</comments>
		<pubDate>Tue, 29 Jan 2008 09:27:15 +0000</pubDate>
		<dc:creator>Nuwan Bandara</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web Designing & Development]]></category>
		<category><![CDATA[JSF]]></category>

		<guid isPermaLink="false">http://nuwanbando.com/?p=75</guid>
		<description><![CDATA[This is one problem i faced when i worked with select-many and select-one menus in Java Server Faces. For any one who have worked with JSF knows that you have to use custom converters in order to populate select-many and select-on menus with ur own data types. if i elaborate on this a little bit, [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.nuwanbando.com%2F2008%2F01%2Fvalidation-error-value-is-not-valid-famous-validation-error-when-using-custom-converters-in-jsf%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.nuwanbando.com%2F2008%2F01%2Fvalidation-error-value-is-not-valid-famous-validation-error-when-using-custom-converters-in-jsf%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>This is one problem i faced when i worked with select-many and select-one menus in Java Server Faces. For any one who have worked with <span class="misspell" suggestions="SF,NSF,J'S">JSF</span> knows that you have to use custom converters in order to populate select-many and select-on menus with <span class="misspell" suggestions="Ur,Ir,UAR,Ru,U">ur</span> own data types.</p>
<p>if i elaborate on this a little bit, Select menus are not just there to show simple value-label pairs. you can give directly an object to its value and one of its fields as the label. for an example,</p>
<blockquote><p>public <span class="misspell" suggestions="Array List,Array-List,Aerialist,Realist,Arabist">ArrayList</span>&lt;<span class="misspell" suggestions="Select Item,Select-Item,Selected">SelectItem</span>&gt; <span class="misspell">getLandSelectList</span>() {<br />
if (<span class="misspell">landSelectList</span> != null) {<br />
return <span class="misspell">landSelectList</span>;<br />
}<br />
<span class="misspell">    landSelectList</span> = new <span class="misspell" suggestions="Array List,Array-List,Aerialist,Realist,Arabist">ArrayList</span>&lt;<span class="misspell" suggestions="Select Item,Select-Item,Selected">SelectItem</span>&gt;();<br />
List&lt;Land&gt; <span class="misspell" suggestions="land List,land-List,landless,landslid,Landsat">landList</span> = this.<span class="misspell">getLandList</span>();<br />
for (int i = 0; i &lt; <span class="misspell" suggestions="land List,land-List,landless,landslid,Landsat">landList</span>.size(); i++) {<br />
<span class="misspell">        landSelectList</span>.add(new <span class="misspell" suggestions="Select Item,Select-Item,Selected">SelectItem</span>(<span class="misspell" suggestions="land List,land-List,landless,landslid,Landsat">landList</span>.get(i), <span class="misspell" suggestions="land List,land-List,landless,landslid,Landsat">landList</span>.get(i)<br />
.<span class="misspell">getLandsName</span>_DE()));<br />
}<br />
return <span class="misspell">landSelectList</span>;<br />
}</p></blockquote>
<p>The returning Select list can be taken to a select one or a select many list box like..</p>
<blockquote><p>&lt;h:<span class="misspell" suggestions="selectmen,selectman">selectOneMenu</span> id=&#8221;<span class="misspell">listBoxLand</span>&#8221;<br />
value=&#8221;#{<span class="misspell">userManagerBean</span>.land}&#8221; required=&#8221;true&#8221;&gt;<br />
&lt;f:<span class="misspell" suggestions="select Items,select-Items">selectItems</span> value=&#8221;#{<span class="misspell">userManagerBean</span>.<span class="misspell">landSelectList</span>}&#8221; /&gt;<br />
&lt;/h:<span class="misspell" suggestions="selectmen,selectman">selectOneMenu</span>&gt;<br />
&lt;h:message for=&#8221;<span class="misspell">listBoxLand</span>&#8221; /&gt;</p></blockquote>
<p>This component will set the selected land object directly to the backing bean. If you used simple value(some text or the id) &#8211; label pair. you should again query for the object from the selected id and save in the backing bean. but in this way that extra trouble will be handled by <span class="misspell" suggestions="SF,NSF,J'S">JSF</span>.</p>
<p>The problem is if you do it just like this with out anything else.. you will get a wired validation error saying &#8220;<strong>Validation Error: Value is not valid</strong>&#8220;. This is where you start googling and debugging. Well after some hours of googling..(couldn&#8217;t do much debugging because this is a exception thrown by <span class="misspell" suggestions="SF,NSF,J'S">JSF</span> framework) and reading about 10 to 20 forums i found out that the object which is loaded and the object <span class="misspell" suggestions="which,witch,winch,wish,Mich">wich</span> was selected will be compared when setting to the backing bean. So if your object&#8217;s Class has not overridden the equals method this error message is shown.</p>
<p>So what you have to do is. if you are using your own data Objects for the select menus or in that case for any other <span class="misspell" suggestions="SF,NSF,J'S">JSF</span> tag where you will use converters. You have to override the Equals method. Probably do the comparison with the Id, or with some unique value in that data Object. That&#8217;s it.. The problem solved. In my case the equals methods looks like</p>
<blockquote><p>// overridden equals method<br />
public <span class="misspell" suggestions="Boolean,boo lean,boo-lean,Boleyn,Boole">boolean</span> equals(Object obj) {<br />
if (!(obj <span class="misspell" suggestions="instance of,instance-of,instanced,instance,instances">instanceof</span> Land)) {<br />
return false;<br />
}<br />
Land land = (Land) obj;</p>
<p>return (this.id == land.id);</p>
<p>}</p></blockquote>
<p>Yeah hope this will be useful to some one.. !! I will write another post on how to use Java Collections when working with Select-Many menus.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nuwanbando.com/2008/01/validation-error-value-is-not-valid-famous-validation-error-when-using-custom-converters-in-jsf/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>Joomla Hack! Automated Joomla user registration via JSF form</title>
		<link>http://www.nuwanbando.com/2008/01/joomla-hack-automated-joomla-user-registration-via-jsf-form/</link>
		<comments>http://www.nuwanbando.com/2008/01/joomla-hack-automated-joomla-user-registration-via-jsf-form/#comments</comments>
		<pubDate>Sat, 26 Jan 2008 18:42:39 +0000</pubDate>
		<dc:creator>Nuwan Bandara</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Joomla]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web Designing & Development]]></category>
		<category><![CDATA[JSF]]></category>

		<guid isPermaLink="false">http://nuwanbando.com/?p=74</guid>
		<description><![CDATA[Well this post is some what continuation of my last post. What is the use of single sign on if you have to register in two different sites ? yeah this is the solution for that&#8230; What i wanted to do is, when a user registers in my java web application i wanted to register [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.nuwanbando.com%2F2008%2F01%2Fjoomla-hack-automated-joomla-user-registration-via-jsf-form%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.nuwanbando.com%2F2008%2F01%2Fjoomla-hack-automated-joomla-user-registration-via-jsf-form%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Well this post is some what continuation of my last post.<br />
What is the use of single sign on if you have to register in two different sites ? yeah this is the solution for that&#8230; What i wanted to do is, when a user registers in my java web application i wanted to register the same user in the <span class="misspell" suggestions="PHIP,PP,PH,HP,PHI">PHP</span> app. Since these two applications have different user data-tables (well in my project i cannot merge these tables or use one database. if that is your case just ignore this post.)</p>
<p>When a new user registers in my JAVA web app am taking that user form data and insert those to the <span class="misspell" suggestions="Jamal,Romola,Jammal,Joela,Kamila">joomla</span> database. <img src='http://www.nuwanbando.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  (Yup I know.. What is there to blog about this ?)<br />
But what went wrong is <span class="misspell" suggestions="Jamal,Romola,Jammal,Joela,Kamila">joomla</span> use some extra data from 2 other different tables other than <span class="misspell" suggestions="Jo's,Jose,Josi,Josy,joys">jos</span>_users (in joomla database).</p>
<p>those tables are <span style="font-style: italic" class="misspell" suggestions="Jo's,Jose,Josi,Josy,joys">jos</span><span style="font-style: italic">_core_</span><span style="font-style: italic" class="misspell" suggestions="ACLU,Cal,cal,AC,AL">acl</span><span style="font-style: italic">_</span><span style="font-style: italic" class="misspell" suggestions="Ari,Ario,Afro,Aron,Argo">aro</span><span style="font-style: italic"> </span>and <span style="font-style: italic; font-weight: bold" class="misspell" suggestions="Jo's,Jose,Josi,Josy,joys">jos</span><span style="font-style: italic; font-weight: bold">_core_</span><span style="font-style: italic; font-weight: bold" class="misspell" suggestions="ACLU,Cal,cal,AC,AL">acl</span><span style="font-style: italic; font-weight: bold">_groups_</span><span style="font-style: italic; font-weight: bold" class="misspell" suggestions="Ari,Ario,Afro,Aron,Argo">aro</span><span style="font-style: italic; font-weight: bold">_map</span> so when you are inserting the data to the <span style="font-style: italic" id="bad_word" class="misspell" suggestions="Jo's,Jose,Josi,Josy,joys">jos</span><span style="font-style: italic">_users</span> table.. also save the data in to the other two tables as well.<br />
there are foreign key constrains over these tables. so</p>
<p>1- Insert the user to the <span class="misspell" suggestions="Jo's,Jose,Josi,Josy,joys">jos</span>_users<br />
2<span class="misspell" suggestions="ND,Nd,Ned,nod,MD"></span>- take the user id from a select query and insert that user to the <span class="misspell" suggestions="Jo's,Jose,Josi,Josy,joys">jos</span>_core_<span class="misspell" suggestions="ACLU,Cal,cal,AC,AL">acl</span>_<span class="misspell" suggestions="Ari,Ario,Afro,Aron,Argo">aro</span><br />
3- takes <span class="misspell" suggestions="Jo's,Jose,Josi,Josy,joys">jos</span>_core_<span class="misspell" suggestions="ACLU,Cal,cal,AC,AL">acl</span>_<span class="misspell" suggestions="Ari,Ario,Afro,Aron,Argo">aro</span> id from a select query and insert it in to the <span class="misspell" suggestions="Jo's,Jose,Josi,Josy,joys">jos</span>_core_<span class="misspell" suggestions="ACLU,Cal,cal,AC,AL">acl</span>_groups_<span class="misspell" suggestions="Ari,Ario,Afro,Aron,Argo">aro</span>_map</p>
<p>take a look at the three tables then you will realize what you should do.</p>
<p>The other task is password encryption. well <span class="misspell" suggestions="Jamal,Romola,Jammal,Joela,Kamila">Joomla</span> 1.5 uses <span class="misspell" suggestions="MD,Md,mad,med,mid">md</span>5 encryption mechanism to hash the passwords.  When a password is created, it is hashed with a 32 character salt that is appended to the end of the password string.  The password is stored as {TOTAL HASH}:{ORIGINAL SALT}.</p>
<p>you can see this method at <span class="misspell" suggestions="plug ins,plug-ins,polygons,plugs,plugging">plugins</span>/authentication/<span class="misspell" suggestions="Jamal,Romola,Jammal,Joela,Kamila">joomla</span>.<span class="misspell" suggestions="Phip,PP,pH,pp,HP">php</span> lines 80-116.</p>
<p>So what you have to do is take your password and make a {TOTAL HASH}:{ORIGINAL SALT} from it and save the created string. I found this information also in a <a href="http://forum.joomla.org/index.php?topic=207689.0;wap2" title="discussion forum" id="n.k5">discussion forum</a>. which had shown a java class to do this task.. so yeah it was quite useful..</p>
<p>so that&#8217;s all about behind the seen registration <img src='http://www.nuwanbando.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Have fun !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nuwanbando.com/2008/01/joomla-hack-automated-joomla-user-registration-via-jsf-form/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

