<?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-12929415</id><updated>2011-11-28T08:25:19.017+08:00</updated><category term='glassfish'/><category term='arquillian'/><category term='ssh'/><category term='scala'/><category term='wicket'/><category term='google+1'/><title type='text'>Occasional Coder</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://locrianmode.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12929415/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://locrianmode.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Iskandar Salim</name><uri>http://www.blogger.com/profile/09428506537445048234</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>10</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-12929415.post-6986608339875450823</id><published>2011-07-28T12:14:00.001+08:00</published><updated>2011-07-28T12:34:52.482+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='scala'/><title type='text'>Scala by-name parameter</title><content type='html'>&lt;p&gt;I was reading the section "Call-by-Name" in the book &lt;a href="http://www.apress.com/9781430219897"&gt;"Begining Scala"&lt;/a&gt; by David Pollak,&lt;br /&gt;
trying to get my head around by-name parameters. He gave an example,&lt;br /&gt;
&lt;/p&gt;&lt;pre class="brush: scala"&gt;def nano() = {
    println("Getting nano")
    System.nanoTime
}

def delayed(t: =&gt; Long) = { // =&gt; indicates a by-name parameter
    println("In delayed method")
    println("Param: "+t)
    t
}

println(delayed(nano()))
&lt;/pre&gt;&lt;p&gt;Coming from Java and used to call-by-reference, I was expecting the output to be&lt;br /&gt;
&lt;/p&gt;&lt;pre class="brush: plain"&gt;Getting nano
In delayed method
Param: 4513758999378
4513758999378     // same value as Param
&lt;/pre&gt;&lt;p&gt;but the output was&lt;/p&gt;&lt;pre class="brush: plain"&gt;In delayed method
Getting nano
Param: 4475258994017
Getting nano
4475259694720     // different value from Param
&lt;/pre&gt;&lt;p&gt;Re-reading that section a couple of times still doesn't ring a bell (the book is really good though).&lt;br /&gt;
Googling "scala by-name parameters" returns long examples and explanations&lt;br /&gt;
on the subject, and more confusion for an absolute Scala beginner like me.&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;Referring to the &lt;a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"&gt;Scala Language Specification&lt;/a&gt;, section &lt;strong&gt;4.6.1 By-Name Parameters&lt;/strong&gt; finally defreezes my brain.&lt;/p&gt;&lt;blockquote&gt;... argument is not evaluated at the point of function application, but instead is &lt;strong&gt;evaluated at each use within the function&lt;/strong&gt;.&lt;br /&gt;
&lt;/blockquote&gt;&lt;p&gt;Ok. Got it. Back to the example,&lt;br /&gt;
&lt;/p&gt;&lt;pre class="brush: scala"&gt;def delayed(t: =&gt; Long) = {
    println("In delayed method")
    println("Param: "+t) // t or nano() used, so "Getting nano" printed,
                         // then print "Param: " and the return of nano(), e.g. System.nanoTime
    t                    // t or nano() used again, thus print "Getting nano" and the System.nanoTime
                         // would have now elapsed
}
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12929415-6986608339875450823?l=locrianmode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://locrianmode.blogspot.com/feeds/6986608339875450823/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://locrianmode.blogspot.com/2011/07/scala-by-name-parameter.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12929415/posts/default/6986608339875450823'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12929415/posts/default/6986608339875450823'/><link rel='alternate' type='text/html' href='http://locrianmode.blogspot.com/2011/07/scala-by-name-parameter.html' title='Scala by-name parameter'/><author><name>Iskandar Salim</name><uri>http://www.blogger.com/profile/09428506537445048234</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-12929415.post-1348461348568624009</id><published>2011-07-27T11:35:00.005+08:00</published><updated>2011-07-28T12:36:22.203+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='google+1'/><category scheme='http://www.blogger.com/atom/ns#' term='wicket'/><title type='text'>Google +1 callback and Wicket</title><content type='html'>&lt;p&gt;Google plusone tag's &lt;tt&gt;callback&lt;/tt&gt; &lt;a href="http://code.google.com/apis/+1button/#jsapi"&gt;parameter&lt;/a&gt; let's you call a JavaScript function when the plusone button is     clicked. As an example, &lt;/p&gt;&lt;pre class="brush: html"&gt;&amp;lt;g:plusone size="tall" callback="callWicket"&amp;gt;&amp;lt;/g:plusone&amp;gt;
&amp;nbsp;
&lt;/pre&gt;&lt;pre class="brush: js"&gt;&amp;lt;script type="text/javascript"&amp;gt;
        function callWicket(data) {
            // Do something here
        }
    &amp;lt;/script&amp;gt;
