<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-608930707326476211</id><updated>2012-02-02T04:35:55.743-08:00</updated><title type='text'>aspemo</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>49</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-6204853557522992176</id><published>2011-12-14T00:59:00.001-08:00</published><updated>2011-12-14T00:59:24.421-08:00</updated><title type='text'>AOP and Spring</title><content type='html'>&lt;table align="left" border="0" width="800"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;div align="left"&gt;&lt;pre&gt;Logging aspects and Spring.&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt; &lt;pre&gt;Add this to your applicationContext.xml file.&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt; &lt;pre&gt; &lt;bean id="loggingAdvice" class="com.aja.LoggingAdvice"&gt;&lt;br /&gt;       &lt;property name="enabled" value="false"&gt;&lt;br /&gt;   &lt;/property&gt;&lt;/bean&gt;&lt;br /&gt;     &lt;br /&gt;   &lt;bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"&gt;&lt;br /&gt;       &lt;property name="beanNames"&gt;&lt;br /&gt;           &lt;value&gt;service,logic,integration&lt;/value&gt;&lt;br /&gt;       &lt;/property&gt;&lt;br /&gt;       &lt;property name="interceptorNames"&gt;&lt;br /&gt;           &lt;list&gt;&lt;br /&gt;               &lt;value&gt;loggingAdvice&lt;/value&gt;&lt;br /&gt;           &lt;/list&gt;&lt;br /&gt;       &lt;/property&gt;&lt;br /&gt;   &lt;/bean&gt;&lt;br /&gt; &lt;br /&gt;   &lt;bean id="exporter" class="org.springframework.jmx.export.MBeanExporter"&gt;&lt;br /&gt;               &lt;property name="beans"&gt;&lt;br /&gt;                       &lt;map&gt;&lt;br /&gt;                       &lt;entry key="bean:name=TestLogging"&gt; &lt;ref bean="loggingAdvice"&gt;&lt;/ref&gt;&lt;/entry&gt;&lt;br /&gt;                       &lt;/map&gt;&lt;br /&gt;               &lt;/property&gt;&lt;br /&gt;               &lt;/bean&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt; &lt;ul&gt;&lt;li&gt;&lt;pre&gt;This will cause the three beans, service, logic and integration to be logged.&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;pre&gt;This will cause the "bean" loggingAdvice to be exposed in the JMX console with the name TestLogging&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;pre&gt;This will expose the property enabled to the JMX console, set that to true and the aop starts to log.&lt;/pre&gt; &lt;/li&gt;&lt;/ul&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt; &lt;pre&gt;Below is the complete Logging advice class.&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt; &lt;pre&gt;package com.aja;&lt;br /&gt;&lt;br /&gt;import org.springframework.aop.AfterReturningAdvice;&lt;br /&gt;import org.springframework.aop.MethodBeforeAdvice;&lt;br /&gt;import org.springframework.aop.ThrowsAdvice;&lt;br /&gt;&lt;br /&gt;import com.ericsson.sdp.media.eup.charging.error.ErrorHandler;&lt;br /&gt;&lt;br /&gt;import java.lang.reflect.Method;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt;* Logging interceptor.&lt;br /&gt;*/&lt;br /&gt;public class LoggingAdvice implements MethodBeforeAdvice, AfterReturningAdvice,&lt;br /&gt;   ThrowsAdvice {&lt;br /&gt;   private boolean enabled = true;&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;  &lt;br /&gt;   /**&lt;br /&gt;    * Transcodeeates a new instance of &lt;code&gt;LoggingAdvice&lt;/code&gt;.&lt;br /&gt;    */&lt;br /&gt;   public LoggingAdvice() {&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   /* (non-Javadoc)&lt;br /&gt;    * @see org.springframework.aop.MethodBeforeAdvice#before(java.lang.reflect.Method, java.lang.Object[], java.lang.Object)&lt;br /&gt;    */&lt;br /&gt;   public void before(Method method, Object[] args, Object target)&lt;br /&gt;       throws Throwable {&lt;br /&gt;       if (!enabled) {&lt;br /&gt;           return;&lt;br /&gt;       }&lt;br /&gt;&lt;br /&gt;       StringBuffer builder = new StringBuffer();&lt;br /&gt;       builder.append("enter ").append(method.getName()).append("(");&lt;br /&gt;&lt;br /&gt;       for (int i = 0; args == null?false:(i &amp;lt; args.length); i++) {&lt;br /&gt;           builder.append(args[i]);&lt;br /&gt;&lt;br /&gt;           if (i &amp;lt; (args.length - 1)) {&lt;br /&gt;               builder.append(", ");&lt;br /&gt;           }&lt;br /&gt;       }&lt;br /&gt;&lt;br /&gt;       builder.append(")");&lt;br /&gt;     &lt;br /&gt;       ErrorHandler.handleDebug(builder.toString());&lt;br /&gt;  &lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   /* (non-Javadoc)&lt;br /&gt;    * @see org.springframework.aop.AfterReturningAdvice#afterReturning(java.lang.Object, java.lang.reflect.Method, java.lang.Object[], java.lang.Object)&lt;br /&gt;    */&lt;br /&gt;   public void afterReturning(Object returnValue, Method method,&lt;br /&gt;       Object[] args, Object target) throws Throwable {&lt;br /&gt;       if (!enabled) {&lt;br /&gt;           return;&lt;br /&gt;       }&lt;br /&gt;&lt;br /&gt;       ErrorHandler.handleDebug(RETURN + method.getName());&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   /**&lt;br /&gt;    * @param method&lt;br /&gt;    * @param args&lt;br /&gt;    * @param target&lt;br /&gt;    * @param exc&lt;br /&gt;    */&lt;br /&gt;   public void afterThrowing(Method method, Object[] args, Object target,&lt;br /&gt;       Throwable exc) {&lt;br /&gt;       if (!enabled) {&lt;br /&gt;           return;&lt;br /&gt;       }&lt;br /&gt;      &lt;br /&gt;       ErrorHandler.handleDebug("return " + method.getName() + exc.getMessage());&lt;br /&gt;     &lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   /**&lt;br /&gt;    * @return the enabled&lt;br /&gt;    */&lt;br /&gt;   public boolean isEnabled() {&lt;br /&gt;       return enabled;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   /**&lt;br /&gt;    * @param enabled the enabled to set&lt;br /&gt;    */&lt;br /&gt;   public void setEnabled(boolean enabled) {&lt;br /&gt;       this.enabled = enabled;&lt;br /&gt;   }&lt;br /&gt;}&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-6204853557522992176?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/6204853557522992176/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/12/aop-and-spring.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/6204853557522992176'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/6204853557522992176'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/12/aop-and-spring.html' title='AOP and Spring'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-6671704847002788846</id><published>2011-12-14T00:58:00.002-08:00</published><updated>2011-12-14T00:59:01.225-08:00</updated><title type='text'>Struts2 and portlet</title><content type='html'>&lt;p&gt;This is a short how to get a Struts2 application up and running in JBoss portal framework. &lt;/p&gt;       &lt;p&gt;We will use the following tools one at a time in this tutorial.&lt;/p&gt;&lt;p&gt;Tools:&lt;/p&gt;&lt;p&gt;JBoss  4.0.5 with the portal extension.&lt;/p&gt;&lt;p&gt;Maven 2.0.4&lt;/p&gt;&lt;p&gt;Struts 2.0.6&lt;/p&gt;&lt;p&gt;Ubuntu Edgy Eft&lt;/p&gt;&lt;p&gt;Java 5.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;Note this. There is a fundamental difference between Struts1 and struts2. The whole concept is changed and Struts has moved&lt;br /&gt;away  from the straight flow based approach to a more object oriented way  with dependency injection. There are a multitude of sites about this,  but the best staring point is probably the &lt;a href="http://struts.apache.org/2.x/" title="Struts"&gt;Struts&lt;/a&gt; homepage.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;So  before starting. The disclaimer is that in a serious production  environment, this application will not be enough. This is just a test  for the home cooker.&lt;br /&gt;Step 1. &lt;/p&gt;&lt;p&gt;Install JBoss 4.0.5 and pick the  one with version number 4.0.5 and choose Run Installer. That's right,  make sure you choose "Run Installer". &lt;/p&gt;       &lt;p&gt;Pick installation language.&lt;br /&gt;This  should be standard stuff. You go next all the time and accept the  license agreement (well, only if you accept it of course). pick  installation directory.&lt;br /&gt;For the sake of argument I choose /jbossportlet. Pick your choice and then press next.&lt;br /&gt;let the installation program create the directory. Press ok.&lt;br /&gt;You have to choose protal here. &lt;/p&gt;       &lt;p&gt;In your jbossportal/bin directory there are two files of interest.&lt;br /&gt;run.sh  and run.conf make a copy of each and name them debug.sh and debug.conf.  Edit debug.sh and find the one and only occurence of the word run.conf  in the file. Change this to debug.conf.&lt;br /&gt;Now change the debug.sh file and remove the bracket# in fron ot the line where it says something like this,&lt;br /&gt;#JAVA_OPTS="$JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y"&lt;br /&gt;When youe are done the ine should be like this&lt;br /&gt;JAVA_OPTS="$JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y"&lt;br /&gt;OK. Test JBoss now go to the installation directory/bin and type ./run.sh this should fire up your JBoss app server.&lt;/p&gt;       &lt;p&gt;To  see if it works type http://localhost:8080/portal and the JBoss portal  page should appear. Do not panic if it takes a while. If you do not see  this page&lt;br /&gt;without errors do not bother to proceed, something is major wrong at your place right now. &lt;/p&gt;       &lt;p&gt;Maven&lt;br /&gt;Install Maven go to &lt;a href="http://maven.apache.org/" title="Maven"&gt;Mavens&lt;/a&gt; home page.&lt;br /&gt;I used version 2.0.4. Not that it really matters, but version numbers are important in ceratin circles.&lt;br /&gt;There is a web.xml file in the WEB-INF directory, if you don't do this Maven doesn't build your web app.&lt;br /&gt;Add one pom.xml to the main MyPortlet directory and add one pom.xml to the MyPortlet.war directory.&lt;br /&gt;The content is as follows.&lt;br /&gt;The top pom.xml shall look like this. This is the pom in the MyPortlet directory.&lt;br /&gt;&lt;project&gt;&lt;br /&gt;  &lt;modelversion&gt;4.0.0&lt;/modelversion&gt;&lt;br /&gt;  &lt;name&gt;Maven Default Project&lt;/name&gt;&lt;br /&gt;  &lt;groupid&gt;com.aja.myportlet&lt;/groupid&gt;&lt;br /&gt;  &lt;artifactid&gt;MyPortlet&lt;/artifactid&gt;&lt;br /&gt;  &lt;version&gt;1.0&lt;/version&gt;&lt;br /&gt;  &lt;packaging&gt;pom&lt;/packaging&gt;&lt;br /&gt;  &lt;modules&gt;&lt;br /&gt;    &lt;module&gt;MyPortlet.war&lt;/module&gt;&lt;br /&gt;  &lt;/modules&gt;&lt;br /&gt;&lt;build&gt;&lt;br /&gt;&lt;plugins&gt;&lt;br /&gt;      &lt;plugin&gt;&lt;br /&gt;        &lt;groupid&gt;org.apache.maven.plugins&lt;/groupid&gt;&lt;br /&gt;        &lt;artifactid&gt;maven-compiler-plugin&lt;/artifactid&gt;&lt;br /&gt;          &lt;configuration&gt;&lt;br /&gt;            &lt;source&gt;1.5&lt;br /&gt;            &lt;target&gt;1.5&lt;/target&gt;&lt;br /&gt;         &lt;/configuration&gt;&lt;br /&gt;     &lt;/plugin&gt;&lt;br /&gt;   &lt;/plugins&gt;&lt;br /&gt;&lt;/build&gt;&lt;br /&gt;&lt;/project&gt;&lt;/p&gt;       &lt;p&gt;The pom.xml in the MyPortlet.war directory shall look like this.&lt;br /&gt;&lt;project&gt;&lt;br /&gt;  &lt;modelversion&gt;4.0.0&lt;/modelversion&gt;&lt;br /&gt;  &lt;parent&gt;&lt;br /&gt;    &lt;groupid&gt;com.aja.myportlet&lt;/groupid&gt;&lt;br /&gt;    &lt;artifactid&gt;MyPortlet&lt;/artifactid&gt;&lt;br /&gt;    &lt;version&gt;1.0&lt;/version&gt;&lt;br /&gt;  &lt;/parent&gt;&lt;br /&gt;     &lt;artifactid&gt;MyPortlet.war&lt;/artifactid&gt;&lt;br /&gt;  &lt;packaging&gt;war&lt;/packaging&gt;&lt;br /&gt;    &lt;dependencies&gt;&lt;br /&gt;            &lt;dependency&gt;&lt;br /&gt;              &lt;groupid&gt;junit&lt;/groupid&gt;&lt;br /&gt;              &lt;artifactid&gt;junit&lt;/artifactid&gt;&lt;br /&gt;              &lt;version&gt;4.1&lt;/version&gt;&lt;br /&gt;              &lt;scope&gt;test&lt;/scope&gt;&lt;br /&gt;            &lt;/dependency&gt;&lt;br /&gt;            &lt;dependency&gt;&lt;br /&gt;                &lt;groupid&gt;log4j&lt;/groupid&gt;&lt;br /&gt;                &lt;artifactid&gt;log4j&lt;/artifactid&gt;&lt;br /&gt;                &lt;scope&gt;provided&lt;/scope&gt;&lt;br /&gt;                &lt;version&gt;1.2.13&lt;/version&gt;&lt;br /&gt;            &lt;/dependency&gt;&lt;br /&gt;        &lt;dependency&gt;&lt;br /&gt;                        &lt;groupid&gt;javax.servlet&lt;/groupid&gt;&lt;br /&gt;                        &lt;artifactid&gt;servlet-api&lt;/artifactid&gt;&lt;br /&gt;                        &lt;version&gt;2.5&lt;/version&gt;&lt;br /&gt;                        &lt;scope&gt;provided&lt;/scope&gt;&lt;br /&gt;                &lt;/dependency&gt;   &lt;br /&gt;        &lt;dependency&gt;&lt;br /&gt;              &lt;groupid&gt;opensymphony&lt;/groupid&gt;&lt;br /&gt;              &lt;artifactid&gt;xwork&lt;/artifactid&gt;&lt;br /&gt;              &lt;version&gt;2.0.1&lt;/version&gt;&lt;br /&gt;            &lt;/dependency&gt;&lt;br /&gt;            &lt;dependency&gt;&lt;br /&gt;              &lt;groupid&gt;commons-logging&lt;/groupid&gt;&lt;br /&gt;              &lt;artifactid&gt;commons-logging&lt;/artifactid&gt;&lt;br /&gt;              &lt;version&gt;1.0.4&lt;/version&gt;&lt;br /&gt;            &lt;/dependency&gt;&lt;br /&gt;            &lt;dependency&gt;&lt;br /&gt;              &lt;groupid&gt;commons-attributes&lt;/groupid&gt;&lt;br /&gt;              &lt;artifactid&gt;commons-attributes-api&lt;/artifactid&gt;&lt;br /&gt;              &lt;version&gt;2.1&lt;/version&gt;&lt;br /&gt;            &lt;/dependency&gt;&lt;br /&gt;            &lt;dependency&gt;&lt;br /&gt;              &lt;groupid&gt;commons-collections&lt;/groupid&gt;&lt;br /&gt;              &lt;artifactid&gt;commons-collections&lt;/artifactid&gt;&lt;br /&gt;              &lt;version&gt;3.2&lt;/version&gt;&lt;br /&gt;            &lt;/dependency&gt;&lt;br /&gt;            &lt;dependency&gt;&lt;br /&gt;              &lt;groupid&gt;freemarker&lt;/groupid&gt;&lt;br /&gt;              &lt;artifactid&gt;freemarker&lt;/artifactid&gt;&lt;br /&gt;              &lt;version&gt;2.3.4&lt;/version&gt;&lt;br /&gt;            &lt;/dependency&gt;&lt;br /&gt;        &lt;dependency&gt;&lt;br /&gt;              &lt;groupid&gt;org.apache.struts&lt;/groupid&gt;&lt;br /&gt;              &lt;artifactid&gt;struts2-core&lt;/artifactid&gt;&lt;br /&gt;              &lt;version&gt;2.0.6&lt;/version&gt;&lt;br /&gt;            &lt;/dependency&gt;&lt;br /&gt;            &lt;dependency&gt;&lt;br /&gt;              &lt;groupid&gt;asm&lt;/groupid&gt;&lt;br /&gt;              &lt;artifactid&gt;asm&lt;/artifactid&gt;&lt;br /&gt;              &lt;version&gt;1.5.3&lt;/version&gt;&lt;br /&gt;            &lt;/dependency&gt;&lt;br /&gt;      &lt;/dependencies&gt;&lt;br /&gt;&lt;/project&gt;&lt;br /&gt;Go to the MyPortlet.war directory and exceute this command.&lt;br /&gt;mvn clean install&lt;br /&gt;Eclipse.&lt;br /&gt;I assume you know Eclipse. Otherwise you are in for a long journey. Now make the eclipse project file in maven by&lt;br /&gt;executing this mvn eclipse:eclipse.&lt;br /&gt;Import  the project. You must define your Maven repository in the Eclipse  class-path setting. The variable is called M2_REPO and you must point to  your Maven repository. If you are unsure check out the Maven  documentation.&lt;br /&gt;In windows most of the time you'll find the REPO in the Documents folder.&lt;br /&gt;Coding&lt;br /&gt;When we are done the following files will exist in our project.&lt;br /&gt;In the WEB-INF directory&lt;br /&gt;jboss-app.xml&lt;br /&gt;jboss-portlet.xml&lt;br /&gt;MyPortlet-object.xml&lt;br /&gt;portlet.xml&lt;br /&gt;web.xml&lt;br /&gt;I also felt a need to add this tld as well. It can be found in the Struts2.0.6.core jar in the /META-INF directory.&lt;br /&gt;I don't think you need them but I have to verify that.&lt;br /&gt;struts-tags.tld&lt;br /&gt;In the src/main/resources directory&lt;br /&gt;struts.xml&lt;br /&gt;In the WEB-INF/pages/view (Yes you must create that directory)&lt;br /&gt;helloForm.jsp&lt;br /&gt;helloWorld.jsp&lt;br /&gt;And we'll do one Java class and put it in&lt;br /&gt;src/main/java/com/aja/mp/action/HelloWorldAction.java&lt;br /&gt;The content of all files (except tlds) will be shonw below. If you add this content your application will work.&lt;br /&gt;struts.xml&lt;/p&gt;       &lt;p&gt;&lt;!--?xml version="1.0" encoding="ISO-8859-1"?--&gt;&lt;br /&gt;&lt;br /&gt;&lt;xwork&gt;&lt;br /&gt;    &lt;include file="struts-default.xml"&gt;&lt;br /&gt;    &lt;include file="struts-portlet-default.xml"&gt;&lt;br /&gt;&lt;br /&gt;    &lt;package name="view" extends="struts-portlet-default" namespace="/view"&gt;&lt;br /&gt;        &lt;action name="index" class="com.aja.mp.action.HelloWorldAction"&gt;&lt;br /&gt;            &lt;result name="success"&gt;/WEB-INF/pages/view/helloForm.jsp&lt;/result&gt;&lt;br /&gt;        &lt;/action&gt;&lt;br /&gt;        &lt;action name="helloWorldInput" class="com.aja.mp.action.HelloWorldAction"&gt;&lt;br /&gt;            &lt;result name="success"&gt;/WEB-INF/pages/view/helloForm.jsp&lt;/result&gt;&lt;br /&gt;        &lt;/action&gt;&lt;br /&gt;        &lt;action name="helloWorld" class="com.aja.mp.action.HelloWorldAction"&gt;&lt;br /&gt;            &lt;result name="success"&gt;/WEB-INF/pages/view/helloWorld.jsp&lt;/result&gt;&lt;br /&gt;        &lt;/action&gt;&lt;br /&gt;    &lt;/package&gt;&lt;br /&gt;&lt;/include&gt;&lt;/include&gt;&lt;/xwork&gt;&lt;br /&gt;jboss-app.xml&lt;/p&gt;       &lt;p&gt;&lt;jboss-app&gt;&lt;br /&gt;   &lt;app-name&gt;MyPortlet&lt;/app-name&gt;&lt;br /&gt;&lt;/jboss-app&gt;&lt;br /&gt;jboss-portlet.xml&lt;/p&gt;       &lt;p&gt;&lt;textarea rows="10" cols="70"&gt;&amp;lt;portlet-app&amp;gt;&lt;br /&gt;   &amp;lt;portlet&amp;gt;&lt;br /&gt;      &amp;lt;portlet-name&amp;gt;MyPortlet&amp;lt;/portlet-name&amp;gt;&lt;br /&gt;      &amp;lt;security&amp;gt;&lt;br /&gt;      &amp;lt;/security&amp;gt;&lt;br /&gt;   &amp;lt;/portlet&amp;gt;&lt;br /&gt;&amp;lt;/portlet-app&amp;gt;&lt;br /&gt;&lt;/textarea&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;MyPortlet-object.xml&lt;br /&gt;&lt;br /&gt;&lt;textarea rows="10" cols="70"&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br /&gt;&amp;lt;deployments&amp;gt;&lt;br /&gt;    &amp;lt;deployment&amp;gt;&lt;br /&gt;        &amp;lt;if-exists&amp;gt;overwrite&amp;lt;/if-exists&amp;gt;&lt;br /&gt;        &amp;lt;parent-ref&amp;gt;default&amp;lt;/parent-ref&amp;gt;&lt;br /&gt;        &amp;lt;properties /&amp;gt;&lt;br /&gt;        &amp;lt;page&amp;gt;&lt;br /&gt;            &amp;lt;page-name&amp;gt;MyPortlet Tutorial&amp;lt;/page-name&amp;gt;&lt;br /&gt;            &amp;lt;properties /&amp;gt;&lt;br /&gt;            &amp;lt;window&amp;gt;&lt;br /&gt;                &amp;lt;window-name&amp;gt;MyPortletWindow&amp;lt;/window-name&amp;gt;&lt;br /&gt;                &amp;lt;instance-ref&amp;gt;MyPortletInstance&amp;lt;/instance-ref&amp;gt;&lt;br /&gt;                &amp;lt;region&amp;gt;center&amp;lt;/region&amp;gt;&lt;br /&gt;                &amp;lt;height&amp;gt;0&amp;lt;/height&amp;gt;&lt;br /&gt;            &amp;lt;/window&amp;gt;&lt;br /&gt;        &amp;lt;/page&amp;gt;&lt;br /&gt;    &amp;lt;/deployment&amp;gt;&lt;br /&gt;    &amp;lt;deployment&amp;gt;&lt;br /&gt;        &amp;lt;if-exists&amp;gt;overwrite&amp;lt;/if-exists&amp;gt;&lt;br /&gt;        &amp;lt;instance&amp;gt;&lt;br /&gt;            &amp;lt;instance-name&amp;gt;MyPortletInstance&amp;lt;/instance-name&amp;gt;&lt;br /&gt;            &amp;lt;component-ref&amp;gt;MyPortlet.MyPortlet&amp;lt;/component-ref&amp;gt;&lt;br /&gt;        &amp;lt;/instance&amp;gt;&lt;br /&gt;    &amp;lt;/deployment&amp;gt;&lt;br /&gt;&amp;lt;/deployments&amp;gt;&lt;br /&gt;&lt;/textarea&gt;&lt;br /&gt;portlet.xml&lt;/p&gt;       &lt;p&gt;&lt;br /&gt;&lt;portlet-app version="1.0" xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd" xsi="http://www.w3.org/2001/XMLSchema-instance" schemalocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd  http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"&gt;&lt;br /&gt;  &lt;portlet&gt;&lt;br /&gt;    &lt;description&gt;My very first struts Portlet&lt;/description&gt;&lt;br /&gt;    &lt;portlet-name&gt;MyPortlet&lt;/portlet-name&gt;&lt;br /&gt;    &lt;display-name&gt;My first WebWork Portlet&lt;/display-name&gt;&lt;br /&gt;&lt;br /&gt;    &lt;portlet-class&gt;org.apache.struts2.portlet.dispatcher.Jsr168Dispatcher&lt;/portlet-class&gt;&lt;br /&gt;&lt;br /&gt;    &lt;init-param&gt;&lt;br /&gt;      &lt;!-- The view mode namespace. Maps to a namespace in the xwork config file --&gt;&lt;br /&gt;      &lt;name&gt;viewNamespace&lt;/name&gt;&lt;br /&gt;      &lt;value&gt;/view&lt;/value&gt;&lt;br /&gt;    &lt;/init-param&gt;&lt;br /&gt;    &lt;init-param&gt;&lt;br /&gt;      &lt;!-- The default action to invoke in view mode --&gt;&lt;br /&gt;      &lt;name&gt;defaultViewAction&lt;/name&gt;&lt;br /&gt;      &lt;value&gt;index&lt;/value&gt;&lt;br /&gt;    &lt;/init-param&gt;&lt;br /&gt;&lt;br /&gt;    &lt;expiration-cache&gt;0&lt;/expiration-cache&gt;&lt;br /&gt;&lt;br /&gt;    &lt;supports&gt;&lt;br /&gt;      &lt;mime-type&gt;text/html&lt;/mime-type&gt;&lt;br /&gt;    &lt;/supports&gt;&lt;br /&gt;&lt;br /&gt;    &lt;supported-locale&gt;en&lt;/supported-locale&gt;&lt;br /&gt;&lt;br /&gt;    &lt;portlet-info&gt;&lt;br /&gt;      &lt;title&gt;My very own WebWork Portlet&lt;/title&gt;&lt;br /&gt;      &lt;short-title&gt;WWPortlet&lt;/short-title&gt;&lt;br /&gt;      &lt;keywords&gt;struts,portlet&lt;/keywords&gt;&lt;br /&gt;    &lt;/portlet-info&gt;&lt;br /&gt;  &lt;/portlet&gt;&lt;br /&gt;&lt;/portlet-app&gt;&lt;/p&gt;       &lt;p&gt;web.xml&lt;/p&gt;       &lt;p&gt;&lt;br /&gt;&lt;!--?xml version="1.0" encoding="UTF-8"?--&gt;&lt;br /&gt;&lt;br /&gt;&lt;web-app&gt;&lt;br /&gt;    &lt;filter&gt;&lt;br /&gt;        &lt;filter-name&gt;struts&lt;/filter-name&gt;&lt;br /&gt;        &lt;filter-class&gt;&lt;br /&gt;            org.apache.struts2.dispatcher.FilterDispatcher&lt;br /&gt;        &lt;/filter-class&gt;&lt;br /&gt;    &lt;/filter&gt;&lt;br /&gt;&lt;br /&gt;    &lt;filter-mapping&gt;&lt;br /&gt;        &lt;filter-name&gt;struts&lt;/filter-name&gt;&lt;br /&gt;        &lt;url-pattern&gt;/*&lt;/url-pattern&gt;&lt;br /&gt;    &lt;/filter-mapping&gt;&lt;br /&gt;&lt;br /&gt;    &lt;listener&gt;&lt;br /&gt;        &lt;listener-class&gt;&lt;br /&gt;            org.apache.struts2.portlet.context.ServletContextHolderListener&lt;br /&gt;        &lt;/listener-class&gt;&lt;br /&gt;    &lt;/listener&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    &lt;servlet&gt;&lt;br /&gt;        &lt;servlet-name&gt;preparator&lt;/servlet-name&gt;&lt;br /&gt;        &lt;servlet-class&gt;&lt;br /&gt;            org.apache.struts2.portlet.context.PreparatorServlet&lt;br /&gt;        &lt;/servlet-class&gt;&lt;br /&gt;    &lt;/servlet&gt;&lt;br /&gt;&lt;br /&gt;    &lt;taglib&gt;&lt;br /&gt;        &lt;taglib-uri&gt;/struts-tags&lt;/taglib-uri&gt;&lt;br /&gt;        &lt;taglib-location&gt;/WEB-INF/struts-tags.tld&lt;/taglib-location&gt;&lt;br /&gt;    &lt;/taglib&gt;&lt;br /&gt;&lt;br /&gt;&lt;/web-app&gt;&lt;/p&gt;       &lt;p&gt;helloForm.jsp&lt;/p&gt;       &lt;p&gt;&amp;lt;%@ taglib uri="/struts-tags" prefix="ww" %&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;h2&gt;Hi there! Please enter your name&lt;/h2&gt;&lt;br /&gt;&lt;ww:form action="helloWorld" method="POST"&gt;&lt;br /&gt;    &lt;ww:textfield label="First name" name="firstName" value=""&gt;&lt;br /&gt;    &lt;ww:textfield label="Last name" name="lastName" value=""&gt;&lt;br /&gt;    &lt;ww:submit value="Say hello!"&gt;&lt;br /&gt;&lt;/ww:submit&gt;&lt;/ww:textfield&gt;&lt;/ww:textfield&gt;&lt;/ww:form&gt;&lt;br /&gt;helloWorld.jsp&lt;p&gt;&lt;/p&gt;       &lt;p&gt;&amp;lt;%@ taglib uri="/struts-tags" prefix="ww" %&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;h2&gt;Hello &lt;ww:property value="firstName"&gt; &lt;ww:property value="lastName"&gt;&lt;/ww:property&gt;&lt;/ww:property&gt;&lt;/h2&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;a href="/oldsite/%3Cww:url%20action="&gt;"&amp;gt;Back to form&lt;/a&gt;&lt;/p&gt;       &lt;p&gt;HelloWorldAction.java&lt;/p&gt;       &lt;p&gt;package com.aja.mp.action;&lt;br /&gt;&lt;br /&gt;import java.util.Collection;&lt;br /&gt;&lt;br /&gt;import com.opensymphony.xwork2.ActionSupport;&lt;br /&gt;&lt;br /&gt;public class HelloWorldAction extends ActionSupport {&lt;br /&gt;    /**&lt;br /&gt;     *&lt;br /&gt;     */&lt;br /&gt;    private static final long serialVersionUID = 2452536171755317259L;&lt;br /&gt;    private String firstName;&lt;br /&gt;    private String lastName;&lt;br /&gt;    public String getFirstName() {&lt;br /&gt;        return firstName;&lt;br /&gt;    }&lt;br /&gt;    public void setFirstName(String firstName) {&lt;br /&gt;        this.firstName = firstName;&lt;br /&gt;    }&lt;br /&gt;    public String getLastName() {&lt;br /&gt;        return lastName;&lt;br /&gt;    }&lt;br /&gt;    public void setLastName(String lastName) {&lt;br /&gt;        this.lastName = lastName;&lt;br /&gt;    }&lt;br /&gt;    @Override&lt;br /&gt;    public String execute() throws Exception {&lt;br /&gt;        // TODO Auto-generated method stub&lt;br /&gt;        return super.execute();&lt;br /&gt;    }&lt;br /&gt;    @Override&lt;br /&gt;    public Collection getActionMessages() {&lt;br /&gt;        // TODO Auto-generated method stub&lt;br /&gt;        return super.getActionMessages();&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;We are done, build and deploy the application.&lt;br /&gt;mvn clean install&lt;br /&gt;Rename and copy war to /jbossportal/server/default/deploy/MyPortlet.war&lt;br /&gt;You  will most probably get two errors at start up time, you can ignore  those if it one complaining about a dev property and another complaining  about i18.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-6671704847002788846?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/6671704847002788846/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/12/struts2-and-portlet.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/6671704847002788846'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/6671704847002788846'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/12/struts2-and-portlet.html' title='Struts2 and portlet'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-4354167138422029061</id><published>2011-12-14T00:58:00.001-08:00</published><updated>2011-12-14T00:58:34.800-08:00</updated><title type='text'>Struts</title><content type='html'>&lt;p&gt;This is a short how to get a Struts application up and running.&lt;br /&gt;The following run time configuration was used&lt;br /&gt;jdk1.5.0_09&lt;br /&gt;Jboss4.0.5&lt;br /&gt;Ubuntu Edgy Eft&lt;br /&gt;The following development environment was used&lt;br /&gt;Eclipse3.2.2&lt;br /&gt;Web Tools plugin 1.5.1&lt;br /&gt;Struts version used is 1.3.8.&lt;br /&gt;If you need a more thorough explanation on the MVC2 pattern browse the net.&lt;br /&gt;You need some things to get it to work. First off the struts-config.xml file.&lt;br /&gt;This file should be in the WEB-INF directory. Remember, WEB-INF makes the file inaccessible to the outside world.&lt;br /&gt;&lt;!--?xml version="1.0" encoding="UTF-8"?--&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;struts-config&gt;&lt;br /&gt; &lt;br /&gt;  &lt;form-beans&gt;&lt;br /&gt;    &lt;form-bean name="StartForm" type="com.aja.lib.form.StartForm"&gt;&lt;br /&gt;  &lt;/form-bean&gt;&lt;/form-beans&gt;&lt;br /&gt;  &lt;br /&gt;    &lt;action path="/StartAction" name="StartForm" scope="request" validate="false" input="/start.jsp" type="com.aja.lib.action.StartAction"&gt;&lt;br /&gt;      &lt;forward name="success" path="/success.jsp"&gt;&lt;br /&gt;      &lt;forward name="fail" path="/start.jsp"&gt;&lt;br /&gt;   &lt;/forward&gt;&lt;/forward&gt;&lt;/action&gt;&lt;br /&gt;  &lt;br /&gt;  &lt;br /&gt; &lt;br /&gt; &lt;br /&gt;&lt;/struts-config&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Well, well what does all that mean.&lt;br /&gt;First off a form-bean. And now, what does a form bean do? It basically means that&lt;br /&gt;if you post data Struts make sure that your parameters are sent to the server and handled there.&lt;br /&gt;For  instance if you post a user name that name will be sent to the server,  and the instance of the form class will use getters/setters and use  that.&lt;br /&gt;All form beans must extend the  org.apache.struts.action.ActionForm; Please override the validate method  since this makes it possible for you&lt;br /&gt;to handle erroneous data in a good way. I have implemented the reset method as well.&lt;br /&gt;my form bean&lt;br /&gt;public class StartForm extends ActionForm {&lt;br /&gt;&lt;br /&gt;    /**&lt;br /&gt;     *&lt;br /&gt;     */&lt;br /&gt;    private static final long serialVersionUID = -3219629289363196387L;&lt;br /&gt;   &lt;br /&gt;    private String name;&lt;br /&gt;   &lt;br /&gt;    public String getName() {&lt;br /&gt;        return name;&lt;br /&gt;    }&lt;br /&gt;    public void setName(String name) {&lt;br /&gt;        this.name = name;&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;    /**&lt;br /&gt;     * Reset all properties to their default values.&lt;br /&gt;     *&lt;br /&gt;     * @param mapping The mapping used to select this instance&lt;br /&gt;     * @param request The servlet request we are processing&lt;br /&gt;     */&lt;br /&gt;    public void reset(ActionMapping mapping, HttpServletRequest request) {&lt;br /&gt;        this.name=null;&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;    /**&lt;br /&gt;     * Reset all properties to their default values.&lt;br /&gt;     *&lt;br /&gt;     * @param mapping The mapping used to select this instance&lt;br /&gt;     * @param request The servlet request we are processing&lt;br /&gt;   * @return errors&lt;br /&gt;     */&lt;br /&gt;  public ActionErrors validate(&lt;br /&gt;      ActionMapping mapping, HttpServletRequest request ) {&lt;br /&gt;      ActionErrors errors = new ActionErrors();&lt;br /&gt;     &lt;br /&gt;      if( getName() == null || getName().length() &amp;lt; 1 ) {&lt;br /&gt;        errors.add("name",new ActionMessage("error.name.required"));&lt;br /&gt;      }&lt;br /&gt;    &lt;br /&gt;&lt;br /&gt;      return errors;&lt;br /&gt;  }&lt;br /&gt;Ok, now we are done with the Form. This is the Model aprt of the pattern. The model can be seen as a stupid data carrier.&lt;br /&gt;We'll take the action now.&lt;/p&gt;&lt;p&gt;public class StartAction extends Action {&lt;br /&gt;package com.aja.lib.action;&lt;br /&gt;&lt;br /&gt;import javax.servlet.http.HttpServletRequest;&lt;br /&gt;import javax.servlet.http.HttpServletResponse;&lt;br /&gt;&lt;br /&gt;import org.apache.struts.action.Action;&lt;br /&gt;import org.apache.struts.action.ActionErrors;&lt;br /&gt;import org.apache.struts.action.ActionForm;&lt;br /&gt;import org.apache.struts.action.ActionForward;&lt;br /&gt;import org.apache.struts.action.ActionMapping;&lt;br /&gt;    @Override&lt;br /&gt;     public ActionForward execute(ActionMapping mapping, ActionForm form,  HttpServletRequest request, HttpServletResponse response) throws  Exception {&lt;br /&gt;       &lt;br /&gt;        ActionErrors errors = form.validate(mapping, request);&lt;br /&gt;       &lt;br /&gt;        if (errors.size() &amp;gt; 0){&lt;br /&gt;            return mapping.findForward("fail");   &lt;br /&gt;        }&lt;br /&gt;       &lt;br /&gt;       &lt;br /&gt;        return mapping.findForward("success");&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;As  you can see, extend the org.apache.struts.action.Action class and  override the execute method. You have two different outcomes. In case of  a success go to&lt;br /&gt;"success" and in case of error go to "fail". These two paths must be mapped in the struts-config.xml file. Remember this code.&lt;br /&gt;&lt;forward name="success" path="/success.jsp"&gt;&lt;br /&gt;&lt;forward name="fail" path="/start.jsp"&gt;&lt;br /&gt;The  action in our case is where you usually put your calls to the tiers  behind the presentation tier, i.e business tier. This is the C in MVC,  the control part, the traffic handler.&lt;br /&gt;What about the View? Well, look above in the code "success.jsp" and fail.jsp that's our views. They must exist.&lt;br /&gt;First off the start point that we defined in the struts-config.xml, start.jap&lt;br /&gt;&amp;lt;%@ page language="java" pageEncoding="ISO-8859-1"%&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%&amp;gt;&lt;br /&gt;&amp;lt;%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%&amp;gt;&lt;br /&gt;&amp;lt;%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;   &lt;html:html&gt;&lt;br /&gt;&lt;br /&gt;   &lt;br /&gt;&lt;br /&gt;   &lt;title&gt;Wddfsd&lt;/title&gt;&lt;br /&gt;&lt;br /&gt;   &lt;html:base&gt;&lt;br /&gt;&lt;br /&gt;   &lt;br /&gt;&lt;br /&gt;   &lt;br /&gt;&lt;br /&gt;   &lt;html:form action="/StartAction"&gt;&lt;br /&gt;&lt;br /&gt;   &lt;html:errors&gt;&lt;br /&gt;&lt;br /&gt;   &lt;/html:errors&gt;&lt;/html:form&gt;&lt;/html:base&gt;&lt;/html:html&gt;&lt;/forward&gt;&lt;/forward&gt;&lt;/p&gt;&lt;table&gt;&lt;br /&gt;&lt;br /&gt;        &lt;tbody&gt;&lt;tr&gt;&lt;br /&gt;&lt;br /&gt;          &lt;td colspan="2" align="center"&gt;&lt;br /&gt;        &lt;span style="font-size:130%;"&gt;Please Enter the Following Details&lt;/span&gt;&lt;br /&gt;     &lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;    &lt;tr&gt;&lt;br /&gt;          &lt;td align="right"&gt;&lt;br /&gt;            Name&lt;br /&gt;          &lt;/td&gt;&lt;br /&gt;          &lt;td align="left"&gt;&lt;br /&gt;            &lt;html:text property="name" size="30" maxlength="30"&gt;&lt;br /&gt;          &lt;/html:text&gt;&lt;/td&gt;&lt;br /&gt;        &lt;/tr&gt;&lt;br /&gt;      &lt;br /&gt;    &lt;tr&gt;&lt;br /&gt;          &lt;td align="right"&gt;&lt;br /&gt;            &lt;html:submit&gt;Save&lt;/html:submit&gt;&lt;br /&gt;          &lt;/td&gt;&lt;br /&gt;          &lt;td align="left"&gt;&lt;br /&gt;            &lt;html:cancel&gt;Cancel&lt;/html:cancel&gt;&lt;br /&gt;          &lt;/td&gt;&lt;br /&gt;        &lt;/tr&gt;&lt;br /&gt;  &lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;   &lt;br /&gt;   &lt;br /&gt;   &lt;br /&gt;Now here we see some magic. Note the html:text property="name", this will be mapped towards our form beans setName method.&lt;br /&gt;I made it simple here, success just forwards to a stupid empty page, and fail back to start.jsp. below is my success.jsp&lt;br /&gt;&amp;lt;%@ page language="java" pageEncoding="ISO-8859-1"%&amp;gt;&lt;br /&gt;&amp;lt;%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %&amp;gt;&lt;br /&gt; &lt;br /&gt;   &lt;html:html&gt;&lt;br /&gt;&lt;br /&gt;   &lt;br /&gt;&lt;br /&gt;   &lt;title&gt;Sucess&lt;/title&gt;&lt;br /&gt;&lt;br /&gt;   &lt;html:base&gt;&lt;br /&gt;&lt;br /&gt;   &lt;br /&gt;&lt;br /&gt;   &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;     &lt;br /&gt;   &lt;/html:base&gt;&lt;/html:html&gt;&lt;br /&gt;Deploy it and write http://locahost:8080/LibWeb/start.jsp. Good luck now.&lt;br /&gt;One  final word, if you develop something for real, you will most likely for  instance not have a .jsp instead you can add in the configuration a lot  of default handling stuff.&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-4354167138422029061?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/4354167138422029061/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/12/struts.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/4354167138422029061'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/4354167138422029061'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/12/struts.html' title='Struts'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-8547862791323235390</id><published>2011-12-14T00:57:00.002-08:00</published><updated>2011-12-14T00:58:17.798-08:00</updated><title type='text'>Create a simple JavaEE application with XFire</title><content type='html'>This is simple step by step tutorial on how to build an application  that will display content on web pages. Everything will be done in a  pedagogic simple way.The nuild is done with the &lt;a href="http://maven.apache.org/"&gt;Apache Maven&lt;/a&gt; framework instead of ant.&lt;p&gt;Below  is a small list of tools used. All fancy words or strange settings will  be omitted. In 90% of the applications you build you can use the  default settings and they will work.&lt;/p&gt;&lt;p&gt;This tutorial contains these parts;&lt;br /&gt;Part 1 - Create a stand alone application accessing a database with Hibernate.&lt;br /&gt;Part 2 - Add web pages and access the database by calling methods on the application built in part 1. Deploy it on a server.&lt;br /&gt;Part 3 - Change the application to use a datasource instead of a driver manager.&lt;br /&gt;Part 4 - Add Ajax to interact with server.&lt;br /&gt;&lt;br /&gt;Part 5 - Add ejb to use as a session facade to the methods created in part 1.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;I  used hiberate as the orm mapping system. Nobody uses raw sql anymore,  at least not professionally. Many use the new JPA standard that was  introduced together with EJB3.0 (which indirectly use TopLink or  Hibernate). Most of the time I use JPA as well and use the underlying  implementation on the application server. For JBoss default is &lt;a href="http://www.hibernate.org/"&gt;Hibernate&lt;/a&gt; and for Sun it is &lt;a href="http://www.oracle.com/technology/products/ias/toplink/JPA/index.html"&gt;Oracles Toplink&lt;/a&gt;. In this tutorial we use the "old fashioned" Hibernate directly.&lt;/p&gt; &lt;p style="font-family: Arial,Helvetica,sans-serif; font-style: normal; font-weight: bold; background-color: #ffffcc"&gt;Tools used&lt;/p&gt;&lt;p&gt;&lt;br /&gt;Eclipse 3.3.1.1 - to edit files&lt;br /&gt;MySql 5.0.5 to store content&lt;br /&gt;Maven 2.0.9 - to build project&lt;br /&gt;Part 2 Apache 2.0 - to run web application&lt;br /&gt;Part 2 Tomcat 5.5.17 - to execute java code&lt;br /&gt;Part 5 JBoss 5.0.0 - to run Java EE app&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Tutorial One, create a web service project with XFire &lt;/strong&gt;&lt;/p&gt;&lt;p&gt;This  tutorial will show how you can create an application with XFire from  Codehouse. It will not access the database and it will have hardwired  properties.Note that today most people use the JAX-WS API directly in  the Java EE and do not use aweb service framework at all.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Step 1. Create project&lt;/strong&gt;&lt;br /&gt;People do this differently, but this is how I do it. Create three folders, call the first one &lt;strong&gt;book&lt;/strong&gt;, add two folders within this one, call them &lt;strong&gt;bookjar &lt;/strong&gt;and &lt;strong&gt;bookwar&lt;/strong&gt;. The war project is not needed for the moment.&lt;br /&gt;I  always add a suffix to my projects to indicate which type of packaging  to use, jar, war, ejb or ear. In each folder add a file called pom.xml. &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;&lt;strong&gt;Step 2. Create pom files in each folder&lt;/strong&gt; &lt;/p&gt;&lt;p&gt;In the top folder book add this &lt;a href="http://aspemo.com/it/toppom.xml"&gt;pom&lt;/a&gt;  file whichjust define some aspects of the project. Note that there is  probably as many ways as there are developers out there when it comes to  writing pom files.&lt;/p&gt;As you can see I have already added the MySql to the pom because I know I will need it later.&lt;br /&gt;&lt;p&gt;In the bookjar folder add this &lt;a href="http://aspemo.com/it/jarpom.xml"&gt;pom&lt;/a&gt; file.&lt;br /&gt;In the bookwar folder add this &lt;a href="http://aspemo.com/it/warpom.xml" target="_blank"&gt;pom&lt;/a&gt; file.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Step 3. Create files needed for the build&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Now you are almost done. First, before you can build the application you must have directory structure.&lt;/p&gt;&lt;p&gt;The jar project shall have this structure;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;src/main/java&lt;/li&gt;&lt;li&gt;src/main/resources&lt;/li&gt;&lt;li&gt;src/test/java&lt;/li&gt;&lt;li&gt;src/test/resources&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The war project must have this structure;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;src/main/java&lt;/li&gt;&lt;li&gt;src/main/resources&lt;/li&gt;&lt;li&gt;src/test/java&lt;/li&gt;&lt;li&gt;src/test/resources&lt;/li&gt;&lt;li&gt;src/main/webapp/WEB-INF&lt;/li&gt;&lt;li&gt;src/main/webapp/META-INF&lt;/li&gt;&lt;/ul&gt;&lt;p&gt; It is very important to understand that Maven will not be able to build the application without a &lt;a href="http://aspemo.com/it/web.xml"&gt;web.xm&lt;/a&gt;l file in the WEB-INF directory. This is just a simple plain one. &lt;/p&gt; &lt;p style="font-family: Arial,Helvetica,sans-serif; font-style: normal; font-weight: bold; background-color: #ffffcc"&gt;If  maven do not find the dependency jars you must install them into your  repository. Note. Sometimes it can be a bit confusing or some overhead  to get Maven to work. For instance you might need jar files which do not  exist in the maven repository. These will have to be installed  manually. Do not give up, it is worth the extra job. After that you will  notice how much easier it is to run the build process.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;What  we need to do now is create the "stuff" we will work with. I will not go  into the details, instead see the import statement in the file header,  these will indicate where these files shall reside. I.e. in which java  packages they are expected to be found.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;strong&gt;Step 4. Create java files needed in the application&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Write eclipse:eclipse and import the projects into Eclipse. &lt;/p&gt;&lt;p&gt;We will create 3 java files. &lt;/p&gt;&lt;ul&gt;&lt;li&gt;se.aja.xfire.Book.java (java class)&lt;/li&gt;&lt;li&gt;se.aja.xfire.BookService.java (java class)&lt;/li&gt;&lt;li&gt;se.aja.xfire.BookServiceImpl.java (java interface) &lt;/li&gt;&lt;/ul&gt;&lt;p&gt;One  is our domain object (book), this is what the site is about, books.  Since it is so small we use the same object from the database out to our  jsp pages.This is one strategy, the other is to convert the objects  before displaying them.Two is the service. Put all these objects in the  jar project. Thus when you are done in the jar project you shall have  these files;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;src/main/java/se/aja/xfire/Book.java &lt;/li&gt;&lt;li&gt;src/main/java/se/aja/xfire/BookService.java &lt;/li&gt;&lt;li&gt;src/main/java/se/aja/xfire/BookServiceImpl.java &lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;Step 5. Create XFire service file and modify web.xml&lt;/strong&gt; &lt;/p&gt;&lt;p&gt;You  will need to add the XFire services.xml file to the META-INF directory.  When you are done in the war project it shall look like this.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;src/main/webapp/WEB-INF/web.xml (standard web app file)&lt;/li&gt;&lt;li&gt;src/main/webapp/META-INF/services.xml (XFire configuration file)&lt;/li&gt;&lt;/ul&gt;Services  is the main xfire configuration file. In here you tell the system which  service is to be published. In our case the service is called  BookService. Quite fitting when it comes to my big interest, books.&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Step 6. The service.xml file content&lt;/strong&gt; &lt;/p&gt;&lt;p&gt;The file might look like this.&lt;br /&gt;&lt;beans xmlns="http://xfire.codehaus.org/config/1.0"&gt;&lt;br /&gt;  &lt;service&gt;&lt;br /&gt;    &lt;name&gt;BookService&lt;/name&gt;&lt;br /&gt;    &lt;namespace&gt;http://xfire.codehaus.org/BookService&lt;/namespace&gt;&lt;br /&gt;    &lt;serviceclass&gt;se.aja.xfire.BookService&lt;/serviceclass&gt;&lt;br /&gt;    &lt;implementationclass&gt;se.aja.xfire.BookServiceImpl&lt;/implementationclass&gt;&lt;br /&gt;  &lt;/service&gt;&lt;br /&gt;&lt;/beans&gt;&lt;br /&gt;The  service class indicates which service to publish and the implementation  class is the concrete class implementing the interface. &lt;/p&gt;&lt;p style="font-family: Arial,Helvetica,sans-serif; font-style: normal; font-weight: bold; background-color: #ffffcc"&gt;One  strange thing occurd to me, and is is also written about it on  codehaus. I got a file not found error. I followed this instruction and  got it to work.&lt;br /&gt;Try "WEB-INF/classes/META-INF/xfire/services.xml" if  the system cannot find the file. I.e. add a directory META-INF into the  classes directory and add the services.xml there.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Step 7. The domain object (Book.java) &lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Let's  assume the book class just contain an author and a title. It might look  like this then. Pls. ignore the obious bad programming regarding null  pointers and whatsoever. This is a pojo.&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;package  se.aja.xfire.Book;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;import java.io.Serializable;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;public class Book implements Serializable{&lt;br /&gt;&lt;br /&gt;    private String author;&lt;br /&gt;    private String title;&lt;br /&gt;   &lt;br /&gt;    public String getAuthor() {&lt;br /&gt;        return this.author;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void setAuthor(String author) {&lt;br /&gt;        this.author = auhtor;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public String getTitle() {&lt;br /&gt;        return this.title;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void setTitle(String title) {&lt;br /&gt;        this.title = title;&lt;br /&gt;    }&lt;br /&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Step 8. The service definition (BookService.java) &lt;/strong&gt;&lt;/p&gt;&lt;p&gt;BookService.java - Our service interface, remember S(ervice)OA.&lt;br /&gt;The service just publishes some methods.&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;public interface BookService extends Serializable {&lt;br /&gt;    public List getBooks();&lt;br /&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Step 9. The service implementation (BookServiceImpl.java) &lt;/strong&gt;&lt;/p&gt;&lt;p&gt; BookServiceImpl.java - Our class implementing the interface.&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;public class BookServiceImpl implements BookService {&lt;br /&gt;    private List books;&lt;br /&gt;   &lt;br /&gt;    public BookServiceImpl(){&lt;br /&gt;        books = new Arrayist();&lt;br /&gt;        Boook b1 = new Book();&lt;br /&gt;        b1.setAuthor("Jonas");&lt;br /&gt;        b1.setTitle("Blaha");&lt;br /&gt;&lt;br /&gt;        Boook b2 = new Book();&lt;br /&gt;        b2.setAuthor("Aspemo");&lt;br /&gt;        b2.setTitle("Blaha again");&lt;br /&gt;       &lt;br /&gt;        books.add(b1);&lt;br /&gt;        books.add(b2);&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;    public List getBooks(){&lt;br /&gt;        return books;&lt;br /&gt;    }&lt;br /&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Step 10. Configure the web.xml file to handle XFire &lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;You have to add the xfire servlet to your web.xml file. Add the following between the webapp tag in that file.&lt;br /&gt;&lt;br /&gt; &lt;span style="font-family:courier new,courier;"&gt;&lt;servlet&gt;&lt;br /&gt;    &lt;servlet-name&gt;XFireServlet&lt;/servlet-name&gt;&lt;br /&gt;    &lt;display-name&gt;XFire Servlet&lt;/display-name&gt;&lt;br /&gt;    &lt;servlet-class&gt;&lt;br /&gt;        org.codehaus.xfire.transport.http.XFireConfigurableServlet&lt;br /&gt;    &lt;/servlet-class&gt;&lt;br /&gt;  &lt;/servlet&gt;&lt;br /&gt;&lt;br /&gt;  &lt;servlet-mapping&gt;&lt;br /&gt;    &lt;servlet-name&gt;XFireServlet&lt;/servlet-name&gt;&lt;br /&gt;    &amp;lt;&lt;url-pattern&gt;/servlet/XFireServlet/*&lt;/url-pattern&gt;&lt;br /&gt;  &lt;/servlet-mapping&gt;&lt;br /&gt;&lt;br /&gt;  &lt;servlet-mapping&gt;&lt;br /&gt;    &lt;servlet-name&gt;XFireServlet&lt;/servlet-name&gt;&lt;br /&gt;    &lt;url-pattern&gt;/services/*&lt;/url-pattern&gt;&lt;br /&gt;  &lt;/servlet-mapping&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Your &lt;a href="http://aspemo.com/it/web2.xml"&gt;web.xml&lt;/a&gt; file should look like this now.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Step 11. Fix context root for Sun Application Server&lt;br /&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Your application will default to the name of the war, i.e. war-1.0.0. If you want to define a context name do like this.&lt;/p&gt;&lt;p&gt;Add sun-web.xml file to the WEB-INF directory and add this code there&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;&lt;!--?xml version="1.0" encoding="UTF-8"?--&gt;&lt;br /&gt;&lt;br /&gt;&lt;sun-web-app&gt;&lt;br /&gt;  &lt;context-root&gt;/book&lt;/context-root&gt;&lt;br /&gt;&lt;/sun-web-app&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt; if running on a Sun Application Server or add a jboss-web.xml into the&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Step 12. Fix context root for JBoss Application Server&lt;/strong&gt; &lt;/p&gt;&lt;p&gt;Your application will default to the name of the war, i.e. war-1.0.0. If you want to define a context name do like this.&lt;/p&gt;&lt;p&gt;Add jboss-web.xml file to the WEB-INF directory and add this code there;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;&lt;jboss-web&gt;&lt;/jboss-web&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt; &lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;&lt;context-root&gt;book&lt;/context-root&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt; &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Step 13. Deploy the application &lt;/strong&gt;&lt;br /&gt;Run the web application by deploying it to your favourite servlet container. &lt;/p&gt;&lt;p&gt;Type,&lt;br /&gt;http://localhost:8080/book/services/BookService?wsdl and you see your exposed web service.&lt;/p&gt;&lt;p&gt;That is what the default context name should be.If you are unsure and wants to define context. &lt;/p&gt;&lt;p&gt;Your first xfire app is working. Test the methods with SOAP UI. Take a break. Drink a coke or a coffee.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Step 14. What's left&lt;/strong&gt; &lt;/p&gt;&lt;p&gt;Well most obviously we lack the functionality to access things in the database. The Book file is hardwired with some data. That&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-8547862791323235390?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/8547862791323235390/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/12/create-simple-javaee-application-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/8547862791323235390'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/8547862791323235390'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/12/create-simple-javaee-application-with.html' title='Create a simple JavaEE application with XFire'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-6307076082594823919</id><published>2011-12-14T00:57:00.001-08:00</published><updated>2011-12-14T00:57:55.262-08:00</updated><title type='text'>EJBPoolSize</title><content type='html'>&lt;p&gt;I had a discussion on the EJB Pool size on a Sun Application Server.  The documentation is a bit vague (to say at least) on how it really  works.&lt;/p&gt;&lt;p&gt;First the definition. The EJB pool size is a way for the  EJB container to create (pool) stateless session beans to serve client  requests. The max pool size do sound a lot like a theoretical limit on  how many request that can be served simultaneously. But that is not so  actually. This is just a number on how many EJBs that are pooled over a  long run. If more requests comes in, more beans are created. So, even if  you have 200 as a max size, 500 clients can be served at the same time.  Interesting?&lt;/p&gt;&lt;p&gt;The annotation @PostConstruct will show you the  meaning of the pool. If you have a pool size of 5, you send in 10  simultaneous  10 calls to the @PostConstruct will be shown, BUT, the  next request coming after say 1 second will not call @PostConstruct  since those pools are pooled and the @PostConstruct are called before  the bean is created and used by a client. This is the implications of  the pool size.&lt;/p&gt;&lt;p style="font-family: Arial,Helvetica,sans-serif; font-style: normal; font-weight: bold; background-color: #ffffcc"&gt;Note  also that the pool handling is application vendor specific. This is  tried and verified on a Sun Application Server version 9.1.&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;hr size="2" width="100%"&gt;I will let you create the project by yourself since that is no issue. In the ejb I added these methods.&lt;p&gt; &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;hr size="2" width="100%"&gt;@PostConstruct&lt;br /&gt;   public void createIdentity(){&lt;br /&gt;      System.out.println(" PostConstruct ");&lt;br /&gt;   }&lt;p&gt; &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;This  will print out the row PostConstruct every time an ejb is created. And  yes, I would naturally never use Sys out in a real enterprise project.&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;public String getTimerName(){&lt;br /&gt;      System.out.println("Get Timer Name");&lt;br /&gt;      try&lt;br /&gt;      {&lt;br /&gt;         Thread.sleep(10000);&lt;br /&gt;      } catch (Exception e)&lt;br /&gt;      {&lt;br /&gt;         e.printStackTrace();&lt;br /&gt;      }&lt;br /&gt;      return "Jonas A";&lt;br /&gt;   }&lt;/p&gt;&lt;p&gt;This will sleep the thread for 10 seconds. &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;hr size="2" width="100%"&gt;Next I changed the pool size setting in the App server to be max 5.&lt;p&gt; &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;hr size="2" width="100%"&gt;Then I made a servlet with this method in;&lt;p&gt; &lt;/p&gt;&lt;hr size="2" width="100%"&gt;long start = System.currentTimeMillis();&lt;br /&gt;         InitialContext ic = new InitialContext();&lt;br /&gt;         BookService bk = (BookService) ic.lookup("Jonas");&lt;br /&gt;         bk.getTimerName();&lt;br /&gt;        &lt;br /&gt;         long end = System.currentTimeMillis();&lt;br /&gt;        &lt;br /&gt;        &lt;br /&gt;          diff = end - start;&lt;p&gt; &lt;/p&gt;&lt;p&gt;No  matter how many simultaneous calls you make this method only takes 10  seconds and the trace shows that the app server creates as many  PostConstruct statements as simultaneos calls, no matter how many they  are.&lt;/p&gt;&lt;hr size="2" width="100%"&gt;After a time you might notice new  PostConstruct statements even if you only make one call. This is because  pooled instances are discarded after a while. A new flag STEADY_STATE  can configure this behaviour as well.&lt;br /&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-6307076082594823919?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/6307076082594823919/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/12/ejbpoolsize.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/6307076082594823919'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/6307076082594823919'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/12/ejbpoolsize.html' title='EJBPoolSize'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-5332599895643537847</id><published>2011-12-14T00:56:00.003-08:00</published><updated>2011-12-14T00:56:50.976-08:00</updated><title type='text'>Aspects and Maven</title><content type='html'>&lt;p&gt;Many times you might want to implement restrictions on what  developers are allowed to do. For instance, you might want to prohibit  the usage of System.out in Java EE applications.&lt;/p&gt;&lt;p&gt;One way is to add  triggers in your version control system. Another way is to add aspects.  This short how to shows what you need to do the get aspects working.&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;hr size="2" width="100%"&gt;Step 1&lt;p&gt; &lt;/p&gt;&lt;p&gt;Create  a new project, and add it to the super pom. Thus if you want to build a  book application your super pom might look like this;&lt;/p&gt;&lt;p&gt;&lt;modules&gt;&lt;/modules&gt;&lt;/p&gt;&lt;p&gt;&lt;module&gt;book-jar&lt;/module&gt;&lt;/p&gt;&lt;p&gt;&lt;module&gt;book-war&lt;/module&gt;&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt; Now add the new project which will contain your aspects, call it for instance aspect (or whatever).&lt;/p&gt;&lt;p&gt;your super pom shall look like this now;&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;&lt;modules&gt;&lt;/modules&gt;&lt;/p&gt;&lt;p&gt;&lt;module&gt;book-jar&lt;/module&gt;&lt;/p&gt;&lt;p&gt;&lt;module&gt;book-war&lt;/module&gt;&lt;/p&gt;&lt;p&gt;&lt;module&gt;aspect&lt;/module&gt; &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;hr size="2" width="100%"&gt;Create the aspect project with normal directory structure.&lt;p&gt; &lt;/p&gt;&lt;p&gt;src/main/java/org/aja/aspect/&lt;/p&gt;&lt;p&gt;In the aspect directory we shall add our restriction;&lt;/p&gt;&lt;p&gt;Let's call it DoNotPrint.aj&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;hr size="2" width="100%"&gt;&lt;p&gt;File DoNotPrint.aj &lt;/p&gt;&lt;p&gt;public aspect DoNotPrint {&lt;br /&gt;&lt;br /&gt;        private pointcut withinBook() : within(org.aja..*);&lt;br /&gt;&lt;br /&gt;        declare error:&lt;br /&gt;        withinBook() &amp;amp;&amp;amp;&lt;br /&gt;        get(* System.out):&lt;br /&gt;        "Accessing System.out is not allowed.";&lt;br /&gt;       &lt;br /&gt;        declare error:&lt;br /&gt;        withinBook() &amp;amp;&amp;amp;&lt;br /&gt;        get(* System.err):&lt;br /&gt;        "Accessing System.err is not allowed.";&lt;br /&gt;&lt;br /&gt;        declare error:&lt;br /&gt;        withinBook() &amp;amp;&amp;amp;&lt;br /&gt;        call(* java.lang.Throwable.printStackTrace()):&lt;br /&gt;        "Calling Throwable.printStackTrace() is not allowed.";&lt;br /&gt;} &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;The  file says that it shall weave all files in the package structur org.aja  and send an error when it finds a System.out. Change decalre error to  declare warning if you think that is sufficient. &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;hr size="2" width="100%"&gt;Now manipulate the pom.xml in the aspect project. The super pom is finished.&lt;p&gt; &lt;/p&gt;&lt;p&gt;Step 1, add a dependency to the proper aspect jar and all projects we shall weave&lt;/p&gt;&lt;p&gt; &lt;dependency&gt;&lt;br /&gt;&lt;groupid&gt;aspectj&lt;/groupid&gt;&lt;br /&gt;&lt;artifactid&gt;aspectjrt&lt;/artifactid&gt;&lt;br /&gt;&lt;version&gt;1.5.2a&lt;/version&gt;&lt;br /&gt;&lt;scope&gt;provided&lt;/scope&gt;&lt;br /&gt;&lt;/dependency&gt;&lt;/p&gt;&lt;dependency&gt;&lt;br /&gt;&lt;groupid&gt;org.aja&lt;/groupid&gt;&lt;br /&gt;&lt;artifactid&gt;book-jar&lt;/artifactid&gt;&lt;br /&gt;&lt;version&gt;1.0.0&lt;/version&gt;&lt;br /&gt;&lt;scope&gt;provided&lt;/scope&gt;&lt;br /&gt;&lt;/dependency&gt;&lt;p&gt; &lt;dependency&gt;&lt;br /&gt; &lt;groupid&gt;org.aja&lt;/groupid&gt;&lt;br /&gt; &lt;artifactid&gt;book-war&lt;/artifactid&gt;&lt;br /&gt; &lt;version&gt;1.0.0&lt;/version&gt;&lt;br /&gt; &lt;scope&gt;provided&lt;/scope&gt;&lt;br /&gt; &lt;/dependency&gt;&lt;/p&gt;&lt;p&gt;So,  we added both a dependency to the aspect jar which is needed for all  operations and the two projects we want to verify, or weave. &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;hr size="2" width="100%"&gt;Add this to the build tag.&lt;p&gt; &lt;/p&gt;&lt;p&gt; &lt;build&gt;           &lt;br /&gt;    &lt;plugins&gt;            &lt;br /&gt;                 &lt;plugin&gt;&lt;br /&gt;&lt;groupid&gt;org.codehaus.mojo&lt;/groupid&gt;&lt;br /&gt;&lt;artifactid&gt;aspectj-maven-plugin&lt;/artifactid&gt;&lt;br /&gt;&lt;executions&gt;&lt;br /&gt;&lt;execution&gt;&lt;br /&gt;&lt;goals&gt;&lt;br /&gt;&lt;goal&gt;compile&lt;/goal&gt;&lt;br /&gt;&lt;/goals&gt;&lt;br /&gt;&lt;/execution&gt;&lt;br /&gt;&lt;/executions&gt;&lt;br /&gt;&lt;configuration&gt;&lt;br /&gt;                    &lt;source&gt;1.5&lt;br /&gt;                    &lt;target&gt;1.5&lt;/target&gt;&lt;br /&gt;                     &lt;weavedependencies&gt;&lt;br /&gt;                        &lt;weavedependency&gt;&lt;br /&gt;                            &lt;groupid&gt;org.aja&lt;/groupid&gt;&lt;br /&gt;                            &lt;artifactid&gt;book-jar&lt;/artifactid&gt;&lt;br /&gt;                        &lt;/weavedependency&gt;&lt;br /&gt;                        &lt;weavedependency&gt;&lt;br /&gt;                            &lt;groupid&gt;org.aja&lt;/groupid&gt;&lt;br /&gt;                             &lt;artifactid&gt;book-jar&lt;/artifactid&gt;&lt;br /&gt;                        &lt;/weavedependency&gt;&lt;br /&gt;                      &lt;/weavedependencies&gt;         &lt;br /&gt;                &lt;/configuration&gt;&lt;br /&gt;&lt;br /&gt;&lt;/plugin&gt;&lt;br /&gt;&lt;/plugins&gt;&lt;br /&gt; &lt;/build&gt; &lt;/p&gt;&lt;p&gt; &lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;hr size="2" width="100%"&gt; That's  it. Everytime you stand in the top of the project and build the  book-jar, book-war and aspect it will browse through all your classes  and the build will fail with an error message if it finds any instances  of System.out in the code.&lt;br /&gt;&lt;p&gt; &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-5332599895643537847?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/5332599895643537847/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/12/aspects-and-maven.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/5332599895643537847'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/5332599895643537847'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/12/aspects-and-maven.html' title='Aspects and Maven'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-6446310708234541263</id><published>2011-12-14T00:56:00.001-08:00</published><updated>2011-12-14T00:56:27.933-08:00</updated><title type='text'>Classpath</title><content type='html'>&lt;p&gt;If you don't work in an IDE, such as Eclipse or Netbeans, where do you put your java files?&lt;/p&gt;&lt;p&gt;The answer is in your &lt;java_jre&gt;/classes directory.&lt;/java_jre&gt;&lt;/p&gt;&lt;p&gt;Step 1 &lt;/p&gt;&lt;p&gt;Let's assume you create a class called DumbNumber which prints a digit.&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;hr size="2" width="100%"&gt;public class DumbNumber {&lt;p&gt; &lt;/p&gt;&lt;p&gt;    public static void main(String...args) {&lt;/p&gt;&lt;p&gt;        System.out.println("Dumb number is 7"); &lt;/p&gt;&lt;p&gt;    }&lt;/p&gt;&lt;p&gt;} &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-6446310708234541263?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/6446310708234541263/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/12/classpath.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/6446310708234541263'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/6446310708234541263'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/12/classpath.html' title='Classpath'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-1467176274435457165</id><published>2011-12-14T00:55:00.004-08:00</published><updated>2011-12-14T00:56:01.484-08:00</updated><title type='text'>JPA</title><content type='html'>&lt;p&gt;This is a a step by step instruction on how to create an ejb project  and call it from a stand alone java class and from a web page. Basically  what the application will do is connect Authors and Books and display  it in a GUI.&lt;/p&gt;&lt;p&gt;The work order is.&lt;/p&gt;&lt;p&gt;One ejb (Steteless session bean)&lt;/p&gt;&lt;p&gt;Two entity classes&lt;br /&gt;One pom.xml file per project (all in all 2 pom files)&lt;br /&gt;Everything will be built with maven&lt;/p&gt;&lt;hr  width="100%" style="font-size:85%;"&gt;&lt;p&gt; Step 1 -Create maven project structure&lt;/p&gt;&lt;p&gt;Top directory is called &lt;strong&gt;book &lt;/strong&gt;and beneath it we create two projects, &lt;strong&gt;bookejb &lt;/strong&gt;and &lt;strong&gt;bookwar&lt;/strong&gt;&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;hr size="2" width="100%"&gt;Step 2 - Add two pom files, first the top pom. &lt;p&gt; &lt;/p&gt;&lt;p&gt;&lt;!--?xml version="1.0" encoding="UTF-8"?--&gt;&lt;br /&gt;&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xsi="http://www.w3.org/2001/XMLSchema-instance" schemalocation="http://maven.apache.org/POM/4.0.0  http://maven.apache.org/maven-v4_0_0.xsd"&gt;&lt;br /&gt;  &lt;br /&gt;   &lt;modelversion&gt;4.0.0&lt;/modelversion&gt;&lt;br /&gt;&lt;br /&gt;   &lt;name&gt;Parent&lt;/name&gt;&lt;br /&gt;   &lt;groupid&gt;org.aja.book&lt;/groupid&gt;&lt;br /&gt;   &lt;artifactid&gt;parent&lt;/artifactid&gt;&lt;br /&gt;   &lt;version&gt;1.0.0&lt;/version&gt;&lt;br /&gt;   &lt;br /&gt;   &lt;packaging&gt;pom&lt;/packaging&gt;&lt;br /&gt;   &lt;br /&gt;   &lt;br /&gt;   &lt;modules&gt;&lt;br /&gt;      &lt;module&gt;ejb&lt;/module&gt;  &lt;br /&gt;   &lt;/modules&gt;&lt;br /&gt;  &lt;br /&gt;    &lt;build&gt;&lt;br /&gt;        &lt;plugins&gt;&lt;br /&gt;       &lt;br /&gt;            &lt;plugin&gt;&lt;br /&gt;                &lt;groupid&gt;org.apache.maven.plugins&lt;/groupid&gt;&lt;br /&gt;                &lt;artifactid&gt;maven-compiler-plugin&lt;/artifactid&gt;&lt;br /&gt;                &lt;version&gt;2.0.2&lt;/version&gt;&lt;br /&gt;                &lt;configuration&gt;&lt;br /&gt;                    &lt;source&gt;1.5&lt;br /&gt;                    &lt;target&gt;1.5&lt;/target&gt;&lt;br /&gt;                &lt;/configuration&gt;&lt;br /&gt;            &lt;/plugin&gt;&lt;br /&gt;        &lt;br /&gt;           &lt;br /&gt;        &lt;/plugins&gt;&lt;br /&gt;    &lt;/build&gt;&lt;br /&gt;   &lt;br /&gt;&lt;/project&gt;&lt;/p&gt;&lt;hr size="2" width="100%"&gt;Step 3 - Add pom file in ejb project&lt;br /&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt; &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xsi="http://www.w3.org/2001/XMLSchema-instance" schemalocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;&lt;br /&gt;       &lt;parent&gt;&lt;br /&gt;        &lt;groupid&gt;org.aja.book&lt;/groupid&gt;&lt;br /&gt;        &lt;artifactid&gt;parent&lt;/artifactid&gt;&lt;br /&gt;        &lt;version&gt;1.0.0&lt;/version&gt;&lt;br /&gt;    &lt;/parent&gt;&lt;br /&gt;        &lt;groupid&gt;org.aja.book&lt;/groupid&gt;&lt;br /&gt;        &lt;modelversion&gt;4.0.0&lt;/modelversion&gt;&lt;br /&gt;        &lt;artifactid&gt;ejb&lt;/artifactid&gt;&lt;br /&gt;        &lt;version&gt;1.0.0&lt;/version&gt;&lt;br /&gt;        &lt;packaging&gt;ejb&lt;/packaging&gt;&lt;br /&gt;        &lt;name&gt;Aja EJB&lt;/name&gt;&lt;br /&gt;       &lt;br /&gt;    &lt;br /&gt;        &lt;dependencies&gt;&lt;br /&gt;        &lt;dependency&gt;&lt;br /&gt;         &lt;groupid&gt;java&lt;/groupid&gt;&lt;br /&gt;         &lt;artifactid&gt;java-ee&lt;/artifactid&gt;&lt;br /&gt;         &lt;version&gt;5.0&lt;/version&gt;&lt;br /&gt;         &lt;scope&gt;provided&lt;/scope&gt;&lt;br /&gt;      &lt;/dependency&gt;    &lt;br /&gt;             &lt;/dependencies&gt;&lt;br /&gt;  &lt;br /&gt;      &lt;br /&gt;&lt;/project&gt;&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;hr size="2" width="100%"&gt;Step 4 - Now we must create an ejb-jar.xml file in the directory structur, otherwise maven will not build.&lt;br /&gt;&lt;br /&gt;In the ejb project create this. src/main/resources/META-INF/ejb-jar.xml&lt;p&gt;This file must contain this;&lt;/p&gt;&lt;p&gt;&lt;!--?xml version="1.0"?--&gt;&lt;br /&gt;&lt;ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/javaee&lt;br /&gt; http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" version="3.0" id="ejb-jar_ID"&gt;&lt;br /&gt; &lt;display-name&gt;aja-book-ejb&lt;/display-name&gt;&lt;br /&gt;&lt;/ejb-jar&gt;&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;hr size="2" width="100%"&gt;Step 5 - build&lt;p&gt; &lt;/p&gt;&lt;p&gt;execute mvn clean install&lt;/p&gt;&lt;hr size="2" width="100%"&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;Create data source&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;First step is to add the actual database handling.&lt;/span&gt;  &lt;span style="font-family:Arial;font-size:85%;"&gt;Since we are using ejbs we must use an EJB container to run it, in our&lt;/span&gt; &lt;br /&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;case the Sun Server.&lt;/span&gt; &lt;span style="font-family:Arial;font-size:85%;"&gt;Let's add a data connection. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;How to do it can be found elsewhere but in&lt;/span&gt;  &lt;span style="font-family:Arial;font-size:85%;"&gt;short, in&lt;/span&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt; the App Server, go to &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Resources-&amp;gt;JDBC-&amp;gt;Connection&lt;/span&gt;  &lt;span style="font-family:Arial;font-size:85%;"&gt;Pools;&lt;/span&gt;&lt;/strong&gt;  &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Choose DataSource class name. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;If you work with say mysql or toplink, you must put&lt;/span&gt;  &lt;span style="font-family:Arial;font-size:85%;"&gt;the jar file in the App Servers lib directory. I doesn't matter in&lt;/span&gt; &lt;br /&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;which lib (the AppServers top lib directory, or the domain lib&lt;/span&gt;  &lt;span style="font-family:Arial;font-size:85%;"&gt;directory) . As you probably understand, in the top lib all&lt;/span&gt; &lt;br /&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;applications can share it, in the domain only those classes find it.&lt;/span&gt;  &lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Make sure the connection type is &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;javax.sql.ConnectionPoolDataSource.&lt;/span&gt; &lt;br /&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Make sure to ping the database when you are done. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Ok, add&lt;/span&gt; &lt;br /&gt;&lt;strong&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Resources-&amp;gt;JDBC-&amp;gt;JDBC Resources &lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Add a jndi name to your&lt;/span&gt;  &lt;span style="font-family:Arial;font-size:85%;"&gt;connection pool. I will call my pool &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;strong&gt;jdbc/BookPool&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Now, add a persistence.xml, in the src/main/resources/ folder. My file looks like this;&lt;/span&gt;&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;hr size="2" width="100%"&gt;&lt;!--?xml version="1.0" encoding="UTF-8"?--&gt;&lt;br /&gt;&lt;persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0"&gt;&lt;br /&gt;    &lt;persistence-unit name="BookPU" type="JTA"&gt;&lt;br /&gt;&lt;jta-data-source&gt;jdbc/__default&lt;/jta-data-source&gt;&lt;br /&gt;&lt;properties&gt;&lt;br /&gt;&lt;!-- Options are "create-tables", "drop-and-create-tables" or&lt;br /&gt;"none" --&gt;&lt;br /&gt;&lt;property name="toplink.ddl-generation" value="create-tables"&gt;&lt;br /&gt;        &lt;/property&gt;&lt;/properties&gt;&lt;br /&gt;    &lt;/persistence-unit&gt;&lt;br /&gt;&lt;/persistence&gt;&lt;p&gt; &lt;/p&gt;&lt;hr size="2" width="100%"&gt;&lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Bascially the file contain the name of the Pool which&lt;/span&gt; &lt;br /&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;we deined in the App Server. If everything is ok, they will connect&lt;/span&gt; &lt;br /&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;with each other and live happily ever after. At the moment we leave all&lt;/span&gt; &lt;br /&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;transaction handling and stuff like that to&lt;/span&gt; &lt;br /&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;the wise care of the application server and all default vales. These&lt;/span&gt; &lt;br /&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;values are often sensible and in 99% of the cases you can let them stay&lt;/span&gt; &lt;br /&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;as they are.&lt;/span&gt; &lt;br /&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;      &lt;/span&gt; &lt;br /&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;    &lt;/span&gt;  &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;hr size="2" width="100%"&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;Create java classes&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;The  business objects contain all getter/setters we need and we will create  it in org.book.business. We build a really small application so we will  use the same objects within the whole application, from the database to  the exposed services. We are now only working in the ejb project.&lt;/p&gt;&lt;hr size="2" width="100%"&gt;&lt;p&gt; Step 6- Add Author entity&lt;/p&gt;&lt;p&gt;Add the Author. &lt;/p&gt;&lt;p&gt;package org.aja.book.business;&lt;br /&gt;&lt;br /&gt;import java.io.Serializable;&lt;br /&gt;import java.util.Collection;&lt;br /&gt;&lt;br /&gt;import javax.persistence.Entity;&lt;br /&gt;import javax.persistence.Id;&lt;br /&gt;import javax.persistence.NamedQueries;&lt;br /&gt;import javax.persistence.NamedQuery;&lt;br /&gt;import javax.persistence.OneToMany;&lt;br /&gt;import javax.persistence.Table;&lt;br /&gt;&lt;br /&gt;import static javax.persistence.CascadeType.ALL;&lt;br /&gt;&lt;br /&gt;@Entity&lt;br /&gt;@NamedQueries( {&lt;br /&gt;     @NamedQuery(name = "getAllBooksByAuthor", query = "SELECT A FROM Author  A WHERE A.firstName = :firstName AND A.lastName = :lastName")})&lt;br /&gt;&lt;br /&gt;@Table(name = "AUTHOR")&lt;br /&gt;public class Author implements Serializable {&lt;br /&gt;   &lt;br /&gt;    /**&lt;br /&gt;     *&lt;br /&gt;     */&lt;br /&gt;    private static final long serialVersionUID = 5172793849216643729L;&lt;br /&gt;&lt;br /&gt;    protected Collection&lt;book&gt; books;&lt;br /&gt;   &lt;br /&gt;    @OneToMany(cascade = ALL, mappedBy = "author")&lt;br /&gt;    public Collection&lt;book&gt; getBooks() {&lt;br /&gt;        return books;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void setBooks(Collection&lt;book&gt; books) {&lt;br /&gt;        this.books = books;&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;   private String firstName;&lt;br /&gt;   &lt;br /&gt;    private String lastName;&lt;br /&gt;   &lt;br /&gt;    private String id;&lt;br /&gt;   &lt;br /&gt;    @Id&lt;br /&gt;    public String getId() {&lt;br /&gt;        return id;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void setId(String id) {&lt;br /&gt;        this.id = id;&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;    public String getFirstName() {&lt;br /&gt;        return firstName;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void setFirstName(String firstName) {&lt;br /&gt;        this.firstName = firstName;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public String getLastName() {&lt;br /&gt;        return lastName;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void setLastName(String lastName) {&lt;br /&gt;        this.lastName = lastName;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;/book&gt;&lt;/book&gt;&lt;/book&gt;&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;hr size="2" width="100%"&gt;Step 7 - Add the book entity.&lt;p&gt; &lt;/p&gt;&lt;p&gt;package org.aja.book.business;&lt;br /&gt;import java.io.Serializable;&lt;br /&gt;&lt;br /&gt;import javax.persistence.Entity;&lt;br /&gt;import javax.persistence.Id;&lt;br /&gt;import javax.persistence.ManyToOne;&lt;br /&gt;import javax.persistence.NamedQueries;&lt;br /&gt;import javax.persistence.NamedQuery;&lt;br /&gt;import javax.persistence.Table;&lt;br /&gt;&lt;br /&gt;@Entity&lt;br /&gt;@NamedQueries( {&lt;br /&gt;    @NamedQuery(name = "getAllBooks", query = "SELECT B FROM Book B")})&lt;br /&gt;@Table(name = "BOOK")&lt;br /&gt;public class Book implements Serializable {&lt;br /&gt;   &lt;br /&gt;    /**&lt;br /&gt;     *&lt;br /&gt;     */&lt;br /&gt;    private static final long serialVersionUID = -5901348294266358004L;&lt;br /&gt;&lt;br /&gt;    private Author author;&lt;br /&gt;   &lt;br /&gt;    private String title;&lt;br /&gt;   &lt;br /&gt;    private int pages;&lt;br /&gt;   &lt;br /&gt;    private String id;&lt;br /&gt;   &lt;br /&gt;    @Id&lt;br /&gt;    public String getId() {&lt;br /&gt;        return id;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void setId(String id) {&lt;br /&gt;        this.id = id;&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;    public String getTitle() {&lt;br /&gt;        return title;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void setTitle(String title) {&lt;br /&gt;        this.title = title;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public int getPages() {&lt;br /&gt;        return pages;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void setPages(int pages) {&lt;br /&gt;        this.pages = pages;&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;    @ManyToOne&lt;br /&gt;    public Author getAuthor() {&lt;br /&gt;        return author;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void setAuthor(Author author) {&lt;br /&gt;        this.author = author;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;   &lt;br /&gt;}  &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;hr size="2" width="100%"&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;Step 8 - Add remote interface&lt;/p&gt;&lt;p&gt;package org.aja.book.service;&lt;br /&gt;&lt;br /&gt;import javax.ejb.Remote;&lt;br /&gt;&lt;br /&gt;@Remote&lt;br /&gt;public interface BookServiceRemote extends BookService {&lt;br /&gt;&lt;br /&gt;}&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;hr size="2" width="100%"&gt;Step 9 - Add local interface&lt;p&gt; &lt;/p&gt;&lt;p&gt;package org.aja.book.service;&lt;br /&gt;&lt;br /&gt;import javax.ejb.Local;&lt;br /&gt;@Local&lt;br /&gt;public interface BookServiceLocal extends BookService {&lt;br /&gt;&lt;br /&gt;}&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;hr size="2" width="100%"&gt;Step 10 - Add service interface&lt;p&gt; &lt;/p&gt;&lt;p&gt;package org.aja.book.service;&lt;br /&gt;&lt;br /&gt;import java.util.List;&lt;br /&gt;&lt;br /&gt;import org.aja.book.business.Author;&lt;br /&gt;import org.aja.book.business.Book;&lt;br /&gt;&lt;br /&gt;public interface BookService {&lt;br /&gt;&lt;br /&gt;    public void addBook(Book book);&lt;br /&gt;&lt;br /&gt;    public List&lt;book&gt; getAllBooksByAuthor(Author author);&lt;br /&gt;&lt;br /&gt;    public List&lt;book&gt; getAllBooks();&lt;br /&gt;}&lt;/book&gt;&lt;/book&gt;&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;hr size="2" width="100%"&gt;Step 11 - Add concrete class implementing the service interface&lt;p&gt; &lt;/p&gt;&lt;p&gt; package org.aja.book.service.impl;&lt;br /&gt;&lt;br /&gt;import java.util.List;&lt;br /&gt;&lt;br /&gt;import javax.ejb.Local;&lt;br /&gt;import javax.ejb.Remote;&lt;br /&gt;import javax.ejb.Stateless;&lt;br /&gt;import javax.persistence.EntityManager;&lt;br /&gt;import javax.persistence.PersistenceContext;&lt;br /&gt;import javax.persistence.Query;&lt;br /&gt;&lt;br /&gt;import org.aja.book.business.Author;&lt;br /&gt;import org.aja.book.business.Book;&lt;br /&gt;import org.aja.book.service.BookService;&lt;br /&gt;import org.aja.book.service.BookServiceLocal;&lt;br /&gt;import org.aja.book.service.BookServiceRemote;&lt;br /&gt;&lt;br /&gt;@Stateless(mappedName = "aja/BookService")&lt;br /&gt;@Local(BookServiceLocal.class)&lt;br /&gt;@Remote(BookServiceRemote.class)&lt;br /&gt;public class BookServiceImpl implements BookService {&lt;br /&gt;   &lt;br /&gt;   &lt;br /&gt;    @PersistenceContext&lt;br /&gt;    EntityManager em;&lt;br /&gt;&lt;br /&gt;    public void addBook(Book book) {&lt;br /&gt;        em.persist(book);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    @SuppressWarnings("unchecked")&lt;br /&gt;    public List&lt;book&gt; getAllBooksByAuthor(Author author) {&lt;br /&gt;       &lt;br /&gt;        Query q = em.createNamedQuery("getAllBooksByAuthor");&lt;br /&gt;        q.setParameter("firstName", author.getFirstName());&lt;br /&gt;        q.setParameter("lastName", author.getLastName());&lt;br /&gt;        return q.getResultList();&lt;/book&gt;&lt;/p&gt;&lt;p&gt;            }&lt;br /&gt;   &lt;br /&gt;    @SuppressWarnings("unchecked")&lt;br /&gt;    public List&lt;book&gt; getAllBooks() {&lt;br /&gt;      Query q = em.createNamedQuery("getAllBooks");&lt;br /&gt;        return q.getResultList();&lt;/book&gt;&lt;/p&gt;&lt;p&gt;           }&lt;br /&gt;&lt;br /&gt;}&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-1467176274435457165?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/1467176274435457165/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/12/jpa.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/1467176274435457165'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/1467176274435457165'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/12/jpa.html' title='JPA'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-8958117882670446016</id><published>2011-12-14T00:55:00.003-08:00</published><updated>2011-12-14T00:55:42.677-08:00</updated><title type='text'>Constructor exception</title><content type='html'>&lt;p&gt;Is it possible to create a class which throws an Exception in the constructor. Yes.&lt;/p&gt;&lt;p&gt;The following shows one example.&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;hr size="2" width="100%"&gt;public class Foo {&lt;p&gt; &lt;/p&gt;&lt;p&gt;    public Foo() {&lt;/p&gt;&lt;p&gt;        throw new RuntimeException();&lt;/p&gt;&lt;p&gt;    }&lt;/p&gt;&lt;p&gt;    public void calculate() { &lt;/p&gt;&lt;p&gt;        System.out.println("I am now calculating");&lt;/p&gt;&lt;p&gt;    }&lt;/p&gt;&lt;p&gt;} &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;hr size="2" width="100%"&gt;The  class above will always throw a run time exception whenever someone  tries to instantiate it. Is there a way round it and call the calculate  method? Yes there is. The class below actually succeeds. The solution is  that Foo is not a final class. I will sub-class it and operate on that  instance.&lt;p&gt; &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;public class Bar extends Foo {&lt;/p&gt;&lt;p&gt;    public static Foo foo;&lt;/p&gt;&lt;p&gt;    @Override&lt;/p&gt;&lt;p&gt;    protected void finalize() throws Throwable {&lt;/p&gt;&lt;p&gt;        foo = this; &lt;/p&gt;&lt;p&gt;    } &lt;/p&gt;&lt;p&gt;} &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;hr size="2" width="100%"&gt;Create a runner which will do the job.&lt;p&gt; &lt;/p&gt;&lt;p&gt;public class Runner {&lt;/p&gt;&lt;p&gt;    public static void main(String...args) {&lt;/p&gt;&lt;p&gt;        try { &lt;/p&gt;&lt;p&gt;            Foo foo = new Bar(); &lt;/p&gt;&lt;p&gt;        } catch (Exception e) {&lt;/p&gt;&lt;p&gt;            System.out.println("Just to show exception caught "  + e.getMessage()); &lt;/p&gt;&lt;p&gt;        } &lt;/p&gt;&lt;p&gt;        System.gc(); &lt;/p&gt;&lt;p&gt;        System.runFinalization(); &lt;/p&gt;&lt;p&gt;        System.out.println("My instance " + Bar.foo);&lt;/p&gt;&lt;p&gt;        Bar.foo.caluclate());    &lt;/p&gt;&lt;p&gt;    } &lt;/p&gt;&lt;p&gt;} &lt;/p&gt;&lt;hr size="2" width="100%"&gt;This  example shows that you should always use the final word when you do not  want people to be able to create incomplete instances.&lt;br /&gt;&lt;p&gt; &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-8958117882670446016?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/8958117882670446016/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/12/constructor-exception.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/8958117882670446016'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/8958117882670446016'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/12/constructor-exception.html' title='Constructor exception'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-1379136759961658863</id><published>2011-12-14T00:55:00.001-08:00</published><updated>2011-12-14T00:55:19.100-08:00</updated><title type='text'>LifeCycleManagement + JMX</title><content type='html'>&lt;p&gt;Sometimes you might want to make sure that when an enterprise  application is started, something is executed. This example shows how to  do it on a Sun Application Server. &lt;/p&gt;&lt;p&gt;In real life, this example was built with &lt;a href="http://maven.apache.org/"&gt;Maven&lt;/a&gt;  which you will have to configure by yourself if you haven't done it  already. But it is only snippets below in the example so no pom.xml  files are included. It is not of interest how you build it.&lt;/p&gt;&lt;p&gt;First  you must create a web application which is bundled into the ear file.  This web application shall contain a web.xml file in the WEB-INF  directory. Make sure to include the content below in the file;&lt;/p&gt;&lt;p&gt;************************************************** &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;&lt;!--?xml version="1.0" encoding="UTF-8"?--&gt;&lt;br /&gt;&lt;web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xsi="http://www.w3.org/2001/XMLSchema-instance" schemalocation="http://java.sun.com/xml/ns/j2ee  http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"&gt;&lt;br /&gt;  &lt;listener&gt;&lt;br /&gt;    &lt;listener-class&gt;org.aja.book.webapp.listener.LifeCycleManager&lt;/listener-class&gt;&lt;br /&gt;  &lt;/listener&gt;&lt;br /&gt;&lt;/web-app&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;*************************************************************** &lt;/p&gt;&lt;p&gt;In  fact, this is the only rows needed in the file. This is our Listener  servlet. This will ensure that the application handles this start up in a  correct fashion.&lt;/p&gt;&lt;p&gt;Now, create a class, name it LifeCycleManager and make sure it implements the ServletContextListener.&lt;/p&gt;&lt;p&gt;********************************************************* &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;package org.aja.book.webapp.listener;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;import javax.servlet.ServletContextListener;&lt;br /&gt;&lt;br /&gt;public class LifeCycleManager implements ServletContextListener {&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:comic sans ms,sans-serif;"&gt;public void contextDestroyed(ServletContextEvent arg0) {&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:comic sans ms,sans-serif;"&gt;} &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;public void contextInitialized(ServletContextEvent arg0) {&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;} &lt;/span&gt;&lt;/p&gt;&lt;p&gt;********************************************************&lt;/p&gt;&lt;p&gt;As you can see two methods needs to be implemented. Now try it. Write a simple System.out and see that it is written out.&lt;/p&gt;&lt;p&gt;You are now done. This shows how you can do it if you need to implement a Listener class.&lt;/p&gt;&lt;p&gt;Step 2&lt;/p&gt;&lt;p&gt;What  shall you use this for? Ok, assume you want to have a JMX bean in the  application server which you shall access to do stuff. For instance,  assume you want to change the log level in run time, you could do this   by implementing a JMX bean. Let's do it.&lt;/p&gt;&lt;p&gt;***************************************&lt;/p&gt;&lt;p&gt;You would probably implement a helper class doing all this, but instead I just stash it into the servlet.&lt;/p&gt;&lt;p&gt;In the contextInitialized method do this;&lt;/p&gt;&lt;p&gt;*****************************&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;           Context ic = new InitialContext();&lt;br /&gt;&lt;br /&gt;            MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();&lt;br /&gt;            ObjectName name = new ObjectName(&lt;br /&gt;                    "&lt;strong&gt;aja:ear=,jar=aja-startup-ejb-0.1.jar&lt;/strong&gt;," +&lt;br /&gt;                            "name=BootStrapImpl,service=EJB3");&lt;br /&gt;&lt;br /&gt;            BootStrap o = (BootStrap) ic.lookup("&lt;strong&gt;aja/BootStrap&lt;/strong&gt;");&lt;br /&gt;            BootStrap mbean = (BootStrap) PortableRemoteObject.narrow(o,&lt;br /&gt;                    BootStrap.class);&lt;br /&gt;&lt;br /&gt;            BootStrap mb = new BootStrapImpl();&lt;br /&gt;            mbs.registerMBean(mb, name);&lt;br /&gt;&lt;br /&gt;            mbean.start();&lt;/span&gt;&lt;/p&gt;&lt;p&gt;**********************&lt;/p&gt;&lt;p&gt; In the contextDestroyed method do this;&lt;/p&gt;&lt;p&gt;************************************************ &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt; Context ic = new InitialContext();&lt;br /&gt;&lt;br /&gt;            MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();&lt;br /&gt;            ObjectName name = new ObjectName(&lt;br /&gt;                    "&lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;&lt;strong&gt;aja:ear=,jar=aja-startup-ejb-0.1.jar&lt;/strong&gt;," +&lt;br /&gt;                            "name=BootStrapImpl,service=EJB3");&lt;br /&gt;&lt;br /&gt;            BootStrap o = (BootStrap) ic.lookup(&lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;&lt;strong&gt;aja/BootStrap&lt;/strong&gt;);&lt;br /&gt;            BootStrap mbean = (BootStrap) PortableRemoteObject.narrow(o,&lt;br /&gt;                    BootStrap.class);&lt;br /&gt;&lt;br /&gt;            mbs.unregisterMBean(name);&lt;br /&gt;            mbean.destroy();&lt;/span&gt;&lt;/p&gt;&lt;p&gt; ********************************************&lt;/p&gt;&lt;p&gt;This  will call our "BootStrap" ejb which initializes some things through the  start method(). Also you can add another method called  changeLogLevel(int level). Make sure that the names in bold corresponds  to your beans name. You can see that in the JMX console if you are  unsure.&lt;/p&gt;&lt;p&gt;Thus now you must create three different things;&lt;/p&gt;&lt;p&gt;1) One interface called BootStrap &lt;/p&gt;&lt;p&gt;2) One ejb class called BootStrapImpl&lt;/p&gt;&lt;p&gt;3) One interface extending the BootStrap interface called BootStrapImplMBean&lt;/p&gt;&lt;p&gt;Note  here one important thing. It was a bug in the implementation which  forced you to create the MBean interface with the same name as the bean  with the suffix MBean. Worthless huh! And, you had to have it in the  same package as the Bean class as well.&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;Besides that everything is pretty straighforward;&lt;/p&gt;&lt;p&gt;**************&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;package org.aja.book.boot;&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;public interface &lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;BootStrap{&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;void start();&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;void destroy();&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;void changeLogLevel(int level);&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;package org.aja.book.boot.impl;&lt;br /&gt;&lt;/span&gt; &lt;/p&gt; &lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;public interface &lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;BootStrapImplMBean extends &lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;BootStrap &lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;p&gt;*******************************&lt;/p&gt;&lt;p&gt;Add the BootImpl ejb. Note the completely erroneous use of System.out, should never be used it is just to exemplify here.&lt;/p&gt;&lt;p&gt;*******************************&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;package org.aja.book.boot.impl;  &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;@EJB&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;public class BootStrapImpl implements BootStrapImplMBean {&lt;/span&gt;&lt;/p&gt;&lt;p&gt; &lt;span style="font-family:courier new,courier;"&gt;public &lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;void start(){&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;   System.out.println("You are now starting");&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt; }&lt;/span&gt;&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt; &lt;span style="font-family:courier new,courier;"&gt;public &lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;void destroy(){&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;   System.out.println("You are now destroying"); &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt; &lt;span style="font-family:courier new,courier;"&gt;public &lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;void &lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;changeLogLevel&lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;(int logLevel){&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;   System.out.println("You are now trying to change the log level"); &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;} &lt;/span&gt;&lt;/p&gt;&lt;p&gt;******************************* &lt;/p&gt;&lt;p&gt;That's it. What happened now was 2 things. &lt;/p&gt;&lt;p&gt;Number  one is that your ejb is wrapped as an JMX bean and it has been  instantiated and used by the start method. Number 2 is that you through  the JMX console you  can call the changeLogLevel anytime and change the  log level. &lt;/p&gt;&lt;p&gt;The JMX part and the initializtion part has nothing to  do with each other, they are just commonly used together that's why I  showed them both here.&lt;/p&gt;&lt;p&gt;Good luck. &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-1379136759961658863?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/1379136759961658863/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/12/lifecyclemanagement-jmx.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/1379136759961658863'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/1379136759961658863'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/12/lifecyclemanagement-jmx.html' title='LifeCycleManagement + JMX'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-255771356429594090</id><published>2011-12-14T00:54:00.003-08:00</published><updated>2011-12-14T00:54:59.371-08:00</updated><title type='text'>JAAS and Sun Application Server</title><content type='html'>&lt;p&gt;Aha, you to Brutus.&lt;/p&gt;&lt;p&gt;Security, one of the most interesting  topics as well as most mythological as well. People tend to get  hysterical when it comes to security, especially managers. There are  several different ways to do it. In the good old days I remember hwo we  made our own cookies and checked for users in files and databases  without no standard whatsoever. Now I tend to use JAAS. Here is a small  How to implement JAAS.&lt;/p&gt;&lt;p&gt;Everything below is made towards a solution on a Sun Application Server , for JBoss you must pick another how to somewhere else.&lt;/p&gt;&lt;h2 class="caption"&gt;Step 1 - Create a authentication realm&lt;/h2&gt;&lt;table style="background-color: #ccc933" height="35" border="0" width="473"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;span style="font-family:courier new,courier;"&gt;asadmin  create-auth-realm --classname  com.sun.enterprise.security.auth.realm.file.FileRealm --property  jaas-context=fileRealm:file=aja_keyfile aja_realm&lt;/span&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;h2 class="caption"&gt;Step 2 - Create  a user to store in the realm&lt;/h2&gt;&lt;table style="background-color: #ccc933" height="22" border="0" width="472"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;span style="font-family:courier new,courier;"&gt;asadmin create-file-user --authrealmname aja_realm --groups aja_admins jonas  &lt;/span&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt; You will be promted for a password twice. This will create a new user, "jonas". &lt;/p&gt;&lt;h2 class="caption"&gt;Step 3 - List the users in the realm&lt;/h2&gt;&lt;p&gt; &lt;/p&gt;&lt;table style="background-color: #ccc933" height="19" border="0" width="471"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;span style="font-family:courier new,courier;"&gt;asadmin list-file-users --authrealmname aja_realm&lt;/span&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;h2 class="caption"&gt;Step 4 - Delete a user in the realm&lt;/h2&gt;&lt;table style="background-color: #ccc933" height="18" border="0" width="470"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;span style="font-family:courier new,courier;"&gt;asadmin delete-file-user --authrealmname aja_realm &lt;user name=""&gt;&lt;/user&gt;&lt;/span&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;List and delete are really not needed here but can be shown out of interest.&lt;/p&gt;&lt;p&gt;Take a break, you now have a realm and a user.&lt;/p&gt;&lt;h2&gt;&lt;span class="caption"&gt;Step 5 - Create a proper sun-web.xml file&lt;/span&gt;&lt;br /&gt;&lt;/h2&gt;&lt;p&gt; I  want include any files since they are so small, but you do like this.  Add (if you do not have it already) a sun-web.xml file into the WEB-INF  directory of youweb application.&lt;/p&gt;&lt;p&gt;This shall be included&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;&lt;!--?xml version="1.0" encoding="UTF-8"?--&gt;&lt;br /&gt;&lt;br /&gt;&lt;sun-web-app url=""&gt;&lt;br /&gt;  &lt;context-root&gt;/aja&lt;/context-root&gt;&lt;br /&gt;  &lt;class-loader delegate="true"&gt;&lt;br /&gt;  &lt;security-role-mapping&gt;&lt;br /&gt;    &lt;role-name&gt;aja_admins&lt;/role-name&gt;&lt;br /&gt;    &lt;group-name&gt;aja_admins&lt;/group-name&gt;&lt;br /&gt;  &lt;/security-role-mapping&gt;&lt;br /&gt;  &lt;class-loader delegate="true"&gt;&lt;br /&gt;  &lt;jsp-config&gt;&lt;br /&gt;    &lt;property name="keepgenerated" value="true"&gt;&lt;br /&gt;      &lt;description&gt;Keep a copy of the generated servlet class' java code.&lt;/description&gt;&lt;br /&gt;    &lt;/property&gt;&lt;br /&gt;  &lt;/jsp-config&gt;&lt;br /&gt;&lt;/class-loader&gt;&lt;/class-loader&gt;&lt;/sun-web-app&gt;&lt;/span&gt;&lt;/p&gt;&lt;h2 class="caption"&gt;Step 6 - Create a proper web.xml file &lt;/h2&gt;&lt;p&gt;Include this anywhere in the file;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;&lt;security-constraint&gt;&lt;br /&gt;        &lt;web-resource-collection&gt;&lt;br /&gt;            &lt;web-resource-name&gt;restricted&lt;/web-resource-name&gt;&lt;br /&gt;            &lt;url-pattern&gt;/*&lt;/url-pattern&gt;&lt;br /&gt;        &lt;/web-resource-collection&gt;&lt;br /&gt;        &lt;auth-constraint&gt;&lt;br /&gt;            &lt;role-name&gt;aja_admins&lt;/role-name&gt;&lt;br /&gt;           &lt;/auth-constraint&gt;&lt;br /&gt;    &lt;/security-constraint&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;&lt;security-constraint&gt;&lt;br /&gt;        &lt;web-resource-collection&gt;&lt;br /&gt;            &lt;web-resource-name&gt;&lt;br /&gt;                unrestricted stylesheets&lt;br /&gt;            &lt;/web-resource-name&gt;&lt;br /&gt;            &lt;url-pattern&gt;/css/*&lt;/url-pattern&gt;&lt;br /&gt;            &lt;http-method&gt;GET&lt;/http-method&gt;&lt;br /&gt;        &lt;/web-resource-collection&gt;&lt;br /&gt;    &lt;/security-constraint&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt; and&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;&lt;login-config&gt;&lt;br /&gt;        &lt;auth-method&gt;FORM&lt;/auth-method&gt;&lt;br /&gt;        &lt;realm-name&gt;aja_realm&lt;/realm-name&gt;&lt;br /&gt;        &lt;form-login-config&gt;&lt;br /&gt;            &lt;form-login-page&gt;/login/login.html&lt;/form-login-page&gt;&lt;br /&gt;            &lt;form-error-page&gt;&lt;br /&gt;                &lt;/form-error-page&gt;&lt;/form-login-config&gt;&lt;/login-config&gt;&lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;/login&lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;/loginerror.html&lt;br /&gt;            &lt;br /&gt;        &lt;br /&gt;    &lt;br /&gt;&lt;br /&gt;    &lt;security-role&gt;&lt;br /&gt;        &lt;role-name&gt;aja_admins&lt;/role-name&gt;&lt;br /&gt;    &lt;/security-role&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;&lt;welcome-file-list&gt;&lt;br /&gt;        &lt;welcome-file&gt;one.html&lt;/welcome-file&gt;&lt;br /&gt;    &lt;/welcome-file-list&gt;&lt;/span&gt; &lt;/p&gt;&lt;h2 class="caption"&gt;Step 7 - Create a login page&lt;br /&gt;&lt;/h2&gt; &lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;form action="j_security_check" method="post"&gt;&lt;span style="font-family:courier new,courier;"&gt;&lt;br /&gt;                        &lt;table id="logintable"&gt;&lt;br /&gt;                             &lt;tbody&gt;&lt;tr&gt;&lt;td&gt;User Name:&lt;/td&gt;&lt;td&gt;&lt;input name="j_username" type="text"&gt;&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;                             &lt;tr&gt;&lt;td&gt;Password :&lt;/td&gt;&lt;td&gt;&lt;input name="j_password" type="password"&gt;&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;                            &lt;tr&gt;&lt;td&gt; &lt;/td&gt;&lt;td align="right"&gt;&lt;br /&gt;                            &lt;input class="submitbutton" value="Login" type="submit"&gt;&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;                        &lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;                    &lt;/span&gt;&lt;/form&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;That's it. You are done now.&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;h2 class="caption"&gt;Step 8 - A note of caution&lt;/h2&gt;&lt;p&gt;Please note this fundamentally important thing. If you do have a link to a style sheet in the login page, like &lt;/p&gt;&lt;p&gt;&lt;link href="/oldsite/../css/login.css" p=""&gt;&lt;/p&gt;&lt;p&gt;you  MUST make sure that that directory is unprotected with an unristricted  code block, like the one above. Otherwise you will be re-routed to the  style sheet and not to your start page. &lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-255771356429594090?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/255771356429594090/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/12/jaas-and-sun-application-server.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/255771356429594090'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/255771356429594090'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/12/jaas-and-sun-application-server.html' title='JAAS and Sun Application Server'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-1561728386915056517</id><published>2011-12-14T00:54:00.001-08:00</published><updated>2011-12-14T00:54:36.702-08:00</updated><title type='text'>JBoss and Basic Authentication</title><content type='html'>&lt;p&gt;This is a short how to enable basic auth on a JBoss server and a small test client.&lt;/p&gt;&lt;p&gt;This example is run on Java5, Ubuntu Edgy Eft and JBoss 4.5. It assumes you are working with a web application.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Step 1 Add a jboss-web.xml file to your webapps WEB-INF directory.&lt;/strong&gt;&lt;br /&gt;Add the following content&lt;br /&gt;&lt;br /&gt;&amp;lt; jboss&amp;gt; &lt;br /&gt;   &amp;lt; jboss-web&amp;gt;&lt;br /&gt;   &amp;lt; security-domain&amp;gt;java:/jaas/myapplication &lt;br /&gt;   &amp;lt; /security-domain&amp;gt;&lt;br /&gt;   &amp;lt; /jboss-web&amp;gt;&lt;br /&gt;   &amp;lt; /jboss&amp;gt;&lt;br /&gt;&lt;br /&gt;Change your web.xml file and add the following rows.&lt;br /&gt;    &amp;lt; security-constraint&amp;gt;&lt;br /&gt;        &amp;lt; web-resource-collection&amp;gt;&lt;br /&gt;    &amp;lt; web-resource-name&amp;gt;UserResources&lt;br /&gt;    &amp;lt; description&amp;gt;&lt;br /&gt;    /services/*&lt;br /&gt;    &lt;br /&gt;        &amp;lt; auth-constraint&amp;gt;&lt;br /&gt;        &amp;lt; role-name&amp;gt;user&lt;br /&gt;        &lt;br /&gt;        &lt;br /&gt;        &amp;lt; security-role&amp;gt; &lt;br /&gt;        &amp;lt; role-name&amp;gt;user&lt;br /&gt;    &lt;br /&gt;    &amp;lt; security-role&amp;gt;&lt;br /&gt;    &amp;lt; role-name&amp;gt;operator&lt;br /&gt;    &lt;br /&gt;    &amp;lt; security-role&amp;gt;&lt;br /&gt;    &amp;lt; role-name&amp;gt;admin&lt;br /&gt;     &lt;br /&gt;&lt;br /&gt;    &amp;lt; login-config&amp;gt;&lt;br /&gt;    &amp;lt; auth-method&amp;gt;BASIC&lt;br /&gt;    &amp;lt; realm-name&amp;gt;MyApplicationRealm&lt;br /&gt;    &lt;br /&gt;&lt;br /&gt;Change some files on your JBoss application server files.&lt;br /&gt;Change the file login-config.xml in the conf directory.&lt;br /&gt;&amp;lt; application-policy name="myapplication"&amp;gt;&lt;br /&gt;       &amp;lt; authentication&amp;gt;&lt;br /&gt;          &amp;lt; login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule"&lt;br /&gt;             flag = "required"&amp;gt;&lt;br /&gt;           &amp;lt; module-option name="usersProperties"&amp;gt;props/rk-users.properties&lt;br /&gt;           &amp;lt; module-option name="rolesProperties"&amp;gt;props/rk-roles.properties&lt;br /&gt;          &lt;br /&gt;       &lt;br /&gt;    &lt;br /&gt;&lt;br /&gt;Create two new files in the conf/props.&lt;br /&gt;&lt;br /&gt;One file with the users called rk-users.properties&lt;br /&gt;&lt;br /&gt;Add the following user&lt;br /&gt;&lt;br /&gt;admin=adminpwd&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;One file with the roles called rk-roles.properties&lt;br /&gt;&lt;br /&gt;Add the following roles&lt;br /&gt;&lt;br /&gt;admin=sysadmin,user&lt;br /&gt;&lt;br /&gt;I made a xfire client calling my xfire web services. see xfire codehaus for an examle on a web client.&lt;/p&gt;&lt;p&gt;Then add these lines of code&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;org.codehaus.xfire.client.Client client = org.codehaus.xfire.client.Client.getInstance(service);&lt;/p&gt;&lt;p&gt;client.setProperty(Channel.USERNAME, "admin");&lt;/p&gt;&lt;p&gt;client.setProperty(Channel.PASSWORD, "adminpwd"); &lt;/p&gt;       &lt;span class="article_separator"&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-1561728386915056517?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/1561728386915056517/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/12/jboss-and-basic-authentication.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/1561728386915056517'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/1561728386915056517'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/12/jboss-and-basic-authentication.html' title='JBoss and Basic Authentication'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-5771765048283485664</id><published>2011-12-14T00:53:00.000-08:00</published><updated>2011-12-14T00:54:00.915-08:00</updated><title type='text'>Ws security and Jax WS</title><content type='html'>&lt;p&gt;I had some annoying problems with the WS security examples found on  the net. I had an application which simply refused to pass along the  header data as they should. I followed every tutorial available and did  like this;&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;table border="0"&gt;&lt;tbody&gt;&lt;tr style="background-color: #f0e68c"&gt;&lt;td&gt;&lt;span&gt;bp.getRequestContext().put(javax.xml.&lt;strong class="highlight"&gt;ws&lt;/strong&gt;.&lt;strong class="highlight"&gt;BindingProvider&lt;/strong&gt;.&lt;strong class="highlight"&gt;USERNAME_PROPERTY&lt;/strong&gt;, "admin");&lt;/span&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style="background-color: #f0e68c"&gt;&lt;td&gt;&lt;span&gt;bp.getRequestContext().put(javax.xml.&lt;strong class="highlight"&gt;ws&lt;/strong&gt;.&lt;strong class="highlight"&gt;BindingProvider&lt;/strong&gt;.&lt;strong class="highlight"&gt;PASSWORD_PROPERTY&lt;/strong&gt;,"adminpwd")&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;So  I had to make the header of the request myself. This is how I did it.  As always, even though it doesn't matter I made it in Eclipse building  it in Maven. &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;table border="0"&gt;&lt;tbody&gt;&lt;tr style="background-color: #f0e68c"&gt;&lt;td&gt;Server files&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;On the server side a made on class, call it Service.&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;@WebService&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;@HandlerChain(file="MyChain.xml")&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;public class Service {&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;@WebMethod&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;public String getName(){&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;return "King Kong";&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;} &lt;/span&gt;&lt;/p&gt;&lt;p&gt;Note  that the file path is relative so for simplicity I just put the file  (MyChain.xml) in the same directory as this file, i.e. in the source  package.&lt;/p&gt;&lt;p&gt;Thexml file just contain a pointer towards a handler.&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;&lt;!--?xml version="1.0" encoding="UTF-8"?--&gt;&lt;br /&gt;&lt;br /&gt;&lt;jws:handler-chains jws="http://java.sun.com/xml/ns/javaee"&gt;&lt;br /&gt;&lt;br /&gt;    &lt;jws:handler-chain name="MyHandlerChain"&gt;&lt;br /&gt;&lt;br /&gt;          &lt;jws:handler&gt;&lt;br /&gt;            &lt;jws:handler-class&gt;com.aja.util.MySOAPHandler&lt;/jws:handler-class&gt;&lt;br /&gt;        &lt;/jws:handler&gt;&lt;br /&gt;&lt;br /&gt;        &lt;/jws:handler-chain&gt;&lt;br /&gt;&lt;br /&gt;&lt;/jws:handler-chains&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;Now we only lack the handler class.&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;***************************************************** &lt;/p&gt;&lt;p&gt;package &lt;span style="font-family:courier new,courier;"&gt;com.aja.util&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt;&lt;br /&gt;import java.io.PrintStream;&lt;br /&gt;import java.util.Map;&lt;br /&gt;import java.util.Set;&lt;br /&gt;&lt;br /&gt;import javax.xml.namespace.QName;&lt;br /&gt;import javax.xml.soap.SOAPMessage;&lt;br /&gt;import javax.xml.ws.handler.MessageContext;&lt;br /&gt;import javax.xml.ws.handler.soap.SOAPHandler;&lt;br /&gt;import javax.xml.ws.handler.soap.SOAPMessageContext;&lt;br /&gt;&lt;br /&gt;import java.io.PrintStream;&lt;br /&gt;import java.util.Iterator;&lt;br /&gt;import java.util.Map;&lt;br /&gt;import java.util.Set;&lt;br /&gt;&lt;br /&gt;import javax.annotation.PostConstruct;&lt;br /&gt;import javax.annotation.PreDestroy;&lt;br /&gt;import javax.xml.soap.SOAPEnvelope;&lt;br /&gt;import javax.xml.soap.SOAPHeader;&lt;br /&gt;import javax.xml.soap.SOAPMessage;&lt;br /&gt;import javax.xml.soap.SOAPPart;&lt;br /&gt;import javax.xml.ws.handler.Handler;&lt;br /&gt;import javax.xml.ws.handler.MessageContext;&lt;br /&gt;import javax.xml.ws.handler.soap.SOAPMessageContext;&lt;br /&gt;&lt;br /&gt;import org.w3c.dom.Element;&lt;br /&gt;import org.w3c.dom.Node;&lt;br /&gt;import org.w3c.dom.NodeList;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public class MySOAPHandler implements SOAPHandler&lt;soapmessagecontext&gt;&lt;br /&gt;{&lt;br /&gt;   private static final String WS_SEC = "wsse:Security";&lt;br /&gt;  private static final String WSSE_USERNAME = "wsse:Username";&lt;br /&gt;   private static final String WSSE_PASSWORD = "wsse:Password";&lt;br /&gt;&lt;br /&gt;   protected PrintStream out = System.out;&lt;br /&gt;&lt;br /&gt;   protected String HandlerName = "Handler";&lt;br /&gt;&lt;br /&gt;   @PostConstruct&lt;br /&gt;   public void init()&lt;br /&gt;   {&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   @PreDestroy&lt;br /&gt;   public void destroy()&lt;br /&gt;   {&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   /**&lt;br /&gt;    * {@inheritDoc}&lt;br /&gt;    */&lt;br /&gt;   public void close(@SuppressWarnings("unused")&lt;br /&gt;   MessageContext context)&lt;br /&gt;   {&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   /**&lt;br /&gt;    * {@inheritDoc}&lt;br /&gt;    */&lt;br /&gt;   @SuppressWarnings("unchecked")&lt;br /&gt;   public boolean handleMessage(SOAPMessageContext messagecontext)&lt;br /&gt;   {&lt;br /&gt;&lt;br /&gt;      try&lt;br /&gt;      {&lt;br /&gt;         SOAPMessage message = messagecontext.getMessage();&lt;br /&gt;         SOAPPart part = message.getSOAPPart();&lt;br /&gt;         SOAPEnvelope envelope = part.getEnvelope();&lt;br /&gt;         SOAPHeader header = envelope.getHeader();&lt;br /&gt;         String username;&lt;br /&gt;         String password;&lt;br /&gt;&lt;br /&gt;         Element sec = null;&lt;br /&gt;&lt;br /&gt;         for (Iterator&lt;element&gt; k = header.getChildElements(); k.hasNext();)&lt;br /&gt;         {&lt;br /&gt;            Element element = k.next();&lt;br /&gt;            if (element.getNodeName().equals(WS_SEC))&lt;br /&gt;            {&lt;br /&gt;               sec = element;&lt;br /&gt;&lt;br /&gt;               NodeList e = sec.getElementsByTagName(WSSE_USERNAME);&lt;br /&gt;&lt;br /&gt;               Node tok = e.item(0);&lt;br /&gt;&lt;br /&gt;               NodeList child = tok.getChildNodes();&lt;br /&gt;               if (child != null)&lt;br /&gt;               {&lt;br /&gt;                  username = child.item(0).getNodeValue();&lt;br /&gt;                  if (!(username.equals("admin")))&lt;br /&gt;                  {&lt;br /&gt;                     return false;&lt;br /&gt;                  }&lt;br /&gt;               }&lt;br /&gt;&lt;br /&gt;               NodeList f = sec.getElementsByTagName(WSSE_PASSWORD);&lt;br /&gt;&lt;br /&gt;               Node t = f.item(0);&lt;br /&gt;               NodeList c = t.getChildNodes();&lt;br /&gt;               if (c != null)&lt;br /&gt;               {&lt;br /&gt;                  password = c.item(0).getNodeValue();&lt;br /&gt;                  if (!(password.equals("adminpwd")))&lt;br /&gt;                  {&lt;br /&gt;                     return false;&lt;br /&gt;                  }&lt;br /&gt;               }&lt;br /&gt;&lt;br /&gt;            }&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt;      }&lt;br /&gt;      catch (Exception e)&lt;br /&gt;      {&lt;br /&gt;              return false;&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;      return true;&lt;br /&gt;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   /**&lt;br /&gt;    * Subclassing children of this method will determine if to process the&lt;br /&gt;    * request.&lt;br /&gt;    *&lt;br /&gt;    * @return True if we are to continue with authentication, false otherwise.&lt;br /&gt;    */&lt;br /&gt;   protected boolean doAuthentication()&lt;br /&gt;   {&lt;br /&gt;      return true;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   /**&lt;br /&gt;    * When the userid and password is extracted from the request it will call&lt;br /&gt;    * this method and return the value returned by this method.&lt;br /&gt;    *&lt;br /&gt;    * @param userName&lt;br /&gt;    *              The username extracted from the request.&lt;br /&gt;    * @param password&lt;br /&gt;    *              The password extracted from the request.&lt;br /&gt;    * @return See method description on this method.&lt;br /&gt;    */&lt;br /&gt;   protected boolean isValidAuthentication(String userName, String password)&lt;br /&gt;   {&lt;br /&gt;      return true;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   /**&lt;br /&gt;    * {@inheritDoc}&lt;br /&gt;    */&lt;br /&gt;   public Set&lt;qname&gt; getHeaders()&lt;br /&gt;   {&lt;br /&gt;      // TODO Auto-generated method stub&lt;br /&gt;      return null;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   /**&lt;br /&gt;    * {@inheritDoc}&lt;br /&gt;    */&lt;br /&gt;   public boolean handleFault(SOAPMessageContext arg0)&lt;br /&gt;   {&lt;br /&gt;      // TODO Auto-generated method stub&lt;br /&gt;      return false;&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;***************************************************&lt;/qname&gt;&lt;/element&gt;&lt;/soapmessagecontext&gt;&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;This method can be tested by SOAP UI by sending this request, try to change the pwd and you will be rejected.&lt;/p&gt;&lt;p&gt;***************************************************** &lt;/p&gt;&lt;p&gt;&lt;soapenv:envelope soapenv="http://schemas.xmlsoap.org/soap/envelope/" ser="http://service.aja.com/"&gt;&lt;br /&gt;   &lt;soapenv:header&gt;&lt;br /&gt;&lt;wsse:security mustunderstand="0" wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"&gt;&lt;br /&gt;            &lt;wsse:usernametoken id="token-1-1205175076833-11112467"&gt;&lt;br /&gt;                &lt;wsse:username&gt;admin&lt;/wsse:username&gt;&lt;br /&gt;                &lt;wsse:password&gt;adminpwd&lt;/wsse:password&gt;&lt;br /&gt;            &lt;/wsse:usernametoken&gt;&lt;br /&gt;        &lt;/wsse:security&gt;&lt;br /&gt;&lt;/soapenv:header&gt;&lt;br /&gt;   &lt;soapenv:body&gt;&lt;br /&gt;      &lt;ser:getname&gt;&lt;br /&gt;   &lt;/ser:getname&gt;&lt;/soapenv:body&gt;&lt;br /&gt;&lt;/soapenv:envelope&gt; &lt;/p&gt;&lt;p&gt;******************************************************** &lt;/p&gt;&lt;table border="0"&gt;&lt;tbody&gt;&lt;tr style="background-color: #f0e68c"&gt;&lt;td&gt;Client files&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;Make a similar handler file, I don't use the same sice the client is  separate from the server. Call it ClientHandler.xml&lt;/p&gt;&lt;p&gt; ****************&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;&lt;!--?xml version="1.0" encoding="UTF-8"?--&gt;&lt;br /&gt;&lt;br /&gt;&lt;jws:handler-chains jws="http://java.sun.com/xml/ns/javaee"&gt;&lt;br /&gt;&lt;br /&gt;    &lt;jws:handler-chain name="MyHandlerChainClient"&gt;&lt;br /&gt;&lt;br /&gt;          &lt;jws:handler&gt;&lt;br /&gt;            &lt;jws:handler-class&gt;com.aja.client.Handler&lt;/jws:handler-class&gt;&lt;br /&gt;        &lt;/jws:handler&gt;&lt;br /&gt;&lt;br /&gt;        &lt;/jws:handler-chain&gt;&lt;br /&gt;&lt;br /&gt;&lt;/jws:handler-chains&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;****************************************** &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;Make the handler file, Handler.java.&lt;/p&gt;&lt;p&gt;*******************************************&lt;/p&gt;&lt;p&gt;package com.aja.client;&lt;br /&gt;&lt;br /&gt;import java.util.Set;&lt;br /&gt;&lt;br /&gt;import javax.xml.namespace.QName;&lt;br /&gt;import javax.xml.soap.Name;&lt;br /&gt;import javax.xml.soap.SOAPElement;&lt;br /&gt;import javax.xml.soap.SOAPEnvelope;&lt;br /&gt;import javax.xml.soap.SOAPFactory;&lt;br /&gt;import javax.xml.soap.SOAPHeader;&lt;br /&gt;import javax.xml.soap.SOAPHeaderElement;&lt;br /&gt;import javax.xml.soap.SOAPMessage;&lt;br /&gt;import javax.xml.soap.SOAPPart;&lt;br /&gt;import javax.xml.ws.handler.MessageContext;&lt;br /&gt;import javax.xml.ws.handler.soap.SOAPHandler;&lt;br /&gt;import javax.xml.ws.handler.soap.SOAPMessageContext;&lt;br /&gt;&lt;br /&gt;public class Handler implements SOAPHandler&lt;soapmessagecontext&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;   private static final String WSSE = "wsse";&lt;br /&gt;   private static final String WS_SEC = "Security";&lt;br /&gt;   private static final String USERNAME_TOKEN = "UsernameToken";&lt;br /&gt;   private static final String USERNAME = "Username";&lt;br /&gt;   private static final String PASSWORD = "Password";&lt;br /&gt;    private static final String NAME_SPACE_URI =  "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";&lt;br /&gt;&lt;br /&gt;     public SecurityHandler()&lt;br /&gt;   {&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   public Set&lt;qname&gt; getHeaders()&lt;br /&gt;   {&lt;br /&gt;      return null;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   public boolean handleFault(SOAPMessageContext messageContext)&lt;br /&gt;   {&lt;br /&gt;      return true;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   public boolean handleMessage(SOAPMessageContext messageContext)&lt;br /&gt;   {&lt;br /&gt;      secureClient(messageContext);&lt;br /&gt;      return true;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   public void close(MessageContext messageContext)&lt;br /&gt;   {&lt;br /&gt;   }&lt;br /&gt; &lt;br /&gt;   private void secureClient(SOAPMessageContext messageContext)&lt;br /&gt;   {&lt;br /&gt;      try&lt;br /&gt;      {&lt;br /&gt;         SOAPMessage message = messageContext.getMessage();&lt;br /&gt;         SOAPPart part = message.getSOAPPart();&lt;br /&gt;         SOAPEnvelope envelope = part.getEnvelope();&lt;br /&gt;         SOAPHeader header = envelope.getHeader();&lt;br /&gt;&lt;br /&gt;         if (header == null)&lt;br /&gt;         {&lt;br /&gt;            header = envelope.addHeader();&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt;         SOAPFactory factory = SOAPFactory.newInstance();&lt;br /&gt;&lt;br /&gt;         Name security = factory.createName(WS_SEC, WSSE, NAME_SPACE_URI);&lt;br /&gt;         SOAPHeaderElement orderHeader = header.addHeaderElement(security);&lt;br /&gt;&lt;br /&gt;         Name userNameToken = factory.createName(USERNAME_TOKEN, WSSE,&lt;br /&gt;               NAME_SPACE_URI);&lt;br /&gt;         Name user = factory.createName(USERNAME, WSSE, NAME_SPACE_URI);&lt;br /&gt;         Name pwd = factory.createName(PASSWORD, WSSE, NAME_SPACE_URI);&lt;br /&gt;&lt;br /&gt;         SOAPElement elem = orderHeader.addChildElement(userNameToken);&lt;br /&gt;         SOAPElement userElement = elem.addChildElement(user);&lt;br /&gt;         userElement.addTextNode("admin");&lt;br /&gt;         SOAPElement pwdElement = elem.addChildElement(pwd);&lt;br /&gt;         pwdElement.addTextNode("adminpwd");&lt;br /&gt;      }&lt;br /&gt;      catch (Exception e)&lt;br /&gt;      {&lt;br /&gt;         System.out.println("Exec " + e.getMessage());&lt;br /&gt;&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;   }&lt;br /&gt;}&lt;/qname&gt;&lt;/soapmessagecontext&gt;&lt;/p&gt;&lt;p&gt;**************************************************************** &lt;/p&gt;&lt;p&gt; And finally hook up to the file every time a web service request is called. I added this where I receive my web service client.&lt;/p&gt;&lt;p&gt; ********************************************&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new,courier;"&gt;@HandlerChain(file="ClientHandler.xml")&lt;/span&gt; &lt;/p&gt;&lt;p&gt;public class MyClient {&lt;/p&gt;&lt;p&gt;} &lt;/p&gt;&lt;p&gt; ************************************************&lt;/p&gt;&lt;p&gt;In  the example above the manager is an instance of my web service cleint  part. This is autogenerated by maven with the wsgen and wsimport  commands.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-5771765048283485664?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/5771765048283485664/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/12/ws-security-and-jax-ws.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/5771765048283485664'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/5771765048283485664'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/12/ws-security-and-jax-ws.html' title='Ws security and Jax WS'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-5355467456277417958</id><published>2011-12-14T00:52:00.002-08:00</published><updated>2011-12-14T00:53:26.025-08:00</updated><title type='text'>Double checked locking</title><content type='html'>Read this small good &lt;a href="http://en.wikipedia.org/wiki/Double_checked_locking" title="Wikipedia"&gt;article &lt;/a&gt;about double checked locking.       &lt;span class="article_separator"&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-5355467456277417958?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/5355467456277417958/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/12/double-checked-locking.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/5355467456277417958'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/5355467456277417958'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/12/double-checked-locking.html' title='Double checked locking'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-5648374189734508349</id><published>2011-12-14T00:52:00.001-08:00</published><updated>2011-12-14T00:52:41.672-08:00</updated><title type='text'>Java threads</title><content type='html'>&lt;p&gt;Threads, a topic causing people to become dazed and confused. In  general, a difficult topic to grasp. Many persons implementing JavaEE  applications never bother with Threads and synchronization. Below are  some discussions and examples around Threads and what they are.&lt;/p&gt;&lt;p&gt;Multi  threading refers to how to handle two or more tasks occurring  "simultaneously" in an application.Thus for instance, assume that one  person writes data to a object then a threaded application may prevent  another user to read the data before the write has succeeded.&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;h3&gt;We will show three objects and their methods of interest&lt;/h3&gt;&lt;p&gt; &lt;/p&gt; &lt;table align="center" border="0"&gt;   &lt;tbody&gt;&lt;tr&gt;   &lt;td&gt; &lt;table border="1" width="107"&gt;  &lt;tbody&gt;&lt;tr align="center"&gt;&lt;td&gt;&lt;strong&gt;Object&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;p&gt;     notify()&lt;/p&gt;&lt;p&gt;     notifyAll()&lt;/p&gt;&lt;p&gt;     wait()&lt;/p&gt;&lt;p&gt;     wait(long)&lt;/p&gt;&lt;p&gt;     wait(long, int) &lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/td&gt;  &lt;td&gt;            &lt;/td&gt;  &lt;td&gt; &lt;table border="1" width="107"&gt;  &lt;tbody&gt;&lt;tr align="center"&gt;&lt;td&gt;&lt;strong&gt;Thread&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;p&gt;     sleep()&lt;/p&gt;&lt;p&gt; yield()&lt;/p&gt;&lt;p&gt;run()      &lt;/p&gt;&lt;p&gt;sleep(long) &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/td&gt; &lt;td&gt; &lt;/td&gt; &lt;td&gt; &lt;table border="1" width="107"&gt;  &lt;tbody&gt;&lt;tr align="center"&gt;&lt;td&gt;&lt;strong&gt;Runnable&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;p&gt;     run()&lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/td&gt;   &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;I will try to avoid to dig to much into the deep of all this, instead just go give some highlights of some things.&lt;/p&gt;&lt;p&gt;Below is the simplest start.&lt;/p&gt;&lt;pre&gt;public class MyRunnable implements Runnable {&lt;br /&gt;&lt;br /&gt; Thread runner;&lt;br /&gt; public RunnableThread() {&lt;br /&gt; }&lt;br /&gt; public RunnableThread(String threadName) {&lt;br /&gt;  runner = new Thread(this, threadName); &lt;br /&gt;  System.out.println(runner.getName());&lt;br /&gt;  runner.start(); &lt;br /&gt; }&lt;br /&gt; public void run() {&lt;br /&gt;   System.out.println(Thread.currentThread());&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class RunnableExample {&lt;br /&gt;&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  Thread thread1 = new Thread(new MyRunnable (), “thread1″);&lt;br /&gt;  Thread thread2 = new Thread(new MyRunnable (), “thread2″);&lt;br /&gt;  //Start the threads&lt;br /&gt;  thread1.start();&lt;br /&gt;  thread2.start();&lt;br /&gt;  try {&lt;br /&gt;   //delay for one second&lt;br /&gt;   Thread.currentThread().sleep(1000);&lt;br /&gt;  } catch (InterruptedException e) {&lt;br /&gt;  }&lt;br /&gt;  System.out.println(Thread.currentThread());&lt;br /&gt; }&lt;br /&gt;}&lt;/pre&gt;&lt;p&gt;Implement  the Runnable interface in those cases when you want your class to only  use the Run method and you want it to be able to extend another class.  Do not call the run() method, insted you must just the start() method.  If you want the full Monty you will need to exetnd the Thread class, as  below.&lt;/p&gt;&lt;pre&gt;public class MyThread extends Thread {&lt;br /&gt;&lt;br /&gt; MyThread (String threadName) {&lt;br /&gt;  super(threadName); &lt;br /&gt;  start();&lt;br /&gt; }&lt;br /&gt; public void run() {&lt;br /&gt;  System.out.println(Thread.currentThread().getName());&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class ThreadExample {&lt;br /&gt;&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  Thread thread1 = new MyThread ("A");&lt;br /&gt;  Thread thread2 = new MyThread("B");&lt;br /&gt;  Thread thread3 = new MyThread(”C″);&lt;br /&gt;  //Start the threads&lt;br /&gt;  thread1.start();&lt;br /&gt;  thread2.start();&lt;br /&gt;  thread3.start();&lt;br /&gt;  try {&lt;br /&gt;   Thread.currentThread().sleep(1000);&lt;br /&gt;  } catch (InterruptedException e) {&lt;br /&gt;  }&lt;br /&gt;  System.out.println(Thread.currentThread());&lt;br /&gt; }&lt;br /&gt;}&lt;/pre&gt;&lt;p&gt;Sleep  causes the current thread to suspend execution for a specified period.  For instance assume you really want to wait a number of milliseconds  before trying again. An example might be that you do not have a call  back functionality, instead you poll. Say for instance, you see if a log  file has changed it's time stamp, and you do it every 10 seconds.&lt;/p&gt;&lt;h3&gt;&lt;span class="caption"&gt;Non synchronization &lt;/span&gt;&lt;br /&gt;&lt;/h3&gt;&lt;pre&gt;&lt;span class="caption"&gt;public class Counter {&lt;br /&gt;   private int c = 0;&lt;br /&gt;&lt;br /&gt;   public void increment() {&lt;br /&gt;       c++;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   public void decrement() {&lt;br /&gt;       c--;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   public int value() {&lt;br /&gt;       return c;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;Interference happens when two operations, running in different threads, but acting on the same data, &lt;em&gt;interleave&lt;/em&gt;. This means that the two operations consist of multiple steps, and the sequences of steps overlap. &lt;br /&gt;&lt;br /&gt;&lt;h3&gt;&lt;span class="caption"&gt;Synchronized methods &lt;/span&gt;&lt;/h3&gt;&lt;pre&gt;public class SynchronizedCounter {&lt;br /&gt;   private int c = 0;&lt;br /&gt;&lt;br /&gt;   public synchronized void increment() {&lt;br /&gt;       c++;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   public synchronized void decrement() {&lt;br /&gt;       c--;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   public synchronized int value() {&lt;br /&gt;       return c;&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Read and understand the below statement and you will understand what all is about;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;First,  it is not possible for two invocations of synchronized     methods on  the same object to interleave. When one thread is     executing a  synchronized method for an object, all other threads     that invoke  synchronized methods for the same object block     (suspend execution)  until the first thread is done with the     object.     &lt;/li&gt;&lt;li&gt;Second, when a synchronized method exits, it automatically     establishes a happens-before relationship with &lt;em&gt;any subsequent         invocation&lt;/em&gt;  of a synchronized method for the same object.     This guarantees that  changes to the state of the object are     visible to all threads. &lt;/li&gt;&lt;/ul&gt;&lt;p&gt; &lt;/p&gt;&lt;h3&gt;&lt;span class="caption"&gt;Synchronized statements&lt;/span&gt;&lt;/h3&gt;&lt;pre&gt;public class MsLunch {&lt;br /&gt;   private long c1 = 0;&lt;br /&gt;   private long c2 = 0;&lt;br /&gt;   private Object lock1 = new Object();&lt;br /&gt;   private Object lock2 = new Object();&lt;br /&gt;&lt;br /&gt;   public void inc1() {&lt;br /&gt;       synchronized(lock1) {&lt;br /&gt;           c1++;&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   public void inc2() {&lt;br /&gt;       synchronized(lock2) {&lt;br /&gt;           c2++;&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;}&lt;/pre&gt;&lt;p&gt;Synchronized statements are useful for improving concurrency with fine-grained synchronization.  &lt;/p&gt;&lt;h3&gt;Re-cap&lt;/h3&gt;&lt;p&gt;Locks are used to synchronize access to a shared resource. A lock can be associated with a shared resource.&lt;br /&gt;Threads gain access to a shared resource by first acquiring the lock associated with the object/block of code.&lt;br /&gt;At any given time, at most only one thread can hold the lock and thereby have access to the shared resource.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;This will in the practical world means these two things;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;If  you put synchronized on a static method ALL requests will wait (queue)  when a call is made to that method since ALL requests use the same  static method.&lt;/li&gt;&lt;li&gt;If you put synchronized on an instance method ALL  requests will wait (queue) when a call is made to the same instance  method. Thus if each request call a new instance and only one method is  synchronized it is useless. You do not need to synchronize in that case.&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;The great misunderstanding&lt;br /&gt;&lt;/h3&gt;&lt;p&gt;Many people do not understand that this has the same meaning, &lt;/p&gt;&lt;pre&gt;public synchronized String getName() {&lt;/pre&gt;&lt;pre&gt;   return "x";&lt;/pre&gt;&lt;pre&gt;} &lt;/pre&gt;&lt;p&gt;same as;&lt;/p&gt;&lt;pre&gt;public String getName() {&lt;/pre&gt; &lt;pre&gt;  synchronized(this) {&lt;/pre&gt;&lt;pre&gt;  return "x";&lt;/pre&gt;&lt;pre&gt;  }&lt;br /&gt;&lt;/pre&gt; &lt;pre&gt;} &lt;/pre&gt; &lt;p&gt;It is the same, all requests on the same instance of the class will wait in a queue when the method getName is called. &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;pre&gt; &lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-5648374189734508349?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/5648374189734508349/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/12/java-threads.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/5648374189734508349'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/5648374189734508349'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/12/java-threads.html' title='Java threads'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-1526943685785931321</id><published>2011-12-14T00:51:00.002-08:00</published><updated>2011-12-14T00:52:01.517-08:00</updated><title type='text'>RMI</title><content type='html'>&lt;p&gt;Java R(emote) M(ethod) I(nvocation) is a feature that has had a  shrinking part of distributed applications over the last years. Both EJB  3.0 with its simplicity and web services has superseded RMI. Naturally  EJB uses RMI under the hood, but I am here more concerened with pure  RMI. Most of the below examples are taken from the Sun &lt;a href="http://java.sun.com/docs/books/tutorial/rmi/overview.html" title="RMI"&gt;page&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;In brief to get RMI to work, you need to have a Registry accepting calls.In the LocalRegistryAPI this text can be found;&lt;/p&gt;&lt;p&gt;"LocateRegistry  iis used to obtain a reference to a bootstrap  remote object registry  on a particular host (including the local host), or  to create a remote  object registry that accepts calls on a specific port."&lt;/p&gt;&lt;p&gt;So we need this architecture to get it to work;&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;&lt;img src="http://aspemo.com/images/rmi.gif" alt="RMI" title="RMI" height="181" border="0" width="355" /&gt; &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;The picture explains everything pretty well.&lt;/p&gt;&lt;h3&gt;We need the following files;&lt;/h3&gt;&lt;p&gt;An object to pass between the client and the server, this object will implement the Task interface.&lt;/p&gt;&lt;pre style="background-color: #cccccc"&gt;package compute;&lt;br /&gt;&lt;br /&gt;public interface Task&lt;t&gt; {&lt;br /&gt;   T execute();&lt;br /&gt;}&lt;br /&gt;&lt;/t&gt;&lt;/pre&gt;&lt;p&gt;A remote interface to use by our class acting as a server, the interface is Compute.&lt;/p&gt;&lt;pre style="background-color: #cccccc"&gt;package compute;&lt;br /&gt;&lt;br /&gt;import java.rmi.Remote;&lt;br /&gt;import java.rmi.RemoteException;&lt;br /&gt;&lt;br /&gt;public interface Compute extends Remote {&lt;br /&gt;   &lt;t&gt; T executeTask(Task&lt;t&gt; t) throws RemoteException;&lt;br /&gt;}&lt;br /&gt;&lt;/t&gt;&lt;/t&gt;&lt;/pre&gt;&lt;p&gt;Server side, create a registry and accept calls on ports 1199.&lt;/p&gt;&lt;pre style="background-color: #cccccc"&gt;package engine;&lt;br /&gt;&lt;br /&gt;import java.rmi.RemoteException;&lt;br /&gt;import java.rmi.registry.LocateRegistry;&lt;br /&gt;import java.rmi.registry.Registry;&lt;br /&gt;import java.rmi.server.UnicastRemoteObject;&lt;br /&gt;import compute.Compute;&lt;br /&gt;import compute.Task;&lt;br /&gt;&lt;br /&gt;public class ComputeEngine implements Compute {&lt;br /&gt;&lt;br /&gt;   public ComputeEngine() {&lt;br /&gt;       super();&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   public &lt;t&gt; T executeTask(Task&lt;t&gt; t) {&lt;br /&gt;       return t.execute();&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;    public static void main(String[] args) {&lt;br /&gt;       if (System.getSecurityManager() == null) {&lt;br /&gt;           System.setSecurityManager(new SecurityManager());&lt;br /&gt;       }&lt;br /&gt;       try {&lt;br /&gt;           LocateRegistry.createRegistry(1199);&lt;br /&gt;           String name = "Compute";&lt;br /&gt;           Compute engine = new ComputeEngine();&lt;br /&gt;           Compute stub =&lt;br /&gt;               (Compute) UnicastRemoteObject.exportObject(engine, 0);&lt;br /&gt;            Registry registry = LocateRegistry.getRegistry(1199);&lt;br /&gt;           registry.rebind(name, stub);&lt;br /&gt;           System.out.println("ComputeEngine bound");&lt;br /&gt;       } catch (Exception e) {&lt;br /&gt;           System.err.println("ComputeEngine exception:");&lt;br /&gt;           e.printStackTrace();&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;/t&gt;&lt;/t&gt;&lt;/pre&gt;&lt;p&gt;Client side, first class implementing Task&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;pre style="background-color: #cccccc"&gt;package client;&lt;br /&gt;&lt;br /&gt;import compute.Task;&lt;br /&gt;import java.io.Serializable;&lt;br /&gt;import java.math.BigDecimal;&lt;br /&gt;&lt;br /&gt;public class Pi implements Task&lt;bigdecimal&gt;, Serializable {&lt;br /&gt;&lt;br /&gt;   private static final long serialVersionUID = 227L;&lt;br /&gt;&lt;br /&gt;   /** constants used in pi computation */&lt;br /&gt;   private static final BigDecimal FOUR =&lt;br /&gt;       BigDecimal.valueOf(4);&lt;br /&gt;&lt;br /&gt;   /** rounding mode to use during pi computation */&lt;br /&gt;   private static final int roundingMode =&lt;br /&gt;       BigDecimal.ROUND_HALF_EVEN;&lt;br /&gt;&lt;br /&gt;   /** digits of precision after the decimal point */&lt;br /&gt;   private final int digits;&lt;br /&gt;  &lt;br /&gt;   /**&lt;br /&gt;    * Construct a task to calculate pi to the specified&lt;br /&gt;    * precision.&lt;br /&gt;    */&lt;br /&gt;   public Pi(int digits) {&lt;br /&gt;       this.digits = digits;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   /**&lt;br /&gt;    * Calculate pi.&lt;br /&gt;    */&lt;br /&gt;   public BigDecimal execute() {&lt;br /&gt;       return computePi(digits);&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   /**&lt;br /&gt;    * Compute the value of pi to the specified number of&lt;br /&gt;    * digits after the decimal point.  The value is&lt;br /&gt;    * computed using Machin's formula:&lt;br /&gt;    *&lt;br /&gt;    *          pi/4 = 4*arctan(1/5) - arctan(1/239)&lt;br /&gt;    *&lt;br /&gt;    * and a power series expansion of arctan(x) to&lt;br /&gt;    * sufficient precision.&lt;br /&gt;    */&lt;br /&gt;   public static BigDecimal computePi(int digits) {&lt;br /&gt;       int scale = digits + 5;&lt;br /&gt;       BigDecimal arctan1_5 = arctan(5, scale);&lt;br /&gt;       BigDecimal arctan1_239 = arctan(239, scale);&lt;br /&gt;       BigDecimal pi = arctan1_5.multiply(FOUR).subtract(&lt;br /&gt;                                 arctan1_239).multiply(FOUR);&lt;br /&gt;       return pi.setScale(digits,&lt;br /&gt;                          BigDecimal.ROUND_HALF_UP);&lt;br /&gt;   }&lt;br /&gt;   /**&lt;br /&gt;    * Compute the value, in radians, of the arctangent of&lt;br /&gt;    * the inverse of the supplied integer to the specified&lt;br /&gt;    * number of digits after the decimal point.  The value&lt;br /&gt;    * is computed using the power series expansion for the&lt;br /&gt;    * arc tangent:&lt;br /&gt;    *&lt;br /&gt;    * arctan(x) = x - (x^3)/3 + (x^5)/5 - (x^7)/7 +&lt;br /&gt;    *     (x^9)/9 ...&lt;br /&gt;    */  &lt;br /&gt;   public static BigDecimal arctan(int inverseX,&lt;br /&gt;                                   int scale)&lt;br /&gt;   {&lt;br /&gt;       BigDecimal result, numer, term;&lt;br /&gt;       BigDecimal invX = BigDecimal.valueOf(inverseX);&lt;br /&gt;       BigDecimal invX2 =&lt;br /&gt;           BigDecimal.valueOf(inverseX * inverseX);&lt;br /&gt;&lt;br /&gt;       numer = BigDecimal.ONE.divide(invX,&lt;br /&gt;                                     scale, roundingMode);&lt;br /&gt;&lt;br /&gt;       result = numer;&lt;br /&gt;       int i = 1;&lt;br /&gt;       do {&lt;br /&gt;           numer =&lt;br /&gt;               numer.divide(invX2, scale, roundingMode);&lt;br /&gt;           int denom = 2 * i + 1;&lt;br /&gt;           term =&lt;br /&gt;               numer.divide(BigDecimal.valueOf(denom),&lt;br /&gt;                            scale, roundingMode);&lt;br /&gt;           if ((i % 2) != 0) {&lt;br /&gt;               result = result.subtract(term);&lt;br /&gt;           } else {&lt;br /&gt;               result = result.add(term);&lt;br /&gt;           }&lt;br /&gt;           i++;&lt;br /&gt;       } while (term.compareTo(BigDecimal.ZERO) != 0);&lt;br /&gt;       return result;&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;/bigdecimal&gt;&lt;/pre&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;And then client calling server and passing object. &lt;/p&gt;&lt;pre&gt; &lt;/pre&gt;&lt;pre style="background-color: #cccccc"&gt;package client;&lt;br /&gt;&lt;br /&gt;import java.rmi.registry.LocateRegistry;&lt;br /&gt;import java.rmi.registry.Registry;&lt;br /&gt;import java.math.BigDecimal;&lt;br /&gt;import compute.Compute;&lt;br /&gt;&lt;br /&gt;public class ComputePi {&lt;br /&gt;   public static void main(String args[]) {&lt;br /&gt;       if (System.getSecurityManager() == null) {&lt;br /&gt;           System.setSecurityManager(new SecurityManager());&lt;br /&gt;       }&lt;br /&gt;       try {&lt;br /&gt;           String name = "Compute";&lt;br /&gt;           Registry registry = LocateRegistry.getRegistry(1199);&lt;br /&gt;           Compute comp = (Compute) registry.lookup(name);&lt;br /&gt;           Pi task = new Pi(Integer.parseInt(45);&lt;br /&gt;           BigDecimal pi = comp.executeTask(task);&lt;br /&gt;           System.out.println(pi);&lt;br /&gt;       } catch (Exception e) {&lt;br /&gt;           System.err.println("ComputePi exception:");&lt;br /&gt;           e.printStackTrace();&lt;br /&gt;       }&lt;br /&gt;   }   &lt;br /&gt;}&lt;/pre&gt;&lt;pre&gt; &lt;/pre&gt;&lt;p&gt;You must now add two security files, server.policy to the server project and client.policy to he client project.&lt;/p&gt;&lt;p&gt; My files are identivcal in appearence and look like this;&lt;/p&gt;&lt;p style="background-color: #cccccc"&gt;grant {&lt;br /&gt;    permission java.security.AllPermission;&lt;br /&gt;}; &lt;/p&gt;&lt;p&gt;Add them to your runtime environment by doing this in both the server and the client project.&lt;/p&gt;&lt;p&gt;&lt;img src="http://aspemo.com/images/path.jpg" alt="Path" height="285" border="0" width="400" /&gt; &lt;/p&gt;&lt;p&gt; In  the client project the VM option should be  -Djava.security.policy=client.policy and in the server project  -Djava.security.policy=server.policy&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-1526943685785931321?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/1526943685785931321/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/12/rmi.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/1526943685785931321'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/1526943685785931321'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/12/rmi.html' title='RMI'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-9035158465657654956</id><published>2011-12-14T00:51:00.001-08:00</published><updated>2011-12-14T00:51:20.194-08:00</updated><title type='text'>JAAS and Derby</title><content type='html'>&lt;p&gt;Did you read the previous document about JAAS and Sun Application Server? That implemented a file&lt;/p&gt; &lt;p&gt;based JAAS security handling. I wanted to experiment with a database solution which in my humble opinion is better,&lt;/p&gt; &lt;p&gt;since it more distributable (to name just one advantage)&lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;p&gt;To give credit where it is due, it took almost everything form &lt;a title="Sun" href="http://blogs.sun.com/swchan/entry/jdbcrealm_in_glassfish_with_mysql"&gt;here&lt;/a&gt;.&lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;p&gt;You only need to do four things, and those are quite simple.&lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;p&gt;&lt;span style="background-color: #ffcc99;"&gt;Fix database&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="background-color: #ffffff;"&gt;I use to default tablespace  that comes with the Derby database. That is in the latest versions of  Java a Derby database is shipped.&lt;/span&gt;&lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;p&gt;The standard way to work with it is to start it either from the  application servers asadamin, with command, asadmin start-database or  stand alone.&lt;/p&gt; &lt;p&gt;This is the necessary data you need by default&lt;/p&gt; &lt;p&gt;&lt;span style="background-color: #ffffff;"&gt;url: jdbc:derby://localhost:1527/sun-appserv-samples&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="background-color: #ffffff;"&gt;uid: APP&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="background-color: #ffffff;"&gt;pwd: APP&lt;/span&gt;&lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;p&gt;&lt;span style="background-color: #ffffff;"&gt;A connection pool is set up  in the Application Server that goes towards this database. You do not  need to do anything besides start the app server.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;p&gt;&lt;span style="background-color: #ffffff;"&gt;Just run these and everything will be ok. Then your database will be populated with the correct tables.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;pre&gt;create table usertable(userid varchar(10) not null,&lt;br /&gt;password varchar(32) not null, primary key(userid));&lt;br /&gt;create table grouptable(userid varchar(10) not null,&lt;br /&gt;groupid varchar(20) not null, primary key(userid));&lt;br /&gt;alter table grouptable add constraint FK_USERID&lt;br /&gt;foreign key(userid) references usertable(userid);&lt;br /&gt;&lt;br /&gt;Note that the default handling of pwd will be hex so you cannot add a plain text password manually&lt;br /&gt;into the database. This will fail. &lt;br /&gt;&lt;br /&gt;Thus, log into the Derby database, with squirrel or something else. Then execute the three scripts above.&lt;br /&gt;&lt;/pre&gt; &lt;table border="1"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;th&gt;&lt;code&gt;&lt;/code&gt;&lt;br /&gt;&lt;/th&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;pre&gt;&lt;span style="background-color: #ffcc99;"&gt;Create realm in Sun Application Server&lt;/span&gt;&lt;br /&gt;Create this realm in the admin console. You do this by doing this;&lt;br /&gt;&lt;br /&gt;log in to admin console with http://localhost:4848, go to&lt;br /&gt;Configuration-&amp;gt;Security-&amp;gt;Realms. Since I had created my realm previously I saw it here. If you haven't&lt;br /&gt;just create a new one here.&lt;br /&gt;Make sure that className is JdbcRealm. Then a lot of textboxes will appear. Fill in those so that they look like below.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt; &lt;table border="1"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;th&gt;&lt;code&gt;Property Name&lt;/code&gt;&lt;/th&gt;&lt;th&gt;&lt;code&gt;Property Value &lt;/code&gt;&lt;/th&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;datasource-jndi&lt;/code&gt;&lt;/td&gt; &lt;td&gt;&lt;code&gt;jdbc/security&lt;/code&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;user-table&lt;/code&gt;&lt;/td&gt; &lt;td&gt;&lt;code&gt;usertable&lt;/code&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;user-name-column&lt;/code&gt;&lt;/td&gt; &lt;td&gt;&lt;code&gt;userid&lt;/code&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;password-column&lt;/code&gt;&lt;/td&gt; &lt;td&gt;&lt;code&gt;password&lt;/code&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;group-table&lt;/code&gt;&lt;/td&gt; &lt;td&gt;&lt;code&gt;grouptable&lt;/code&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;group-name-column&lt;/code&gt;&lt;/td&gt; &lt;td&gt;&lt;code&gt;groupid&lt;/code&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;jaas-context&lt;/code&gt;&lt;/td&gt; &lt;td&gt;&lt;code&gt;jdbcRealm&lt;/code&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;pre&gt;&lt;span style="background-color: #ffcc99;"&gt;Add the html files&lt;br /&gt;&lt;/span&gt;In the previous example we added the necessary files, but here is a replay.&lt;br /&gt;&lt;span style="background-color: #ffcc99;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="background-color: #ffcc99;"&gt;Sun-web.xml file&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;These files indicate the userid and groupid.&lt;br /&gt;&lt;br /&gt;&lt;!--?xml version="1.0" encoding="UTF-8"?--&gt;&lt;br /&gt;&lt;br /&gt;&lt;sun-web-app url=""&gt;&lt;br /&gt; &lt;context-root&gt;/WebApplication1&lt;/context-root&gt;&lt;br /&gt; &lt;security-role-mapping&gt;&lt;br /&gt;   &lt;role-name&gt;jonas_admins&lt;/role-name&gt;&lt;br /&gt;   &lt;principal-name&gt;jonas&lt;/principal-name&gt;&lt;br /&gt;   &lt;!--&lt;group-name&gt;jonas_admins&lt;/group-name&gt;--&gt;&lt;br /&gt; &lt;/security-role-mapping&gt;&lt;br /&gt; &lt;class-loader delegate="true"&gt;&lt;br /&gt; &lt;jsp-config&gt;&lt;br /&gt;   &lt;property name="keepgenerated" value="true"&gt;&lt;br /&gt;     &lt;description&gt;Keep a copy of the generated servlet class' java code.&lt;/description&gt;&lt;br /&gt;   &lt;/property&gt;&lt;br /&gt; &lt;/jsp-config&gt;&lt;br /&gt;&lt;/class-loader&gt;&lt;/sun-web-app&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="background-color: #ffcc99;"&gt;&lt;/span&gt;&lt;span style="background-color: #ffcc99;"&gt;&lt;br /&gt;login.html&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;   &lt;title&gt;&lt;/title&gt;&lt;br /&gt;   &lt;meta equiv="Content-Type" content="text/html; charset=UTF-8"&gt;&lt;br /&gt; &lt;br /&gt; &lt;form action="j_security_check" method="post"&gt;&lt;br /&gt;                       &lt;table id="logintable"&gt;&lt;br /&gt;                           &lt;tbody&gt;&lt;tr&gt;&lt;td&gt;User Name:&lt;/td&gt;&lt;td&gt;&lt;input name="j_username" type="text"&gt;&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;                           &lt;tr&gt;&lt;td&gt;Password :&lt;/td&gt;&lt;td&gt;&lt;input name="j_password" type="password"&gt;&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;                           &lt;tr&gt;&lt;td&gt; &lt;/td&gt;&lt;td align="right"&gt;&lt;br /&gt;                           &lt;input class="submitbutton" value="Login" type="submit"&gt;&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;                       &lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;                   &lt;/form&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="background-color: #ffcc99;"&gt;index.jsp&lt;/span&gt;&lt;br /&gt;&amp;lt;%@page contentType="text/html" pageEncoding="UTF-8"%&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;br /&gt;       &lt;meta equiv="Content-Type" content="text/html; charset=UTF-8"&gt;&lt;br /&gt;       &lt;title&gt;JSP Page&lt;/title&gt;&lt;br /&gt;   &lt;br /&gt;   &lt;br /&gt;       &lt;h1&gt;Hello World!&lt;/h1&gt;&lt;br /&gt;   &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="background-color: #ffcc99;"&gt;web.xml&lt;/span&gt;&lt;br /&gt;&lt;!--?xml version="1.0" encoding="UTF-8"?--&gt;&lt;br /&gt;&lt;web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xsi="http://www.w3.org/2001/XMLSchema-instance" schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt;&lt;br /&gt;   &lt;session-config&gt;&lt;br /&gt;       &lt;session-timeout&gt;&lt;br /&gt;           30&lt;br /&gt;       &lt;/session-timeout&gt;&lt;br /&gt;   &lt;/session-config&gt;&lt;br /&gt;   &lt;welcome-file-list&gt;&lt;br /&gt;       &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;&lt;br /&gt;       &lt;/welcome-file-list&gt;&lt;br /&gt;       &lt;security-constraint&gt;&lt;br /&gt;       &lt;web-resource-collection&gt;&lt;br /&gt;           &lt;web-resource-name&gt;restricted&lt;/web-resource-name&gt;&lt;br /&gt;           &lt;url-pattern&gt;/*&lt;/url-pattern&gt;&lt;br /&gt;       &lt;/web-resource-collection&gt;&lt;br /&gt;       &lt;auth-constraint&gt;&lt;br /&gt;           &lt;role-name&gt;jonas_admins&lt;/role-name&gt;&lt;br /&gt;          &lt;/auth-constraint&gt;&lt;br /&gt;   &lt;/security-constraint&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;security-constraint&gt;&lt;br /&gt;       &lt;web-resource-collection&gt;&lt;br /&gt;           &lt;web-resource-name&gt;&lt;br /&gt;               unrestricted stylesheets&lt;br /&gt;           &lt;/web-resource-name&gt;&lt;br /&gt;           &lt;url-pattern&gt;/css/*&lt;/url-pattern&gt;&lt;br /&gt;           &lt;http-method&gt;GET&lt;/http-method&gt;&lt;br /&gt;       &lt;/web-resource-collection&gt;&lt;br /&gt;   &lt;/security-constraint&gt;&lt;br /&gt;&lt;br /&gt;&lt;login-config&gt;&lt;br /&gt;       &lt;auth-method&gt;FORM&lt;/auth-method&gt;&lt;br /&gt;       &lt;realm-name&gt;jonas_realm&lt;/realm-name&gt;&lt;br /&gt;       &lt;form-login-config&gt;&lt;br /&gt;           &lt;form-login-page&gt;/login.html&lt;/form-login-page&gt;&lt;br /&gt;           &lt;form-error-page&gt;&lt;br /&gt;               /loginerror.html&lt;br /&gt;           &lt;/form-error-page&gt;&lt;br /&gt;       &lt;/form-login-config&gt;&lt;br /&gt;   &lt;/login-config&gt;&lt;br /&gt;&lt;br /&gt;   &lt;security-role&gt;&lt;br /&gt;       &lt;role-name&gt;jonas_admins&lt;/role-name&gt;&lt;br /&gt;   &lt;/security-role&gt;&lt;br /&gt;   &lt;/web-app&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;That's it. Just deploy the app and it will work. You will be forced to add a uid/pwd to be accepted.&lt;br /&gt;The file to add users/pwds in the database in hex format can be found below, taken from Sun.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="background-color: #ffcc99;"&gt;File to populate database with pwd in hex&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;import java.security.MessageDigest;&lt;br /&gt;import java.sql.Connection;&lt;br /&gt;import java.sql.DriverManager;&lt;br /&gt;import java.sql.PreparedStatement;&lt;br /&gt;&lt;br /&gt;public class CreateJdbcRealmUser {&lt;br /&gt;   private static final String driver = "org.apache.derby.jdbc.ClientDriver";&lt;br /&gt;   private static final String jdbcUrl = "jdbc:derby://localhost:1527/sun-appserv-samples";&lt;br /&gt;   private static final String userSql = "insert into usertable values(?, ?)";&lt;br /&gt;   private static final String groupSql = "insert into grouptable values(?, ?)";&lt;br /&gt;&lt;br /&gt;   private static final char[] HEXADECIMAL = { '0', '1', '2', '3',&lt;br /&gt;       '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };&lt;br /&gt;&lt;br /&gt;   private static String hashPassword(String password) throws Exception {&lt;br /&gt;       MessageDigest md = MessageDigest.getInstance("MD5");&lt;br /&gt;       md.reset();&lt;br /&gt;&lt;br /&gt;       byte[] bytes = md.digest(password.getBytes());&lt;br /&gt;       StringBuilder sb = new StringBuilder(2 * bytes.length);&lt;br /&gt;       for (int i = 0; i &amp;lt; bytes.length; i++) {&lt;br /&gt;           int low = (int)(bytes[i] &amp;amp; 0x0f);&lt;br /&gt;           int high = (int)((bytes[i] &amp;amp; 0xf0) &amp;gt;&amp;gt; 4);&lt;br /&gt;           sb.append(HEXADECIMAL[high]);&lt;br /&gt;           sb.append(HEXADECIMAL[low]);&lt;br /&gt;       }&lt;br /&gt;       return sb.toString();&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   public static void main(String args[]) throws Exception {&lt;br /&gt;       String dbUser = null;&lt;br /&gt;       String dbPassword = null;&lt;br /&gt;       String user = null;&lt;br /&gt;       String password = null;&lt;br /&gt;       String group = null;&lt;br /&gt;&lt;br /&gt;       if (args.length != 5){&lt;br /&gt;           System.err.println("Usage java CreateJDBCRealmUser &lt;dbuser&gt; &lt;dbpassord&gt; &lt;user&gt; &lt;password&gt; &lt;group&gt;");&lt;br /&gt;           System.exit(2);&lt;br /&gt;       } else {&lt;br /&gt;           dbUser = args[0];&lt;br /&gt;           dbPassword = args[1];&lt;br /&gt;           user = args[2];&lt;br /&gt;           password = args[3];&lt;br /&gt;           group = args[4];&lt;br /&gt;       }&lt;br /&gt;&lt;br /&gt;       Class.forName(driver);&lt;br /&gt;       String hPassword = hashPassword(password);&lt;br /&gt;       Connection conn = DriverManager.getConnection(&lt;br /&gt;           jdbcUrl, dbUser, dbPassword);&lt;br /&gt;       PreparedStatement userStmt = conn.prepareStatement(userSql);&lt;br /&gt;       userStmt.setString(1, user);&lt;br /&gt;       userStmt.setString(2, hPassword);&lt;br /&gt;       userStmt.executeUpdate();&lt;br /&gt;       userStmt.close();&lt;br /&gt;&lt;br /&gt;       PreparedStatement groupStmt = conn.prepareStatement(groupSql);&lt;br /&gt;       groupStmt.setString(1, user);&lt;br /&gt;       groupStmt.setString(2, group);&lt;br /&gt;       groupStmt.executeUpdate();&lt;br /&gt;       groupStmt.close();&lt;br /&gt;&lt;br /&gt;       conn.close();&lt;br /&gt;   }&lt;br /&gt;}&lt;/group&gt;&lt;/password&gt;&lt;/user&gt;&lt;/dbpassord&gt;&lt;/dbuser&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-9035158465657654956?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/9035158465657654956/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/12/jaas-and-derby.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/9035158465657654956'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/9035158465657654956'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/12/jaas-and-derby.html' title='JAAS and Derby'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-4284248147425711914</id><published>2011-12-14T00:49:00.004-08:00</published><updated>2011-12-14T00:50:46.435-08:00</updated><title type='text'>Java is pass by value</title><content type='html'>&lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif"&gt;First a definition so everything is clear.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif"&gt;Pass  by value - The actual value of a parameter is copied into a "new"  memory address and any manipulation of this value will not cause the  original value to change. Every call to the method will create a new  parameter with a new value which is uniquely changed in the method.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif"&gt;Pass  by reference - The parameter is just an alias for the actual value.  every time the alias is used the real value is actually used. Thus a  change to the value in the method will change the value of the object if  it is called from outside the method as well.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif"&gt;Java is pass by value. See the formal explanation &lt;a href="http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#37472" title="Sun"&gt;here&lt;/a&gt;. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif"&gt;Why the confusion then?&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif"&gt;Well  because even though in a formal sense Java is pass by value there are  some instances where the result seem to contradict this. For all you  zealots out there, I know the differenceon pass by value/reference and  the below example is merely to show why some people have a hard time to  grasp this. In a formal sense this is pass by value even though the  result is "odd".&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif"&gt;    &lt;/span&gt;&lt;/p&gt;&lt;p&gt; &lt;/p&gt; &lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif"&gt;First a small pojo.&lt;/span&gt;&lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;p&gt;******************************&lt;/p&gt; &lt;p&gt;&lt;span style="font-family: courier new,courier"&gt;public class A&lt;br /&gt;{&lt;br /&gt;private String name;&lt;br /&gt;private int age;&lt;br /&gt;/**&lt;br /&gt;* @return the name&lt;br /&gt;*/&lt;br /&gt;public String getName()&lt;br /&gt;{&lt;br /&gt;return name;&lt;br /&gt;}&lt;br /&gt;/**&lt;br /&gt;* @param name the name to set&lt;br /&gt;*/&lt;br /&gt;public void setName(String name)&lt;br /&gt;{&lt;br /&gt;this.name = name;&lt;br /&gt;}&lt;br /&gt;/**&lt;br /&gt;* @return the age&lt;br /&gt;*/&lt;br /&gt;public int getAge()&lt;br /&gt;{&lt;br /&gt;return age;&lt;br /&gt;}&lt;br /&gt;/**&lt;br /&gt;* @param age the age to set&lt;br /&gt;*/&lt;br /&gt;public void setAge(int age)&lt;br /&gt;{&lt;br /&gt;this.age = age;&lt;br /&gt;}&lt;br /&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p&gt;*********************************&lt;/p&gt; &lt;p&gt;The a class using this pojo.&lt;/p&gt; &lt;p&gt;**********************************&lt;/p&gt; &lt;p&gt;&lt;span style="font-family: courier new,courier"&gt;public class Runner&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt;* @param args&lt;br /&gt;*/&lt;br /&gt;public static void main(String[] args)&lt;br /&gt;{&lt;br /&gt;Runner r = new Runner();&lt;br /&gt;r.init();&lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;private void init(){&lt;br /&gt;&lt;br /&gt;A a = new A();&lt;br /&gt;a.setName("King");&lt;br /&gt;a.setAge(25);&lt;br /&gt;&lt;br /&gt;System.out.println("A name before method call" + a.getName());&lt;br /&gt;System.out.println("A age before method call" + a.getAge());&lt;br /&gt;&lt;br /&gt;this.changeValue(a);&lt;br /&gt;&lt;br /&gt;System.out.println("A name after method call" + a.getName());&lt;br /&gt;System.out.println("A age after method call" + a.getAge());&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;private void changeValue(final A a){&lt;br /&gt;&lt;br /&gt;a.setName("Kong");&lt;br /&gt;a.setAge(35);&lt;br /&gt;&lt;br /&gt;System.out.println("A name in method: " + a.getName());&lt;br /&gt;System.out.println("A age in method: " + a.getAge());&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;}&lt;/p&gt; &lt;p&gt;*********************************************&lt;/p&gt; &lt;p&gt;The output on the screen is&lt;/p&gt; &lt;p&gt;A name before method callKing&lt;br /&gt;A age before method call25&lt;br /&gt;A name in method: Kong&lt;br /&gt;A age in method: 35&lt;br /&gt;A name after method callKong&lt;br /&gt;A age after method call35&lt;/p&gt; &lt;p&gt;*************************************************&lt;/p&gt; &lt;p&gt;&lt;span style="font-family: arial,helvetica,sans-serif"&gt;Now from my point of view this looks like some kind of reference. And here is the rather dubious part of this,&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;em&gt;Object references are passed by value&lt;/em&gt;.&lt;/p&gt; &lt;p&gt;Read  that again. It is fundamental. It is actually the "pointer" towards the  memory address which is copied and sent to the method as a formal  parameter. this means that all changes inside the object is actully  propagated outside of the method.&lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;p&gt;OK but what about this?&lt;/p&gt; &lt;p&gt;private void changeValueComplex(final A a){&lt;br /&gt;&lt;br /&gt;A b = a;&lt;br /&gt;b.setName("Jonas");&lt;br /&gt;b.setAge(35);&lt;br /&gt;&lt;br /&gt;System.out.println("B name in method: " + b.getName());&lt;br /&gt;System.out.println("A name in method: " + a.getName());&lt;br /&gt;System.out.println("B age in method: " + b.getAge());&lt;br /&gt;System.out.println("A age in method: " + a.getAge());&lt;br /&gt;}&lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;p&gt;********************&lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;p&gt;Sorry mate, no use. Same result. Hrm what to do. Wait, I got it!&lt;/p&gt; &lt;p&gt;Add this to A:&lt;/p&gt; &lt;p&gt;&lt;span style="font-family: courier new,courier"&gt;implements Cloneable&lt;/span&gt;&lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;p&gt;and this method&lt;/p&gt; &lt;p&gt;&lt;span style="font-family: courier new,courier"&gt;public Object clone() throws CloneNotSupportedException {&lt;br /&gt;return (A) super.clone();&lt;br /&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;p&gt;private void changeValueByClone(final A a){&lt;br /&gt;&lt;br /&gt;try {&lt;br /&gt;A b = (A)a.clone();&lt;br /&gt;b.setName("Jonas");&lt;br /&gt;b.setAge(35);&lt;br /&gt;&lt;br /&gt;System.out.println("B name in method: " + b.getName());&lt;br /&gt;System.out.println("A name in method: " + a.getName());&lt;br /&gt;System.out.println("B age in method: " + b.getAge());&lt;br /&gt;System.out.println("A age in method: " + a.getAge());&lt;br /&gt;}catch (Exception e){&lt;br /&gt;e.printStackTrace();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;/p&gt; &lt;p&gt;Now we actually could manipulate the values in one object without affecting the other one.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-4284248147425711914?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/4284248147425711914/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/12/java-is-pass-by-value.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/4284248147425711914'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/4284248147425711914'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/12/java-is-pass-by-value.html' title='Java is pass by value'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-3516087990114448642</id><published>2011-12-14T00:49:00.003-08:00</published><updated>2011-12-14T00:49:39.115-08:00</updated><title type='text'>Remote EJB call in Glassfish</title><content type='html'>&lt;p&gt;Properties props = new Properties();&lt;br /&gt;props.setProperty("java.naming.factory.initial",&lt;br /&gt;"com.sun.enterprise.naming.SerialInitContextFactory");&lt;br /&gt;props.setProperty("java.naming.factory.url.pkgs",&lt;br /&gt;"com.sun.enterprise.naming");&lt;br /&gt;props.setProperty("java.naming.factory.state",&lt;br /&gt;"com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");&lt;br /&gt;&lt;br /&gt;props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");&lt;br /&gt;props.setProperty("org.omg.CORBA.ORBInitialPort","3700");&lt;br /&gt;&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;Context ic = new InitialContext(props);&lt;br /&gt;ServiceRemote remote = (ServiceRemote ) ic&lt;br /&gt;.lookup("aja/ServiceBean");&lt;br /&gt;remote.lala();&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;catch (Exception e)&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Create a stateless bean and do like this&lt;/p&gt; &lt;p&gt;@Stateless(mappedName="aja/ServiceBean")&lt;/p&gt; &lt;p&gt;public ServiceBean implements ServiceRemote&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-3516087990114448642?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/3516087990114448642/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/12/remote-ejb-call-in-glassfish.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/3516087990114448642'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/3516087990114448642'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/12/remote-ejb-call-in-glassfish.html' title='Remote EJB call in Glassfish'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-5413335707733075229</id><published>2011-12-14T00:49:00.001-08:00</published><updated>2011-12-14T00:49:13.093-08:00</updated><title type='text'>wsimport and wsgen</title><content type='html'>&lt;p&gt;Difference between ws-import and ws-gen.&lt;/p&gt; &lt;p&gt;&lt;a href="http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=/com.ibm.websphere.express.doc/info/exp/ae/rwbs_wsimport.html"&gt;wsimport &lt;/a&gt;- The &lt;span class="cmdname"&gt;wsimport&lt;/span&gt;  command-line tool supports the top-down approach to developing JAX-WS  Web services. When you start with an existing WSDL file, use the &lt;span class="cmdname"&gt;wsimport&lt;/span&gt; command-line tool to generate the required JAX-WS artifacts.&lt;/p&gt; &lt;p&gt;&lt;a href="http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=/com.ibm.websphere.express.doc/info/exp/ae/rwbs_wsgen.html"&gt;wsgen &lt;/a&gt;-  When using a bottoms-up approach to develop JAX-WS Web services and you  are starting from a service endpoint implementation, use the &lt;span class="cmdname"&gt;wsgen&lt;/span&gt; tool to generate the required JAX-WS artifacts.&lt;/p&gt; &lt;p&gt;A great article combining maven/NetBeans with the above tools can be found &lt;a href="http://java.sun.com/mailers/techtips/enterprise/2008/TechTips_Jan08.html"&gt;here&lt;/a&gt;. And mind you, it actually works right out of the box.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-5413335707733075229?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/5413335707733075229/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/12/wsimport-and-wsgen.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/5413335707733075229'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/5413335707733075229'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/12/wsimport-and-wsgen.html' title='wsimport and wsgen'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-8327697197644110416</id><published>2011-12-14T00:48:00.001-08:00</published><updated>2011-12-14T00:48:25.954-08:00</updated><title type='text'>Jax-RS</title><content type='html'>This is just a placeholder for a longer article. Use this &lt;a href="https://jersey.dev.java.net/use/getting-started.html"&gt;link&lt;/a&gt; as of now.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-8327697197644110416?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/8327697197644110416/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/12/jax-rs_14.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/8327697197644110416'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/8327697197644110416'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/12/jax-rs_14.html' title='Jax-RS'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-8559956144285666580</id><published>2011-12-14T00:47:00.001-08:00</published><updated>2011-12-14T00:47:39.059-08:00</updated><title type='text'>Jax WS small annotated class</title><content type='html'>package helloservice.basicauth.endpoint;&lt;br /&gt;&lt;div id=":1bo" class="ii gt"&gt;&lt;br /&gt;import javax.jws.WebMethod;&lt;br /&gt;import javax.jws.WebService;&lt;br /&gt;import javax.annotation.security.&lt;wbr&gt;RolesAllowed;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;@WebService&lt;br /&gt;public class Hello {&lt;br /&gt;private String message = new String("Hello, ");&lt;br /&gt;&lt;br /&gt;@WebMethod&lt;br /&gt;@RolesAllowed("msa_admins")&lt;br /&gt;public String sayHello(String name) {&lt;br /&gt;return message + name + ".";&lt;br /&gt;}&lt;br /&gt;}&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-8559956144285666580?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/8559956144285666580/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/12/jax-ws-small-annotated-class.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/8559956144285666580'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/8559956144285666580'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/12/jax-ws-small-annotated-class.html' title='Jax WS small annotated class'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-522697969861976132</id><published>2011-12-14T00:46:00.003-08:00</published><updated>2011-12-14T00:46:54.372-08:00</updated><title type='text'>Java runtime</title><content type='html'>First, java.exe does not take a directory structure to start, rather it  takes the name of the class. You can speficy the classpath if you don't  want . as the classpath.&lt;br /&gt;&lt;br /&gt;E.g.&lt;br /&gt;&lt;br /&gt;To run your Temp_prog from Current you could use:&lt;br /&gt;java -classpath Sub Temp_prog&lt;br /&gt;or&lt;br /&gt;java -classpath c:\Current\Sub Temp_prog&lt;br /&gt;&lt;br /&gt;if Temp_Prog was actually defined in the package Sub then you could execute:&lt;br /&gt;java Sub.Temp_prog&lt;br /&gt;or&lt;br /&gt;java -classpath c:\Current Sub.Temp_prog&lt;br /&gt;&lt;br /&gt;You could also call the programs main directly if its in the classpath&lt;br /&gt;e.g.&lt;br /&gt;java -classpath .;Sub Cur_prog&lt;br /&gt;And in your class,&lt;br /&gt;Temp_Prog.main(new String[]{"Arg1,"Arg2"});&lt;br /&gt;&lt;br /&gt;If you really do want to change the current directory, then you could just use the 3 argument version of exec&lt;br /&gt;e.g.&lt;br /&gt;Runtime.getRuntime().exec(" &lt;div id=":19l" class="ii gt"&gt;&lt;wbr&gt;java Temp_prog",null,new File("Sub"));&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-522697969861976132?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/522697969861976132/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/12/java-runtime.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/522697969861976132'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/522697969861976132'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/12/java-runtime.html' title='Java runtime'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-868932491536785141</id><published>2011-12-14T00:46:00.001-08:00</published><updated>2011-12-14T00:46:23.095-08:00</updated><title type='text'>Microscopic small JPA class</title><content type='html'>&lt;pre style="margin-left: 40px;"&gt;import javax.annotation.Resource;&lt;br /&gt;import javax.naming.Context;&lt;br /&gt;import javax.persistence.&lt;wbr&gt;EntityManager;&lt;br /&gt;import javax.persistence.&lt;wbr&gt;PersistenceContext;&lt;br /&gt;&lt;br /&gt;@PersistenceContext(name = "persistence/LogicalName",&lt;br /&gt;unitName = "jpawebPU")&lt;br /&gt;public class CustomerDAO {&lt;br /&gt;@Resource&lt;br /&gt;private javax.transaction.&lt;wbr&gt;UserTransaction utx;&lt;br /&gt;protected void persist(Object object) {&lt;br /&gt;&lt;br /&gt;try {&lt;br /&gt;Context ctx =&lt;br /&gt;(Context) new javax.naming.InitialContext().&lt;br /&gt;lookup("java:comp/env");&lt;br /&gt;utx.begin();&lt;br /&gt;EntityManager em = (EntityManager)&lt;br /&gt;ctx.lookup("persistence/&lt;wbr&gt;LogicalName");&lt;br /&gt;&lt;br /&gt;em.persist(object);&lt;br /&gt;utx.commit();&lt;br /&gt;} catch (Exception e) {&lt;br /&gt;java.util.logging.Logger.&lt;wbr&gt;getLogger(&lt;br /&gt;getClass().getName()).log(&lt;br /&gt;java.util.logging.Level.&lt;wbr&gt;SEVERE,&lt;br /&gt;"exception caught", e);&lt;br /&gt;throw new RuntimeException(e);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;See this &lt;a href="http://www.packtpub.com/article/interacting-with-databases-through-java-persistence-api"&gt;link&lt;/a&gt;.&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-868932491536785141?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/868932491536785141/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/12/microscopic-small-jpa-class.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/868932491536785141'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/868932491536785141'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/12/microscopic-small-jpa-class.html' title='Microscopic small JPA class'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-8297624235400414544</id><published>2011-12-14T00:45:00.003-08:00</published><updated>2011-12-14T00:45:43.035-08:00</updated><title type='text'>Login</title><content type='html'>package guessNumber;&lt;br /&gt;&lt;br /&gt;import java.io.IOException;&lt;br /&gt;import java.net. &lt;div id=":vh" class="ii gt"&gt;&lt;wbr&gt;MalformedURLException;&lt;br /&gt;&lt;br /&gt;import javax.servlet.Filter;&lt;br /&gt;import javax.servlet.FilterChain;&lt;br /&gt;import javax.servlet.FilterConfig;&lt;br /&gt;import javax.servlet.&lt;wbr&gt;ServletException;&lt;br /&gt;import javax.servlet.ServletRequest;&lt;br /&gt;import javax.servlet.ServletResponse;&lt;br /&gt;import javax.servlet.http.&lt;wbr&gt;HttpServletRequest;&lt;br /&gt;import javax.servlet.http.&lt;wbr&gt;HttpSession;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt;* A filter which is located "on-top" of the j_security_check made by Glassfish&lt;br /&gt;* server when the user is trying to access a restricted webresource.&lt;br /&gt;* This filter creates Login jobs. Logout jobs are created by the MsaWebSessionListener&lt;br /&gt;* class.&lt;br /&gt;*&lt;br /&gt;* @author Ericsson MIEP Team&lt;br /&gt;* @since Dec 1, 2008&lt;br /&gt;*/&lt;br /&gt;public class LoginFilter implements Filter&lt;br /&gt;{&lt;br /&gt;protected FilterConfig filterConfig = null;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt;* {@inheritDoc}&lt;br /&gt;*/&lt;br /&gt;public void init(FilterConfig config) throws ServletException&lt;br /&gt;{&lt;br /&gt;this.filterConfig = config;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt;* {@inheritDoc}&lt;br /&gt;*/&lt;br /&gt;public void destroy()&lt;br /&gt;{&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt;* {@inheritDoc}&lt;br /&gt;*/&lt;br /&gt;public void doFilter(ServletRequest request, ServletResponse response,&lt;br /&gt;FilterChain chain) throws IOException, ServletException&lt;br /&gt;{&lt;br /&gt;HttpServletRequest httpRequest = null;&lt;br /&gt;&lt;br /&gt;if (!(request instanceof HttpServletRequest))&lt;br /&gt;{&lt;br /&gt;chain.doFilter(request, response);&lt;br /&gt;return;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;httpRequest = (HttpServletRequest) request;&lt;br /&gt;HttpSession session = httpRequest.getSession();&lt;br /&gt;String remoteUser = httpRequest.getRemoteUser();&lt;br /&gt;&lt;br /&gt;chain.doFilter(request, response);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;i web.xml&lt;br /&gt;&lt;br /&gt;&lt;filter&gt;&lt;br /&gt;&lt;filter-name&gt;LoginFilter&lt;!--&lt;wbr--&gt;filter-name&amp;gt;&lt;br /&gt;&lt;filter-class&gt;guessNumber.&lt;wbr&gt;LoginFilter&lt;/filter-class&gt;&lt;br /&gt;&lt;/filter-name&gt;&lt;/filter&gt;&lt;br /&gt;&lt;filter-mapping&gt;&lt;br /&gt;&lt;filter-name&gt;LoginFilter&lt;!--&lt;wbr--&gt;filter-name&amp;gt;&lt;br /&gt;&lt;url-pattern&gt;/*&lt;/url-pattern&gt;&lt;br /&gt;&lt;/filter-name&gt;&lt;/filter-mapping&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-8297624235400414544?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/8297624235400414544/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/12/login.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/8297624235400414544'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/8297624235400414544'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/12/login.html' title='Login'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-6373420467082759477</id><published>2011-12-14T00:45:00.001-08:00</published><updated>2011-12-14T00:45:18.758-08:00</updated><title type='text'>JAX RS</title><content type='html'>&lt;p&gt;This example is taken from the &lt;a href="http://www.myeclipseide.com/documentation/quickstarts/webservices_rest/"&gt;MyEclipse&lt;/a&gt; web site.&lt;/p&gt; &lt;p&gt;3 things needed to get it to work.&lt;/p&gt; &lt;p&gt;web.xml&lt;/p&gt; &lt;p&gt;***********************************&lt;/p&gt; &lt;p&gt;&lt;!--?xml version="1.0" encoding="UTF-8"?--&gt;&lt;br /&gt;&lt;web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/javaee&lt;br /&gt;http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt;&lt;br /&gt;&lt;servlet&gt;&lt;br /&gt;&lt;display-name&gt;JAX-RS REST Servlet&lt;/display-name&gt;&lt;br /&gt;&lt;servlet-name&gt;JAX-RS REST Servlet&lt;/servlet-name&gt;&lt;br /&gt;&lt;servlet-class&gt;&lt;br /&gt;com.sun.jersey.spi.container.servlet.ServletContainer&lt;br /&gt;&lt;/servlet-class&gt;&lt;br /&gt;&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;&lt;br /&gt;&lt;/servlet&gt;&lt;br /&gt;&lt;servlet-mapping&gt;&lt;br /&gt;&lt;servlet-name&gt;JAX-RS REST Servlet&lt;/servlet-name&gt;&lt;br /&gt;&lt;url-pattern&gt;/services/*&lt;/url-pattern&gt;&lt;br /&gt;&lt;/servlet-mapping&gt;&lt;br /&gt;&lt;welcome-file-list&gt;&lt;br /&gt;&lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;&lt;br /&gt;&lt;/welcome-file-list&gt;&lt;br /&gt;&lt;/web-app&gt;&lt;/p&gt; &lt;p&gt;*******************************************************&lt;/p&gt; &lt;p&gt;A service annotated properly.&lt;/p&gt; &lt;p&gt;package com.myeclipseide.ws;&lt;br /&gt;&lt;br /&gt;import java.util.ArrayList;&lt;br /&gt;import java.util.List;&lt;br /&gt;import java.util.TreeMap;&lt;br /&gt;&lt;br /&gt;import javax.ws.rs.Consumes;&lt;br /&gt;import javax.ws.rs.GET;&lt;br /&gt;import javax.ws.rs.POST;&lt;br /&gt;import javax.ws.rs.Path;&lt;br /&gt;import javax.ws.rs.PathParam;&lt;br /&gt;import javax.ws.rs.Produces;&lt;br /&gt;&lt;br /&gt;import com.sun.jersey.spi.resource.Singleton;&lt;br /&gt;&lt;br /&gt;@Produces("application/xml")&lt;br /&gt;@Path("customers")&lt;br /&gt;@Singleton&lt;br /&gt;public class CustomerResource {&lt;br /&gt;&lt;br /&gt;private TreeMap&lt;integer, customer=""&gt; customerMap = new TreeMap&lt;integer, customer=""&gt;();&lt;br /&gt;&lt;br /&gt;public CustomerResource() {&lt;br /&gt;Customer customer = new Customer();&lt;br /&gt;customer.setName("Harold Abernathy");&lt;br /&gt;customer.setAddress("Sheffield, UK");&lt;br /&gt;addCustomer(customer);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;@GET&lt;br /&gt;public List&lt;customer&gt; getCustomers() {&lt;br /&gt;List&lt;customer&gt; customers = new ArrayList&lt;customer&gt;();&lt;br /&gt;customers.addAll(customerMap.values());&lt;br /&gt;return customers;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;@GET&lt;br /&gt;@Path("{id}")&lt;br /&gt;public Customer getCustomer(@PathParam("id") int cId) {&lt;br /&gt;return customerMap.get(cId);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;@POST&lt;br /&gt;@Path("add")&lt;br /&gt;@Produces("text/plain")&lt;br /&gt;@Consumes("application/xml")&lt;br /&gt;public String addCustomer(Customer customer) {&lt;br /&gt;int id = customerMap.size();&lt;br /&gt;customer.setId(id);&lt;br /&gt;customerMap.put(id, customer);&lt;br /&gt;return "Customer " + customer.getName() + " added with Id " + id;&lt;br /&gt;}&lt;br /&gt;}&lt;/customer&gt;&lt;/customer&gt;&lt;/customer&gt;&lt;/integer,&gt;&lt;/integer,&gt;&lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;p&gt;*****************&lt;/p&gt; &lt;p&gt;An entity to work with&lt;/p&gt; &lt;p&gt;package com.myeclipseide.ws;&lt;br /&gt;&lt;br /&gt;import javax.xml.bind.annotation.XmlRootElement;&lt;br /&gt;&lt;br /&gt;@XmlRootElement&lt;br /&gt;public class Customer {&lt;br /&gt;&lt;br /&gt;private int id;&lt;br /&gt;private String name;&lt;br /&gt;private String address;&lt;br /&gt;&lt;br /&gt;public int getId() {&lt;br /&gt;return id;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void setId(int id) {&lt;br /&gt;this.id = id;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public String getName() {&lt;br /&gt;return name;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void setName(String name) {&lt;br /&gt;this.name = name;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public String getAddress() {&lt;br /&gt;return address;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void setAddress(String address) {&lt;br /&gt;this.address = address;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;/p&gt; &lt;p&gt;*************************&lt;/p&gt; &lt;p&gt;That's it. You will need some jars implementing the rs api.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-6373420467082759477?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/6373420467082759477/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/12/jax-rs.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/6373420467082759477'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/6373420467082759477'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/12/jax-rs.html' title='JAX RS'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-6376811320386607590</id><published>2011-12-14T00:44:00.001-08:00</published><updated>2011-12-14T00:44:40.724-08:00</updated><title type='text'>Derby with JUnit</title><content type='html'>package xxx;&lt;br /&gt;&lt;br /&gt;import java.sql.Connection;&lt;br /&gt;import java.sql.DriverManager;&lt;br /&gt;import java.sql.ResultSet;&lt;br /&gt;import java.sql.SQLException;&lt;br /&gt;import java.sql.Statement;&lt;br /&gt;import java.util.List;&lt;br /&gt;import java.util.Properties;&lt;br /&gt;&lt;br /&gt;import org.jmock.Mockery;&lt;br /&gt;import org.junit.After;&lt;br /&gt;import org.junit.Before;&lt;br /&gt;import org.junit.Test;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public class A  {&lt;br /&gt;&lt;br /&gt;Mockery context = new Mockery();&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;private String protocol = "jdbc:derby:";&lt;br /&gt;private Connection conn;&lt;br /&gt;&lt;br /&gt;String strUrl = "jdbc:derby:DefaultAddressBook;create=true";&lt;br /&gt;&lt;br /&gt;private String strCreateAddressTable =&lt;br /&gt;"CREATE table APP.BAPOR (ID INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY"&lt;br /&gt;+ "(START WITH 1, INCREMENT BY 1),"&lt;br /&gt;+ "LASTNAME    VARCHAR(30))";&lt;br /&gt;&lt;br /&gt;@Before&lt;br /&gt;public void setUp() throws Exception {&lt;br /&gt;super.setUp();&lt;br /&gt;&lt;br /&gt;String userHomeDir = System.getProperty("user.home", ".");&lt;br /&gt;String systemDir = userHomeDir + "/.addressbook";&lt;br /&gt;&lt;br /&gt;// Set the db system directory.&lt;br /&gt;System.setProperty("derby.system.home", systemDir);&lt;br /&gt;&lt;br /&gt;Properties props = new Properties();&lt;br /&gt;props.put("user", "dbuser");&lt;br /&gt;props.put("password", "dbuserpwd");&lt;br /&gt;&lt;br /&gt;String driver = "org.apache.derby.jdbc.EmbeddedDriver";&lt;br /&gt;Class.forName(driver).newInstance();&lt;br /&gt;&lt;br /&gt;conn = DriverManager.getConnection(strUrl, props);&lt;br /&gt;Statement statement = conn.createStatement();&lt;br /&gt;//statement.execute(strCreateAddressTable);&lt;br /&gt;&lt;br /&gt;// DriverManager.getConnection("jdbc:derby:;shutdown=true") &amp;amp;&amp;amp;&lt;br /&gt;//this.createTables(conn);&lt;br /&gt;//this.insert();&lt;br /&gt;this.select();&lt;br /&gt;System.out.println("jjjjjj");&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;@Test&lt;br /&gt;public void testDummy() throws Exception {&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;@After&lt;br /&gt;public void tearDown() {&lt;br /&gt;try {&lt;br /&gt;&lt;br /&gt;//DriverManager.getConnection("jdbc:derby:DefaultAddressBook;shutdown=true");&lt;br /&gt;&lt;br /&gt;} catch (Exception e) {&lt;br /&gt;e.printStackTrace();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public void insert() {&lt;br /&gt;&lt;br /&gt;Statement stmt = null;&lt;br /&gt;try {&lt;br /&gt;stmt = conn.createStatement();&lt;br /&gt;stmt.executeUpdate("INSERT INTO APP.BAPOR( LASTNAME ) VALUES ( 'Kungen' ) ");&lt;br /&gt;stmt.close();&lt;br /&gt;} catch (Exception e) {&lt;br /&gt;e.printStackTrace();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void select() {&lt;br /&gt;&lt;br /&gt;Statement stmt = null;&lt;br /&gt;try {&lt;br /&gt;stmt = conn.createStatement();&lt;br /&gt;ResultSet rs = stmt.executeQuery("SELECT * FROM APP.BAPOR");&lt;br /&gt;&lt;br /&gt;while (rs.next()) {&lt;br /&gt;int numColumns = rs.getMetaData().getColumnCount();&lt;br /&gt;for (int i = 1; i &amp;lt;= numColumns; i++) {&lt;br /&gt;// Column numbers start at 1.&lt;br /&gt;// Also there are many methods on the result set to return&lt;br /&gt;// the column as a particular type. Refer to the Sun&lt;br /&gt;// documentation&lt;br /&gt;// for the list of valid conversions.&lt;br /&gt;System.out.println("COLUMN " + i + " = " + rs.getObject(i));&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;rs.close();&lt;br /&gt;&lt;br /&gt;stmt.close();&lt;br /&gt;} catch (Exception e) {&lt;br /&gt;e.printStackTrace();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;       &lt;span class="article_separator"&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-6376811320386607590?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/6376811320386607590/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/12/derby-with-junit.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/6376811320386607590'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/6376811320386607590'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/12/derby-with-junit.html' title='Derby with JUnit'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-7765380826014173407</id><published>2011-12-14T00:43:00.002-08:00</published><updated>2011-12-14T00:44:06.438-08:00</updated><title type='text'>Glassfish remote debugging</title><content type='html'>&lt;p&gt;I did this to get my glassfish up and running and enabled for jmx remote connection.&lt;/p&gt; &lt;p&gt;Check this line in the domains/domain1/config/domain.xml&lt;/p&gt; &lt;p&gt;&lt;jmx-connector all="false" address="0.0.0.0" name="admin-realm" enabled="true" name="system" port="8686" protocol="rmi_jrmp" enabled="false"&gt;&lt;/jmx-connector&gt;&lt;/p&gt; &lt;p&gt;and change false to true.&lt;/p&gt; &lt;p&gt;Add this line.&lt;/p&gt; &lt;p&gt;&lt;jvm-options&gt;-Djava.rmi.server.hostname=&lt;your_ip&gt;&lt;/your_ip&gt;&lt;/jvm-options&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;In the log domains/domain1/logs/server.log you will see a log  statement lookling like this that shows that jmx is activated, it looks  like this&lt;/p&gt; &lt;p&gt;&lt;code style="font-weight: bold;"&gt;service:jmx:rmi:///jndi/rmi://&lt;your_ip&gt;:8686/jmxrmi&lt;/your_ip&gt;&lt;/code&gt;&lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;p&gt;Verify that you can connect with this connection string in jconsole&lt;/p&gt; &lt;p&gt;&lt;code style="font-weight: bold;"&gt;service:jmx:rmi:///jndi/rmi://&lt;your_ip&gt;:8686/jmxrmi&lt;/your_ip&gt;&lt;/code&gt;&lt;/p&gt; &lt;p&gt;uid and pwd is by default admin/adminadmin&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-7765380826014173407?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/7765380826014173407/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/12/glassfish-remote-debugging.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/7765380826014173407'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/7765380826014173407'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/12/glassfish-remote-debugging.html' title='Glassfish remote debugging'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-7330080604434686779</id><published>2011-12-14T00:43:00.001-08:00</published><updated>2011-12-14T00:43:40.742-08:00</updated><title type='text'>Ruby On Rails (Install on Ubuntu)</title><content type='html'>&lt;p&gt;&lt;strong&gt;How to install Ruby on Rails on Ubuntu 9.04&lt;/strong&gt;&lt;/p&gt; &lt;ul&gt;&lt;li&gt;sudo apt-get install ruby1.8-dev&lt;/li&gt;&lt;li&gt;sudo apt-get install rubygems&lt;/li&gt;&lt;li&gt;gem install rails (Didn't help me. Claims it did not find rails afterwards.)&lt;/li&gt;&lt;li&gt;sudo apt-get install rails&lt;/li&gt;&lt;li&gt;rails blog&lt;/li&gt;&lt;li&gt;cd blog&lt;/li&gt;&lt;li&gt;sudo gem install sqlite3-ruby  (generates a lot of errors)&lt;/li&gt;&lt;li&gt;rake db:create (generate warnings)&lt;/li&gt;&lt;li&gt;vi &lt;tt&gt;app/views/home/index.html.erb (and edit the file)&lt;br /&gt;&lt;/tt&gt;&lt;/li&gt;&lt;li&gt;&lt;code class="html"&gt;script/generate controller home index (generates warnings)&lt;/code&gt;&lt;/li&gt;&lt;li&gt;script/server&lt;/li&gt;&lt;li&gt;Go to http://127.0.0.1:3000/  (In browser it shows start page.)&lt;/li&gt;&lt;li&gt;Go to &lt;tt&gt;http://localhost:3000/home/index and see the default index file that is created at the beginningand which you edited.&lt;/tt&gt;&lt;/li&gt;&lt;/ul&gt; This is it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-7330080604434686779?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/7330080604434686779/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/12/ruby-on-rails-install-on-ubuntu.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/7330080604434686779'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/7330080604434686779'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/12/ruby-on-rails-install-on-ubuntu.html' title='Ruby On Rails (Install on Ubuntu)'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-7432603154538287575</id><published>2011-12-14T00:42:00.001-08:00</published><updated>2011-12-14T00:42:44.030-08:00</updated><title type='text'>Netbeans and Google App engine</title><content type='html'>Interested in the cloud? Well, besides using gmail and google docs and  stuff like that. It has been possible for a while to upload web  applications onto Googles servers.&lt;br /&gt;&lt;br /&gt;Step 1: Sign up for a Google App engine account&lt;br /&gt;Navigate here  &lt;a title="Google App Engine" href="http://appengine.google.com/"&gt;http://appengine.google.com&lt;/a&gt; and create an account if you do not have it already.&lt;br /&gt;&lt;br /&gt;Step 2: Create an application by browsing here, &lt;a href="https://appengine.google.com/start/createapp"&gt;https://appengine.google.com/start/createapp&lt;/a&gt;.&lt;br /&gt;I named my first application just aspemo. Thus, my finished application url will be  &lt;a href="http://aspemo.appspot.com/"&gt;http://aspemo.appspot.com/&lt;/a&gt; .&lt;br /&gt;&lt;br /&gt;Step 3: Install the Google app sdk&lt;br /&gt;Go here and download the sdk,&lt;a href="http://code.google.com/appengine/downloads.html#Download_the_Google_App_Engine_SDK"&gt; http://code.google.com/appengine/downloads.html#Download_the_Google_App_Engine_SDK&lt;/a&gt;.&lt;br /&gt;I am more familiar with Java than with Python so I use my Java sdk to do this.&lt;br /&gt;&lt;br /&gt;Step 4: Download the &lt;a href="http://netbeans.org/downloads/"&gt;Netbeans&lt;/a&gt; IDE.&lt;br /&gt;&lt;br /&gt;Step 5: Install the Google app plugin for Netbeans.&lt;br /&gt;Go &lt;a href="http://kenai.com/projects/nbappengine/pages/NBInstall"&gt;here&lt;/a&gt; and follow the instructions (only two lines).&lt;br /&gt;&lt;br /&gt;Step 6: Install Google App engine as a service&lt;br /&gt;Go  to the folder services (in Netbeans) and choose Server and add a new  Google App engine. Point it towards your installation of the Google sdk.&lt;br /&gt;&lt;br /&gt;Step 7: Build the guestbook application&lt;br /&gt;Go inot Netbeans and choose;&lt;br /&gt;File-&amp;gt;New Project&lt;br /&gt;Samples-&amp;gt;Google App Engine&lt;br /&gt;Remember  to change the application tag in the applicationContext.xml file to be  the same as the application name you used in Google App Engine. In my  case, I must change this to aspemo.&lt;br /&gt;Now right click on the project  gusetbook and do clean and build followed by deploy to Google App  Engine. You will be promted for credentials. Your app should be found in  your http://.appspot.com.&lt;br /&gt;My app can be found at &lt;a href="http://aspemo.appspot.com/"&gt;http://aspemo.appspot.com&lt;/a&gt;&lt;br /&gt;Click the green run button when you are done.&lt;br /&gt;&lt;br /&gt;Then  I used netbeans to create my sample application. Remember to name your  application (in the appengine-web.xml file) with the same name as you  created the application with on Google app enging.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-7432603154538287575?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/7432603154538287575/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/12/netbeans-and-google-app-engine.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/7432603154538287575'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/7432603154538287575'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/12/netbeans-and-google-app-engine.html' title='Netbeans and Google App engine'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-1309712018445384763</id><published>2011-12-14T00:41:00.001-08:00</published><updated>2011-12-14T00:41:24.915-08:00</updated><title type='text'>Subversion and svnsync and websvn</title><content type='html'>&lt;p&gt;This tutorial shows how to syncronzie your own local repository with a  remote repository and sync with it. The result shall be displayed in  the websvn GUI. How to add basic security is shown in apache2 and basic  security on this web site.&lt;/p&gt; &lt;p&gt;------------------------------------------------&lt;/p&gt; &lt;h3&gt;Time to setup a local  repository.&lt;/h3&gt; &lt;p&gt;Step 1 Create a local directory to store checked out files.&lt;/p&gt; &lt;p&gt;mkdir /development/localcopy&lt;/p&gt; &lt;p&gt;Step 2 Create a subversion repository.&lt;/p&gt; &lt;p&gt;mkdir /development/repos/&lt;/p&gt; &lt;p&gt;svnadmin create /development/repos/svn&lt;/p&gt; &lt;p&gt;Step 3 Check out (nothing) to localcopy&lt;/p&gt; &lt;p&gt;cd /development/localcopy&lt;/p&gt; &lt;p&gt;svn co file:///development/repos/svn/&lt;/p&gt; &lt;p&gt;Check to see that you have a .svn file in /development/localcopy (then you are home free)&lt;/p&gt; &lt;p&gt;Ok so far what do we got.&lt;/p&gt; &lt;p&gt;We have one local repository (shall be synked) and one place to put our checked out files.&lt;/p&gt; &lt;p&gt;------------------------------------------------------------------------------&lt;/p&gt; &lt;h3&gt;Time to connect local repository with remote&lt;/h3&gt; &lt;p&gt;Let us now sync our local repository with the remote repository. Let  us assume our remote repository is https://svn.foo.bar.com/svn. Let us  assume that there is a user svnuser and a  password there svnpwd.&lt;/p&gt; &lt;p&gt;Do like this. Edit this file&lt;/p&gt; &lt;p&gt;vi /development/repos/svn/hooks/pre-revprop-change.tmpl and make it look like this;&lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;table style="background-color: #7f807f;" border="0"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;p&gt;USER="$3"&lt;/p&gt; &lt;p&gt;if [ "$USER" = "svnuser" ]; then exit 0; fi&lt;br /&gt;echo "Only the svnsync user can change revprops" &amp;gt;&amp;amp;2&lt;br /&gt;exit 1&lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;p&gt;and save it as /development/repos/svn/hooks/pre-revprop-change (that is without file ending)&lt;/p&gt; &lt;p&gt;Go to the repository.&lt;/p&gt; &lt;p&gt;cd /development/repos/svn&lt;/p&gt; &lt;p&gt;svnsync init --username svnuser file:///development/repos/svn/ https://svn.foo.bar.com/svn&lt;/p&gt; &lt;p&gt;This will set up the sync of your local repository.&lt;/p&gt; &lt;p&gt;And now sync;&lt;/p&gt; &lt;p&gt;svnsync sync file:///development/repos/svn/&lt;/p&gt; &lt;p&gt;This might take a while, but in the end your repository will be synchronized.&lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;h3&gt;Time to connect svnweb with local repository&lt;/h3&gt; &lt;p&gt;Edit this websvn file.&lt;/p&gt; &lt;p&gt;vi /usr/share/websvn/include/config.php&lt;/p&gt; &lt;p&gt;Add this line.&lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;p&gt;$config-&amp;gt;addRepository('NameToDisplay', 'file:///development/repos/svn');&lt;/p&gt; &lt;h3&gt;Crontab job&lt;/h3&gt; &lt;p&gt;How do we  make svnsync do it regulary, well a crontab job. Let's do it every 30 minutes.&lt;/p&gt; &lt;p&gt;Create script to call from crontab and save it as sync.sh in /development/repository&lt;/p&gt; &lt;p&gt;#!/bin/sh&lt;br /&gt;cd /development/repository&lt;br /&gt;svnsync sync file:///development/repository/svn&lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;p&gt;chmod file to 755&lt;/p&gt; &lt;p&gt;Do this&lt;/p&gt; &lt;p&gt;crontab -e&lt;/p&gt; &lt;p&gt;add line&lt;/p&gt; &lt;p&gt;*/5 * * * * /development/repository/sync.sh&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-1309712018445384763?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/1309712018445384763/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/12/subversion-and-svnsync-and-websvn.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/1309712018445384763'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/1309712018445384763'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/12/subversion-and-svnsync-and-websvn.html' title='Subversion and svnsync and websvn'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-8458792490291440076</id><published>2011-12-14T00:39:00.000-08:00</published><updated>2011-12-14T00:40:11.897-08:00</updated><title type='text'>Add basic auth to apache2</title><content type='html'>&lt;p&gt;Here is an extremely short how to allow basic auth to an apache2 web server.&lt;/p&gt; &lt;p&gt;The prerequisites are (in my case):&lt;/p&gt; &lt;table style="background-color: #7c837f;" border="0"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;Ubuntu 9.10                                                                 &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Apache2&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;p&gt;Step 1: Install appropriate packages.&lt;/p&gt; &lt;p&gt;apt-get install subversion&lt;/p&gt; &lt;p&gt;apt-get install websvn (this will be stored in /usr/share/websvn)&lt;/p&gt; &lt;p&gt;Step 2: Add basic auth to apache2 configuration&lt;/p&gt; &lt;p&gt;Edit vi /etc/apache2/sites-available/default&lt;/p&gt; &lt;table style="background-color: #7c837f;" border="0"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;directory var="" www=""&gt;&lt;br /&gt;Options Indexes Includes FollowSymLinks MultiViews&lt;br /&gt;AllowOverride AuthConfig&lt;br /&gt;Order allow,deny &lt;/directory&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Allow from all&lt;br /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;p&gt;Step 3: Create a directory ouside of apache2 for password file&lt;/p&gt; &lt;table style="background-color: #7c837f;" border="0"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;mkdir /dev/secure                                                          &lt;br /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;p&gt;&lt;br /&gt;Step 4: Add a new user (for basic auth)&lt;/p&gt; &lt;table style="background-color: #7c837f;" border="0"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;htpasswd -c /dev/secure/password testuser                  &lt;br /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;p&gt; &lt;/p&gt; &lt;p&gt;Step 5) Create a test directory in the webserver such as /var/www/test&lt;/p&gt; &lt;p&gt;Step 6) Add a .htaccess file there&lt;br /&gt;Add this content to that file&lt;/p&gt; &lt;table style="background-color: #7c837f;" border="0"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;AuthType Basic&lt;br /&gt;AuthName "Restricted Access"&lt;br /&gt;AuthUserFile /dev/secure/password&lt;br /&gt;Require user testuser&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;p&gt; &lt;/p&gt; &lt;p&gt;Step 7) Add a simple index.html file in the directory&lt;br /&gt;Add content to index.html&lt;/p&gt; &lt;table style="background-color: #7c837f;" border="0"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;hola&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;p&gt;Step 8) Restart apache2 /etc/init.d/apache2 restart&lt;/p&gt; &lt;p&gt;That's it&lt;br /&gt;&lt;br /&gt;If you browse to localhost/test you shall be promted  to enter user testuser and the password you used when creating the  password file in step 4&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-8458792490291440076?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/8458792490291440076/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/12/add-basic-auth-to-apache2.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/8458792490291440076'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/8458792490291440076'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/12/add-basic-auth-to-apache2.html' title='Add basic auth to apache2'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-2486736979430694932</id><published>2011-12-02T04:47:00.000-08:00</published><updated>2011-12-02T04:48:58.769-08:00</updated><title type='text'>RestService</title><content type='html'>Add jersey libs in WEB-INF/lib directory&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;web.xml&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;!--?xml version="1.0" encoding="UTF-8"?--&gt;&lt;/div&gt;&lt;div&gt;&lt;web-app xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"&gt;&lt;/web-app&gt;&lt;/div&gt;&lt;div&gt;  &lt;display-name&gt;org.aja&lt;/display-name&gt;&lt;/div&gt;&lt;div&gt;  &lt;servlet&gt;&lt;/servlet&gt;&lt;/div&gt;&lt;div&gt;    &lt;servlet-name&gt;Jersey REST Service&lt;/servlet-name&gt;&lt;/div&gt;&lt;div&gt;    &lt;servlet-class&gt;com.sun.jersey.spi.container.servlet.ServletContainer&lt;/servlet-class&gt;&lt;/div&gt;&lt;div&gt;    &lt;init-param&gt;&lt;/init-param&gt;&lt;/div&gt;&lt;div&gt;      &lt;param-name&gt;com.sun.jersey.config.property.packages&lt;/param-name&gt;&lt;/div&gt;&lt;div&gt;      &lt;param-value&gt;org.aja&lt;/param-value&gt;&lt;/div&gt;&lt;div&gt;    &lt;/div&gt;&lt;div&gt;    &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;&lt;/div&gt;&lt;div&gt;  &lt;/div&gt;&lt;div&gt;  &lt;servlet-mapping&gt;&lt;/servlet-mapping&gt;&lt;/div&gt;&lt;div&gt;    &lt;servlet-name&gt;Jersey REST Service&lt;/servlet-name&gt;&lt;/div&gt;&lt;div&gt;    &lt;url-pattern&gt;/rest/*&lt;/url-pattern&gt;&lt;/div&gt;&lt;div&gt;  &lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Java classes:&lt;/div&gt;&lt;div&gt;&lt;div&gt;package org.aja;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;import javax.ws.rs.GET;&lt;/div&gt;&lt;div&gt;import javax.ws.rs.Path;&lt;/div&gt;&lt;div&gt;import javax.ws.rs.Produces;&lt;/div&gt;&lt;div&gt;import javax.ws.rs.core.MediaType;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;@Path("/hello")&lt;/div&gt;&lt;div&gt;public class Hello {&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;// This method is called if TEXT_PLAIN is request&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;@GET&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;@Produces(MediaType.TEXT_PLAIN)&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;public String sayPlainTextHello() {&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;return "Hello Jersey";&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;// This method is called if XML is request&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;@GET&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;@Produces(MediaType.TEXT_XML)&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;public String sayXMLHello() {&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;return "&lt;!--?xml version=\"1.0\"?--&gt;" + "&lt;hello&gt; Hello Jersey" + "&lt;/hello&gt;";&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;// This method is called if HTML is request&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;@GET&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;@Produces(MediaType.TEXT_HTML)&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;public String sayHtmlHello() {&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;return " " + "&lt;title&gt;" + "Hello Jersey" + "&lt;/title&gt;"&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;     &lt;/span&gt;+ "&lt;h1&gt;" + "Hello Jersey" + "&lt;/h1&gt;" + " ";&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;// This method is called if HTML is request&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;    &lt;/span&gt;@GET&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;    &lt;/span&gt;@Produces(MediaType.APPLICATION_JSON)&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;    &lt;/span&gt;public String sayJsonHello() {&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;     &lt;/span&gt;return " " + "&lt;title&gt;" + "Hello Jersey" + "&lt;/title&gt;"&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;       &lt;/span&gt;+ "&lt;h1&gt;" + "Hello Jersey" + "&lt;/h1&gt;" + " ";&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;    &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Java classes:&lt;/div&gt;&lt;div&gt;&lt;div&gt;package org.aja;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;import javax.ws.rs.GET;&lt;/div&gt;&lt;div&gt;import javax.ws.rs.Path;&lt;/div&gt;&lt;div&gt;import javax.ws.rs.Produces;&lt;/div&gt;&lt;div&gt;import javax.ws.rs.core.MediaType;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;import org.aja.model.Todo;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;@Path("/todo")&lt;/div&gt;&lt;div&gt;public class TodoResource {&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;// This method is called if XMLis request&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;@GET&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;@Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;public Todo getXML() {&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;Todo todo = new Todo();&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;todo.setSummary("This is my first todo");&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;todo.setDescription("This is my first todo");&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;return todo;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;// This can be used to test the integration with the browser&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;@GET&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;@Produces( { MediaType.TEXT_XML })&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;public Todo getHTML() {&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;Todo todo = new Todo();&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;todo.setSummary("This is my first todo");&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;todo.setDescription("This is my first todo");&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;return todo;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;*************&lt;/div&gt;&lt;div&gt;&lt;div&gt;package org.aja.model;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;import javax.xml.bind.annotation.XmlRootElement;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;@XmlRootElement&lt;/div&gt;&lt;div&gt;// JAX-RS supports an automatic mapping from JAXB annotated class to XML and JSON&lt;/div&gt;&lt;div&gt;// Isn't that cool?&lt;/div&gt;&lt;div&gt;public class Todo {&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;private String summary;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;private String description;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;public String getSummary() {&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;return summary;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;public void setSummary(String summary) {&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;this.summary = summary;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;public String getDescription() {&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;return description;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;public void setDescription(String description) {&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;this.description = description;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;div&gt;*********************&lt;/div&gt;&lt;div&gt;&lt;div&gt;package org.aja;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;import java.net.URI;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;import javax.ws.rs.core.MediaType;&lt;/div&gt;&lt;div&gt;import javax.ws.rs.core.UriBuilder;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;import com.sun.jersey.api.client.Client;&lt;/div&gt;&lt;div&gt;import com.sun.jersey.api.client.ClientResponse;&lt;/div&gt;&lt;div&gt;import com.sun.jersey.api.client.WebResource;&lt;/div&gt;&lt;div&gt;import com.sun.jersey.api.client.config.ClientConfig;&lt;/div&gt;&lt;div&gt;import com.sun.jersey.api.client.config.DefaultClientConfig;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;public class TestClient {&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;public static void main(String[] args) {&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;ClientConfig config = new DefaultClientConfig();&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;Client client = Client.create(config);&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;WebResource service = client.resource(getBaseURI());&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;// Fluent interfaces&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;System.out.println(service.path("rest").path("hello").accept(&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;    &lt;/span&gt;MediaType.TEXT_PLAIN).get(ClientResponse.class).toString());&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;// Get plain text&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;System.out.println(service.path("rest").path("hello").accept(&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;    &lt;/span&gt;MediaType.TEXT_PLAIN).get(String.class));&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;// Get XML&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;System.out.println(service.path("rest").path("hello").accept(&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;    &lt;/span&gt;MediaType.TEXT_XML).get(String.class));&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;// The HTML&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;System.out.println(service.path("rest").path("hello").accept(&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;    &lt;/span&gt;MediaType.TEXT_HTML).get(String.class));&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;// The HTML&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;    &lt;/span&gt;System.out.println(service.path("rest").path("hello").accept(&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;      &lt;/span&gt;MediaType.APPLICATION_JSON).get(String.class));&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;    &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;    &lt;/span&gt;System.out.println(service.path("rest").path("hello").accept(&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;      &lt;/span&gt;MediaType.APPLICATION_JSON).get(ClientResponse.class).toString());&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;    &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;    &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;    &lt;/span&gt;System.out.println(service.path("rest").path("todo").accept(&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;      &lt;/span&gt;MediaType.TEXT_XML).get(String.class));&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;    &lt;/span&gt;// Get XML for application&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;    &lt;/span&gt;System.out.println(service.path("rest").path("todo").accept(&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;      &lt;/span&gt;MediaType.APPLICATION_JSON).get(String.class));&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;    &lt;/span&gt;// Get JSON for application&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;    &lt;/span&gt;System.out.println(service.path("rest").path("todo").accept(&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;      &lt;/span&gt;MediaType.APPLICATION_XML).get(String.class));&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;    &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;private static URI getBaseURI() {&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;return UriBuilder.fromUri(&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;    &lt;/span&gt;"http://localhost:8080/TestRest").build();&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-2486736979430694932?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/2486736979430694932/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/12/restservice.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/2486736979430694932'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/2486736979430694932'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/12/restservice.html' title='RestService'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-9186790194346533175</id><published>2011-10-17T05:01:00.001-07:00</published><updated>2011-10-17T05:01:29.172-07:00</updated><title type='text'>git https error push</title><content type='html'>Create a .netrc-file in the $HOME-directory and provide it with  the needed login:  &lt;pre class="escaped"&gt;machine &lt;servername&gt; login &lt;username&gt; password &lt;password&gt; &lt;/password&gt;&lt;/username&gt;&lt;/servername&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-9186790194346533175?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/9186790194346533175/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/10/git-https-error-push.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/9186790194346533175'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/9186790194346533175'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/10/git-https-error-push.html' title='git https error push'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-3789856313355839246</id><published>2011-10-17T00:23:00.000-07:00</published><updated>2011-10-17T00:25:36.527-07:00</updated><title type='text'>git clone https error</title><content type='html'>Error message.&lt;br /&gt;apache2 error error: server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none while accessing&lt;br /&gt;&lt;br /&gt;&lt;pre class="message"&gt;GIT_SSL_NO_VERIFY=1 git clone &lt;a href="https://alioth.debian.org/anonscm/git/pkg-wml/pkg-wml.git"&gt;https://&amp;lt;server&lt;server&gt;&amp;gt;/&amp;lt;gitreponame&lt;reponame&gt;&amp;gt;.git&lt;/reponame&gt;&lt;/server&gt;&lt;/a&gt;&lt;br /&gt;You can make the workaround permanent&lt;br /&gt;with   echo '[http] sslverify = false' &amp;gt;&amp;gt; ~/.gitconfig&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-3789856313355839246?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/3789856313355839246/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/10/git-clone-https-error.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/3789856313355839246'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/3789856313355839246'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/10/git-clone-https-error.html' title='git clone https error'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-679368163078022122</id><published>2011-10-12T02:44:00.000-07:00</published><updated>2011-10-17T03:07:43.776-07:00</updated><title type='text'>Apache2 ssl php</title><content type='html'>Ok, I started with a broken configuration so I did like this.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Plain http&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;sudo apt-get install apache2 (just to get everything into the db)&lt;br /&gt;&lt;br /&gt;sudo apt-get remove --purge apache2 apache2-utils (remove everything except var/www/)&lt;br /&gt;&lt;br /&gt;sudo apt-get install apache2 (reinstall it)&lt;br /&gt;&lt;br /&gt;Browse to http://localhost&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;Proceed to https&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;sudo a2enmod ssl&lt;br /&gt;&lt;br /&gt;sudo a2ensite default-ssl&lt;br /&gt;&lt;br /&gt;sudo /etc/init.d/apache2 reload&lt;br /&gt;&lt;br /&gt;sudo /etc/init.d/apache2 restart&lt;br /&gt;&lt;br /&gt;Browse to https://localhost&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Proceed to php&lt;/span&gt;&lt;br /&gt;&lt;pre class="screen"&gt;&lt;span class="command"&gt;&lt;strong&gt;sudo apt-get install php5 libapache2-mod-php5 (I got an error php5 do not exists)&lt;br /&gt;&lt;br /&gt;sudo apt-get purge &lt;/strong&gt;&lt;strong&gt;&lt;strong&gt;libapache2-mod-php5&lt;/strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;sudo apt-get install &lt;span class="command"&gt;&lt;strong&gt;&lt;strong&gt;libapache2-mod-php5&lt;/strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;sudo /etc/init.d/apache2 restart&lt;br /&gt;&lt;/pre&gt;Test php installation with the now famous&lt;br /&gt;&lt;br /&gt;mv /var/www/index.html /var/www/index.bak&lt;br /&gt;&lt;br /&gt;create file index.php in /var/www and add this;&lt;br /&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;Do http://localhost&lt;br /&gt;&lt;/pre&gt;Install Git&lt;br /&gt;(To do later)&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Install webapp viewgit&lt;/span&gt;&lt;br /&gt;cp file /var/www/viewgit/inc/config.php to /var/www/viewgit/inc/localconfig.php&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="screen"&gt;&lt;span class="command"&gt;&lt;strong&gt;You are done.&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-679368163078022122?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/679368163078022122/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/10/apache2-ssl.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/679368163078022122'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/679368163078022122'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/10/apache2-ssl.html' title='Apache2 ssl php'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-5125796715621359690</id><published>2011-10-06T01:01:00.000-07:00</published><updated>2011-10-06T01:14:08.079-07:00</updated><title type='text'>Git</title><content type='html'>&lt;div&gt;Assume user name of kingkong&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Generate ssh key if you do not have one&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;mkdir ~/.ssh&lt;/div&gt;&lt;div&gt;chmod 700 ~/.ssh&lt;/div&gt;&lt;div&gt;ssh-keygen -t rsa&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;Generating public/private rsa key pair.&lt;/div&gt;&lt;div&gt;Enter file in which to save the key (/home/kingkong/.ssh/id_rsa):&lt;/div&gt;&lt;meta equiv="content-type" content="text/html; charset=utf-8"&gt;&lt;div&gt;Enter passphrase (empty for no passphrase):&lt;/div&gt;&lt;div&gt;Enter same passphrase again:&lt;/div&gt;&lt;div&gt;Your identification has been saved in /home/kingkong/.ssh/id_rsa.&lt;/div&gt;&lt;meta equiv="content-type" content="text/html; charset=utf-8"&gt;&lt;div&gt;Your public key has been saved in /home/kingkong/.ssh/id_rsa.pub.&lt;/div&gt;&lt;meta equiv="content-type" content="text/html; charset=utf-8"&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Now GIT&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;sudo apt-get -y install git-core gitosis&lt;div&gt;sudo -H -u gitosis gitosis-init &amp;lt; yourKeyFileName&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;(Your key name is the ssh public key name stored in your /home/&lt;user&gt;/.ssh/ without the ending, for instance id_rsa.pub could be the file name then write id_rsa)&lt;/user&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Create an empty directory somewhere&lt;/div&gt;&lt;div&gt;mkdir /tmp/testProj&lt;/div&gt;&lt;div&gt;cd /tmp/testProj&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Clone git repo&lt;/div&gt;&lt;div&gt;git clone gitosis@localhost:gitosis-admin.git&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;Edit file&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;cd gitosis-admin&lt;/div&gt;&lt;div&gt;vi gitosis.conf&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;//add these lines&lt;/div&gt;&lt;div&gt;[group team]&lt;/div&gt;&lt;div&gt;writable = testproject&lt;/div&gt;&lt;div&gt;members = keyfilename&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;//git commands&lt;/div&gt;&lt;div&gt;git commit -a -m "Added a new project"&lt;/div&gt;&lt;div&gt;git push&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;//&lt;/div&gt;&lt;div&gt;mkdir /tmp/testproject&lt;/div&gt;&lt;div&gt;cd /tmp/testproject&lt;/div&gt;&lt;div&gt;git init&lt;/div&gt;&lt;div&gt;touch text_file.txt&lt;/div&gt;&lt;div&gt;git add .&lt;/div&gt;&lt;div&gt;git commit -a -m "Initial import"&lt;/div&gt;&lt;div&gt;git remote add origin gitosis@localhost:testproject.git&lt;/div&gt;&lt;div&gt;git push origin master&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;See: &lt;a href="https://help.ubuntu.com/community/Git"&gt;Ubuntu help page&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-5125796715621359690?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/5125796715621359690/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/10/git.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/5125796715621359690'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/5125796715621359690'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/10/git.html' title='Git'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-2823078314922099772</id><published>2011-07-07T12:15:00.000-07:00</published><updated>2011-07-07T12:16:08.700-07:00</updated><title type='text'>javap</title><content type='html'>javap -c -private TestBytecodeSize):&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-2823078314922099772?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/2823078314922099772/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/07/javap.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/2823078314922099772'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/2823078314922099772'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/07/javap.html' title='javap'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-12222648101523011</id><published>2011-07-07T12:05:00.001-07:00</published><updated>2011-07-07T12:05:54.585-07:00</updated><title type='text'>maven opts</title><content type='html'>-Xms512M -Xmx1024M -XX:MaxPermSize=256M -XX:PermSize=64M&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-12222648101523011?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/12222648101523011/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/07/maven-opts.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/12222648101523011'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/12222648101523011'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/07/maven-opts.html' title='maven opts'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-257042397795512609</id><published>2011-07-07T11:52:00.001-07:00</published><updated>2011-07-07T11:53:14.101-07:00</updated><title type='text'>OPen x</title><content type='html'>ssh -X &lt;a href="http://cf.tgb.verkstad.net/" target="_blank"&gt;&amp;lt;&lt;hostname&gt;&amp;gt;&lt;/hostname&gt;&lt;/a&gt; -l &amp;lt;&lt;username&gt;&amp;gt;&lt;/username&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-257042397795512609?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/257042397795512609/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/07/open-x.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/257042397795512609'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/257042397795512609'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/07/open-x.html' title='OPen x'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-877884246886307346</id><published>2011-06-14T02:59:00.001-07:00</published><updated>2011-06-14T02:59:50.248-07:00</updated><title type='text'>Recursive search and replace on file sed</title><content type='html'>find ./ -type f -exec sed -i ‘s/something/somethingelse/’ {} \;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-877884246886307346?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/877884246886307346/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/06/recursive-search-and-replace-on-file.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/877884246886307346'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/877884246886307346'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/06/recursive-search-and-replace-on-file.html' title='Recursive search and replace on file sed'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-7468353482043076323</id><published>2011-05-22T01:15:00.000-07:00</published><updated>2011-05-22T01:16:32.480-07:00</updated><title type='text'>How to remove avg search from Firefox</title><content type='html'>Tired of having search go through avg.search.com?&lt;br /&gt;&lt;br /&gt;Open Firefox. print about.config in address bar. Search for avg. Reset that value.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-7468353482043076323?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/7468353482043076323/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/05/how-to-remove-avg-search-from-firefox.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/7468353482043076323'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/7468353482043076323'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/05/how-to-remove-avg-search-from-firefox.html' title='How to remove avg search from Firefox'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-3963568660036066612</id><published>2011-05-16T22:46:00.001-07:00</published><updated>2011-05-16T22:46:51.605-07:00</updated><title type='text'>maven release command</title><content type='html'>mvn release:perform -DpreparationGoals="clean install" -Dusername=xxxxx&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-3963568660036066612?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/3963568660036066612/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/05/maven-release-command.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/3963568660036066612'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/3963568660036066612'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/05/maven-release-command.html' title='maven release command'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-6433771543302270225</id><published>2011-05-16T05:05:00.001-07:00</published><updated>2011-05-17T04:18:23.300-07:00</updated><title type='text'>jenkins start on ubuntu</title><content type='html'>sudo -u jenkins java -jar /usr/share/jenkins/jenkins.war --webroot=/var/run/jenkins/war/ --httpPort=8080 --ajp13Port=-1&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-6433771543302270225?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/6433771543302270225/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/05/jenkins-start-on-ubuntu.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/6433771543302270225'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/6433771543302270225'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/05/jenkins-start-on-ubuntu.html' title='jenkins start on ubuntu'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-4032141422912089318</id><published>2011-05-15T23:10:00.000-07:00</published><updated>2011-05-15T23:46:11.268-07:00</updated><title type='text'>svn command</title><content type='html'>svn diff pom.xml&lt;br /&gt;svn commit -m ""&lt;br /&gt;su - mongrel -c 'svn export https://&lt;server&gt;/svn/&lt;name&gt;/trunk/ --username=xxx --password=xxx&lt;br /&gt;&lt;/name&gt;&lt;/server&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-4032141422912089318?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/4032141422912089318/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/05/svn-command.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/4032141422912089318'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/4032141422912089318'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/05/svn-command.html' title='svn command'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-8685623604987250491</id><published>2011-05-11T04:02:00.000-07:00</published><updated>2011-05-11T04:04:06.113-07:00</updated><title type='text'>Add glassfish parameters in command line</title><content type='html'>./asadmin create-jdbc-connection-pool --user admin --passwordfile ./password.txt --datasourceclassname com.mysql.jdbc.jdbc2.optional.MysqlDataSource --restype javax.sql.DataSource --property portNumber=1527:Password=root:User=root:serverName=localhost:databaseName=cthweb_db:Url=jdbc\\:mysql\\://localhost\\:3306/test_db TestDBSQL&lt;br /&gt;&lt;br /&gt;./asadmin create-jdbc-resource --user admin --passwordfile ./password.txt --connectionpoolid TestDBSQL  jdbc/TestDBSQL&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-8685623604987250491?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/8685623604987250491/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/05/add-glassfish-parameters-in-command.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/8685623604987250491'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/8685623604987250491'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/05/add-glassfish-parameters-in-command.html' title='Add glassfish parameters in command line'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-8852362225179116381</id><published>2011-05-06T05:51:00.000-07:00</published><updated>2011-05-06T05:52:06.982-07:00</updated><title type='text'>Ubuntu when scm fails</title><content type='html'>Tag manually.&lt;br /&gt;&lt;br /&gt;svn copy http://&lt;address_from&gt;/trunk http://&lt;address_to&gt;/tags/snapshot-1.7 -m "Tagging the version manually"&lt;br /&gt;&lt;br /&gt;Note, the tags library need to be present.&lt;br /&gt;&lt;br /&gt;&lt;/address_to&gt;&lt;/address_from&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-8852362225179116381?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/8852362225179116381/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/05/ubuntu-when-scm-fails.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/8852362225179116381'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/8852362225179116381'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/05/ubuntu-when-scm-fails.html' title='Ubuntu when scm fails'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-8840615595080516630</id><published>2011-05-06T01:06:00.000-07:00</published><updated>2011-05-06T01:08:19.692-07:00</updated><title type='text'>Maven crashes on Ubuntu</title><content type='html'>Error: An Ant BuildException has occured: java.lang.InternalError: Can't connect to X11 window server using&lt;br /&gt;&lt;br /&gt;Solution: Add -Djava.awt.headless=true to mvn, like this&lt;br /&gt;&lt;br /&gt;mvn install  -Djava.awt.headless=true&lt;pre&gt;&lt;code&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-8840615595080516630?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/8840615595080516630/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/05/maven-crashes-on-ubuntu.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/8840615595080516630'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/8840615595080516630'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/05/maven-crashes-on-ubuntu.html' title='Maven crashes on Ubuntu'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-608930707326476211.post-2121552538780326325</id><published>2011-05-05T03:38:00.000-07:00</published><updated>2011-05-05T03:39:55.731-07:00</updated><title type='text'>SOAPUI on Ubuntu 11.04</title><content type='html'>Err message:&lt;br /&gt;&lt;br /&gt;linux soapui error Exception in thread "XpcMessageLoop" java.lang.RuntimeException: java.io.FileNotFoundException: Library libgthread-2.0 not found at any known locations !&lt;br /&gt;&lt;br /&gt;Uncomment this line.&lt;br /&gt;JAVA_OPTS="$JAVA_OPTS -Dsoapui.jxbrowser.disable=true"&lt;br /&gt;&lt;br /&gt;in file soapui.sh&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/608930707326476211-2121552538780326325?l=aspemo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspemo.blogspot.com/feeds/2121552538780326325/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspemo.blogspot.com/2011/05/soapui-on-ubuntu-1104.html#comment-form' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/2121552538780326325'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/608930707326476211/posts/default/2121552538780326325'/><link rel='alternate' type='text/html' href='http://aspemo.blogspot.com/2011/05/soapui-on-ubuntu-1104.html' title='SOAPUI on Ubuntu 11.04'/><author><name>Aspemo</name><uri>http://www.blogger.com/profile/07217272488635218038</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>8</thr:total></entry></feed>
