<?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>Welcome to XP Link Co., Ltd. &#187; Java</title>
	<atom:link href="http://www.xp-link.com/category/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.xp-link.com</link>
	<description>XP Link Co., Ltd is a software consultant company specializes in Java Technology from Thailand.</description>
	<lastBuildDate>Tue, 10 Jan 2012 09:11:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Manage test data for integration tests using Spring and DBUnit</title>
		<link>http://www.xp-link.com/2010/01/22/manage-test-data-for-integration-tests-using-spring-and-dbunit/</link>
		<comments>http://www.xp-link.com/2010/01/22/manage-test-data-for-integration-tests-using-spring-and-dbunit/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 09:57:45 +0000</pubDate>
		<dc:creator>Supanit</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.xp-link.com/?p=110</guid>
		<description><![CDATA[ &#160;&#160; &#160;Testing is very important to application development. Most enterprise applications are related with persistence data in database system. If you have to test integration between DAOs and databases, called Data Access Objects Testing (DAOs Testing), you will prepare data in database for these testing. There are many ways to prepare test data in database. [...] ]]></description>
			<content:encoded><![CDATA[<p>
	<br />&nbsp;&nbsp; &nbsp;Testing is very important to application development. Most enterprise applications are related with persistence data in database system. If you have to test integration between DAOs and databases, called Data Access Objects Testing (DAOs Testing), you will prepare data in database for these testing. There are many ways to prepare test data in database.</p>
<ul>
<li>1. Inserting test data using SQL script by manually.</li>
<li>2. Import and Export data automatically by other applications.</li>
</ul>
<p><br/></p>
<p>DBUnit is a tool which provides for Data Access Objects Testing.</p>
<p><br/><br />
<span id="more-110"></span></p>
<h4>Process of DBUnit</h4>
<p>
	&nbsp;&nbsp; &nbsp;DBUnit export set of data in the one database to flat file (XML) before running the test. Then the tests are run, it import these test data from XML file to another database and deletes the test data when the tests are finish.
<p>
<br/></p>
<h4>Spring Framework and DBUnit</h4>
<p>
	&nbsp;&nbsp; &nbsp;Spring framework provides ?AbstractTransactionalDataSourceSpringContextTests? class for DBUnit. This class has ?onSetUpInTransaction? and ?onTearDownInTransaction? methods which can be overridden to use to insert and delete test data. Spring-managed beans defined in the integration tests are injected into the integration tests. Junit 4 and TestNG provide a more sophisticated lifecycle.</p>
<p><br/></p>
<h4>Advantages of DBUnit</h4>
<p>&nbsp;&nbsp; &nbsp;1. Simple and easy to implement.<br />
&nbsp;&nbsp; &nbsp;2. Test data of each tests is independent because it insert the test data when the tests is run and delete when tests is finished<br />
&nbsp;&nbsp; &nbsp;3. Support Spring framework, objects is injected automatically.<br />
&nbsp;&nbsp; &nbsp;4. XML file, that is created to store data, as a template and developer can modify its.<br /><br/><br />
<strong>Reference : </strong><a href="http://www.theserverside.com/tt/articles/article.tss?l=ManageTestDataSpringandDBunit">http://www.theserverside.com/tt/articles/article.tss?l=ManageTestDataSpringandDBunit</a> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.xp-link.com/2010/01/22/manage-test-data-for-integration-tests-using-spring-and-dbunit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SSO and Identity Management</title>
		<link>http://www.xp-link.com/2010/01/18/sso-and-identity-management/</link>
		<comments>http://www.xp-link.com/2010/01/18/sso-and-identity-management/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 09:33:48 +0000</pubDate>
		<dc:creator>Supanit</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.xp-link.com/?p=63</guid>
		<description><![CDATA[ &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Nowadays, web-applications have grown over to support business processes in many organization. Each application has many users, groups and roles, that is responsible of administrator to manages its. Single sign-on (SSO) and identity management can reduce the administrator work about managing user information that is kept in a centralized repository. &#160; Single sign-on (SSO) [...] ]]></description>
			<content:encoded><![CDATA[<p>	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Nowadays, web-applications have grown over to support business processes in many organization. Each application has many users, groups and roles, that is responsible of administrator to manages its. Single sign-on (SSO) and identity management can reduce the administrator work about managing user information that is kept in a centralized repository.<br />
	&nbsp;</p>
<p><span id="more-63"></span></p>
<h4>
	Single sign-on (SSO) Concept</h4>
<p>
	<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; There is a central repository to keep user information such as username, password, group, role, etc. for authentication and authorization. When user authenticates, they assigned a token. This token is passport that application subscriber use to verify who can access to their application so user is authenticated only once after that they can bypass the authentication process to use application subscriber<br />
	&nbsp;</p>
<h4>
	The benefits to using SSO</h4>
<p>
	&nbsp;</p>
<ul>
<li>
		User is not remembers username and password of each application.</li>
<li>
		&nbsp;All applications use the same method of authentication.</li>
<li>
		Reduce number of authentication credentials in replicated passwords for a user</li>
</ul>
<p>
	<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; There are many external authentication systems that provide for web-application so you should design your application to support them that became to more flexible. When developing your application to support the external authentication system. You must&nbsp; focus to 4 parts</p>
<ul>
<li>
		&nbsp;Authentication &ndash; The process of verifying the credentials that provided by the requesting user.</li>
<li>
		&nbsp;Authorization &#8211; The process of verifying role and group mapping of requesting user that can access to application</li>
<li>
		Profile &ndash; Then personal details and preferences of user</li>
<li>
		Management &ndash; Creating, modifying and deleting of user information, security rules and relationships</li>
</ul>
<p>
	<br />
	** Other application should not write information to the database of authentication server because this database uses to keep profile information for authentication system only.</p>
<p>	There are many solutions for SSO both open source solutions (JAAS, JOSSO, CAS, OpenSSO, OpenID) and commercial solutions (Siteminder, IDX).<br />
	<strong><br />
	Reference link :</strong><a href="http://www.theserverside.com/tt/articles/article.tss?l=SSOIdentityManagement "> http://www.theserverside.com/tt/articles/article.tss?l=SSOIdentityManagement </p>
]]></content:encoded>
			<wfw:commentRss>http://www.xp-link.com/2010/01/18/sso-and-identity-management/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache POI</title>
		<link>http://www.xp-link.com/2010/01/15/apache-poi/</link>
		<comments>http://www.xp-link.com/2010/01/15/apache-poi/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 11:51:12 +0000</pubDate>
		<dc:creator>Thipbodee</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.xp-link.com/?p=59</guid>
		<description><![CDATA[ &#160;&#160; &#160;Apache POI เป็น API ที่ช่่วยเราในการเขียนและอ่านเอกสาร ของ Microsoft Office ซึ่งสามารถหาดูตัวอย่างและdownload source code มาใช้งานได้ที่ http://poi.apache.org โดยเราสามารถแบ่ง Component ใน POIได้เป็นส่วนๆดังนี้ Excel Word PowerPoint OpenXML4J OLE2 FileSystem Outlook Visio Publisher &#160;&#160; &#160;โดยส่วนที่ผมต้องการจะกล่าวถึงคือส่วนของ Word(HWPF+XHWPF) โดยเนื้อหาที่ต้อง การกล่าวถึงคือการใช้ POI ในการเขียน Word อย่างง่ายขึ้นมาเพื่อ ตอบสนองความต้องการในการเขียน เอกสารอย่างง่ายด้วยภาษา JAVA &#160;&#160; &#160;ในที่นี้ผมจะเรียกComponent ในส่วนนี้ว่า HWPFโดยเรียกตามเอกสารของApache POI HWPF มีความสามารถในการเขีบยน File เอกสารเพื่อให้ Microsoft Word 97-2007อ่านFileเอกสาร และไม่รองรับการอ่านเอกสารแบบ.docx ข้อดี สามารถเขียน File [...] ]]></description>
			<content:encoded><![CDATA[<p>
	<br />
	&nbsp;&nbsp; &nbsp;Apache POI เป็น API ที่ช่่วยเราในการเขียนและอ่านเอกสาร ของ Microsoft Office</p>
<p>
	ซึ่งสามารถหาดูตัวอย่างและdownload source code มาใช้งานได้ที่ http://poi.apache.org</p>
<p>
	โดยเราสามารถแบ่ง Component ใน POIได้เป็นส่วนๆดังนี้</p>
<ul>
<li>
		Excel</li>
<li>
		Word</li>
<li>
		PowerPoint</li>
<li>
		OpenXML4J</li>
<li>
		OLE2 FileSystem</li>
<li>
		Outlook</li>
<li>
		Visio</li>
<li>
		Publisher</li>
</ul>
<p><span id="more-59"></span></p>
<p>
	&nbsp;&nbsp; &nbsp;โดยส่วนที่ผมต้องการจะกล่าวถึงคือส่วนของ Word(HWPF+XHWPF) โดยเนื้อหาที่ต้อง<br />
	การกล่าวถึงคือการใช้ POI ในการเขียน Word อย่างง่ายขึ้นมาเพื่อ ตอบสนองความต้องการในการเขียน<br />
	เอกสารอย่างง่ายด้วยภาษา JAVA<br />
	&nbsp;&nbsp; &nbsp;ในที่นี้ผมจะเรียกComponent ในส่วนนี้ว่า HWPFโดยเรียกตามเอกสารของApache POI<br />
	HWPF มีความสามารถในการเขีบยน File เอกสารเพื่อให้ Microsoft Word 97-2007อ่านFileเอกสาร<br />
	และไม่รองรับการอ่านเอกสารแบบ.docx</p>
<h4>ข้อดี</h4>
</p>
<ul>
<li>
		สามารถเขียน File Word Document</li>
<li>
		Open Source</li>
</ul>
<p><h4>ข้อเสีย</h4>
</p>
<ul>
<li>
		มีปัญหาเรื่องภาษาไทย</li>
<li>
		ไม่สามารถแทรกรุป หรือ ตารางได้</li>
<li>
		HWPF ไม่มีการพัฒนาต่อในช่วงปี2009</li>
</ul>
<p><h4>
	ตัวอย่างcode การเขียน&nbsp; worddocument โดยใช้poi</h4>
<pre class="code">	import java.io.*;
	import org.apache.poi.hpsf.CustomProperties;
	import org.apache.poi.hpsf.DocumentSummaryInformation;
	import org.apache.poi.hwpf.HWPFDocument;
	import org.apache.poi.hwpf.usermodel.*;
	import org.apache.poi.poifs.filesystem.POIFSFileSystem;

	public class CreateWordDoc {
	&nbsp;&nbsp;&nbsp; public static void main(String[] args) throws Exception {
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // POI apparently can&#39;t create a document from scratch,
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // so we need an existing empty dummy document
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(&quot;c:\\data\\sample.dot&quot;));
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HWPFDocument doc = new HWPFDocument(fs);

	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // centered paragraph with large font size
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Range range = doc.getRange();
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Range r1 = doc.getRange();

	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; r1.numSections(); ++i) {
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Section s = r1.getSection(i);
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int x = 0; x &lt; s.numParagraphs(); x++) {
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Paragraph p = s.getParagraph(x);
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int z = 0; z &lt; p.numCharacterRuns(); z++) {
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // character run
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CharacterRun run = p.getCharacterRun(z);
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // character run text
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String text = run.text();
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (text.equalsIgnoreCase(&quot;CurrDate&quot;)) {
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String theDate = &quot;28-05-2009&quot;;
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (theDate != null) {
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; run.replaceWith(theDate);
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (text.equalsIgnoreCase(&quot;XYZ&quot;)) {
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String theapplicantName = &quot;Mr.John&quot;;
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (theapplicantName != null) {
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; run.replaceWith(theapplicantName);
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }

	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // add a custom document property (needs POI 3.5; POI 3.2 doesn&#39;t save
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // custom properties)
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DocumentSummaryInformation dsi = doc.getDocumentSummaryInformation();
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CustomProperties cp = dsi.getCustomProperties();
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (cp == null)
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cp = new CustomProperties();
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cp.put(&quot;myProperty&quot;, &quot;foo bar baz&quot;);
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dsi.setCustomProperties(cp);
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; doc.write(new FileOutputStream(&quot;c:\\data\\new-hwpf-file.doc&quot;));
	&nbsp;&nbsp;&nbsp; }
	}
</pre>
<p><h4>สรุป<br />
	</h4>
</p>
<p>
	&nbsp;&nbsp; &nbsp;ในการใช้งาน Apache POI นั้นอาจเกิดปัญหาและอุปสรรค์หลากหลายอย่างแต่เนื่องจากที่Apache POI เป็น Opensource และเป็นทางเรื่อกที่สามมารถประหยัดค่าใช้จ่ายได้ในกรณีที่ต้องการลดค่าใช้จ่ายในส่วนนี้<br />
	ผู้ใช้งานจึงควรศึกษาข้อจำกัดของPOIเพื่อประโยชน์ต่อการใช้งาน<br />
	<strong>เอกสารอ้างอิง</strong><br />
<a href="http://poi.apache.com">http://poi.apache.com </p>
]]></content:encoded>
			<wfw:commentRss>http://www.xp-link.com/2010/01/15/apache-poi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting multiple JAVA_OPTS in Tomcat</title>
		<link>http://www.xp-link.com/2010/01/15/setting-multi-java_opts-in-tomcat/</link>
		<comments>http://www.xp-link.com/2010/01/15/setting-multi-java_opts-in-tomcat/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 11:34:39 +0000</pubDate>
		<dc:creator>Sorawit Laosinchai</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Tomcat]]></category>

		<guid isPermaLink="false">http://www.xp-link.com/?p=45</guid>
		<description><![CDATA[ Every JAVA Developer should know how to set Java runtime options. Tomcat&#8217;s document said that setting Tomcat&#8217;s Java runtime options is as easy as setting ordinary Java runtime options by set those options in environment variable named JAVA_OPTS. When I try to set multi Java runtime options in Tomcat core script, catalina.bat, it appear that [...] ]]></description>
			<content:encoded><![CDATA[<p> Every JAVA Developer should know how to set Java runtime options. Tomcat&#8217;s document said that setting Tomcat&#8217;s Java runtime options is as easy as setting ordinary Java runtime options by set those options in environment variable named <span style="color: #ff9900;">JAVA_OPTS</span>. When I try to set multi Java runtime options in Tomcat core script, catalina.bat, it appear that I cannot start my Tomcat Server due to fault configuration in <span style="color: #ff9900;">JAVA_OPTS</span> that lead to fault execute command in the last part of core script. What is happening here?<br />
<span id="more-45"></span></p>
<h4>First</h4>
<p>I have to mention about setting multiple Java runtime options. We know each option is separate by space</p>
<h3>example:</h3>
<pre class="code">java -Xms128M -Xmx512M</pre>
<p>The problem is having a space in JAVA_OPTS leading to having a space in  execute command in the last part of core script.</p>
<h3>If you use normal setting, Tomcat will execute by this line.</h3>
<pre class="code">%_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%</pre>
<p>If you trace back to find the real command of this line you will see that the <span style="color: #ff9900;">%_EXECJAVA%</span> is set by this statements</p>
<pre class="code">if not "%OS%" == "Windows_NT" goto noTitle
set _EXECJAVA=start "Tomcat" %_RUNJAVA%
goto gotTitle
:noTitle
set _EXECJAVA=start %_RUNJAVA%</pre>
<p>Thats mean the real command that execute in execution line is <span style="color: #ff9900;">start </span>with a lot of arguments. So the <span style="color: #ff9900;">%JAVA_OPTS%</span> is only an argument of <span style="color: #ff9900;">start</span> command. This explained why setting value of multiple Java runtime options in <span style="color: #ff9900;">%JAVA_OPTS%</span> as normal multiple Java runtime options when you call <span style="color: #ff9900;">java</span> is not working here. Because a space in normal multiple Java runtime options will treat as argument separator of <span style="color: #ff9900;">start</span> command and your second Java runtime options will treat as an argument next to <span style="color: #ff9900;">%JAVA_OPTS%</span>. Now we know what is the problem and everyone know how to fix the problem ?Just add double quote around value of <span style="color: #ff9900;">%JAVA_OPTS%</span>? but is it enough?.<br />
<br />
While our propose now is printing double quote around value of <span style="color: #ff9900;">%JAVA_OPTS%</span> in execution command but the double quote is a wrapper sign of batch script. So the line</p>
<pre class="code">set JAVA_OPTS="-Xms128M -Xmx512M"</pre>
<p>will print</p>
<pre class="code">-Xms128M -Xmx512M</pre>
<p>without double quote around it in the <span style="color: #ff9900;">%JAVA_OPTS%</span> part of <span style="color: #ff9900;">start</span> command. Yes, have or have not double quote around the value of <span style="color: #ff9900;">set JAVA_OPTS=</span> is the same.<br />
<br />
You have two easy options to force printing double quote around value of <span style="color: #ff9900;">%JAVA_OPTS%</span> in execution command.</p>
<h6>One is</h6>
<p>add  double quote around <span style="color: #ff9900;">%JAVA_OPTS%</span> in each execution line. The fixed version of the above execution line will look like this</p>
<pre class="code">%_EXECJAVA% "%JAVA_OPTS%" %CATALINA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%</pre>
<p>But don&#8217;t forget that it has 4 execution line in Tomcat&#8217;s core script. Luckily they are at the last part of the script.</p>
<h6>The other way</h6>
<p>is adding double quote around double quoted value of <span style="color: #ff9900;">set JAVA_OPTS=</span>. The fixed version of <span style="color: #ff9900;">set JAVA_OPTS=</span> line will look like this</p>
<pre class="code">set JAVA_OPTS=""-Xms128M -Xmx512M""</pre>
<p>Yes, its look funny but its work because double quote mean using everything inside double quote as is. As a result, the value of <span style="color: #ff9900;">%JAVA_OPTS%</span> is <span style="color: #ff9900;">&#8220;-Xms128M -Xmx512M&#8221;</span> with double quote around it and it will print those double quote in to execution line.<br />
<br />
I prefer to latter way because we do not edit any Tomcat&#8217;s core script. We only fix our added line</p>
<pre class="code">set JAVA_OPTS=""-Xms128M -Xmx512M""</pre>
<p>in order to make our application usable. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.xp-link.com/2010/01/15/setting-multi-java_opts-in-tomcat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>การใช้งาน Tapesty ร่วมกับ Spring Framework</title>
		<link>http://www.xp-link.com/2007/08/03/using_tapestry_with_spring/</link>
		<comments>http://www.xp-link.com/2007/08/03/using_tapestry_with_spring/#comments</comments>
		<pubDate>Fri, 03 Aug 2007 07:35:37 +0000</pubDate>
		<dc:creator>nuttarut</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Spring Framework]]></category>
		<category><![CDATA[Tapestry]]></category>

		<guid isPermaLink="false">http://www.xp-link.com/2007/08/03/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b9%83%e0%b8%8a%e0%b9%89%e0%b8%87%e0%b8%b2%e0%b8%99-tapesty-%e0%b8%a3%e0%b9%88%e0%b8%a7%e0%b8%a1%e0%b8%81%e0%b8%b1%e0%b8%9a-spring-framework/</guid>
		<description><![CDATA[&#160;&#160;&#160;Tapestry เป็นเฟรมเวิร์คสำหรับพัฒนาเว็บแอพพลิเคชั่นด้วยจาวาที่มีประสิทธิภาพมากเฟรมเวิร์คหนึ่ง ด้วยการทำงานในรูปแบบ Component-Centric ที่มีความสามารถหลักๆคือทำให้เราสามารถนำโค๊ดเก่ามาใช้ใหม่ได้ ง่าย และยังมี HiveMind ที่ทำให้สามารถใช้แนวคิด Inversion of Control (IoC)ในการพัฒนาได้อีกด้วย &#160;&#160;&#160;แต่การพัฒนาแอพพลิเคชั่นด้วยแนวคิดแบบ IoC ในปัจจุบันนั้น การใช้ Spring Framework จะเป็นที่นิยมแพร่หลายมากกว่า ฉะนั้นถ้าเราสามารถนำ Spring Framework มาใช้งานร่วมกับ Tapestry ได้ ก็จะเป็นประโยชน์มากทีเดียว &#160;&#160;&#160;โชคดีที่ทั้ง Spring Framework และ Tapestry นั้นมีสถาปัตยกรรมที่ค่อนข้างจะยืดหยุ่น ทำให้การนำเฟรมเวิร์คอื่นๆมาใช้งานร่วมด้วยนั้นสามารถทำได้ง่าย และมีประสิทธิภาพ โดยการนำ Spring Framework และ Tapestry มาใช้งานร่วมกันสามารถทำได้ดังนี้ การ config web.xml &#160;&#160;&#160;ก่อนอื่นเราจะต้องทำให้เว็บแอพลิเคชั่นที่พัฒนาด้วย Tapestryของเรานั้นหาไฟล์ config ของ Spring ให้เจอเสียก่อนโดยใช้ listener ที่ชื่อ ContextLoaderListener โดยทำการเพิ่ม config [...]]]></description>
			<content:encoded><![CDATA[<p><!-- 		@page { size: 8.5in 11in; margin: 0.79in } 		P { margin-bottom: 0.08in } 	-->             &nbsp;&nbsp;&nbsp;<a href="http://tapestry.apache.org/">Tapestry</a> เป็นเฟรมเวิร์คสำหรับพัฒนาเว็บแอพพลิเคชั่นด้วยจาวาที่มีประสิทธิภาพมากเฟรมเวิร์คหนึ่ง ด้วยการทำงานในรูปแบบ  Component-Centric ที่มีความสามารถหลักๆคือทำให้เราสามารถนำโค๊ดเก่ามาใช้ใหม่ได้ ง่าย และยังมี <a href="http://hivemind.apache.org/">HiveMind</a> ที่ทำให้สามารถใช้แนวคิด Inversion of Control (IoC)ในการพัฒนาได้อีกด้วย<br />
<br />
<!-- 		@page { size: 8.5in 11in; margin: 0.79in } 		P { margin-bottom: 0.08in } 	-->   &nbsp;&nbsp;&nbsp;แต่การพัฒนาแอพพลิเคชั่นด้วยแนวคิดแบบ IoC ในปัจจุบันนั้น การใช้ <a href="http://www.springframework.org/">Spring Framework</a> จะเป็นที่นิยมแพร่หลายมากกว่า  ฉะนั้นถ้าเราสามารถนำ Spring Framework มาใช้งานร่วมกับ Tapestry ได้ ก็จะเป็นประโยชน์มากทีเดียว<br />
<br /><span id="more-29"></span><br />
<!-- 		@page { size: 8.5in 11in; margin: 0.79in } 		P { margin-bottom: 0.08in } 	--></p>
<p>&nbsp;&nbsp;&nbsp;โชคดีที่ทั้ง Spring Framework และ Tapestry นั้นมีสถาปัตยกรรมที่ค่อนข้างจะยืดหยุ่น ทำให้การนำเฟรมเวิร์คอื่นๆมาใช้งานร่วมด้วยนั้นสามารถทำได้ง่าย และมีประสิทธิภาพ โดยการนำ Spring Framework และ Tapestry มาใช้งานร่วมกันสามารถทำได้ดังนี้<br />
</p>
<h4>การ config web.xml</h4>
<p>&nbsp;&nbsp;&nbsp;ก่อนอื่นเราจะต้องทำให้เว็บแอพลิเคชั่นที่พัฒนาด้วย Tapestryของเรานั้นหาไฟล์ config ของ Spring ให้เจอเสียก่อนโดยใช้ listener ที่ชื่อ ContextLoaderListener โดยทำการเพิ่ม config ใน web.xml ดังนี้<br />
<br />
<!-- 		@page { size: 8.5in 11in; margin: 0.79in } 		P { margin-bottom: 0.08in } 	--></p>
<pre class="code">
&lt;listener&gt;
    	&lt;listener-class&gt;
                 org.springframework.web.context.ContextLoaderListener
        &lt;/listener-class&gt;
&lt;/listener&gt;
</pre>
<p>
<!-- 		@page { size: 8.5in 11in; margin: 0.79in } 		P { margin-bottom: 0.08in } 	--></p>
<p>
<!-- 		@page { size: 8.5in 11in; margin: 0.79in } 		P { margin-bottom: 0.08in } 	--><br />
&nbsp;&nbsp;&nbsp;ในส่วนต่อไปจะเป็นการทำให้ ContextLoaderListener ทราบว่าจะเข้าไปหาไฟล์ config ของ Spring ได้ที่ไหน ถ้าไม่มีการกำหนดในส่วนนี้ไว้ ContextLoaderListener  จะเข้าไปหาใน /WEB-INF/applicationContext.xml แทน</p>
<p>
<!-- 		@page { size: 8.5in 11in; margin: 0.79in } 		P { margin-bottom: 0.08in } 	--></p>
<pre class="code">
&lt;context-param&gt;
    	&lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
    	&lt;param-value&gt;/WEB-INF/applicationContext*.xml&lt;/param-value&gt;
&lt;/context-param&gt;
</pre>
<h4>การใช้ Dependency Injection เพื่อเรียกใช้ Spring Bean</h4>
<p>&nbsp;&nbsp;&nbsp;เรามาสารถเรียกใช้ Spring Bean จาก page object ของ Tapestry ได้โดยตรงเช่น<br />
<br />
<!-- 		@page { size: 8.5in 11in; margin: 0.79in } 		P { margin-bottom: 0.08in } 	--></p>
<pre class="code">
WebApplicationContext appContext = WebApplicationContextUtils.getApplicationContext(
    getRequestCycle().getRequestContext().getServlet().getServletContext());
SomeService someService = (SomeService) appContext.getBean("someService");
</pre>
<p><!-- 		@page { size: 8.5in 11in; margin: 0.79in } 		P { margin-bottom: 0.08in } 	--><br />
<br />
&nbsp;&nbsp;&nbsp;แต่การทำแบบนี้จะทำให้แก้ไขลำบากในภายหลัง เพราะเราจะต้องแก้ทุก page object ที่เรียกใช้ Spring Bean และถึงแม้เราจะใช้รูปแบบการเขียนโค๊ดต่างๆ ที่จะสะดวกในการแก้ไขแล้วก็ตาม ตัว Servlet เองก็ไม่ควรเรียกใช้ Application Context โดยตรง หรือรู้ว่าถูกสร้างมาได้อย่างไร ตามหลักของ IoC<br />
<!-- 		@page { size: 8.5in 11in; margin: 0.79in } 		P { margin-bottom: 0.08in } 	--><br />
<br />
&nbsp;&nbsp;&nbsp;เราสามารถแก้ปัญหานี้ได้โดยใช้ไลบราลีที่ชื่อ <a href="http://sourceforge.net/projects/diaphragma">Tapestry-Spring</a> ซึ่งจะใช้ Annotation @InjectObject แทนการเรียกใช้แบบเดิมที่กล่าวไว้ข้างต้น ทำให้เราเรียกใช้ Spring Beanได้ง่ายและยืดหยุ่นมากยิ่งขึ้น โดยให้ทำการดาวน์โหลดไฟล์ไลบราลีมาใส่ไว้ร่วมกับไลบราลีอื่นๆ ที่เราใช้ในเว็บแอพพลิเคชั่น (ปกติจะเป็น /WEB-INF/lib) และทำการเรียกใช้ใน page object ดังนี้<br />
<!-- 		@page { size: 8.5in 11in; margin: 0.79in } 		P { margin-bottom: 0.08in } 	--><br />
</p>
<pre class="code">
@InjectObject("spring:someService")
public abstract SomeService getSomeService();
</pre>
<p><!-- 		@page { size: 8.5in 11in; margin: 0.79in } 		P { margin-bottom: 0.08in } 	--><br />
<br />
&nbsp;&nbsp;&nbsp;สำหรับระบบที่ไม่ได้ใช้ Java5 จะต้องทำการเรียกใช้ Spring Bean ผ่านไฟล์ .page หรือ .jwc ของหน้าเว็บนั้นๆแทนดังนี้<br />
<!-- 		@page { size: 8.5in 11in; margin: 0.79in } 		P { margin-bottom: 0.08in } 	--><br />
</p>
<pre class="code">
&lt;inject property="someService" object="spring:someService"/&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.xp-link.com/2007/08/03/using_tapestry_with_spring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