&amp;nbsp;
&lt;/pre&gt;&lt;p&gt;What if you want to pass Wicket data (for this example, we'll get the JSON object) when the plusone button is     clicked? There's an explanation of &lt;a href="https://cwiki.apache.org/WICKET/calling-wicket-from-javascript.html"&gt;calling     Wicket from JavaScript&lt;/a&gt;.     We can either use the &lt;tt&gt;wicketAjaxGet&lt;/tt&gt; or &lt;th&gt;wicketAjaxPost&lt;/th&gt; functions provided by the contributed &lt;tt&gt;wicket-ajax.js&lt;/tt&gt; when you add an Ajax behaviour to Wicket components, e.g. adding an &lt;tt&gt;AbstractDefaultAjaxBehavior&lt;/tt&gt;. &lt;/p&gt;&lt;p&gt;We have to build the JavaScript as shown, &lt;/p&gt;&lt;pre class="brush: js"&gt;function callWicket() {
        var wcall = wicketAjaxGet('$url$' + '$args$', function() { }, function() { });
    }
&amp;nbsp;
&lt;/pre&gt;&lt;p&gt;to be generated by the wicket component :-&lt;/p&gt;&lt;pre&gt;&amp;lt;script type="text/javascript" wicket:id="pluscallback"&amp;gt;&amp;lt;/script&amp;gt;
&amp;nbsp;
&lt;/pre&gt;&lt;tt&gt;'$url$'&lt;/tt&gt; is obtained from &lt;tt&gt;behave.getCallbackUrl()&lt;/tt&gt; and &lt;tt&gt;$args&lt;/tt&gt; will be constructed from plusone JSON object. Thus, &lt;pre class="brush: java"&gt;final AbstractDefaultAjaxBehavior behave = new AbstractDefaultAjaxBehavior() {

        protected void respond(final AjaxRequestTarget target) {
            // Do what you want with the data
        }
    };
    add(behave);

    CharSequence url = behave.getCallbackUrl();
    CharSequence args = "&amp;href='+data.href+'&amp;state='+data.state";
    StringBuffer sb = new StringBuffer();
    sb.append("function callWicket(data, id) { \n");
    sb.append("     var wcall = wicketAjaxGet('");
    sb.append(url); // the $url$
    sb.append(args); // the $args$
    sb.append(", function() { }, function() { });");
    sb.append("    }");
    Label pluscallback = new Label("pluscallback", sb.toString());   // the script tag
    add(pluscallback);
&amp;nbsp;
&lt;/pre&gt;Getting the parameters from the JavaScript &lt;pre class="brush: java"&gt;RequestCycle.get().getRequest().getParameter("href");
    RequestCycle.get().getRequest().getParameter("state");
&amp;nbsp;
&lt;/pre&gt;&lt;p&gt;You can download the Wicket quickstart &lt;a href="https://sites.google.com/site/locrianmode/plusone.zip?attredirects=0&amp;d=1"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12929415-1348461348568624009?l=locrianmode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://locrianmode.blogspot.com/feeds/1348461348568624009/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://locrianmode.blogspot.com/2011/07/google-1-callback-and-wicket.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12929415/posts/default/1348461348568624009'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12929415/posts/default/1348461348568624009'/><link rel='alternate' type='text/html' href='http://locrianmode.blogspot.com/2011/07/google-1-callback-and-wicket.html' title='Google +1 callback and Wicket'/><author><name>Iskandar Salim</name><uri>http://www.blogger.com/profile/09428506537445048234</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-12929415.post-7242392468860234023</id><published>2011-07-20T22:41:00.015+08:00</published><updated>2011-07-28T12:37:04.128+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='google+1'/><category scheme='http://www.blogger.com/atom/ns#' term='wicket'/><title type='text'>Google +1 and Wicket Ajax Components</title><content type='html'>&lt;p&gt;I wanted to incorporate the google +1 buttons for submitted links on a social bookmarking website I was building, which uses Wicket. Adding +1 buttons was easy. &lt;/p&gt;&lt;p&gt;The html tag: &lt;/p&gt;&lt;pre  class="brush: html"&gt;&amp;lt;g:plusone wicket:id="plusone"&amp;gt;&amp;lt;/g:plusone&amp;gt;
&lt;/pre&gt;&lt;p&gt;Adding a dynamic href attribute to the tag was made simple using the &lt;tt&gt;AttributeModifier&lt;/tt&gt; class: &lt;/p&gt;&lt;pre class="brush: java"&gt;Label plusone = new Label("plusone");
plusone.add(new AttributeModifier("href", true, new Model(submittedLink.getUrl())));
.
&lt;/pre&gt;&lt;p&gt;The rendered html tag, as sent to the browser will be: &lt;/p&gt;&lt;pre class="brush: html"&gt;&amp;lt;g:plusone wicket:id="plusone" href="http://www.exampleurl.com"&amp;gt;&amp;lt;/g:plusone&amp;gt;
&lt;/pre&gt;&lt;p&gt;with it's final form as a &lt;tt&gt;&amp;lt;div&amp;gt;&lt;/tt&gt; tag with lot's of content. &lt;/p&gt;&lt;p&gt;However, the +1 buttons does not show after Wicket's Ajax calls, for example when clicking on a &lt;tt&gt;AjaxFallbackLink&lt;/tt&gt; to refresh the section containing the button. I am guessing that the &lt;tt&gt;&amp;lt;g:plusone&amp;gt;&lt;/tt&gt; tag is rendered to the final button form only initially when the page is first requested/loaded. &lt;/p&gt;&lt;p&gt;You can however fire up the JavaScript to manually render the tag using &lt;tt&gt;gapi.plusone.go()&lt;/tt&gt;. Thus, overriding the Wicket Ajax component's &lt;tt&gt;onAjaxEvent&lt;/tt&gt; will do the trick. &lt;/p&gt;&lt;pre class="brush: java"&gt;@Override
protected void onAjaxEvent(AjaxRequestTarget target) {
   target.appendJavascript("gapi.plusone.go()");
   super.onAjaxEvent(target);
}
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12929415-7242392468860234023?l=locrianmode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://locrianmode.blogspot.com/feeds/7242392468860234023/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://locrianmode.blogspot.com/2011/07/google-plus-one-and-wicket-ajax.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12929415/posts/default/7242392468860234023'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12929415/posts/default/7242392468860234023'/><link rel='alternate' type='text/html' href='http://locrianmode.blogspot.com/2011/07/google-plus-one-and-wicket-ajax.html' title='Google +1 and Wicket Ajax Components'/><author><name>Iskandar Salim</name><uri>http://www.blogger.com/profile/09428506537445048234</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>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12929415.post-8044104396889985809</id><published>2011-06-20T10:27:00.011+08:00</published><updated>2011-07-21T00:47:08.554+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ssh'/><title type='text'>Basic Linux Security - SSH</title><content type='html'>&lt;p&gt;It's been some time since my &lt;a href="http://www.linode.com/"&gt;Linode&lt;/a&gt; VPS has been up. Haven't been paying any attention to it since I've been busy coding a web application. Thought I'd do some housekeeping, starting with the logs files and guess what? There's quite a number of individuals who are keen on getting into the server. Keep trying as I need lots practice to keep you out. I get a couple of these unique visitors daily. Here's one. From the /var/log/auth.log, &lt;/p&gt;

&lt;pre class="brush: bash"&gt;
Jun 19 10:13:03 debian sshd[327]: Invalid user mirain from 210.83.226.181
Jun 19 10:13:03 debian sshd[327]: pam_unix(sshd:auth): check pass; user unknown
Jun 19 10:13:03 debian sshd[327]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=210.83.226.181
Jun 19 10:13:05 debian sshd[327]: Failed password for invalid user mirain from 210.83.226.181 port 58621 ssh2
Jun 19 10:13:06 debian sshd[329]: reverse mapping checking getaddrinfo for reverse.gdsz.cncnet.net [210.83.226.181] failed - POSSIBLE BREAK-IN ATTEMPT!
Jun 19 10:13:06 debian sshd[329]: Invalid user opt2 from 210.83.226.181
Jun 19 10:13:06 debian sshd[329]: pam_unix(sshd:auth): check pass; user unknown
Jun 19 10:13:06 debian sshd[329]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=210.83.226.181
Jun 19 10:13:08 debian sshd[329]: Failed password for invalid user opt2 from 210.83.226.181 port 58909 ssh2
Jun 19 10:13:10 debian sshd[331]: reverse mapping checking getaddrinfo for reverse.gdsz.cncnet.net [210.83.226.181] failed - POSSIBLE BREAK-IN ATTEMPT!
Jun 19 10:13:10 debian sshd[331]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=210.83.226.181  user=root
Jun 19 10:13:12 debian sshd[331]: Failed password for root from 210.83.226.181 port 59144 ssh2
Jun 19 10:13:13 debian sshd[333]: reverse mapping checking getaddrinfo for reverse.gdsz.cncnet.net [210.83.226.181] failed - POSSIBLE BREAK-IN ATTEMPT!
Jun 19 10:13:13 debian sshd[333]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=210.83.226.181  user=root
Jun 19 10:13:16 debian sshd[333]: Failed password for root from 210.83.226.181 port 59447 ssh2
Jun 19 10:13:17 debian sshd[335]: reverse mapping checking getaddrinfo for reverse.gdsz.cncnet.net [210.83.226.181] failed - POSSIBLE BREAK-IN ATTEMPT!
Jun 19 10:13:17 debian sshd[335]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=210.83.226.181  user=root
Jun 19 10:13:19 debian sshd[335]: Failed password for root from 210.83.226.181 port 59763 ssh2
Jun 19 10:13:21 debian sshd[337]: reverse mapping checking getaddrinfo for reverse.gdsz.cncnet.net [210.83.226.181] failed&lt;/pre&gt;
&lt;p&gt;A quick google gives some simple tips for my ssh setup. I'll just list it here for future reference.
&lt;/p&gt;&lt;ul&gt;
&lt;li&gt;
Disable root login. In &lt;code&gt;/etc/ssh/sshd_config&lt;/code&gt;
&lt;code&gt;PermitRootLogin no&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
Change the port sshd is running on, e.g.
&lt;code&gt;Port 2229&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Install &lt;a href="http://www.fail2ban.org/"&gt;fail2ban&lt;/a&gt;. Package description: bans IPs that cause multiple authentication errors &lt;/li&gt;
&lt;li&gt;Change the shell for &lt;code&gt;nobody&lt;/code&gt; to &lt;code&gt;/bin/false&lt;/code&gt; or &lt;code&gt;/bin/nologin&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There's still others but these will do for now. Have to get back to coding.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12929415-8044104396889985809?l=locrianmode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://locrianmode.blogspot.com/feeds/8044104396889985809/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://locrianmode.blogspot.com/2011/06/basic-linux-security-ssh.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12929415/posts/default/8044104396889985809'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12929415/posts/default/8044104396889985809'/><link rel='alternate' type='text/html' href='http://locrianmode.blogspot.com/2011/06/basic-linux-security-ssh.html' title='Basic Linux Security - SSH'/><author><name>Iskandar Salim</name><uri>http://www.blogger.com/profile/09428506537445048234</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-12929415.post-8037145875821785210</id><published>2010-03-27T16:01:00.005+08:00</published><updated>2011-07-28T12:37:32.212+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='arquillian'/><category scheme='http://www.blogger.com/atom/ns#' term='glassfish'/><title type='text'>Integration Testing JPA and EJB 3 with Arquillian and GlassFish Embedded</title><content type='html'>&lt;p&gt;By default, the Arquillian container for GlassFish embedded creates a temporary instance every time you run the &lt;a href="http://community.jboss.org/en/arquillian"&gt;Arquillian&lt;/a&gt; test. So how do we go about setting up JNDI datasources for GlassFish embedded? Well, for now you could make a tiny change to GlassfishEmbeddedContainer.java (in arquillian-glassfish-embedded-30 maven artifact) so it'll setup your embedded instance at a permanent location. Then, you can setup all the datasources you want in the instance's domain.xml file.&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;Make the changes to GlassfishEmbeddedContainer.java and rebuild the jars to your local maven repository&lt;br /&gt;
&lt;/p&gt;&lt;pre class="brush: java"&gt;public GlassFishEmbeddedContainer() {
                final Server.Builder builder = new Server.Builder(GlassFishEmbeddedContainer.class.getName());

                final EmbeddedFileSystem.Builder embeddedFsBuilder = new EmbeddedFileSystem.Builder();

                // final EmbeddedFileSystem embeddedFs = embeddedFsBuilder.build();
                final EmbeddedFileSystem embeddedFs = embeddedFsBuilder.
                    instanceRoot(new File("src/test/glassfish")). // set the instance root
                build();
                builder.embeddedFileSystem(embeddedFs);
                server = builder.build();

                server.addContainer(ContainerBuilder.Type.all);
            }

        &lt;/pre&gt;&lt;br /&gt;
&lt;pre class="brush: java"&gt;@Override
    public void start() throws LifecycleException {
        try {
            for (EmbeddedContainer contianer : server.getContainers()) {
                // do not bind the embedded glassfish to any port
                // instead, the instance will use the port specified in the domain.xml file
                //contianer.bind(server.createPort(port), "http");
                contianer.start();
            }
        } catch (Exception e) {
            throw new LifecycleException("Could not start container", e);
        }
    }
&lt;/pre&gt;&lt;br /&gt;
&lt;p&gt;Here's a screenshot of directory and files generated by the Glassfish embedded when you run the test. However, you have to create your own domain.xml and place it under the config folder. You can copy this file from your GlassFish v3 installation and modify it accordingly.&lt;br /&gt;
&lt;/p&gt;&lt;img src="http://sites.google.com/site/locrianmode/domain.xml.png" alt=""/&gt;&lt;br /&gt;
&lt;p&gt;Sample datasource setup in domain.xml&lt;/p&gt;&lt;pre class="brush: xml"&gt;&lt;resources&gt;
    &lt;jdbc-resource jndi-name="jdbc/helpdesk" pool-name="HelpdeskPool" object-type="user" enabled="true"/&gt;
    &lt;jdbc-connection-pool connection-validation-method="auto-commit"
        datasource-classname="org.h2.jdbcx.JdbcDataSource"
        name="HelpdeskPool"
        res-type="javax.sql.DataSource"&gt;
        &lt;property name="Password" value="helpdesk"/&gt;
        &lt;property name="User" value="helpdesk"/&gt;
        &lt;property name="serverName" value="localhost"/&gt;
        &lt;property name="DatabaseName" value="helpdesk"/&gt;
        &lt;property name="url" value="jdbc:h2:tcp://localhost/~/helpdesk"/&gt;
    &lt;/jdbc-connection-pool&gt;
&lt;/resources&gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;p&gt;The test&lt;br /&gt;
&lt;/p&gt;&lt;pre class="brush: java"&gt;@RunWith(Arquillian.class)
public class TicketFacadeTest {

    @EJB
    private TicketFacade ticketFacade;

    @Deployment
    public static JavaArchive createDeployment() {
        return Archives.create("test.jar", JavaArchive.class).
                addClasses(
                Ticket.class, // be sure to include your JPA entities, else Glassfish embedded will not pick it up
                TicketFacade.class,
                TicketFacadeBean.class).
                addManifestResource(new File("src/main/resources/META-INF/persistence.xml"));
    }

    @Test
    public void shouldBeAbleToInjectEJB() throws Exception {
        Ticket ticket = new Ticket();
        ticket.setDescription("This is a new ticket.");
        ticket.setPriority(Priority.SEVERE);
        ticket.setStatus(Status.NEW);
        ticketFacade.create(ticket);

        List&lt;ticket&gt; tickets = ticketFacade.findAll();
        Assert.assertEquals(1, tickets.size());

    }
}
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;p&gt;&lt;a href="http://sites.google.com/site/locrianmode/helpdesk.zip?attredirects=0&amp;d=1"&gt;Download&lt;/a&gt; the project.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12929415-8037145875821785210?l=locrianmode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://locrianmode.blogspot.com/feeds/8037145875821785210/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://locrianmode.blogspot.com/2010/03/integration-testing-jpa-and-ejb-3-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12929415/posts/default/8037145875821785210'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12929415/posts/default/8037145875821785210'/><link rel='alternate' type='text/html' href='http://locrianmode.blogspot.com/2010/03/integration-testing-jpa-and-ejb-3-with.html' title='Integration Testing JPA and EJB 3 with Arquillian and GlassFish Embedded'/><author><name>Iskandar Salim</name><uri>http://www.blogger.com/profile/09428506537445048234</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-12929415.post-8150350929667163818</id><published>2006-09-08T12:18:00.005+08:00</published><updated>2009-07-12T08:52:45.683+08:00</updated><title type='text'>Calculating page request times for your web application</title><content type='html'>&lt;p&gt;It has been 3 weeks since I started developing jobBoard, a web application for online recruitment/jobs database. Time now for some performance numbers! &lt;/p&gt;
&lt;p&gt;How do you accurately measure the processing time it takes for each request on your web application? An example,&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;User clicks on a link on a page&lt;/li&gt;
  &lt;li&gt;Request goes through a couple of servlet filters, e.g acegi, sitemesh filters &lt;/li&gt;
  &lt;li&gt;The corresponding controllers/actions process the request, calls DAOs&lt;/li&gt;
  &lt;li&gt;DAOs/ORMs queries the native database system and returns results to controller&lt;/li&gt;
  &lt;li&gt;Controller gets results from DAOs and puts request attributes to JSP/Velocity etc. page template &lt;/li&gt;
  &lt;li&gt;Page served up by the web server. &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There's a good article on &lt;a href="http://www.javaworld.com/javaworld/jw-06-2001/jw-0622-filters.html"&gt;servlet filters&lt;/a&gt; with an example just to do the above. However, I needed to present the process time on the requested web page but once the filter chain is executed, I can't put the execution time as a request attribute to be used by the page template. But here's a neat trick.&lt;/p&gt;
&lt;p&gt;Put  the 'before' time into the request attribute, &lt;/p&gt;
&lt;pre class="brush:java"&gt;
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

  long before = System.currentTimeMillis();
  request.setAttribute("before", before); // add here
  chain.doFilter(request, response); 
  long after = System.currentTimeMillis();
&lt;/pre&gt;
&lt;p&gt;Then in my JSP page,&lt;/p&gt;
&lt;pre class="brush:xml"&gt;
Request processed in &lt;%= System.currentTimeMillis() - Long.valueOf(pageContext.getRequest().getAttribute("before").toString()) %&gt; ms
&lt;/pre&gt;
&lt;p&gt;The values are the same as when using the example TimeFilter as it is&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.myjavaserver.com/~jabong/blogger/processtime1.gif" alt="" width="420" height="380" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.myjavaserver.com/~jabong/blogger/processtime2.gif" alt="Process Time" width="420" height="359" /&gt;. &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12929415-8150350929667163818?l=locrianmode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://locrianmode.blogspot.com/feeds/8150350929667163818/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://locrianmode.blogspot.com/2006/09/calculating-page-request-times-for-your.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12929415/posts/default/8150350929667163818'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12929415/posts/default/8150350929667163818'/><link rel='alternate' type='text/html' href='http://locrianmode.blogspot.com/2006/09/calculating-page-request-times-for-your.html' title='Calculating page request times for your web application'/><author><name>Iskandar Salim</name><uri>http://www.blogger.com/profile/09428506537445048234</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-12929415.post-6588054011909129627</id><published>2006-09-01T19:13:00.004+08:00</published><updated>2009-04-19T09:28:52.955+08:00</updated><title type='text'>Testing your Java Persistence API queries interactively</title><content type='html'>&lt;p&gt;One of aspects of developing with ORMs is to test your JPA, EJB, Hibernate QL queries and get the results you wanted before hard coding it into your web application. For Hibernate, there's Hibernate tools but what about JPA? And within the Spring framework. Fortunately, the Spring framework provides a class (org.springframework.test.jpa.AbstractJpaTests;) to test your DAOs, which you can just adapt to make a sort of 'Query Tester'.&lt;/p&gt;
&lt;p&gt;Here's what I did &lt;/p&gt;
&lt;pre class="brush:java;"&gt;
public class JpaJobboardTests extends AbstractJpaTests {

  private JobDao jobDao;
  
  protected String[] getConfigLocations() {
    return new String[] {
      "applicationContext-jpa.xml"
    };
  }
        
    public void testQuery() {
        Query q = sharedEntityManager.createQuery(

                "SELECT DISTINCT j FROM Job j " +
                "JOIN j.industries i " +
                "JOIN j.employmentTypes e " +
                "JOIN j.qualification q " +
                "WHERE " +
                "q.id BETWEEN 2 AND 4" +
                " AND " +
                "i.id IN (4) " +
                " AND e.id IN (3)"

                );
        List&lt;Job&gt; jobs = q.getResultList();
        Iterator iterator = jobs.iterator();
        while (iterator.hasNext()) {
            Job job = (Job)iterator.next();
            System.out.println(job.getId() + " : " + job.getPosition());
            System.out.println(job.getIndustries());
            System.out.println(job.getEmploymentTypes());
            System.out.println(job.getQualification().getId());
        }
    }

    public void testGetAllJobs() {
        List jobs = this.jobDao.findAll();        
    }
    
    public JobDao getJobDao() {
        return jobDao;
    }
    
    public void setJobDao(JobDao jobDao) {
        this.jobDao = jobDao;
    }
    
}
&lt;/pre&gt;
&lt;p&gt;Plug it into my favorite IDE, and run it. You can edit your queries and see the results interactively. &lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.myjavaserver.com/~jabong/blogger/querytester.gif" alt="" width="420" height="415" /&gt;&lt;/p&gt;
&lt;p&gt;Sure, you could code a seperate application just to do this, with named queries stored in a seperate XML file, and changing the queries in the external file, and not the source codes and recompiling every time. &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12929415-6588054011909129627?l=locrianmode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://locrianmode.blogspot.com/feeds/6588054011909129627/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://locrianmode.blogspot.com/2006/09/testing-your-java-persistence-api.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12929415/posts/default/6588054011909129627'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12929415/posts/default/6588054011909129627'/><link rel='alternate' type='text/html' href='http://locrianmode.blogspot.com/2006/09/testing-your-java-persistence-api.html' title='Testing your Java Persistence API queries interactively'/><author><name>Iskandar Salim</name><uri>http://www.blogger.com/profile/09428506537445048234</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-12929415.post-3461481806306324643</id><published>2006-08-31T16:28:00.009+08:00</published><updated>2010-03-27T09:00:54.265+08:00</updated><title type='text'>Using the Display Tag with external sorting and paging</title><content type='html'>&lt;p&gt;I was comparing between using using &lt;a href="http://valuelist.sourceforge.net/"&gt;Value List Handler&lt;/a&gt; and the &lt;a href="http://www.displaytag.org"&gt;Display Tag Library&lt;/a&gt; to do sorting and paging of my web appliaction's result sets and decided on using the Display Tag Library for it's much simpler configuration and because of the latest release's external sorting and paging features. Created a &lt;a href="http://www.myjavaserver.com/~jabong/blogger/DisplayTagHelper.java.txt"&gt;helper class&lt;/a&gt; to get the parameters provided by the display tag to pass to the DAOs, otherwise the code in the controller/action gets a litlle messy. Here's pieces of what i did.&lt;/p&gt;
&lt;p&gt;In the JSP&lt;/p&gt;

&lt;script type="syntaxhighlighter" class="brush: xml"&gt;&lt;![CDATA[
&lt;display:table name="jobs" sort="external" defaultsort="1" pagesize="${pageSize}" id="jobs" partialList="true" size="${size}" requestURI=""&gt;
    &lt;display:column property="datePosted" format="{0,date,dd MMM yy}" sortName="datePosted" sortable="true" title="Date" /&gt;
    &lt;display:column sortable="true" sortName="position" title="Position" &gt;
        &lt;a href="job.view?id=${jobs.id}"&gt;${jobs.position}&lt;/a&gt;
    &lt;/display:column&gt;       
    &lt;display:column property="company.name" sortable="true" sortName="company.name" title="Company" /&gt;
    &lt;display:column property="experience" sortable="true" sortName="experience" title="Exp" /&gt;.     .    
&lt;/display:table&gt;
]]&gt;
&lt;/script&gt;


&lt;p&gt;In the controller (I'm using Spring MVC) &lt;/p&gt;
&lt;script type="syntaxhighlighter" class="brush: java"&gt;&lt;![CDATA[
    public ModelAndView industryHandler(HttpServletRequest request,
        HttpServletResponse response) throws ServletRequestBindingException {
        int pageSize = getPageSize(); // retrieve from application context declaration
        DisplayTagHelper dth = new DisplayTagHelper();
        dth.setDefaultOrder("datePosted desc");
        dth.setOrderByObject("job"); //to match name used in JPAQL in DAO
        dth.setPageSize(pageSize);
        dth.setTableId("jobs"); //to match name in displaytag name property in &lt;display:table&gt; tag
        dth.process(request);

        Long id = ServletRequestUtils.getRequiredLongParameter(request, "id");

        request.setAttribute("size", getJobDao().findByIndustry(id).size());
        request.setAttribute("pageSize", pageSize);
        request.setAttribute("industry", getIndustryDao().load(id).getName());

        List&lt;Job&gt; jobs = getJobDao()
                             .findByIndustry(dth.getStartPosition(), pageSize,
                dth.getOrderBy(), id);

        return new ModelAndView("jobs", "jobs", jobs);
    }
]]&gt;
&lt;/script&gt;
&lt;p&gt;In the DAO &lt;/p&gt;
&lt;script type="syntaxhighlighter" class="brush: java"&gt;&lt;![CDATA[
    public List&lt;Job&gt; findByIndustry(int startPosition, int maxResult,
        String orderBy, Long id) throws DataAccessException {
        Query q = em.createQuery(
                "SELECT DISTINCT job FROM Job job, IN (job.industries) AS i WHERE i.id = :id" +
                orderBy);
        q.setParameter("id", id);
        q.setFirstResult(startPosition);
        q.setMaxResults(maxResult);

        return q.getResultList();
    }
]]&gt;
&lt;/script&gt;
&lt;p&gt;Currently the banner does not show correct values. e.g if u have 10 as the page size, it should show 1-10 for first page, 11-20 for second page. But it always shows 1-10 for all the pages. However, this will probably be &lt;a href="http://jira.codehaus.org/browse/DISPL-303"&gt;fixed&lt;/a&gt; in next release. &lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.myjavaserver.com/~jabong/blogger/pagesort.gif" alt="" width="415" height="287" /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12929415-3461481806306324643?l=locrianmode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://locrianmode.blogspot.com/feeds/3461481806306324643/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://locrianmode.blogspot.com/2006/08/using-display-tag-with-external-sorting.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12929415/posts/default/3461481806306324643'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12929415/posts/default/3461481806306324643'/><link rel='alternate' type='text/html' href='http://locrianmode.blogspot.com/2006/08/using-display-tag-with-external-sorting.html' title='Using the Display Tag with external sorting and paging'/><author><name>Iskandar Salim</name><uri>http://www.blogger.com/profile/09428506537445048234</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>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12929415.post-115589164446863637</id><published>2006-08-18T16:52:00.001+08:00</published><updated>2009-07-18T22:37:31.626+08:00</updated><title type='text'>Spring 2.0 form tags</title><content type='html'>&lt;p&gt;I like the Spring's form tags. It just does what it what I wanted. Registered a custom date editor in the controller and used Spring's select tag for the date selection instead of input to a text box.
&lt;/p&gt;
&lt;pre class="brush:xml"&gt;
&amp;lt;form:select path=&amp;quot;birthDate.date&amp;quot;&amp;gt;
  &amp;lt;c:foreach var=&amp;quot;date&amp;quot; begin=&amp;quot;1&amp;quot; end=&amp;quot;31&amp;quot; step=&amp;quot;1&amp;quot;&amp;gt;
    &amp;lt;form:option value=&amp;quot;${date}&amp;quot;&amp;gt;&amp;lt;/form:option&amp;gt;
  &amp;lt;/c:foreach&amp;gt;
&amp;lt;/form:select&amp;gt;

&amp;lt;form:select path=&amp;quot;birthDate.month&amp;quot;&amp;gt;
  &amp;lt;c:foreach var=&amp;quot;month&amp;quot; begin=&amp;quot;0&amp;quot; end=&amp;quot;11&amp;quot; step=&amp;quot;1&amp;quot;&amp;gt;
    &amp;lt;form:option value=&amp;quot;${month}&amp;quot; label=&amp;quot;${1+ month}&amp;quot;&amp;gt;&amp;lt;/form:option&amp;gt;
  &amp;lt;/c:foreach&amp;gt;
&amp;lt;/form:select&amp;gt;

&amp;lt;form:select path=&amp;quot;birthDate.year&amp;quot;&amp;gt;
  &amp;lt;c:foreach var=&amp;quot;year&amp;quot; begin=&amp;quot;45&amp;quot; end=&amp;quot;106&amp;quot; step=&amp;quot;1&amp;quot;&amp;gt;
    &amp;lt;form:option value=&amp;quot;${year}&amp;quot; label=&amp;quot;${1900 + year}&amp;quot;&amp;gt;&amp;lt;/form:option&amp;gt;
  &amp;lt;/c:foreach&amp;gt;
&amp;lt;/form:select&amp;gt;

  &amp;lt;spring:bind path=&amp;quot;account.birthDate&amp;quot;&amp;gt;
  &amp;lt;span class=&amp;quot;error&amp;quot;&amp;gt;${status.errorMessage}&amp;lt;/span&amp;gt;
  &amp;lt;/spring:bind&amp;gt;
&lt;/pre&gt;
Doing forms for date inputs used to be a pain with Struts.
&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/12929415-115589164446863637?l=locrianmode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://locrianmode.blogspot.com/feeds/115589164446863637/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://locrianmode.blogspot.com/2006/08/i-like-springs-form-tags.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12929415/posts/default/115589164446863637'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12929415/posts/default/115589164446863637'/><link rel='alternate' type='text/html' href='http://locrianmode.blogspot.com/2006/08/i-like-springs-form-tags.html' title='Spring 2.0 form tags'/><author><name>Iskandar Salim</name><uri>http://www.blogger.com/profile/09428506537445048234</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-12929415.post-115589051744644485</id><published>2006-08-18T16:35:00.000+08:00</published><updated>2006-08-18T16:49:32.690+08:00</updated><title type='text'>Hibernate Tools and Java Persistence API?</title><content type='html'>I missed using Hibernate's table generation tools. Currently am working on a web application and wanted to try learning to use the Java Persistence API . I am using netbeans 5.5 beta as my IDE and as of now, the table generation from entity classes can only be used when using the Sun Application server and using JSF as the web framework. As a temporary solution, I used the  JSF/JPA/DDL generation and switched to running Spring MVC+JPA on the same project.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12929415-115589051744644485?l=locrianmode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://locrianmode.blogspot.com/feeds/115589051744644485/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://locrianmode.blogspot.com/2006/08/i-missed-using-hibernates-table.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12929415/posts/default/115589051744644485'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12929415/posts/default/115589051744644485'/><link rel='alternate' type='text/html' href='http://locrianmode.blogspot.com/2006/08/i-missed-using-hibernates-table.html' title='Hibernate Tools and Java Persistence API?'/><author><name>Iskandar Salim</name><uri>http://www.blogger.com/profile/09428506537445048234</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></feed>
