tag:blogger.com,1999:blog-64272874400006367632024-03-05T06:29:53.260-05:00Lab NotesRayDeCampohttp://www.blogger.com/profile/00893357454992134962noreply@blogger.comBlogger57125tag:blogger.com,1999:blog-6427287440000636763.post-32605325221369368862017-07-08T19:00:00.000-04:002017-07-08T19:00:03.982-04:00Migrated to GitHub Pages<p>This blog has been migrated to GitHub Pages. See you there:</p>
<p>
<a href="http://labnotes.decampo.org/">http://labnotes.decampo.org/</a>
</p>RayDeCampohttp://www.blogger.com/profile/00893357454992134962noreply@blogger.com0tag:blogger.com,1999:blog-6427287440000636763.post-46256664207243436622017-04-13T19:30:00.000-04:002017-04-13T19:30:13.535-04:00Publishing to the Maven Central Repository<p>
As an exercise in creating a Java library and submitting it to the Central Repository, I created an implementation of the xirr (irregular internal rate of return) function in Java.
</p>
<p>
If you are interested in what needs to be done to publish to the Maven Central Repository, check out the <a href="https://github.com/RayDeCampo/java-xirr/blob/def7c2ce96654e21c7f41636aab5112cfb20a2da/pom.xml">pom.xml</a> for starters. The <code>distributionManagement</code> section contains configuration for pointing to the Nexus Repository Manager at oss.sonatype.org. This Nexus installation is used as a staging platform for the Central Repository.
</p>
<p>
Next in the <code>plugins</code> section we include the <code>maven-source-plugin</code> and <code>maven-javadoc-plugin</code> in order to generate the source and javadoc jars for the repository. Your library will not be accepted without these.
</p>
<p>
Next there is the <code>maven-gpg-plugin</code> for generating signature files for the artifacts. In order to generate the signature files, you will need to have a GPG key and placed the public key on a keyserver. If you don't have this already, google for some GPG tutorials. More about this in a moment.
</p>
<p>
Finally in the <code>pom.xml</code> we have the <code>nexus-staging-maven-plugin</code> plugin configuration. This plugin overrides the standard deploy plugin to interact with the Nexus Repository Manager.
</p>
<p>
Both the oss.sonatype.org and the GPG key have authentication credentials which need to be managed as part of the build process. To begin, you need to create a maven master password if you have not already done so. If you are not sure, look for the <code>~/.m2/settings-security.xml</code> file to see if it has a <code>master</code> element. All the passwords for maven configuration can be encrypted. To generate an encrypted master password, issue the command <code>mvn --encrypt-master-password</code> and then place the result in your <code>~/.m2/settings-security.xml</code>:
</p>
<script src="https://gist.github.com/RayDeCampo/fa0135b4a8c3615cbc435779dbd428f7.js"></script>
<p>
Then you need to encrypt your passwords using <code>mvn --encrypt-password</code> and put them in your <code>~/.m2/settings.xml</code>:
</p>
<script src="https://gist.github.com/RayDeCampo/f3ead6e3f054028d896f5ba251ed4598.js"></script>
<p>
Note that the first <code>server id</code> corresponds with the <code>id</code> in the <code>distributionManagement</code> section of the <code>pom.xml</code>. The second <code>server id</code> is used by the <code>maven-gpg-plugin</code> by default. Of course that can be changed by configuration, see the documentation of that plugin for details.
</p>
<p>
Finally, there is a pretty cool <a href="https://github.com/RayDeCampo/java-xirr/blob/def7c2ce96654e21c7f41636aab5112cfb20a2da/src/main/java/org/decampo/xirr/Xirr.java">implementation of the xirr</a> function in there as well. Not to mention a <a href="https://github.com/RayDeCampo/java-xirr/blob/def7c2ce96654e21c7f41636aab5112cfb20a2da/src/main/java/org/decampo/xirr/NewtonRaphson.java#L85">concise implementation of Newton-Raphson</a> using Java 8 features.
</p>
<p>Additional Resources:</p>
<ul>
<li><a href="http://central.sonatype.org/pages/apache-maven.html">http://central.sonatype.org/pages/apache-maven.html</a></li>
<li><a href="https://oss.sonatype.org/">https://oss.sonatype.org/</a></li>
</ul>RayDeCampohttp://www.blogger.com/profile/00893357454992134962noreply@blogger.com0tag:blogger.com,1999:blog-6427287440000636763.post-44749491318830815092017-03-30T20:00:00.000-04:002017-03-30T20:00:04.130-04:00XSLT Utilities<p>Some XSLT re-usable templates for posterity:</p>
<script src="https://gist.github.com/RayDeCampo/d8183cddd6f74174f0b82880aa77e544.js"></script>RayDeCampohttp://www.blogger.com/profile/00893357454992134962noreply@blogger.com0tag:blogger.com,1999:blog-6427287440000636763.post-22226907385795598172016-11-15T18:10:00.000-05:002016-11-15T18:10:53.873-05:00Connect to Microsoft VPN from Fedora 24<p>New box, new OS, time for another edition of trying to connect to Microsoft's VPN software. This time it is Fedora's turn.</p>
<p>This first part is adapted from my previous editions for Ubuntu and ultimately are sourced from an Ubuntu forums post by user sweisler at <a href="http://ubuntuforums.org/showpost.php?p=8261958&postcount=6">http://ubuntuforums.org/showpost.php?p=8261958&postcount=6</a>. Thanks sweisler, wherever you are.</p>
<p>First, there was no need to install any additional packages, apparently everything needed is included by default.</p>
<ul>
<li>
Open VPN configuration screen:
<ul>
<li>
Click on the network icon in the upper right of the desktop
</li>
<li>
Expand the <em>VPN</em> menu
</li>
<li>
Select <em>VPN Settings</em>
</li>
<li>
Select <em>Configure VPN…</em>
</li>
</ul>
</li>
<li>
Add a new PPTP connection
</li>
<li>
In the Identity section, set the following:
<ul>
<li>
<em>Connection name</em> (whatever you want)
</li>
<li>
<em>Gateway</em> (this is the VPN server)
</li>
<li>
<em>User name</em> (for domain-based user accounts, use domain\username or username)
</li>
<li>
Do <strong>not</strong> set <em>Password</em>; <strong>do</strong> change the pulldown (hidden in the help icon) to <em>Always Ask</em>
</li>
<li>
Set <em>NT Domain</em> if it is a domain-based account and you feel like it (I tried with <em>User name</em> as plain username and no <em>NT Domain</em> set, with <em>User name</em> as domain\username and no <em>NT Domain</em> and with <em>User name</em> as plain username and <em>NT Domain</em> set and everything worked - a far cry from when I was first trying to connect years ago).
</li>
</ul>
</li>
<li>
PPTP Advanced Options (Advanced button from the Identity section)
<ul>
<li>
Uncheck all authentication methods <strong>except</strong> <em>MSCHAPv2</em>
</li>
<li>
Check <em>Use Point-to-Point encryption (MPPE)</em>
</li>
<li>
Leave <em>Security</em> set at <em>All Available (Default)</em>
</li>
<li>
Check <em>Allow stateful inspection</em>
</li>
<li>
Uncheck <em>Allow BSD data compression</em>
</li>
<li>
Uncheck <em>Allow Deflate data compression</em>
</li>
<li>
Uncheck <em>Use TCP header compression</em>
</li>
<li>
Uncheck <em>Send PPP echo packets</em> (this setting works either way, check it for debugging purposes)
</li>
<li>
Leave <em>Use custom unit number</em> unchecked.
</li>
</ul>
</li>
</ul>
<p>Normally at this point we would save and test the connection, but for Fedora there are additional steps. We need to configure the firewall to allow connections on the GRE protocol.</p>
<p>Note that GRE is a protocol like TCP or UDP, not a particular port.</p>
<p>The Fedora firewall demon allows you to make changes in two modes: permanent changes which affect the configuration but not the running instance and temporary changes which affect the running instance but not the configuration. To enable GRE traffic through your firewall, use the following command:</p>
<code>
sudo firewall-cmd --add-protocol=gre
sudo firewall-cmd --query-protocol=gre
</code>
<p>Now test out your VPN connection. If it is working, save the changes to the configuration of the firewall:</p>
<code>
sudo firewall-cmd --permanent --add-protocol=gre
sudo firewall-cmd --permanent --query-protocol=gre
</code>
<p>Note that if you have multiple network connections (e.g. wireless vs wired), it may be necessary to configure the firewall for each one.</p>
<p>Once the VPN connection is working you may want to try to tweak it further as described below.</p>
<p>One problem with the VPN I connect to is that all traffic ends up using the VPN when I am connected. This is less than ideal if you are connecting to servers on the internet while the VPN is connected since the traffic goes through the VPN server before coming to you. The following describes the settings for routing only the proper traffic to the VPN. (Read them all the way through first to make sure you have all the necessary information.)</p>
<p>Start by opening the <em>IPv4 Settings</em> section in the configuration of your VPN.</p>
<ul>
<li>
Set <em>Additional DNS servers</em> using the IP address of the DNS server for the VPN. (You may need to ask your IT guy for this; there should be a way to discover it when connecting as above but it escapes me.)
</li>
<li>
In the <em>Routes</em> section, add a new route:
<ul>
<li>
For <em>Address</em>, use the internal IP address of the VPN server applied against the netmask below, e.g. if the VPN server is 10.23.34.89 and the netmask is 255.255.255.0, use 10.23.34.0. Again, this should be the <strong>internal</strong> IP address for getting to the machine in the intranet, not the external IP address for getting to the machine from the internet.
</li>
<li>
For <em>Netmask</em>, use the netmask of your intranet. (If you are confused, ask your IT guy what to use for both this and the <em>Address</em>.) For most networks this will be 255.255.255.0, but for many it will be different.
</li>
<li>
For <em>Gateway</em>, use 0.0.0.0.
</li>
<li>
Do not set the <em>Metric</em> unless you know what you are doing.
</li>
</ul>
</li>
<li>
If necessary, add additional routes. E.g. you might have a DMZ in the 10.0.0.0/24 network in the VPN you are connecting to.
</li>
<li>
Check <em>Use this connection only for resources on its network</em>
</li>
<li>
In other versions of the NetworkManager configuration tool, there was a field for <em>Additional search domains</em>. This field is missing on Fedora 24 and some experimenting and testing seems to indicate we don't need it.
</li>
</ul>
<p>OK, so now when you connect you should see regular traffic going directly to the internet and intranet traffic directed to the VPN server. You can test this out with <tt>traceroute</tt> (which you may need to install).</p>
<p>Let me know how these instructions work for you and what type of systems you’ve been able to connect.</p>
RayDeCampohttp://www.blogger.com/profile/00893357454992134962noreply@blogger.com0tag:blogger.com,1999:blog-6427287440000636763.post-3498256956215941852016-09-17T15:56:00.001-04:002017-04-12T19:35:05.800-04:00Dipping my toes into the Node.js ecosystem<p>
Just to get my feet wet, I published a Node.js module called <a href="https://www.npmjs.com/package/xirr">xirr</a>.
</p>
<p>
When I was writing the unit tests for the module I had a particular case where the Newton's method implementation was not converging and the library I was using returned false. My son, who has done a bit of coding was shoulder surfing and was asking me what we needed to do to make the the value be true. When I explained that we actually wanted the library to return a number instead his head practically exploded. So I went into the difference between a statically typed and dynamically typed language and he asked "Why don't you just change it to statically typed?"
</p>
<p>
So, how about EmcsScript committee? Up for making ES7 a statically typed language?
</p>RayDeCampohttp://www.blogger.com/profile/00893357454992134962noreply@blogger.com0tag:blogger.com,1999:blog-6427287440000636763.post-31711291435741135912016-08-21T18:30:00.000-04:002016-08-21T18:30:12.485-04:00Connect to Microsoft VPN from Ubuntu 16.04 Xenial Xerus<p>I recently upgraded from Ubuntu 14.04 on my main desktop machine and discovered that my VPN connection to Windows 2008 Server no longer worked. The bugaboo turned out to be the routing table which no longer requires a gateway entry. Here I have rewritten my post originally written for 12.10 to reflect the new configuration.</p>
<p>If you have ever tried to configure a linux machine to connect to a Microsoft-based VPN, you know that it is not as straightforward as it could be. It is more of a voodoo ritual than a science. I figured it would be a good idea to capture the steps for future reference.</p>
<p>This first part is adapted from the Ubuntu Wiki for posterity. You can check out the original at <a href="https://wiki.ubuntu.com/VPN">https://wiki.ubuntu.com/VPN</a> under the heading <em>VPN setup in Ubuntu 9.10</em>. Apparently this originates from a Ubuntu forums post by user sweisler at <a href="http://ubuntuforums.org/showpost.php?p=8261958&postcount=6">http://ubuntuforums.org/showpost.php?p=8261958&postcount=6</a>. Thanks sweisler, wherever you are.</p>
<p>First, there was no need to install any additional packages, apparently everything needed is included by default.</p>
<ul>
<li>
Open VPN configuration screen:
<ul>
<li>
Click on the network icon in the upper right of the desktop
</li>
<li>
Go to the <em>VPN Connections</em> menu
</li>
<li>
Select <em>Configure VPN…</em>
</li>
</ul>
</li>
<li>
Add a new PPTP connection
</li>
<li>
On the VPN tab, set the following:
<ul>
<li>
<em>Connection name</em> (whatever you want)
</li>
<li>
<em>Gateway</em> (this is the VPN server)
</li>
<li>
<em>User name</em> (for domain-based user accounts, use domain\username)
</li>
<li>
Do <strong>not</strong> set <em>Password</em>; <strong>do</strong> change the pulldown to <em>Always Ask</em>
</li>
<li>
Do <strong>not</strong> set <em>NT Domain</em>
</li>
</ul>
</li>
<li>
PPTP Advanced Options (Advanced button from the VPN tab)
<ul>
<li>
Uncheck all authentication methods <strong>except</strong> <em>MSCHAPv2</em>
</li>
<li>
Check <em>Use Point-to-Point encryption (MPPE)</em>
</li>
<li>
Leave <em>Security</em> set at <em>All Available (Default)</em>
</li>
<li>
Check <em>Allow stateful inspection</em>
</li>
<li>
Uncheck <em>Allow BSD data compression</em>
</li>
<li>
Uncheck <em>Allow Deflate data compression</em>
</li>
<li>
Uncheck <em>Use TCP header compression</em>
</li>
<li>
Uncheck <em>Send PPP echo packets</em> (this setting works either way, check it for debugging purposes)
</li>
</ul>
</li>
</ul>
<p>At this point save it and test it. Once the VPN connection is working you may want to try to tweak it further as described below.</p>
<p>One problem with the VPN I connect to is that all traffic ends up using the VPN when I am connected. This is less than ideal if you are connecting to servers on the internet while the VPN is connected since the traffic goes through the VPN server before coming to you. The following describes the settings for routing only the proper traffic to the VPN. (Read them all the way through first to make sure you have all the necessary information.)</p>
<ul>
<li>
On the <em>IPv4 Settings</em> tab
<ul>
<li>
Set <em>Additional DNS servers</em> using the IP address of the DNS server for the VPN. (You may need to ask your IT guy for this; there should be a way to discover it when connecting as above but it escapes me.)
</li>
<li>
Set <em>Additional search domains</em>. Set this to the domain suffix of the machines on the VPN. For example, if the machines are named like dbserver.example.com then set it to example.com.
</li>
</ul>
</li>
<li>
Click the <em>Routes</em> button.
<ul>
<li>
Check <em>Use this connection only for resources on its network</em>
</li>
<li>
<em>Add</em> a route:
<ul>
<li>
For <em>Address</em>, use the internal IP address of the VPN server applied against the netmask below, e.g. if the VPN server is 10.23.34.89 and the netmask is 255.255.255.0, use 10.23.34.0. Again, this should be the <strong>internal</strong> IP address for getting to the machine in the intranet, not the external IP address for getting to the machine from the internet.
</li>
<li>
For <em>Netmask</em>, use the netmask of your intranet. (If you are confused, ask your IT guy what to use for both this and the <em>Address</em>.) For most networks this will be 255.255.255.0, but for many it will be different.
</li>
<li>
For <em>Gateway</em>, use 0.0.0.0 or simply leave it blank.
</li>
<li>
Do not set the <em>Metric</em> unless you know what you are doing.
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>OK, so now when you connect you should see regular traffic going directly to the internet and intranet traffic directed to the VPN server. You can test this out with <tt>traceroute</tt> (which you may need to install). You should also be able to refer to machines on the intranet using their short names (e.g. dbserver instead of dbserver.example.com).</p>
<p>Let me know how these instructions work for you and what type of systems you’ve been able to connect.</p>
RayDeCampohttp://www.blogger.com/profile/00893357454992134962noreply@blogger.com0tag:blogger.com,1999:blog-6427287440000636763.post-12927418867622349642016-04-04T07:00:00.000-04:002016-04-04T07:00:12.250-04:00Complicated String Joins<p>
So if you have not been under a rock and have used Java 8, you are surely aware of the new String.join() method and the Collectors.joining() method to concatenate arrays or streams of Strings. Sometimes however, a simple concatenation with a delimiter is not quite up to the job.
</p>
<p>
Consider the following method for example:
</p>
<script src="https://gist.github.com/RayDeCampo/12b98878b0b08fdd60ed23bdd250b90c.js"></script>
<p>
Here our plans for a simple invocation of Collectors.joining() is complicated by the intermediate String literals and the particular format desired for the string representation of the entry.
</p>
<p>
At first blush you might attempt to change this to functional style using something like this:
</p>
<script src="https://gist.github.com/RayDeCampo/68768dde668461aa8b68a23f5dc50cfc.js"></script>
<p>
If you are an old salt at Java however, I'm sure your hair is standing on end considering all those temporary String objects being created. Fortunately, using Stream.of() and Stream.flatMap() there is another way:
</p>
<script src="https://gist.github.com/RayDeCampo/3a2cea7738b74d8ee240eb040bcd8a53.js"></script>
<p>
If you want to play around with this code, it is available on GitHub at <a href="https://github.com/RayDeCampo/lab-notes/blob/23bfa214f8fd830a27529aa9f195013f448998a9/lab-notes/src/main/java/org/decampo/examples/functional/StringJoin.java">StringJoin.java</a>
</p>RayDeCampohttp://www.blogger.com/profile/00893357454992134962noreply@blogger.com0tag:blogger.com,1999:blog-6427287440000636763.post-17535412528867484242016-03-28T07:00:00.000-04:002016-03-28T07:00:18.798-04:00Creating a custom Collector<p>
Creating a custom implementation of java.stream.Collector seems daunting at first, but once you give it a try, you'll see that it can actually be pretty easy.
<p>
If you are not used to using lambdas and functional concepts, your first look at the Collector interface will be intimidating. From a pre-Java 8 perspective, there are four interfaces to implement to create a custom Collector implementation: java.util.function.BiConsumer, java.util.function.BinaryOperator, java.util.function.Function and java.util.function.Supplier. Fortunately they are all functional interfaces which will allow us to take some shortcuts with lambdas and functional expressions.
<p>
The example I chose to implement is a Collector for SetValuedMap from Apache's <a href="https://commons.apache.org/proper/commons-collections/">Common Collections</a> project. We'd like a static method similar to the standard Collectors.toMap() method which will generate a Collector instance yielding a SetValuedMap implementation.
<p>
There are a lot of moving parts to the Collector in terms of generics. First, we will have generic parameters for the type in the existing stream <T>, the type of the key in the map <K> and the type of the values in the map <V>. Then we need to identify the three generic parameters to the Collector interface: <T> is the same as before, the type of objects in the stream; <A>, the accumulation type will be SetValuedMap<K,V>; and <R>, the result type, will also be SetValuedMap<K,V>. It is frequently the case with Collectors that <A> and <R> are the same.
<p>
Now that we have our generic ducks in a row, we can start figuring out our Collector implementation. For the supplier, we can use a constructor of a SetValuedMap implementation, e.g. HashSetValuedHashMap::new.
<p>
The accumulator will be a lambda function taking in a map and a stream object, it will need to put the stream object in the map. For that we will need to pass in functions converting the stream objects to keys and values respectively (just like in Collectors.toMap()).
<p>
The combiner will need to accept two maps and return a map containing entries from both. Again this can be specified with a lambda function.
<p>
We don't need anything beyond the identity function for the finisher, which means we ready to create our Collector implementation using the Collector.of() factory method:
<p>
<script src="https://gist.github.com/RayDeCampo/c46ca9a862460693b61d.js"></script>
<p>
This method can be used to create a version of Collectors.groupingBy() which eliminates duplicates simply by passing Function.identity for the valueMapper:
<p>
<script src="https://gist.github.com/RayDeCampo/67563382796446902cd8.js"></script>
<p>
If we wanted to get really fancy we could also pass in a Comparator to use with our set, but I will leave that as an exercise for the reader.
<p>
See the file <a href="https://github.com/RayDeCampo/lab-notes/blob/66f07f506a6dc41d6f7b3bac71512f8ff8a35b2c/lab-notes/src/test/java/org/decampo/examples/collections/MoreCollectorsTest.java">MoreCollectorsTest.java</a> for some examples of these methods in action.
RayDeCampohttp://www.blogger.com/profile/00893357454992134962noreply@blogger.com0tag:blogger.com,1999:blog-6427287440000636763.post-16501492597773739112015-03-09T19:00:00.000-04:002015-03-09T19:00:04.405-04:00JSF EL Implicit Object Reference<p>
Just collecting the implicit objects defined by the JSF 2.2 specification (section 5.6.2.1, table 5-11) which are available in the EL:
</p>
<dl>
<dt>application</dt><dd>externalContext.getContext()</dd>
<dt>applicationScope</dt><dd>externalContext.getApplicationMap()</dd>
<dt>cookie</dt><dd>externalContext.getRequestCookieMap()</dd>
<dt>facesContext</dt><dd>the FacesContext for this request</dd>
<dt>component</dt><dd>the top of the stack of UIComponent instances, as pushed via calls to UIComponent.pushComponentToEL(). See Section 3.1.14 “Lifecycle Management Methods”</dd>
<dt>flowScope</dt><dd>facesContext.getApplication().getFlowHandler().getCurrentFlowScope()</dd>
<dt>cc</dt><dd>the current composite component relative to the declaring page in which the expression appears.</dd>
<dt>flash</dt><dd>externalContext.getFlash()</dd>
<dt>header</dt><dd>externalContext.getRequestHeaderMap()</dd>
<dt>headerValues</dt><dd>externalContext.getRequestHeaderValuesMap()</dd>
<dt>initParam</dt><dd>externalContext.getInitParameterMap()</dd>
<dt>param</dt><dd>externalContext.getRequestParameterMap()</dd>
<dt>paramValues</dt><dd>externalContext.getRequestParameterValuesMap()</dd>
<dt>request</dt><dd>externalContext.getRequest()</dd>
<dt>requestScope</dt><dd>externalContext.getRequestMap()</dd>
<dt>resource</dt><dd>facesContext.getApplication().getResourceHandler()</dd>
<dt>session</dt><dd>externalContext.getSession()</dd>
<dt>sessionScope</dt><dd>externalContext.getSessionMap()</dd>
<dt>view</dt><dd>facesContext.getViewRoot()</dd>
<dt>viewScope</dt><dd>facesContext.getViewRoot().getViewMap()</dd>
<dt>resource</dt><dd>facesContext.getApplication().getResourceHandler()</dd>
</dl>
RayDeCampohttp://www.blogger.com/profile/00893357454992134962noreply@blogger.com0tag:blogger.com,1999:blog-6427287440000636763.post-1272203905889759332015-02-13T20:00:00.000-05:002015-02-13T20:00:00.553-05:00jQuery UI Initialization Issues
<p>
Every once in a while when using jQuery UI I notice that my widget is not being initialized smoothly. For example, when using the menu widget I might see the list items behind the menu briefly. Then the page jumps around and it is a generally unpleasant experience for the user. Who likes it when your jQuery widgets are jumpy and cause the page to feel like one of those old 'punch the monkey' banner ads?
</p>
<p>
This usually means I have done something like this:
</p>
<div class="code">
require(['jquery', 'jquery-ui/menu'], function($, menu) {
$("#navmenu").menu();
});
</div>
<p>
Instead of wrapping the initialization in a function as I should:
</p>
<div class="code">
require(['jquery', 'jquery-ui/menu'], function($, menu) {
$(function() {
$("#navmenu").menu();
});
});
</div>RayDeCampohttp://www.blogger.com/profile/00893357454992134962noreply@blogger.com0tag:blogger.com,1999:blog-6427287440000636763.post-12354618716603352902015-01-17T09:00:00.000-05:002015-02-13T10:54:29.810-05:00JSF: Add Conversation ID to a link or button<p>
To add the conversation ID parameter <code>cid</code> to a <code>h:link</code> or <code>h:button</code>:
<p>
<div class="code">
<h:button value="Go" outcome="go">
<f:param name="cid" value="#{javax.enterprise.context.conversation.id}" />
</h:button>
</div>
RayDeCampohttp://www.blogger.com/profile/00893357454992134962noreply@blogger.com0tag:blogger.com,1999:blog-6427287440000636763.post-24683871016058256062015-01-15T19:00:00.000-05:002015-02-13T10:55:07.870-05:00Retain sessions in WildFly 8<p>
Add the <code>persistent-sessions</code> element to your WildFly configuration to keep sessions persistent across redeployments and restarts:
</p>
<div class="code">
<servlet-container name="default">
<jsp-config/>
<persistent-sessions />
<websockets/>
</servlet-container>
</div>
<p>
See <a href="https://docs.jboss.org/author/display/WFLY8/Undertow+%28web%29+subsystem+configuration">https://docs.jboss.org/author/display/WFLY8/Undertow+%28web%29+subsystem+configuration</a> for more information.
</p>RayDeCampohttp://www.blogger.com/profile/00893357454992134962noreply@blogger.com0tag:blogger.com,1999:blog-6427287440000636763.post-10656992251039105692015-01-07T18:00:00.000-05:002015-04-22T11:45:36.273-04:00WildFly 8.2.0 and Java 8 on CentOS 6.6<p>This post documents how to install and configure <a href="http://www.wildfly.org/">WildFly</a> 8.2.0 on CentOS 6.6. We make some changes to move some of the configuration under <tt>/etc</tt> and also place log files under <tt>/var/log</tt> and temp files under <tt>/tmp</tt> just like a well-behaved POSIX application should.
<p>We’ll start by installing Java; download your desired version as an RPM from Oracle and install:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" style="margin:0.2em 0;">
<tr><td style="padding:0.5em;">
<pre style="margin:0; padding:0;">[root@wxyz ~]# rpm -ivh jdk-8u25-linux-x64.rpm</pre>
</td></tr>
</table>
<p>This installs the JDK in <tt>/usr/java/jdk1.8.0_25</tt>. There is no need to make this the default java used by the system, we'll just configure WildFly to use it.</p>
<p>Next we create a <tt>wildfly</tt> user on the server to build and run WildFly as:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" style="margin:0.2em 0;">
<tr><td style="padding:0.5em;">
<pre style="margin:0; padding:0;">[root@wxyz ~]# useradd --system \
--comment "WildFly Application Server" \
--create-home --home /opt/wildfly \
--user-group wildfly</pre>
</td></tr>
</table>
<p>I assume you already have the WildFly tarball downloaded and ready to go:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><font color="#990000">[</font>wildfly@wxyz <font color="#990000">~]</font>$ tar zxvf wildfly-8<font color="#990000">.</font>2<font color="#990000">.</font>0<font color="#990000">.</font>Final<font color="#990000">.</font>tar<font color="#990000">.</font>gz</tt></pre></td></tr></table>
<p>Now that we have WildFly on the system, we need to configure CentOS to treat it like a service. WildFly comes with some scripts in the <tt>bin/init.d</tt> directory that will help with this. I am using the standalone server, but it is not difficult to modify the instructions for the domain server. First up is the <tt>/etc/wildfly/wildfly.conf</tt> file.</p>
<table border="0" bgcolor="#e8e8e8" width="100%" style="margin:0.2em 0;">
<tr><td style="padding:0.5em;">
<pre style="margin:0; padding:0;">[root@wxyz ~]# cd /etc
[root@wxyz etc]# mkdir wildfly
[root@wxyz etc]# cd wildfly/
[root@wxyz wildfly]# cp /opt/wildfly/wildfly-8.2.0.Final/bin/init.d/wildfly.conf ./
[root@wxyz wildfly]# # We'll just create an empty properties file for now
[root@wxyz wildfly]# touch wildfly.properties</pre>
</td></tr>
</table>
<p>Next edit the file. We need to define a few environment variables, I am only including the ones I've changed:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><i><font color="#9A1900"># General configuration for the init.d scripts,</font></i>
<i><font color="#9A1900"># not necessarily for JBoss AS itself.</font></i>
<i><font color="#9A1900"># default location: /etc/default/wildfly</font></i>
<i><font color="#9A1900">## Location of JDK</font></i>
<font color="#009900">JAVA_HOME</font><font color="#990000">=</font>/usr/java/jdk1.8.0_25
<i><font color="#9A1900">## Location of WildFly</font></i>
<font color="#009900">JBOSS_HOME</font><font color="#990000">=</font>/opt/wildfly/wildfly-8.2.0.Final
<i><font color="#9A1900">## The username who should own the process.</font></i>
<font color="#009900">JBOSS_USER</font><font color="#990000">=</font>wildfly
<i><font color="#9A1900">## Configuration for standalone mode</font></i>
<font color="#009900">JBOSS_CONFIG</font><font color="#990000">=</font>standalone-full.xml
<i><font color="#9A1900">## Location to keep the console log</font></i>
<font color="#009900">JBOSS_CONSOLE_LOG</font><font color="#990000">=</font>"/var/log/wildfly/console.log"
<i><font color="#9A1900"># Need to modify the init script to account for JBOSS_OPTS</font></i>
<i><font color="#9A1900"># Allows us to pass system properties to WildFly</font></i>
<font color="#009900">JBOSS_OPTS</font><font color="#990000">=</font>"--properties=/etc/wildfly/wildfly.properties"
</tt></pre></td></tr></table>
<p>Next up we will deposit the init script in <tt>/etc/init.d</tt> and set the server to start on boot:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" style="margin:0.2em 0;">
<tr><td style="padding:0.5em;">
<pre style="margin:0; padding:0;">[root@wxyz wildfly]# cd /etc/ini t.d/
[root@wxyz init.d]# cp /opt/wildfly/wildfly-8.2.0.Final/bin/init.d/wildfly-init-redhat.sh ./wildfly
[root@wxyz init.d]# chkconfig --add wildfly
[root@wxyz init.d]# chkconfig --level 345 wildfly on
[root@wxyz init.d]# chkconfig --list wildfly
wildfly 0:off 1:off 2:off 3:on 4:on 5:on 6:off</pre>
</td></tr>
</table>
<p>You will need to edit the <tt>wildfly</tt> script in two places; first, to change the default location of the <tt>wildfly.conf</tt> file from <tt>/etc/default/wildfly.conf</tt>, starting at line 19:
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><i><font color="#9A1900"># Load JBoss AS init.d configuration.</font></i>
<b><font color="#0000FF">if</font></b> <font color="#990000">[</font> -z <font color="#FF0000">"$JBOSS_CONF"</font> <font color="#990000">];</font> <b><font color="#0000FF">then</font></b>
<font color="#009900">JBOSS_CONF</font><font color="#990000">=</font><font color="#FF0000">"/etc/wildfly/wildfly.conf"</font>
<b><font color="#0000FF">fi</font></b>
</tt></pre></td></tr></table>
<p>As-is the scripts do not allow passing any additional options to the WildFly process, so we need to edit the <tt>/etc/init.d/wildfly</tt> script to add the <tt>$JBOSS_OPTS</tt> variable whenever WildFly is starting. Here is the edited snippet for the standalone configuration (I’ve added some line breaks for readability) starting from line 104:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><b><font color="#0000FF">if</font></b> <font color="#990000">[</font> <font color="#990000">!</font> -z <font color="#FF0000">"$JBOSS_USER"</font> <font color="#990000">];</font> <b><font color="#0000FF">then</font></b>
<b><font color="#0000FF">if</font></b> <font color="#990000">[</font> <font color="#FF0000">"$JBOSS_MODE"</font> <font color="#990000">=</font> <font color="#FF0000">"standalone"</font> <font color="#990000">];</font> <b><font color="#0000FF">then</font></b>
<b><font color="#0000FF">if</font></b> <font color="#990000">[</font> -r /etc/rc<font color="#990000">.</font>d/init<font color="#990000">.</font>d/functions <font color="#990000">];</font> <b><font color="#0000FF">then</font></b>
daemon --user <font color="#009900">$JBOSS_USER</font> <font color="#009900">LAUNCH_JBOSS_IN_BACKGROUND</font><font color="#990000">=</font><font color="#993399">1</font> <font color="#990000">\</font>
<font color="#009900">JBOSS_PIDFILE</font><font color="#990000">=</font><font color="#009900">$JBOSS_PIDFILE</font> <font color="#009900">$JBOSS_SCRIPT</font> -c <font color="#009900">$JBOSS_CONFIG</font> <font color="#990000">\</font>
<font color="#009900">$JBOSS_OPTS</font> <font color="#993399">2</font><font color="#990000">>&</font><font color="#993399">1</font> <font color="#990000">></font> <font color="#009900">$JBOSS_CONSOLE_LOG</font> <font color="#990000">&</font>
<b><font color="#0000FF">else</font></b>
su - <font color="#009900">$JBOSS_USER</font> -c <font color="#FF0000">"LAUNCH_JBOSS_IN_BACKGROUND=1 \</font>
<font color="#FF0000"> JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT -c $JBOSS_CONFIG \</font>
<font color="#FF0000"> $JBOSS_OPTS"</font> <font color="#993399">2</font><font color="#990000">>&</font><font color="#993399">1</font> <font color="#990000">></font> <font color="#009900">$JBOSS_CONSOLE_LOG</font> <font color="#990000">&</font>
<b><font color="#0000FF">fi</font></b>
<b><font color="#0000FF">else</font></b></tt></pre></td></tr></table>
<p>Next up we create the log directories and redirect the JBoss log directory to <tt>/var/log/wildfly</tt> and the tmp directory to <tt>/tmp/wildfly</tt></p>
<table border="0" bgcolor="#e8e8e8" width="100%" style="margin:0.2em 0;">
<tr><td style="padding:0.5em;">
<pre style="margin:0; padding:0;">[root@wxyz ~]# mkdir /var/log/wildfly
[root@wxyz ~]# chown wildfly:wildfly /var/log/wildfly/</pre>
</td></tr>
</table>
<p>To get WildFly to use these directories, we set the system properties for them in <tt>/etc/wildfly/wildfly.properties</tt>:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><i><font color="#9A1900"># System properties for wildfly</font></i>
<font color="#009900">jboss.server.log.dir</font><font color="#990000">=</font>/var/log/wildfly
<font color="#009900">jboss.server.temp.dir</font><font color="#990000">=</font>/tmp/wildfly</tt></pre></td></tr></table>
<p>At this point you can start the server using the command <tt>service wildfly start</tt>. You won’t be able to do much however, unless you like browsing via <tt>wget</tt> since the server is bound to the localhost interface only (and we are working on a headless server, i.e. no GUI web browser). So we’ll need to bind WildFly to all interfaces and open up the CentOS firewall to allow browsing to WildFly and the management console. Keep in mind that this may not be exactly what you want in a production environment or in environment where unknown users might access your server (like shared hosting).</p>
<p>First we’ll edit the <tt>/etc/wildfly/wildfly.properties</tt> file:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><i><font color="#9A1900"># System properties for wildfly</font></i>
<font color="#009900">jboss.bind.address</font><font color="#990000">=</font>0.0.0.0
<font color="#009900">jboss.bind.address.management</font><font color="#990000">=</font>0.0.0.0
<font color="#009900">jboss.server.log.dir</font><font color="#990000">=</font>/var/log/wildfly
<font color="#009900">jboss.server.temp.dir</font><font color="#990000">=</font>/tmp/wildfly</tt></pre></td></tr></table>
<p>Depending on how your local network is setup you may need further configuration for WildFly to be completely happy binding to all interfaces. If your DNS recognizes the name of the CentOS server you are working on, congratulations, you are all set. On the other hand, if DNS is not configured for the server, you will need to add an entry to the <tt>/etc/hosts</tt> file pointing the name of the server to the external IP.</p>
<p>Next we need to open the firewall for ports 8080 (regular WildFly) and 9990 (the management console). <strong>Be careful</strong> when adjusting the firewall. The commands below use hard-coded line numbers that may not be appropriate for whatever system you are using. If you think you have screwed up your firewall use <tt>service iptables restart</tt> to reset it. Of course, this won’t work after you issue <tt>service iptables save</tt> so be extra sure before you save the rules. You will also need to replace 10.0.0.0 with your subnet below.</p>
<table border="0" bgcolor="#e8e8e8" width="100%" style="margin:0.2em 0;">
<tr><td style="padding:0.5em;">
<pre style="margin:0; padding:0;">[root@wxyz ~]# # 8080 for WildFly applications
[root@wxyz ~]# iptables --insert INPUT 5 \
--match state \
--state NEW \
--protocol tcp \
--destination-port 8080 \
--source 10.0.0.0/24 \
--jump ACCEPT
[root@wxyz ~]# # 9990 for WildFly management
[root@wxyz ~]# iptables --insert INPUT 6 \
--match state \
--state NEW \
--protocol tcp \
--destination-port 9990 \
--source 10.0.0.0/24 \
--jump ACCEPT
[root@wxyz ~]# # Verify the state of the firewall
[root@wxyz ~]# iptables -L --line-numbers
[root@wxyz ~]# # Go and test it out before doing the following
[root@wxyz ~]# service iptables save</pre>
</td></tr>
</table>
<p>At this point you should be ready to go. Start up WildFly and try accessing it from your desktop.</p>RayDeCampohttp://www.blogger.com/profile/00893357454992134962noreply@blogger.com0tag:blogger.com,1999:blog-6427287440000636763.post-17105399271262658362015-01-06T18:00:00.000-05:002015-01-06T18:00:00.084-05:00Network issues with CentOS 6.x under Hyper-V<p>
I had a number of CentOS instances running under Hyper-V using the standard virtual network interface via integration services. Post CentOS 6.3 integration services are included in the install and that has been my experience. However at some point after updating to 6.6, something causes the integration services to no longer work with the virtual network interface.
<p>
To fix, remove the Network Adapter from the Hyper-V configuration and replace it with a Legacy Network Adapter.
<p>
Now you need to boot the virtual machine and access it from the Hyper-V console in order to log in. Backup the file <code>/etc/udev/rules/70.persisent-net.rules</code> and remove it from the <code>/etc/udev/rules</code> directory. This file tells CentOS to look for the old network interface and assign it to <code>eth0</code>.
<p>
Second, backup the <code>/etc/sysconfig/network-scripts/ifcfg-eth0</code> file. Edit the file and remove any reference to <code>UUID</code> or <code>HWADDR</code>.
RayDeCampohttp://www.blogger.com/profile/00893357454992134962noreply@blogger.com0tag:blogger.com,1999:blog-6427287440000636763.post-71451709032339668832014-10-05T10:00:00.000-04:002015-02-13T10:56:13.726-05:00JSF 2.2 Welcome File<p>
Just a quick post in case you are trying to use a JSF page as a welcome file. This is what you'll need in your web.xml:
</p>
<div class="code">
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>
javax.faces.webapp.FacesServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
</div>RayDeCampohttp://www.blogger.com/profile/00893357454992134962noreply@blogger.com0tag:blogger.com,1999:blog-6427287440000636763.post-38262342130906779772014-09-28T10:00:00.000-04:002014-09-28T10:00:00.499-04:00Could not find backup for factory javax.faces.context.FacesContextFactory<div class="paragraph"><p>Recently I was porting a JEE application’s development environment from an outdated version of IDEA to Maven and NetBeans. After some effort I got the two builds to yeild pretty much the same EAR files.</p></div>
<div class="paragraph"><p>The next step was to connect JBoss (version 7.1.1.Final in this case) to the project and begin development. However when I deployed the EAR to JBoss using NetBeans. I got the following error:</p></div>
<div class="listingblock">
<div class="content" style="background-color: #e8e8e8; white-space: nowrap; display: table-cell">
<pre>13:32:42,744 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/sc]] (MSC service thread 1-14)
StandardWrapper.Throwable: java.lang.IllegalStateException: Could not find backup for factory javax.faces.context.FacesContextFactory.
at javax.faces.FactoryFinder$FactoryManager.getFactory(FactoryFinder.java:1008) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:343) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.webapp.FacesServlet.init(FacesServlet.java:302) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1202) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3655) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3873) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_51]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_51]
at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_51]
</pre>
</div></div>
<div class="paragraph"><p>Needless to say, that was unexpected. Now the common answer from Google on this error is that there are multiple copies of JSF confusing the issue. That did not jibe with my situation as I do not pack JSF with this application.</p></div>
<div class="paragraph"><p>The first thing I tried was to make sure the entire tool chain was using JDK 7. NetBeans had been compiling with JDK 8 so it seemed possible this was causing a class loading conflict. But this failed to alleviate the issue.</p></div>
<div class="paragraph"><p>The next thing I tried was taking the exploded EAR file from the Maven target directory and deploying it by hand. No problems when deploying that way.</p></div>
<div class="paragraph"><p>Some more investigation revealed that NetBeans was deploying the EAR archive, not the exploded directory. When I deployed the archive manually, I reproduced the error. At least I had eliminated NetBeans as a potential source of blame.</p></div>
<div class="paragraph"><p>When investigating the differences between the exploded EAR directory and the EAR archive I discovered that what you see is not what you get with Maven. I think the issue is that the various Maven plugins for WAR and EAR building are not applied when creating the exploded directories.</p></div>
<div class="paragraph"><p>So to eliminate these differences I took the Maven EAR archive and extracted it in the JBoss deployments directory and deployed it by hand. To my surprise there was no error.</p></div>
<div class="paragraph"><p>So there seemed to be a difference between deploying the application as an EAR archive vs an EAR directory. I had one final arrow left in my quiver: I would try deploying the EAR archive as produced by the previous build process.</p></div>
<div class="paragraph"><p>That EAR archive worked like a champ. Now I needed to figure out the difference between the two archives. The contents were essentially the same but one difference stood out: the WAR and EJB jar files in the working archive were archives themselves, whereas they were exploded in the broken EAR archive.</p></div>
<div class="paragraph"><p>That was easy enough to fix: just remove the <unpack> directives from the POM for the EAR. Now a I had deployments working from within NetBeans.</p></div>
<div class="paragraph"><p>TL;DR: Don’t use exploded WARs inside of an unexploded EAR archive.</p></div>
RayDeCampohttp://www.blogger.com/profile/00893357454992134962noreply@blogger.com0tag:blogger.com,1999:blog-6427287440000636763.post-89291570112939069812014-02-16T09:30:00.000-05:002014-02-16T09:30:01.569-05:00SELinux and ssh<p>
I've had this one as a draft post for a while and I just ran into the it again, so it's time to to publish it.
</p>
<p>
I had a Linux server setup that I was getting a new developer to connect to. Whatever we tried, we could not get him logged in via ssh using keys. I verified the home directory permissions (at most 755), the <tt>.ssh</tt> directory permissions (700), the permissions of the files in the <tt>.ssh</tt> directory (600). Other users could connect to the server using keys. The developer could use the same client to connect to other ssh servers using keys.
</p>
<p>
Finally it occurred to me to check the SELinux context on the <tt>.ssh</tt> directory; it was missing the ssh_home_t context. The repair is simple: <tt>restorecon -r -vv .ssh</tt>
</p>
<p>
If you don't trust <tt>restorecon</tt> or you are just looking for an alternate fix, you can delete the <tt>.ssh</tt> directory and have the user connect to another ssh server from the target machine. This will build the <tt>.ssh</tt> directory on the target server when the <tt>known_hosts</tt> file is created.
</p>RayDeCampohttp://www.blogger.com/profile/00893357454992134962noreply@blogger.com0tag:blogger.com,1999:blog-6427287440000636763.post-50679449232347368992013-11-17T09:30:00.000-05:002013-11-17T09:30:02.263-05:00Reusing JavaScript Modules in Liferay 6.2<p><a href="http://www.liferay.com">Liferay</a> is a <a href="http://www.jcp.org/en/jsr/detail?id=286">JSR-286</a> compliant portal server that runs on a variety of different application servers. Previously I have explained how to get <a href="2013/11/liferay-62-portal-on-jboss-720.html">Liferay working with JBoss 7.2.0</a>.</p>
<p>Today I would like to focus on getting an example portlet working with Liferay which uses a custom JavaScript module, similar to what we did with the <a href="2013/11/packaging-gatein-javascript-modules-in.html">GateIn portal server earlier</a>. Since developing that example I have learned that ninjas are not always well-behaved, so we will stick to some home-grown JavaScript. We will use JavaScript to place a quote on the screen when the user clicks on a certain area of the portlet.</p>
<p>First things first: Liferay does a fair amount of caching for performance reasons. We will need to deactivate the caching otherwise there will be a great deal of pulling of hair and gnashing of teeth while you wonder why your newly deployed JavaScript changes have not made it to the browser. Fortunately Liferay makes this easy by allowing you to pass the flag <tt>-Dexternal-properties=portal-developer.properties</tt> to the application server on start-up. This incorporates the properties in the <tt>/WEB-INF/classes/portal-developer.properties</tt> file from the Liferay WAR into the Liferay system properties. If, for whatever reason you require more fine-grained control, you can manipulate the same properties by placing them in your <tt>portal-ext.properties</tt> file in your Liferay home directory (typically one directory above your application server home directory).</p>
<p>Now that we have an environment conducive to peaceful code development, we can begin. Liferay incorporates the <a href="http://www.alloyui.com">AlloyUI</a> JavaScript library, which is based on the <a href="http://yuilibrary.com">YUI</a> library from Yahoo (specifically the 3.x series sometimes referred to as YUI3, particularly when using a search engine). AlloyUI inherits the module model from YUI and that gives us a nice scaffold to organize our JavaScript.</p>
<p>Unlike GateIn however, Liferay is not "module-aware". That is, we cannot declare our modules and then declare which modules a particular portlet is dependent on. So we’ll need to work around that by placing our modules in a <a href="https://www.liferay.com/documentation/liferay-portal/6.2/development/-/ai/customize-and-extend-functionality-hooks-liferay-portal-6-2-dev-guide-en">Liferay hooks</a>. Hooks allow us to extend or override core features of Liferay without needing to change Liferay’s source. In our case we will simply use the hook functionality to include our module’s JavaScript in the portal template.</p>
<p>The easy way to get started with a Liferay hook is to use the <a href="http://www.liferay.com/downloads/liferay-projects/liferay-ide">Liferay IDE</a>, a set of extensions for Eclipse. But I have never been a big fan of Eclipse and I am a big fan of doing things manually at least once for better understanding. So I’ll explain how to do the "hard" way (which really isn’t all that bad anyway.</p>
<p>Create a WAR project (using <em>your</em> favorite method) to hold the hook. Add a <tt>/WEB-INF/web.xml</tt> file with an empty <tt><web-app></tt> tag:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><b><font color="#000080"><?xml</font></b> <font color="#009900">version</font><font color="#990000">=</font><font color="#FF0000">"1.0"</font> <font color="#009900">encoding</font><font color="#990000">=</font><font color="#FF0000">"UTF-8"</font><b><font color="#000080">?></font></b>
<b><font color="#0000FF"><web-app</font></b> <font color="#009900">version</font><font color="#990000">=</font><font color="#FF0000">"3.0"</font> <font color="#009900">metadata-complete</font><font color="#990000">=</font><font color="#FF0000">"true"</font>
<font color="#009900">xmlns</font><font color="#990000">=</font><font color="#FF0000">"http://java.sun.com/xml/ns/javaee"</font>
<font color="#009900">xmlns:xsi</font><font color="#990000">=</font><font color="#FF0000">"http://www.w3.org/2001/XMLSchema-instance"</font>
<font color="#009900">xsi:schemaLocation</font><font color="#990000">=</font><font color="#FF0000">"http://java.sun.com/xml/ns/javaee</font>
<font color="#FF0000"> http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"</font><b><font color="#0000FF">></font></b>
<b><font color="#0000FF"></web-app></font></b></tt></pre></td></tr></table>
<p>Next we’ll need a <tt>/WEB-INF/liferay-hook.xml</tt> file telling Liferay where to find our JSP extensions. Liferay has documentation for this file and their other XML configuration files at <a href="http://docs.liferay.com/portal/6.2/definitions/">http://docs.liferay.com/portal/6.2/definitions/</a>. Here is the content of our <tt>/WEB-INF/liferay-hook.xml</tt> file:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><b><font color="#000080"><?xml</font></b> <font color="#009900">version</font><font color="#990000">=</font><font color="#FF0000">"1.0"</font><b><font color="#000080">?></font></b>
<b><font color="#000080"><!DOCTYPE</font></b> <font color="#009900">hook</font> <font color="#009900">PUBLIC</font> <font color="#FF0000">"-//Liferay//DTD Hook 6.2.0//EN"</font>
<font color="#FF0000">"http://www.liferay.com/dtd/liferay-hook_6_2_0.dtd"</font><b><font color="#000080">></font></b>
<b><font color="#0000FF"><hook></font></b>
<b><font color="#0000FF"><custom-jsp-dir></font></b>/WEB-INF/jsp<b><font color="#0000FF"></custom-jsp-dir></font></b>
<b><font color="#0000FF"></hook></font></b></tt></pre></td></tr></table>
<p>Now we need to create the JSP extension file which Liferay will append to the standard JSP. Create <tt>/WEB-INF/jsp/html/common/themes/top_js-ext.jspf</tt>:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><b><font color="#0000FF"><script</font></b> <font color="#009900">type</font><font color="#990000">=</font><font color="#FF0000">"text/javascript"</font> <font color="#009900">src</font><font color="#990000">=</font><font color="#FF0000">"/js/quotify.js"</font><b><font color="#0000FF">></script></font></b>
<b><font color="#0000FF"><script</font></b> <font color="#009900">type</font><font color="#990000">=</font><font color="#FF0000">"text/javascript"</font> <font color="#009900">src</font><font color="#990000">=</font><font color="#FF0000">"https://www.google.com/jsapi"</font><b><font color="#0000FF">></script></font></b></tt></pre></td></tr></table>
<p>The first line is for a JavaScript file we will include in the WAR we created. The second line is an example of including a third-party JavaScript library which is hosted elsewhere.</p>
<p>Finally we will add our YUI JavaScript module source in <tt>/WEB-INF/jsp/js/quotify.js</tt>:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><b><font color="#000000">YUI</font></b><font color="#990000">().</font><b><font color="#000000">add</font></b><font color="#990000">(</font><font color="#FF0000">'com.example.quotify'</font><font color="#990000">,</font> <b><font color="#0000FF">function</font></b><font color="#990000">(</font>Y<font color="#990000">)</font> <font color="#FF0000">{</font>
Y<font color="#990000">.</font><b><font color="#000000">namespace</font></b><font color="#990000">(</font><font color="#FF0000">'com.example'</font><font color="#990000">);</font>
Y<font color="#990000">.</font>com<font color="#990000">.</font>example<font color="#990000">.</font>quotify <font color="#990000">=</font> <font color="#FF0000">{</font>
quotes <font color="#990000">:</font> <font color="#990000">[</font>
<font color="#FF0000">"If at first you don't succeed... so much for sky-diving. -Henny Youngman"</font><font color="#990000">,</font>
<font color="#FF0000">"I intend to live forever. So far, so good. -Steven Wright"</font><font color="#990000">,</font>
<font color="#FF0000">"A day without sunshine is like, you know, night. -Steve Martin"</font><font color="#990000">,</font>
<font color="#FF0000">"Get your facts first, then you can distort them as you please. -Mark Twain"</font><font color="#990000">],</font>
fontSizes<font color="#990000">:</font> <font color="#990000">[</font><font color="#FF0000">'300%'</font><font color="#990000">,</font> <font color="#FF0000">'400%'</font><font color="#990000">,</font> <font color="#FF0000">'400%'</font><font color="#990000">,</font> <font color="#FF0000">'600%'</font><font color="#990000">],</font>
colors<font color="#990000">:</font> <font color="#990000">[</font><font color="#FF0000">'black'</font><font color="#990000">,</font> <font color="#FF0000">'black'</font><font color="#990000">,</font> <font color="#FF0000">'blue'</font><font color="#990000">,</font> <font color="#FF0000">'darkblue'</font><font color="#990000">,</font> <font color="#FF0000">'darkgreen'</font><font color="#990000">,</font> <font color="#FF0000">'darkred'</font><font color="#990000">],</font>
fontStyles<font color="#990000">:</font> <font color="#990000">[</font> <font color="#FF0000">'normal'</font><font color="#990000">,</font> <font color="#FF0000">'italic'</font><font color="#990000">,</font> <font color="#FF0000">'normal'</font><font color="#990000">,</font> <font color="#FF0000">'oblique'</font> <font color="#990000">],</font>
fontVariants<font color="#990000">:</font> <font color="#990000">[</font> <font color="#FF0000">'normal'</font><font color="#990000">,</font> <font color="#FF0000">'normal'</font><font color="#990000">,</font> <font color="#FF0000">'normal'</font><font color="#990000">,</font> <font color="#FF0000">'small-caps'</font> <font color="#990000">],</font>
fontWeights<font color="#990000">:</font> <font color="#990000">[</font> <font color="#FF0000">'normal'</font><font color="#990000">,</font> <font color="#FF0000">'bold'</font><font color="#990000">,</font> <font color="#FF0000">'bold'</font><font color="#990000">,</font> <font color="#FF0000">'bolder'</font><font color="#990000">,</font> <font color="#FF0000">'bolder'</font> <font color="#990000">],</font>
fonts<font color="#990000">:</font> <font color="#990000">[</font> <font color="#FF0000">'serif'</font><font color="#990000">,</font> <font color="#FF0000">'sans-serif'</font><font color="#990000">,</font> <font color="#FF0000">'cursive'</font><font color="#990000">,</font> <font color="#FF0000">'monospace'</font> <font color="#990000">],</font>
random <font color="#990000">:</font> <b><font color="#0000FF">function</font></b><font color="#990000">(</font>array<font color="#990000">)</font> <font color="#FF0000">{</font>
<b><font color="#0000FF">return</font></b> array<font color="#990000">[</font>Math<font color="#990000">.</font><b><font color="#000000">floor</font></b><font color="#990000">(</font>Math<font color="#990000">.</font><b><font color="#000000">random</font></b><font color="#990000">()*</font>array<font color="#990000">.</font>length<font color="#990000">)];</font>
<font color="#FF0000">}</font><font color="#990000">,</font>
add <font color="#990000">:</font> <b><font color="#0000FF">function</font></b><font color="#990000">(</font>x<font color="#990000">,</font> y<font color="#990000">)</font> <font color="#FF0000">{</font>
<b><font color="#0000FF">var</font></b> quote <font color="#990000">=</font> <b><font color="#0000FF">this</font></b><font color="#990000">.</font><b><font color="#000000">random</font></b><font color="#990000">(</font><b><font color="#0000FF">this</font></b><font color="#990000">.</font>quotes<font color="#990000">);</font>
<b><font color="#0000FF">var</font></b> style <font color="#990000">=</font> <font color="#FF0000">"position:absolute; left:50px; top:"</font> <font color="#990000">+</font> <font color="#990000">(</font>y<font color="#990000">-</font><font color="#993399">50</font><font color="#990000">)</font> <font color="#990000">+</font> <font color="#FF0000">"px;"</font>
<font color="#990000">+</font> <font color="#FF0000">"line-height:1.1em; background-color:rgba(128,128,128,.35);"</font>
<font color="#990000">+</font> <font color="#FF0000">"z-index:9999; width:75%; border-radius:.3em; padding: 20px;"</font><font color="#990000">;</font>
<b><font color="#0000FF">var</font></b> div <font color="#990000">=</font> Y<font color="#990000">.</font>Node<font color="#990000">.</font><b><font color="#000000">create</font></b><font color="#990000">(</font><font color="#FF0000">'<div style="'</font> <font color="#990000">+</font> style <font color="#990000">+</font> <font color="#FF0000">'"></div>'</font><font color="#990000">);</font>
div<font color="#990000">.</font><b><font color="#000000">setStyle</font></b><font color="#990000">(</font><font color="#FF0000">'fontSize'</font><font color="#990000">,</font> <b><font color="#0000FF">this</font></b><font color="#990000">.</font><b><font color="#000000">random</font></b><font color="#990000">(</font><b><font color="#0000FF">this</font></b><font color="#990000">.</font>fontSizes<font color="#990000">));</font>
<b><font color="#0000FF">var</font></b> bodyNode <font color="#990000">=</font> Y<font color="#990000">.</font><b><font color="#000000">one</font></b><font color="#990000">(</font>document<font color="#990000">.</font>body<font color="#990000">);</font>
bodyNode<font color="#990000">.</font><b><font color="#000000">append</font></b><font color="#990000">(</font>div<font color="#990000">);</font>
<b><font color="#0000FF">var</font></b> me <font color="#990000">=</font> <b><font color="#0000FF">this</font></b><font color="#990000">;</font>
<b><font color="#0000FF">var</font></b> data <font color="#990000">=</font> <font color="#FF0000">{</font>
words<font color="#990000">:</font> quote<font color="#990000">.</font><b><font color="#000000">split</font></b><font color="#990000">(</font><font color="#FF0000">' '</font><font color="#990000">).</font><b><font color="#000000">reverse</font></b><font color="#990000">(),</font>
append<font color="#990000">:</font> <b><font color="#0000FF">function</font></b><font color="#990000">()</font> <font color="#FF0000">{</font>
<b><font color="#0000FF">var</font></b> span <font color="#990000">=</font> Y<font color="#990000">.</font>Node<font color="#990000">.</font><b><font color="#000000">create</font></b><font color="#990000">(</font><font color="#FF0000">"<span>"</font>
<font color="#990000">+</font> Y<font color="#990000">.</font>Escape<font color="#990000">.</font><b><font color="#000000">html</font></b><font color="#990000">(</font><b><font color="#0000FF">this</font></b><font color="#990000">.</font>words<font color="#990000">.</font><b><font color="#000000">pop</font></b><font color="#990000">())</font> <font color="#990000">+</font> <font color="#FF0000">" </span>"</font><font color="#990000">);</font>
span<font color="#990000">.</font><b><font color="#000000">setStyle</font></b><font color="#990000">(</font><font color="#FF0000">'color'</font><font color="#990000">,</font> me<font color="#990000">.</font><b><font color="#000000">random</font></b><font color="#990000">(</font>me<font color="#990000">.</font>colors<font color="#990000">));</font>
span<font color="#990000">.</font><b><font color="#000000">setStyle</font></b><font color="#990000">(</font><font color="#FF0000">'fontFamily'</font><font color="#990000">,</font> me<font color="#990000">.</font><b><font color="#000000">random</font></b><font color="#990000">(</font>me<font color="#990000">.</font>fonts<font color="#990000">));</font>
span<font color="#990000">.</font><b><font color="#000000">setStyle</font></b><font color="#990000">(</font><font color="#FF0000">'fontVariant'</font><font color="#990000">,</font> me<font color="#990000">.</font><b><font color="#000000">random</font></b><font color="#990000">(</font>me<font color="#990000">.</font>fontVariants<font color="#990000">));</font>
span<font color="#990000">.</font><b><font color="#000000">setStyle</font></b><font color="#990000">(</font><font color="#FF0000">'fontWeight'</font><font color="#990000">,</font> me<font color="#990000">.</font><b><font color="#000000">random</font></b><font color="#990000">(</font>me<font color="#990000">.</font>fontWeights<font color="#990000">));</font>
div<font color="#990000">.</font><b><font color="#000000">append</font></b><font color="#990000">(</font>span<font color="#990000">);</font>
<i><font color="#9A1900">// Let's try to give the quote presentation the cadence of Capt. Kirk</font></i>
<b><font color="#0000FF">var</font></b> f <font color="#990000">=</font> <font color="#990000">[</font>Math<font color="#990000">.</font><b><font color="#000000">floor</font></b><font color="#990000">(</font><font color="#993399">2</font><font color="#990000">*</font>Math<font color="#990000">.</font><b><font color="#000000">random</font></b><font color="#990000">()),</font> Math<font color="#990000">.</font><b><font color="#000000">floor</font></b><font color="#990000">(</font><font color="#993399">2</font><font color="#990000">*</font>Math<font color="#990000">.</font><b><font color="#000000">random</font></b><font color="#990000">())];</font>
<b><font color="#0000FF">var</font></b> r <font color="#990000">=</font> <font color="#990000">[</font><font color="#993399">300</font><font color="#990000">*</font>Math<font color="#990000">.</font><b><font color="#000000">random</font></b><font color="#990000">(),</font> <font color="#993399">200</font><font color="#990000">*</font>Math<font color="#990000">.</font><b><font color="#000000">random</font></b><font color="#990000">(),</font> <font color="#993399">1000</font><font color="#990000">];</font>
<b><font color="#0000FF">var</font></b> when <font color="#990000">=</font> Math<font color="#990000">.</font><b><font color="#000000">floor</font></b><font color="#990000">(</font>r<font color="#990000">[</font><font color="#993399">0</font><font color="#990000">]</font> <font color="#990000">+</font> f<font color="#990000">[</font><font color="#993399">0</font><font color="#990000">]*(</font>r<font color="#990000">[</font><font color="#993399">1</font><font color="#990000">]</font> <font color="#990000">+</font> f<font color="#990000">[</font><font color="#993399">1</font><font color="#990000">]*</font>r<font color="#990000">[</font><font color="#993399">2</font><font color="#990000">]));</font>
<b><font color="#0000FF">if</font></b> <font color="#990000">(</font><b><font color="#0000FF">this</font></b><font color="#990000">.</font>words<font color="#990000">.</font>length <font color="#990000">></font> <font color="#993399">0</font><font color="#990000">)</font> <font color="#FF0000">{</font>
Y<font color="#990000">.</font><b><font color="#000000">later</font></b><font color="#990000">(</font>when<font color="#990000">,</font> <b><font color="#0000FF">this</font></b><font color="#990000">,</font> <font color="#FF0000">'append'</font><font color="#990000">);</font>
<font color="#FF0000">}</font>
<font color="#FF0000">}</font>
<font color="#FF0000">}</font><font color="#990000">;</font>
data<font color="#990000">.</font><b><font color="#000000">append</font></b><font color="#990000">();</font>
Y<font color="#990000">.</font><b><font color="#000000">later</font></b><font color="#990000">(</font><font color="#993399">30</font><font color="#990000">*</font><font color="#993399">1000</font><font color="#990000">,</font> <b><font color="#0000FF">this</font></b><font color="#990000">,</font> <b><font color="#0000FF">function</font></b><font color="#990000">()</font><font color="#FF0000">{</font>bodyNode<font color="#990000">.</font><b><font color="#000000">removeChild</font></b><font color="#990000">(</font>div<font color="#990000">)</font><font color="#FF0000">}</font><font color="#990000">);</font>
<font color="#FF0000">}</font><font color="#990000">,</font>
quotesOnClick <font color="#990000">:</font> <b><font color="#0000FF">function</font></b> <font color="#990000">(</font>node<font color="#990000">)</font> <font color="#FF0000">{</font>
<b><font color="#0000FF">var</font></b> quotify <font color="#990000">=</font> <b><font color="#0000FF">this</font></b><font color="#990000">;</font>
node<font color="#990000">.</font><b><font color="#000000">on</font></b><font color="#990000">(</font><font color="#FF0000">'click'</font><font color="#990000">,</font> <b><font color="#0000FF">function</font></b><font color="#990000">(</font>e<font color="#990000">)</font> <font color="#FF0000">{</font>
quotify<font color="#990000">.</font><b><font color="#000000">add</font></b><font color="#990000">(</font>e<font color="#990000">.</font>pageX<font color="#990000">,</font> e<font color="#990000">.</font>pageY<font color="#990000">);</font>
e<font color="#990000">.</font><b><font color="#000000">preventDefault</font></b><font color="#990000">();</font> <i><font color="#9A1900">// Stop the event's default behavior</font></i>
e<font color="#990000">.</font><b><font color="#000000">stopPropagation</font></b><font color="#990000">();</font> <i><font color="#9A1900">// Stop the event from bubbling up</font></i>
<font color="#FF0000">}</font><font color="#990000">);</font>
<font color="#FF0000">}</font>
<font color="#FF0000">}</font><font color="#990000">;</font>
<font color="#FF0000">}</font><font color="#990000">,</font> <font color="#FF0000">'1.0'</font><font color="#990000">,</font> <font color="#FF0000">{</font>
requires<font color="#990000">:</font> <font color="#990000">[</font><font color="#FF0000">'node'</font><font color="#990000">,</font> <font color="#FF0000">'escape'</font><font color="#990000">,</font> <font color="#FF0000">'yui-later'</font><font color="#990000">,</font> <font color="#FF0000">'event'</font><font color="#990000">]</font>
<font color="#FF0000">}</font><font color="#990000">);</font></tt></pre></td></tr></table>
<p>A quick primer in case you are not familiar with YUI module system: the module is defined using the <tt>YUI.add()</tt> function (an instance of YUI is obtained via the global <tt>YUI()</tt> function). The first argument gives the module name, here we have used <em>com.example.quotify</em>. The second argument is a function that will only be invoked when the module is required. The next argument is an unused version number for the module, then finally an array of modules the new module depends on. Within the module definition function, you are expected to set a property on the passed <tt>YUI</tt> instance containing your module. Since we are using a multilevel namespace, we use the <tt>YUI.namespace()</tt> function to ensure it exists. Then we can set the <tt>Y.com.example.quotify</tt> property. We will get to using the module soon.</p>
<p>That is everything we need for the Liferay hook. Of course, hooks in Liferay provide a great deal more functionality then what we have used here, but this post is going to be long enough as it is. Package your WAR and place it in the Liferay deploy directory.</p>
<p>Now we are ready to create our portlet. Start a new WAR project. Let’s begin with the JavaScript for the portlet which will give a chance to see how to use YUI modules. Create a file named <tt>js/portlet.js</tt>:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><b><font color="#000000">YUI</font></b><font color="#990000">().</font><b><font color="#000000">use</font></b><font color="#990000">([</font><font color="#FF0000">'com.example.quotify'</font><font color="#990000">,</font> <font color="#FF0000">'node'</font><font color="#990000">,</font> <font color="#FF0000">'event'</font><font color="#990000">],</font> <b><font color="#0000FF">function</font></b><font color="#990000">(</font>Y<font color="#990000">)</font> <font color="#FF0000">{</font>
Y<font color="#990000">.</font><b><font color="#000000">on</font></b><font color="#990000">(</font><font color="#FF0000">'domready'</font><font color="#990000">,</font> <b><font color="#0000FF">function</font></b><font color="#990000">()</font> <font color="#FF0000">{</font>
Y<font color="#990000">.</font><b><font color="#000000">all</font></b><font color="#990000">(</font><font color="#FF0000">'.quoteme'</font><font color="#990000">).</font><b><font color="#000000">each</font></b><font color="#990000">(</font><b><font color="#0000FF">function</font></b><font color="#990000">(</font>node<font color="#990000">,</font> index<font color="#990000">,</font> list<font color="#990000">)</font> <font color="#FF0000">{</font>
Y<font color="#990000">.</font>com<font color="#990000">.</font>example<font color="#990000">.</font>quotify<font color="#990000">.</font><b><font color="#000000">quotesOnClick</font></b><font color="#990000">(</font>node<font color="#990000">);</font>
<font color="#FF0000">}</font><font color="#990000">);</font>
<font color="#FF0000">}</font><font color="#990000">);</font>
<font color="#FF0000">}</font><font color="#990000">);</font></tt></pre></td></tr></table>
<p>In order to use a YUI module, we invoke the <tt>YUI.use()</tt> function. The first argument is an array of module names we would like to use. The second argument is a function accepting a <tt>YUI</tt> instance. The YUI system will pass a <tt>YUI</tt> instance that has had the requested modules initialized. This instance will be distinct to this <tt>YUI.use()</tt> invocation; if <tt>YUI.use()</tt> is used a second time to utilize the module that use will get a distinct instance of <tt>Y.com.example.quotify</tt>. (The word <em>use</em> now has no meaning to me after that paragraph. I’ll try not to u— include it again.)</p>
<p>Next we tell Liferay to insert a reference to our JavaScript file in the header for any page containing our portlet. This is done in the <tt>/WEB-INF/liferay-portlet.xml</tt> file:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><b><font color="#000080"><?xml</font></b> <font color="#009900">version</font><font color="#990000">=</font><font color="#FF0000">"1.0"</font> <font color="#009900">encoding</font><font color="#990000">=</font><font color="#FF0000">"UTF-8"</font><b><font color="#000080">?></font></b>
<b><font color="#000080"><!DOCTYPE</font></b> <font color="#009900">liferay</font>-<font color="#009900">portlet</font>-<font color="#009900">app</font>
<font color="#009900">PUBLIC</font> <font color="#FF0000">"-//Liferay//DTD Portlet Application 6.2.0//EN"</font>
<font color="#FF0000">"http://www.liferay.com/dtd/liferay-portlet-app_6_2_0.dtd"</font><b><font color="#000080">></font></b>
<b><font color="#0000FF"><liferay-portlet-app></font></b>
<b><font color="#0000FF"><portlet></font></b>
<i><font color="#9A1900"><!-- TODO: Use the name of your portlet from the portlet.xml here --></font></i>
<b><font color="#0000FF"><portlet-name></font></b>name of your portlet from portlet.xml<b><font color="#0000FF"></portlet-name></font></b>
<b><font color="#0000FF"><instanceable></font></b>true<b><font color="#0000FF"></instanceable></font></b>
<b><font color="#0000FF"><header-portlet-javascript></font></b>/js/portlet.js<b><font color="#0000FF"></header-portlet-javascript></font></b>
<b><font color="#0000FF"></portlet></font></b>
<b><font color="#0000FF"></liferay-portlet-app></font></b></tt></pre></td></tr></table>
<p>Here we reference our JavaScript file in the <tt><header-portlet-javascript></tt> tag. The <tt><instanceable></tt> tag indicates to Liferay whether the portlet may be included on the page once (<em>false</em>) or many times (<em>true</em>). You may need to adjust it depending on whatever portlet you decided to turn into Frankenstein’s monster by sewing my quotify module onto it.</p>
<p>Next make sure that your portlet output has some <tt><span></tt> or <tt><div></tt> tags with the <em>quoteme</em> class defined, e.g. <tt><span class="quoteme">I’m just some innocent text</span></tt>. The <tt>Y.on(<em>domready</em>,…)</tt> idiom executes the function body when the DOM is available; at that point <em>onclick</em> handlers are added to every DOM element with the <em>quoteme</em> class defined.</p>
<p>In summary, Liferay’s support for JavaScript modules, while not as integrated as GateIn’s, is quite serviceable. Liferay supports multiple hooks on a single server, so you can have a separate hook for each JavaScript module if you want and you can easily distribute your modules to third parties as well.</p>
<p>One advantage of GateIn’s approach over the approach above is that GateIn can dynamically include the necessary JavaScript files on the page on demand and omit the unnecessary. However, given the extensibility of the Liferay portal, it is not hard to imagine implementing hooks or extensions it to handle modules the same way. One would need to hook into the deployment event to scan and register the modules and then include the right <tt><script></tt> tags on render.</p>
RayDeCampohttp://www.blogger.com/profile/00893357454992134962noreply@blogger.com0tag:blogger.com,1999:blog-6427287440000636763.post-31455248016261523092013-11-10T09:30:00.000-05:002013-11-10T09:30:00.576-05:00Liferay 6.2 Portal on JBoss 7.2.0<p><a href="http://www.liferay.com">Liferay</a> is a <a href="http://www.jcp.org/en/jsr/detail?id=286">JSR-286</a> (also known as Portal 2.0) compliant portal (and a whole lot more). Since I am in the market for a portal server for an upcoming project, I figured I needed to check Liferay out. The folks at Liferay have bundled version 6.2 with a number of different open-source application servers, including JBoss 7.1.1, but what fun would it be to simply download a bundle? Liferay is also available as a war download for deployment on existing (and closed-source) application servers. So let’s see if we can get Liferay running on the JBoss 7.2.0 server <a href="/2013/10/build-and-install-jboss-720-on-centos-64.html">we built previously</a>.</p>
<p>We will need the Liferay war (<tt>liferay-portal-6.2.0-ce-ga1-20131101192857659.war</tt>) and the Liferay dependencies package (<tt>liferay-portal-dependencies-6.2.0-ce-ga1-20131101192857659.zip</tt>) available from the <a href="http://www.liferay.com/downloads/liferay-portal/additional-files">Additional Files</a> tab on the Liferay download page. I will be using a PostgreSQL database as well, so I’ll need the <a href="http://jdbc.postgresql.org/download.html">PostgreSQL JDBC driver</a> (<tt>postgresql-9.3-1100.jdbc4.jar</tt>) as well. Feel free to substitute the driver for your favorite DBMS.</p>
<p>First, Liferay will be using the directory above the JBoss installation as a installation directory, so let’s create that directory and extract JBoss:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>$ mkdir liferay
$ cd liferay
$ unzip -q <font color="#990000">..</font>/jboss-as-<font color="#993399">7.2</font><font color="#990000">.</font><font color="#993399">0</font><font color="#990000">.</font>Final<font color="#990000">.</font>zip</tt></pre></td></tr></table>
<p>Liferay requires that you install the dependencies at the application server level; for JBoss that means creating a module for Liferay. The Liferay installation instructions bundle the JDBC driver with the Liferay module. That feels wrong to me, so we’ll create a separate module for the JDBC driver. In this case I am using PostgreSQL, but this can easily be adapted for any driver.</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>$ cd jboss-as-<font color="#993399">7.2</font><font color="#990000">.</font><font color="#993399">0</font><font color="#990000">.</font>Final/modules
$ mkdir -p org/postgresql/main
$ cp <font color="#990000">../../..</font>/postgresql-<font color="#993399">9.3</font>-<font color="#993399">1100</font><font color="#990000">.</font>jdbc4<font color="#990000">.</font>jar org/postgresql/main<font color="#990000">/</font>
$ mkdir -p com/liferay/portal/main
$ cd com/liferay/portal/main
$ unzip -q <font color="#990000">\</font>
<font color="#990000">../../../../../../..</font>/liferay-portal-dependencies-<font color="#993399">6.2</font><font color="#990000">.</font><font color="#993399">0</font>-ce-ga<font color="#993399">1</font>-<font color="#993399">20131101192857659</font><font color="#990000">.</font>zip
$ mv liferay-portal-dependencies-<font color="#993399">6.2</font><font color="#990000">.</font><font color="#993399">0</font>-ce-ga<font color="#993399">1</font><font color="#990000">/*</font> <font color="#990000">./</font>
$ rmdir liferay-portal-dependencies-<font color="#993399">6.2</font><font color="#990000">.</font><font color="#993399">0</font>-ce-ga<font color="#993399">1</font>
$ cd <font color="#990000">../../../../../..</font></tt></pre></td></tr></table>
<p>Next you’ll need to create the two <tt>module.xml</tt> files. First, for PostgreSQL create the file <tt>jboss-as-7.2.0.Final/modules/org/postgresql/main/module.xml</tt> with contents:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><b><font color="#000080"><?xml</font></b> <font color="#009900">version</font><font color="#990000">=</font><font color="#FF0000">"1.0"</font><b><font color="#000080">?></font></b>
<b><font color="#0000FF"><module</font></b> <font color="#009900">xmlns</font><font color="#990000">=</font><font color="#FF0000">"urn:jboss:module:1.0"</font> <font color="#009900">name</font><font color="#990000">=</font><font color="#FF0000">"org.postgresql"</font><b><font color="#0000FF">></font></b>
<b><font color="#0000FF"><resources></font></b>
<b><font color="#0000FF"><resource-root</font></b> <font color="#009900">path</font><font color="#990000">=</font><font color="#FF0000">"postgresql-9.3-1100.jdbc4.jar"</font> <b><font color="#0000FF">/></font></b>
<b><font color="#0000FF"></resources></font></b>
<b><font color="#0000FF"><dependencies></font></b>
<b><font color="#0000FF"><module</font></b> <font color="#009900">name</font><font color="#990000">=</font><font color="#FF0000">"javax.api"</font> <b><font color="#0000FF">/></font></b>
<b><font color="#0000FF"><module</font></b> <font color="#009900">name</font><font color="#990000">=</font><font color="#FF0000">"javax.transaction.api"</font> <b><font color="#0000FF">/></font></b>
<b><font color="#0000FF"></dependencies></font></b>
<b><font color="#0000FF"></module></font></b></tt></pre></td></tr></table>
<p>Next for the Liferay module, note that we will be adding a dependency on the PostgreSQL module. The file is <tt>jboss-as-7.2.0.Final/modules/com/liferay/portal/main/module.xml</tt>:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><b><font color="#000080"><?xml</font></b> <font color="#009900">version</font><font color="#990000">=</font><font color="#FF0000">"1.0"</font><b><font color="#000080">?></font></b>
<b><font color="#0000FF"><module</font></b> <font color="#009900">xmlns</font><font color="#990000">=</font><font color="#FF0000">"urn:jboss:module:1.0"</font> <font color="#009900">name</font><font color="#990000">=</font><font color="#FF0000">"com.liferay.portal"</font><b><font color="#0000FF">></font></b>
<b><font color="#0000FF"><resources></font></b>
<b><font color="#0000FF"><resource-root</font></b> <font color="#009900">path</font><font color="#990000">=</font><font color="#FF0000">"hsql.jar"</font> <b><font color="#0000FF">/></font></b>
<b><font color="#0000FF"><resource-root</font></b> <font color="#009900">path</font><font color="#990000">=</font><font color="#FF0000">"portal-service.jar"</font> <b><font color="#0000FF">/></font></b>
<b><font color="#0000FF"><resource-root</font></b> <font color="#009900">path</font><font color="#990000">=</font><font color="#FF0000">"portlet.jar"</font> <b><font color="#0000FF">/></font></b>
<b><font color="#0000FF"></resources></font></b>
<b><font color="#0000FF"><dependencies></font></b>
<b><font color="#0000FF"><module</font></b> <font color="#009900">name</font><font color="#990000">=</font><font color="#FF0000">"javax.api"</font> <b><font color="#0000FF">/></font></b>
<b><font color="#0000FF"><module</font></b> <font color="#009900">name</font><font color="#990000">=</font><font color="#FF0000">"javax.mail.api"</font> <b><font color="#0000FF">/></font></b>
<b><font color="#0000FF"><module</font></b> <font color="#009900">name</font><font color="#990000">=</font><font color="#FF0000">"javax.servlet.api"</font> <b><font color="#0000FF">/></font></b>
<b><font color="#0000FF"><module</font></b> <font color="#009900">name</font><font color="#990000">=</font><font color="#FF0000">"javax.servlet.jsp.api"</font> <b><font color="#0000FF">/></font></b>
<b><font color="#0000FF"><module</font></b> <font color="#009900">name</font><font color="#990000">=</font><font color="#FF0000">"javax.transaction.api"</font> <b><font color="#0000FF">/></font></b>
<b><font color="#0000FF"><module</font></b> <font color="#009900">name</font><font color="#990000">=</font><font color="#FF0000">"org.postgresql"</font> <b><font color="#0000FF">/></font></b>
<b><font color="#0000FF"></dependencies></font></b>
<b><font color="#0000FF"></module></font></b></tt></pre></td></tr></table>
<p>While we are mucking around with the modules, it seems like a good time to make the Liferay-recommended changes to the system modules of JBoss. Open up <tt>jboss-as-7.2.0.Final/modules/system/layers/base/sun/jdk/main/module.xml</tt> and add the following <tt><path></tt> tags under the existing <tt><paths></tt> tag:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><b><font color="#0000FF"><path</font></b> <font color="#009900">name</font><font color="#990000">=</font><font color="#FF0000">"com/sun/crypto"</font> <b><font color="#0000FF">/></font></b>
<b><font color="#0000FF"><path</font></b> <font color="#009900">name</font><font color="#990000">=</font><font color="#FF0000">"com/sun/org/apache/xml/internal/resolver"</font> <b><font color="#0000FF">/></font></b>
<b><font color="#0000FF"><path</font></b> <font color="#009900">name</font><font color="#990000">=</font><font color="#FF0000">"com/sun/org/apache/xml/internal/resolver/tools"</font> <b><font color="#0000FF">/></font></b></tt></pre></td></tr></table>
<p>The <a href="https://www.liferay.com/documentation/liferay-portal/6.2/user-guide/-/ai/installing-liferay-on-jboss-7-liferay-portal-6-2-user-guide-15-en">Liferay documentation</a> at this point indicates there are some steps to do to
work around <a href="https://issues.jboss.org/browse/JBPAPP6-932">JBPAPP6-932</a>. However, that bug only affects environments using the IBM JDK, which I am not planning on doing. Further, I am using JBoss 7.2.0 and the patch is for 7.1.x; it is not clear if the bug exists in 7.2.0 or if the patch is appropriate for 7.2.0. The upshot is I am skipping that step but you may want to consider if you need it.</p>
<p>Next up are some edits to the JBoss configuration file, <tt>standalone-full.xml</tt>. (I typically configure my servers to use <tt>standalone-full.xml</tt> instead of just <tt>standalone.xml</tt>, YMMV.) We’ll start by adding some system properties following the <tt><extensions></tt> tag:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><b><font color="#0000FF"><system-properties></font></b>
<b><font color="#0000FF"><property</font></b> <font color="#009900">name</font><font color="#990000">=</font><font color="#FF0000">"org.apache.catalina.connector.URI_ENCODING"</font>
<font color="#009900">value</font><font color="#990000">=</font><font color="#FF0000">"UTF-8"</font><b><font color="#0000FF">/></font></b>
<b><font color="#0000FF"><property</font></b>
<font color="#009900">name</font><font color="#990000">=</font><font color="#FF0000">"org.apache.catalina.connector.USE_BODY_ENCODING_FOR_QUERY_STRING"</font>
<font color="#009900">value</font><font color="#990000">=</font><font color="#FF0000">"true"</font><b><font color="#0000FF">/></font></b>
<b><font color="#0000FF"></system-properties></font></b></tt></pre></td></tr></table>
<p>We also need a to set a timeout for the deployment scanner by adding the <tt>deployment-timeout</tt> attribute to the existing <tt>deployment-scanner</tt> tag:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><b><font color="#0000FF"><subsystem</font></b> <font color="#009900">xmlns</font><font color="#990000">=</font><font color="#FF0000">"urn:jboss:domain:deployment-scanner:1.1"</font><b><font color="#0000FF">></font></b>
<b><font color="#0000FF"><deployment-scanner</font></b> <font color="#009900">path</font><font color="#990000">=</font><font color="#FF0000">"deployments"</font> <font color="#009900">relative-to</font><font color="#990000">=</font><font color="#FF0000">"jboss.server.base.dir"</font>
<font color="#009900">scan-interval</font><font color="#990000">=</font><font color="#FF0000">"5000"</font> <font color="#009900">deployment-timeout</font><font color="#990000">=</font><font color="#FF0000">"240"</font><b><font color="#0000FF">/></font></b>
<b><font color="#0000FF"></subsystem></font></b></tt></pre></td></tr></table>
<p>Next we need to configure the Liferay login system. Add a <tt><security-domain></tt>
tag to the existing <tt><security-domains></tt> tag in the existing <tt><subsystem xmlns="urn:jboss:domain:security:1.2"></tt> tag</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><b><font color="#0000FF"><security-domain</font></b> <font color="#009900">name</font><font color="#990000">=</font><font color="#FF0000">"PortalRealm"</font><b><font color="#0000FF">></font></b>
<b><font color="#0000FF"><authentication></font></b>
<b><font color="#0000FF"><login-module</font></b> <font color="#009900">code</font><font color="#990000">=</font><font color="#FF0000">"com.liferay.portal.security.jaas.PortalLoginModule"</font>
<font color="#009900">flag</font><font color="#990000">=</font><font color="#FF0000">"required"</font><b><font color="#0000FF">/></font></b>
<b><font color="#0000FF"></authentication></font></b>
<b><font color="#0000FF"></security-domain></font></b></tt></pre></td></tr></table>
<p>We will be replacing the standard JBoss welcome application with Liferay later, so we need to set the <tt>enable-welcome-root</tt> attribute to false on the existing <tt><virtual-server></tt> tag. We will also set the JSP mode to development by adding <tt><configuration></tt> and <tt><jsp-configuration></tt> tags in the web <tt><subsystem></tt>:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><b><font color="#0000FF"><subsystem</font></b> <font color="#009900">xmlns</font><font color="#990000">=</font><font color="#FF0000">"urn:jboss:domain:web:1.4"</font> <font color="#009900">default-virtual-server</font><font color="#990000">=</font><font color="#FF0000">"default-host"</font> <font color="#009900">native</font><font color="#990000">=</font><font color="#FF0000">"false"</font><b><font color="#0000FF">></font></b>
<b><font color="#0000FF"><configuration></font></b>
<b><font color="#0000FF"><jsp-configuration</font></b> <font color="#009900">development</font><font color="#990000">=</font><font color="#FF0000">"true"</font><b><font color="#0000FF">/></font></b>
<b><font color="#0000FF"></configuration></font></b>
<b><font color="#0000FF"><connector</font></b> <font color="#009900">name</font><font color="#990000">=</font><font color="#FF0000">"http"</font> <font color="#009900">protocol</font><font color="#990000">=</font><font color="#FF0000">"HTTP/1.1"</font> <font color="#009900">scheme</font><font color="#990000">=</font><font color="#FF0000">"http"</font>
<font color="#009900">socket-binding</font><font color="#990000">=</font><font color="#FF0000">"http"</font><b><font color="#0000FF">/></font></b>
<b><font color="#0000FF"><virtual-server</font></b> <font color="#009900">name</font><font color="#990000">=</font><font color="#FF0000">"default-host"</font> <font color="#009900">enable-welcome-root</font><font color="#990000">=</font><font color="#FF0000">"false"</font><b><font color="#0000FF">></font></b>
<b><font color="#0000FF"><alias</font></b> <font color="#009900">name</font><font color="#990000">=</font><font color="#FF0000">"localhost"</font><b><font color="#0000FF">/></font></b>
<b><font color="#0000FF"><alias</font></b> <font color="#009900">name</font><font color="#990000">=</font><font color="#FF0000">"example.com"</font><b><font color="#0000FF">/></font></b>
<b><font color="#0000FF"></virtual-server></font></b>
<b><font color="#0000FF"></subsystem></font></b></tt></pre></td></tr></table>
<p>While we are here, let’s create a mail session for Liferay to use by modifying the existing <tt><mail-session></tt> tag in the <tt><subsystem xmlns="urn:jboss:domain:mail:1.0"></tt> tag:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><b><font color="#0000FF"><subsystem</font></b> <font color="#009900">xmlns</font><font color="#990000">=</font><font color="#FF0000">"urn:jboss:domain:mail:1.0"</font><b><font color="#0000FF">></font></b>
<b><font color="#0000FF"><mail-session</font></b>
<font color="#009900">jndi-name</font><font color="#990000">=</font><font color="#FF0000">"java:/mail/MailSession"</font>
<font color="#009900">from</font><font color="#990000">=</font><font color="#FF0000">"MAIL_ADDRESS"</font><b><font color="#0000FF">></font></b>
<b><font color="#0000FF"><smtp-server</font></b> <font color="#009900">outbound-socket-binding-ref</font><font color="#990000">=</font><font color="#FF0000">"mail-smtp"</font><b><font color="#0000FF">></font></b>
<b><font color="#0000FF"><login</font></b> <font color="#009900">name</font><font color="#990000">=</font><font color="#FF0000">"MAIL_USER"</font> <font color="#009900">password</font><font color="#990000">=</font><font color="#FF0000">"MAIL_PASSWORD"</font><b><font color="#0000FF">/></font></b>
<b><font color="#0000FF"></smtp-server></font></b>
<b><font color="#0000FF"></mail-session></font></b>
<b><font color="#0000FF"></subsystem></font></b></tt></pre></td></tr></table>
<p>We also need to tell JBoss that the socket binding <tt>mail-smtp</tt> should talk to the right mail server. Change the <tt>host</tt> attribute of the existing <tt><remote-destination></tt> tag for the <tt>mail-smtp</tt> socket binding:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><b><font color="#0000FF"><outbound-socket-binding</font></b> <font color="#009900">name</font><font color="#990000">=</font><font color="#FF0000">"mail-smtp"</font><b><font color="#0000FF">></font></b>
<b><font color="#0000FF"><remote-destination</font></b> <font color="#009900">host</font><font color="#990000">=</font><font color="#FF0000">"MAIL_HOST"</font> <font color="#009900">port</font><font color="#990000">=</font><font color="#FF0000">"25"</font><b><font color="#0000FF">/></font></b>
<b><font color="#0000FF"></outbound-socket-binding></font></b></tt></pre></td></tr></table>
<p>Of course, replace the <tt>MAIL_ADDRESS</tt>, <tt>MAIL_HOST</tt>, <tt>MAIL_USER</tt> and <tt>MAIL_PASSWORD</tt> tokens in the above with the proper values for your environment.</p>
<p>Finally we create a JDBC data source for Liferay to use in two steps. First, add a <tt><datasource></tt> tag to the existing <tt><datasources></tt> in the <tt><subsystem xmlns="urn:jboss:domain:datasources:1.1"></tt> subsystem:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><b><font color="#0000FF"><datasource</font></b> <font color="#009900">jta</font><font color="#990000">=</font><font color="#FF0000">"true"</font> <font color="#009900">jndi-name</font><font color="#990000">=</font><font color="#FF0000">"java:/jdbc/LiferayPool"</font>
<font color="#009900">pool-name</font><font color="#990000">=</font><font color="#FF0000">"LiferayPool"</font> <font color="#009900">enabled</font><font color="#990000">=</font><font color="#FF0000">"true"</font> <font color="#009900">use-java-context</font><font color="#990000">=</font><font color="#FF0000">"true"</font> <font color="#009900">use-ccm</font><font color="#990000">=</font><font color="#FF0000">"true"</font><b><font color="#0000FF">></font></b>
<b><font color="#0000FF"><connection-url></font></b>jdbc:postgresql://DB_SERVER:5432/DB_DATABASE<b><font color="#0000FF"></connection-url></font></b>
<b><font color="#0000FF"><driver></font></b>postgresql<b><font color="#0000FF"></driver></font></b>
<b><font color="#0000FF"><pool></font></b>
<b><font color="#0000FF"><min-pool-size></font></b>1<b><font color="#0000FF"></min-pool-size></font></b>
<b><font color="#0000FF"><max-pool-size></font></b>20<b><font color="#0000FF"></max-pool-size></font></b>
<b><font color="#0000FF"><prefill></font></b>true<b><font color="#0000FF"></prefill></font></b>
<b><font color="#0000FF"></pool></font></b>
<b><font color="#0000FF"><security></font></b>
<b><font color="#0000FF"><user-name></font></b>DB_USERNAME<b><font color="#0000FF"></user-name></font></b>
<b><font color="#0000FF"><password></font></b>DB_PASSWORD<b><font color="#0000FF"></password></font></b>
<b><font color="#0000FF"></security></font></b>
<b><font color="#0000FF"><validation></font></b>
<b><font color="#0000FF"><valid-connection-checker</font></b> <font color="#009900">class-name</font><font color="#990000">=</font><font color="#FF0000">"org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker"</font><b><font color="#0000FF">/></font></b>
<b><font color="#0000FF"><validate-on-match></font></b>false<b><font color="#0000FF"></validate-on-match></font></b>
<b><font color="#0000FF"><background-validation></font></b>false<b><font color="#0000FF"></background-validation></font></b>
<b><font color="#0000FF"></validation></font></b>
<b><font color="#0000FF"><statement></font></b>
<b><font color="#0000FF"><prepared-statement-cache-size></font></b>16<b><font color="#0000FF"></prepared-statement-cache-size></font></b>
<b><font color="#0000FF"><share-prepared-statements></font></b>true<b><font color="#0000FF"></share-prepared-statements></font></b>
<b><font color="#0000FF"></statement></font></b>
<b><font color="#0000FF"></datasource></font></b></tt></pre></td></tr></table>
<p>Then add a <tt><driver></tt> tag to the existing <tt><drivers></tt> tag within the <tt><datasources></tt> tag:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><b><font color="#0000FF"><driver</font></b> <font color="#009900">name</font><font color="#990000">=</font><font color="#FF0000">"postgresql"</font> <font color="#009900">module</font><font color="#990000">=</font><font color="#FF0000">"org.postgresql"</font><b><font color="#0000FF">></font></b>
<b><font color="#0000FF"><xa-datasource-class></font></b>org.postgresql.xa.PGXADataSource<b><font color="#0000FF"></xa-datasource-class></font></b>
<b><font color="#0000FF"></driver></font></b></tt></pre></td></tr></table>
<p>Again, replace the <tt>DB_SERVER</tt>, <tt>DB_DATABASE</tt>, <tt>DB_USERNAME</tt> and <tt>DB_PASSWORD</tt> tokens with the correct values for your environment. If you are using a different database server, you’ll have to change the <tt><connection-url></tt>, the <tt>class-name</tt> for the <tt><validation-connection-checker></tt> and the <tt><xa-datasource-class></tt> as well, but you knew that already. For the database, use an empty schema and Liferay will populate it when it first starts.</p>
<p>Liferay requires certain system properties to be set when JBoss is started. Use your favorite mechanism to ensure the following values are set:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" style="margin:0.2em 0;">
<tr><td style="padding:0.5em;">
<pre style="margin:0; padding:0;">-Dfile.encoding=UTF-8
-Djava.net.preferIPv4Stack=true
-Djava.security.manager
-Djava.security.policy=$JBOSS_HOME\bin\server.policy
-Djboss.home.dir=$JBOSS_HOME</pre>
</td></tr>
</table>
<p>If you are developing on Windows, use the <tt>standalone/standalone.conf.bat</tt> file. If you have set up JBoss on CentOS per <a href="/2013/10/build-and-install-jboss-720-on-centos-64.html">my instructions</a>, you can use the <tt>/etc/jboss-as/jboss-as.properties</tt> file (drop the <tt>-D</tt> prefixes of course).</p>
<p>Don’t forget to set the set the <tt>-Xmx</tt> and <tt>-XX:MaxPermSize</tt> options while you are editing files in the <tt>bin</tt> directory. Liferay recommends <tt>-Xmx1024m -XX:MaxPermSize=256m</tt>.</p>
<p>The Liferay documentation suggests setting the <tt>user.timezone</tt> property to GMT as well. I encountered problems with that setting when deploying JSP changes. The Liferay deployer left the JSP timestamped with GMT time value on the file system; since these were always in the past for me the JSPs always looked older than their last compile time from JBoss’s point of view. So they did not get recompiled. So I have skipped that setting.</p>
<p>While we are fooling around with the JBoss start-up mechanism, it seems like a good time to create the <tt>server.policy</tt> file in <tt>jboss-as-7.2.0.Final/bin</tt>:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" style="margin:0.2em 0;">
<tr><td style="padding:0.5em;">
<pre style="margin:0; padding:0;">grant {
permission java.security.AllPermission;
};</pre>
</td></tr>
</table>
<p>Next we need to define the <tt>portal-ext.properties</tt> file in the <tt>liferay</tt> directory. We tell Liferay where in the JNDI to find our data source and mail session. We also disable the mechanism where it tries to launch a browser every time it starts.</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><font color="#009900">jdbc.default.jndi.name</font><font color="#990000">=</font>java:/jdbc/LiferayPool
<font color="#009900">mail.session.jndi.name</font><font color="#990000">=</font>java:/mail/MailSession
<font color="#009900">browser.launcher.url</font><font color="#990000">=</font></tt></pre></td></tr></table>
<p>Something to note here is that the Liferay documentation omits the first slash in the JNDI names which causes issues on JBoss 7.2.0. Include the slash and make sure your names are consistent between the <tt>portal-ext.properties</tt> and <tt>standalone-full.xml</tt> files.</p>
<p>OK, we are to install Liferay itself. We extract the contents of the Liferay war download into a new directory under <tt>deployments</tt>. Then we need to delete the <tt>eclipselink.jar</tt> from the <tt>lib</tt> directory. Finally we create a <tt>.dodeploy</tt> file to trigger the deployment:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>$ cd jboss-as-<font color="#993399">7.2</font><font color="#990000">.</font><font color="#993399">0</font><font color="#990000">.</font>Final/standalone/deployments<font color="#990000">/</font>
$ mkdir liferay-portal<font color="#990000">.</font>war
$ cd liferay-portal<font color="#990000">.</font>war
$ jar xf <font color="#990000">../../../../..</font>/liferay-portal-<font color="#993399">6.2</font><font color="#990000">.</font><font color="#993399">0</font>-ce-ga<font color="#993399">1</font>-<font color="#993399">20131101192857659</font><font color="#990000">.</font>war
$ rm WEB-INF/lib/eclipselink<font color="#990000">.</font>jar
$ cd <font color="#990000">..</font>
$ touch liferay-portal<font color="#990000">.</font>war<font color="#990000">.</font>dodeploy</tt></pre></td></tr></table>
<p>Note that we are differing from the Liferay instructions again, mainly because JBoss 7.2.0 does not have a <tt>ROOT.war</tt> deployment to clear out. Instead we use the much clearer name <tt>liferay-portal.war</tt>.</p>
<p>At this point you are ready to go. Fire up JBoss and enjoy your Liferay portal at <a href="http://localhost:8080/">http://localhost:8080/</a>. Don’t forget that we used the <tt>standalone-full.xml</tt> file, not the default <tt>standalone.xml</tt> file when you start your application server.</p>RayDeCampohttp://www.blogger.com/profile/00893357454992134962noreply@blogger.com0tag:blogger.com,1999:blog-6427287440000636763.post-30342213080221991052013-11-03T09:30:00.000-05:002014-01-24T10:51:10.593-05:00Packaging GateIn JavaScript Modules in Separate WARs<p>I have been messing around with the <a href="http://www.jboss.org/gatein">GateIn Portal Server</a> in order to evaluate it for an upcoming project. One nice aspect of the portal is the way JavaScript is handled. JavaScript in GateIn is split into modules and managed via the <a href="http://requirejs.org/">RequireJS</a> library. This allows the portlet developer to keep their JavaScript isolated and only include the dependencies they require. It also allows for re-use of modules defined in one portlet in other portlets. It doesn’t take a lot of imagination to picture the disaster JavaScript could become on a portal which doesn’t provide isolation and re-use, especially if multiple organizations are providing portals.</p>
<p>Starting with the solid foundation provided by GateIn, we just need a couple of tweaks to make things even better. First, one potential gotcha is that the modules all live in the same namespace across the portal. So we will borrow the solution from Java and prefix our module names with the inverse of the our domain name. For the purposes of this post, I will use the prefix com.example.</p>
<p>The second thing is that modules are defined in portlets. This could be an issue if you create a re-usable module in portlet X, it gets used in portlet Y and then down the road portlet X is no longer needed and is removed. The solution is to package our re-usable modules in their our war files separate from the portlets.</p>
<p>Which leads me to the point of this post, demonstrating how to package a JavaScript module for GateIn in its own war archive. Originally inspired by <a href="http://thedailywtf.com">the Daily WTF</a>, I was going to create modules for adding unicorns to the portal. But after going to <a href="http://www.cornify.com">http://www.cornify.com</a> to borrow the JavaScript, I discovered the much cooler http://ninjafy.com. So we will be adding ninjas to the portal instead.</p>
<p>Since I originally posted this entry, it has come to my attention that Google is warning users that ninjafy.com may be serving malware. So the safe thing to do would be to get your own (known safe) ninja pictures and package them with your module. Then adjust the URL parameters in the script below.</p>
<p>Just to demonstrate dependencies and module interaction, we will create two modules, <tt>com.example.ninjafy</tt> and <tt>com.example.module</tt>. Create a <tt>js</tt> directory under the web root of the war and add the file <tt>ninjafy.js</tt>:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><i><font color="#9A1900">// Adapted from http://ninjafy.com/js/ninjafy.js</font></i>
<b><font color="#000000">define</font></b><font color="#990000">(</font><b><font color="#0000FF">function</font></b><font color="#990000">()</font> <font color="#FF0000">{</font>
<b><font color="#0000FF">return</font></b> <font color="#FF0000">{</font>
add <font color="#990000">:</font> <b><font color="#0000FF">function</font></b><font color="#990000">()</font> <font color="#FF0000">{</font>
<b><font color="#0000FF">var</font></b> ninjafy_url <font color="#990000">=</font> <font color="#FF0000">'/path/to/images/'</font><font color="#990000">;</font>
<b><font color="#0000FF">var</font></b> file <font color="#990000">=</font> <font color="#FF0000">'ninja_'</font><font color="#990000">;</font>
<b><font color="#0000FF">var</font></b> count <font color="#990000">=</font> <font color="#993399">7</font><font color="#990000">;</font>
file <font color="#990000">+=</font> Math<font color="#990000">.</font><b><font color="#000000">ceil</font></b><font color="#990000">(</font>Math<font color="#990000">.</font><b><font color="#000000">random</font></b><font color="#990000">()*</font>count<font color="#990000">)</font> <font color="#990000">+</font> <font color="#FF0000">'.gif'</font><font color="#990000">;</font>
<b><font color="#0000FF">var</font></b> div <font color="#990000">=</font> document<font color="#990000">.</font><b><font color="#000000">createElement</font></b><font color="#990000">(</font><font color="#FF0000">'div'</font><font color="#990000">);</font>
div<font color="#990000">.</font>style<font color="#990000">.</font>position <font color="#990000">=</font> <font color="#FF0000">'fixed'</font><font color="#990000">;</font>
<b><font color="#0000FF">var</font></b> height <font color="#990000">=</font> Math<font color="#990000">.</font><b><font color="#000000">random</font></b><font color="#990000">()*.</font><font color="#993399">9</font><font color="#990000">;</font>
<b><font color="#0000FF">if</font></b> <font color="#990000">(</font><b><font color="#0000FF">typeof</font></b><font color="#990000">(</font>window<font color="#990000">.</font>innerHeight<font color="#990000">)</font> <font color="#990000">==</font> <font color="#FF0000">'number'</font><font color="#990000">)</font> <font color="#FF0000">{</font>
height <font color="#990000">=</font> height<font color="#990000">*</font>window<font color="#990000">.</font>innerHeight<font color="#990000">+</font><font color="#FF0000">'px'</font><font color="#990000">;</font>
<font color="#FF0000">}</font> <b><font color="#0000FF">else</font></b> <b><font color="#0000FF">if</font></b><font color="#990000">(</font>document<font color="#990000">.</font>documentElement
<font color="#990000">&&</font> document<font color="#990000">.</font>documentElement<font color="#990000">.</font>clientHeight<font color="#990000">)</font> <font color="#FF0000">{</font>
height <font color="#990000">=</font> height<font color="#990000">+</font>document<font color="#990000">.</font>documentElement<font color="#990000">.</font>clientHeight<font color="#990000">+</font><font color="#FF0000">'px'</font><font color="#990000">;</font>
<font color="#FF0000">}</font> <b><font color="#0000FF">else</font></b> <font color="#FF0000">{</font>
height <font color="#990000">=</font> height<font color="#990000">*</font><font color="#993399">100</font><font color="#990000">+</font><font color="#FF0000">'%'</font><font color="#990000">;</font>
<font color="#FF0000">}</font>
div<font color="#990000">.</font>style<font color="#990000">.</font>top <font color="#990000">=</font> height<font color="#990000">;</font>
div<font color="#990000">.</font>style<font color="#990000">.</font>left <font color="#990000">=</font> Math<font color="#990000">.</font><b><font color="#000000">random</font></b><font color="#990000">()*</font><font color="#993399">90</font> <font color="#990000">+</font> <font color="#FF0000">'%'</font><font color="#990000">;</font>
<b><font color="#0000FF">var</font></b> img <font color="#990000">=</font> document<font color="#990000">.</font><b><font color="#000000">createElement</font></b><font color="#990000">(</font><font color="#FF0000">'img'</font><font color="#990000">);</font>
img<font color="#990000">.</font><b><font color="#000000">setAttribute</font></b><font color="#990000">(</font><font color="#FF0000">'src'</font><font color="#990000">,</font>ninjafy_url<font color="#990000">+</font>file<font color="#990000">);</font>
<b><font color="#0000FF">var</font></b> body <font color="#990000">=</font> document<font color="#990000">.</font><b><font color="#000000">getElementsByTagName</font></b><font color="#990000">(</font><font color="#FF0000">'body'</font><font color="#990000">)[</font><font color="#993399">0</font><font color="#990000">];</font>
body<font color="#990000">.</font><b><font color="#000000">appendChild</font></b><font color="#990000">(</font>div<font color="#990000">);</font>
div<font color="#990000">.</font><b><font color="#000000">appendChild</font></b><font color="#990000">(</font>img<font color="#990000">);</font>
<font color="#FF0000">}</font>
<font color="#FF0000">}</font><font color="#990000">;</font>
<font color="#FF0000">}</font><font color="#990000">);</font></tt></pre></td></tr></table>
<p>Here we have adapted the original ninjafy.js script into a <a href="http://requirejs.org/docs/api.html#define">RequireJS module</a>. The RequireJS module takes the form of a function that returns the module. The result of the function is passed to other modules that depend on this one. We defined one function in the ninjafy module, <tt>add()</tt>.</p>
<p>(A quick note about licensing - I couldn’t find any license information on the ninjafy site but the tone of the site certainly implies that re-using their code is encouraged.)</p>
<p>Next we define our second module, which will use the <tt>com.example.ninjafy</tt> modules. Create a file named <tt>example-module.js</tt> in the <tt>js</tt> directory:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><b><font color="#000000">define</font></b><font color="#990000">([</font><font color="#FF0000">"ninjafy"</font><font color="#990000">],</font> <b><font color="#0000FF">function</font></b><font color="#990000">(</font>ninjafy<font color="#990000">)</font> <font color="#FF0000">{</font>
<b><font color="#0000FF">return</font></b> <font color="#FF0000">{</font>
ninjasOnClick<font color="#990000">:</font> <b><font color="#0000FF">function</font></b><font color="#990000">(</font>element<font color="#990000">)</font> <font color="#FF0000">{</font>
element<font color="#990000">.</font>onclick <font color="#990000">=</font> <b><font color="#0000FF">function</font></b><font color="#990000">()</font> <font color="#FF0000">{</font>
ninjafy<font color="#990000">.</font><b><font color="#000000">add</font></b><font color="#990000">();</font>
<b><font color="#0000FF">return</font></b> <b><font color="#0000FF">false</font></b><font color="#990000">;</font>
<font color="#FF0000">}</font><font color="#990000">;</font>
<font color="#FF0000">}</font>
<font color="#FF0000">}</font><font color="#990000">;</font>
<font color="#FF0000">}</font><font color="#990000">);</font></tt></pre></td></tr></table>
<p>Here we can see that the <tt>com.example.ninjafy</tt> module is passed as the variable <tt>ninjafy</tt>. In this module we define a <tt>ninjasOnClick()</tt> function which adds a ninja-adding <tt>onclick</tt> handler to the given HTML element.</p>
<p>Next we have everybody’s favorite part of JEE development: configuring the XML files. The first two are simple. Create a <tt>web.xml</tt> that contains only a <tt>displayName</tt> element (see <a href="https://issues.jboss.org/browse/GTNPORTAL-3107">https://issues.jboss.org/browse/GTNPORTAL-3107</a>). Then create an "empty" <tt>portlet.xml</tt> containing only the top-level <tt><portlet-app></tt> element. These xml files belong in the <tt>WEB-INF</tt> directory of the war of course.</p>
<p>Next we define the <tt>gatein-resources.xml</tt> file, also in the <tt>WEB-INF</tt> directory. This file defines the modules and manages their dependencies:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><b><font color="#000080"><?xml</font></b> <font color="#009900">version</font><font color="#990000">=</font><font color="#FF0000">"1.0"</font> <font color="#009900">encoding</font><font color="#990000">=</font><font color="#FF0000">"UTF-8"</font><b><font color="#000080">?></font></b>
<b><font color="#0000FF"><gatein-resources</font></b>
<font color="#009900">xmlns:xsi</font><font color="#990000">=</font><font color="#FF0000">"http://www.w3.org/2001/XMLSchema-instance"</font>
<font color="#009900">xsi:schemaLocation</font><font color="#990000">=</font><font color="#FF0000">"http://www.gatein.org/xml/ns/gatein_resources_1_3</font>
<font color="#FF0000"> http://www.gatein.org/xml/ns/gatein_resources_1_3"</font>
<font color="#009900">xmlns</font><font color="#990000">=</font><font color="#FF0000">"http://www.gatein.org/xml/ns/gatein_resources_1_3"</font><b><font color="#0000FF">></font></b>
<b><font color="#0000FF"><module></font></b>
<b><font color="#0000FF"><name></font></b>com.example.ninjafy<b><font color="#0000FF"></name></font></b>
<b><font color="#0000FF"><script></font></b>
<b><font color="#0000FF"><path></font></b>/js/ninjafy.js<b><font color="#0000FF"></path></font></b>
<b><font color="#0000FF"></script></font></b>
<b><font color="#0000FF"></module></font></b>
<b><font color="#0000FF"><module></font></b>
<b><font color="#0000FF"><name></font></b>com.example.module<b><font color="#0000FF"></name></font></b>
<b><font color="#0000FF"><script></font></b>
<b><font color="#0000FF"><path></font></b>/js/example-module.js<b><font color="#0000FF"></path></font></b>
<b><font color="#0000FF"></script></font></b>
<b><font color="#0000FF"><depends></font></b>
<b><font color="#0000FF"><module></font></b>com.example.ninjafy<b><font color="#0000FF"></module></font></b>
<b><font color="#0000FF"><as></font></b>ninjafy<b><font color="#0000FF"></as></font></b>
<b><font color="#0000FF"></depends></font></b>
<b><font color="#0000FF"></module></font></b>
<b><font color="#0000FF"></gatein-resources></font></b></tt></pre></td></tr></table>
<p>For the most part this file is self-explanatory. Note in the <tt><depends></tt> tag for the <tt>com.example.module</tt> module we map the <tt>com.example.ninjafy</tt> module to the name <tt>ninjafy</tt>, as expected by the <tt>example-module.js</tt> script.</p>
<p>Now if you build your war file and deploy it to your GateIn server, you will have a nifty new JavaScript module to play with. But what fun is a new library if we don’t actually use it? Assuming you have a working portlet to start with, I’ll show you how to use the new modules.</p>
<p>When creating JavaScript for portlets in GateIn, the recommended way is to define a module for the portlet. This will not be a re-usable module as before, but a module just for the portlet. Create a file named <tt>js/portlet.js</tt> (remember we are working inside the war for your portlet now, not the same war we created above to hold the JavaScript modules):</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><b><font color="#000000">define</font></b><font color="#990000">([</font><font color="#FF0000">"example"</font><font color="#990000">,</font><font color="#FF0000">"$"</font><font color="#990000">],</font> <b><font color="#0000FF">function</font></b><font color="#990000">(</font>example<font color="#990000">,</font> $<font color="#990000">)</font> <font color="#FF0000">{</font>
$<font color="#990000">(</font>document<font color="#990000">).</font><b><font color="#000000">ready</font></b><font color="#990000">(</font><b><font color="#0000FF">function</font></b><font color="#990000">()</font><font color="#FF0000">{</font>
$<font color="#990000">(</font><font color="#FF0000">".ninjame"</font><font color="#990000">).</font><b><font color="#000000">each</font></b><font color="#990000">(</font><b><font color="#0000FF">function</font></b><font color="#990000">(</font>index<font color="#990000">,</font> element<font color="#990000">)</font> <font color="#FF0000">{</font>
example<font color="#990000">.</font><b><font color="#000000">ninjasOnClick</font></b><font color="#990000">(</font>element<font color="#990000">);</font>
<font color="#FF0000">}</font><font color="#990000">);</font>
<font color="#FF0000">}</font><font color="#990000">);</font>
<font color="#FF0000">}</font><font color="#990000">);</font></tt></pre></td></tr></table>
<p>In this case we are expecting the <tt>com.example.module</tt> module as <tt>example</tt> and <a href="http://www.jquery.com">jQuery</a> as <tt>$</tt>. GateIn supplies a jQuery module for you. (You can also use a different version of jQuery if you are picky about it, see the <a href="https://docs.jboss.org/author/display/GTNPORTAL36/JavaScript+Cookbook">GateIn JavaScript documentation</a> for details.) Our module walks the DOM and invokes our <tt>ninjaOnClick()</tt> function for each HTML element with the class <tt>ninjame</tt>.</p>
<p>Next you need to configure this module in the <tt>gatein-resources.xml</tt> for your portlet:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><b><font color="#000080"><?xml</font></b> <font color="#009900">version</font><font color="#990000">=</font><font color="#FF0000">"1.0"</font> <font color="#009900">encoding</font><font color="#990000">=</font><font color="#FF0000">"UTF-8"</font><b><font color="#000080">?></font></b>
<b><font color="#0000FF"><gatein-resources</font></b>
<font color="#009900">xmlns:xsi</font><font color="#990000">=</font><font color="#FF0000">"http://www.w3.org/2001/XMLSchema-instance"</font>
<font color="#009900">xsi:schemaLocation</font><font color="#990000">=</font><font color="#FF0000">"http://www.gatein.org/xml/ns/gatein_resources_1_3</font>
<font color="#FF0000"> http://www.gatein.org/xml/ns/gatein_resources_1_3"</font>
<font color="#009900">xmlns</font><font color="#990000">=</font><font color="#FF0000">"http://www.gatein.org/xml/ns/gatein_resources_1_3"</font><b><font color="#0000FF">></font></b>
<b><font color="#0000FF"><portlet></font></b>
<i><font color="#9A1900"><!-- TODO: Replace the following with the actual name. --></font></i>
<b><font color="#0000FF"><name></font></b>Use the name from your portlet.xml<b><font color="#0000FF"></name></font></b>
<b><font color="#0000FF"><module></font></b>
<b><font color="#0000FF"><script></font></b>
<b><font color="#0000FF"><path></font></b>/js/portlet.js<b><font color="#0000FF"></path></font></b>
<b><font color="#0000FF"></script></font></b>
<b><font color="#0000FF"><depends></font></b>
<b><font color="#0000FF"><module></font></b>com.example.module<b><font color="#0000FF"></module></font></b>
<b><font color="#0000FF"><as></font></b>example<b><font color="#0000FF"></as></font></b>
<b><font color="#0000FF"></depends></font></b>
<b><font color="#0000FF"><depends></font></b>
<b><font color="#0000FF"><module></font></b>jquery<b><font color="#0000FF"></module></font></b>
<b><font color="#0000FF"><as></font></b>$<b><font color="#0000FF"></as></font></b>
<b><font color="#0000FF"></depends></font></b>
<b><font color="#0000FF"></module></font></b>
<b><font color="#0000FF"></portlet></font></b>
<b><font color="#0000FF"></gatein-resources></font></b></tt></pre></td></tr></table>
<p>Then you just need to add the CSS class <tt>ninjame</tt> to some elements in your portlet HTML. Fire up GateIn and your browser and add ninjas to your heart’s content.</p>
<p>A couple of final notes: I have found it is sometimes necessary to restart GateIn for changes to modules to take effect. And it is always necessary to tell your browser to reload the JavaScript after making changes (shift-reload in Firefox). Finally, GateIn by default will bundle up the shared JavaScript into one merged file which has been minimized. Adding the flag <tt>-Dexo.product.developing=true</tt> to the arguments when starting GateIn will suppress this and lead to a much better JavaScript debugging experience.</p>
RayDeCampohttp://www.blogger.com/profile/00893357454992134962noreply@blogger.com0tag:blogger.com,1999:blog-6427287440000636763.post-54830675512468006442013-10-27T09:30:00.000-04:002013-10-27T09:30:00.339-04:00Building GateIn 3.6.3<p><a href="http://www.jboss.org/gatein">GateIn</a> is a <a href="http://www.jcp.org/en/jsr/detail?id=286">JSR-286</a> (also known as Portal 2.0) compatible portal based on the JBoss application server (soon to be known as WildFly). The latest version of GateIn with a <a href="http://www.jboss.org/gatein/download">provided build</a> is GateIn 3.6.0 and is bundled with JBoss 7.1.1. (There is also a beta build of Red Hat JBoss Portal 6.1.0 which bundles GateIn with JBoss EAP and thus carries a more restrictive license.) Note that GateIn is bundled with the application server and is not an add-on to an existing application server.</p>
<p>In the spirit of do it yourself, I figured why not try bundle GateIn with a later version of JBoss community? I started down the road of using JBoss 7.2.0, but unfortunately GateIn is currently incompatible with that version. So we will have to settle for JBoss 7.1.3. Since there is no download-able build for JBoss 7.1.3 we will need to build it ourselves following the model we used for 7.2.0. And since we are compiling things ourselves, why not grab the latest GateIn release, 3.6.3, and compile it as well?</p>
<p>I will be working on a CentOS 6.4 machine created using the minimal DVD. I will skip the preliminaries which you can follow at <a href="/2013/10/build-and-install-jboss-720-on-centos-64.html">my instructions for the JBoss 7.2.0 build</a>. Below we download JBoss and GateIn and build JBoss.</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><font color="#990000">[</font>jboss@wxyz <font color="#990000">~]</font>$ wget -q -O JBoss-<font color="#993399">7.1</font><font color="#990000">.</font><font color="#993399">3</font><font color="#990000">.</font>Final<font color="#990000">.</font>tar-src<font color="#990000">.</font>tar<font color="#990000">.</font>gz <font color="#990000">\</font>
https<font color="#990000">:</font>//github<font color="#990000">.</font>com/jbossas/jboss-as/archive<font color="#990000">/</font><font color="#993399">7.1</font><font color="#990000">.</font><font color="#993399">3</font><font color="#990000">.</font>Final<font color="#990000">.</font>tar<font color="#990000">.</font>gz
<font color="#990000">[</font>jboss@wxyz <font color="#990000">~]</font>$ wget -q -O GateIn-<font color="#993399">3.6</font><font color="#990000">.</font><font color="#993399">3</font><font color="#990000">.</font>Final-src<font color="#990000">.</font>tar<font color="#990000">.</font>gz <font color="#990000">\</font>
https<font color="#990000">:</font>//github<font color="#990000">.</font>com/gatein/gatein-portal/archive<font color="#990000">/</font><font color="#993399">3.6</font><font color="#990000">.</font><font color="#993399">3</font><font color="#990000">.</font>Final<font color="#990000">.</font>tar<font color="#990000">.</font>gz
<font color="#990000">[</font>jboss@wxyz <font color="#990000">~]</font>$ cd src
<font color="#990000">[</font>jboss@wxyz src<font color="#990000">]</font>$ tar zxf <font color="#990000">..</font>/JBoss-<font color="#993399">7.1</font><font color="#990000">.</font><font color="#993399">3</font><font color="#990000">.</font>Final-src<font color="#990000">.</font>tar<font color="#990000">.</font>gz
<font color="#990000">[</font>jboss@wxyz src<font color="#990000">]</font>$ tar zxf <font color="#990000">..</font>/GateIn-<font color="#993399">3.6</font><font color="#990000">.</font><font color="#993399">3</font><font color="#990000">.</font>Final-src<font color="#990000">.</font>tar<font color="#990000">.</font>gz
<font color="#990000">[</font>jboss@wxyz src<font color="#990000">]</font>$ ls -<font color="#993399">1</font>
gatein-portal-<font color="#993399">3.6</font><font color="#990000">.</font><font color="#993399">3</font><font color="#990000">.</font>Final
jboss-as-<font color="#993399">7.1</font><font color="#990000">.</font><font color="#993399">3</font><font color="#990000">.</font>Final
<font color="#990000">[</font>jboss@wxyz src<font color="#990000">]</font>$ cd jbo ss-as -<font color="#993399">7.1</font><font color="#990000">.</font><font color="#993399">3</font><font color="#990000">.</font>Final<font color="#990000">/</font>
<font color="#990000">[</font>jboss@wxyz jboss-as-<font color="#993399">7.1</font><font color="#990000">.</font><font color="#993399">3</font><font color="#990000">.</font>Final<font color="#990000">]</font>$ <font color="#990000">.</font>/build<font color="#990000">.</font>sh -DskipTests -Drelease<font color="#990000">=</font><b><font color="#0000FF">true</font></b></tt></pre></td></tr></table>
<p>If you are adapting these instructions for different versions, you can get the download URL for different JBoss versions at <a href="https://github.com/jbossas/jboss-as/tags">https://github.com/jbossas/jboss-as/tags</a> (although in the future you’ll need to use <a href="https://github.com/wildfly/wildfly/tags">https://github.com/wildfly/wildfly/tags</a>). The GateIn tags are at <a href="https://github.com/gatein/gatein-portal/tags">https://github.com/gatein/gatein-portal/tags</a>.</p>
<p>Next we need to set up for the GateIn build. Unlike JBoss, GateIn doesn’t package maven with the source tarball. I hoped to piggyback on the maven from the JBoss 7.1.3 tarball but unfortunately it is version 3.0.2 and the GateIn build requires at least 3.0.4 (so close!). So we need to install maven:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" style="margin:0.2em 0;">
<tr><td style="padding:0.5em;">
<pre style="margin:0; padding:0;">[root@wxyz ~]# wget http://supergsego.com/apache/maven/maven-3/3.1.1/binaries/apache-maven-3.1.1-bin.tar.gz
[root@wxyz ~]# cd /opt
[root@wxyz opt]# mkdir maven
[root@wxyz opt]# cd maven
[root@wxyz maven]# tar zxf ~/apache-maven-3.1.1-bin.tar.gz
[root@wxyz maven]# ln -s apache-maven-3.1.1/ latest</pre>
</td></tr>
</table>
<p>As the final touch for maven, we create the file <tt>/etc/prof ile.d/maven.sh</tt> so
that maven is available automatically for all users (if you use another shell, create the corresponding script, e.g. <tt>/etc/prof ile.d/maven.csh</tt>):</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><i><font color="#9A1900"># Maven environment for bash, sh</font></i>
<i><font color="#9A1900">#</font></i>
<font color="#009900">M2_HOME</font><font color="#990000">=</font>/opt/maven/latest
<font color="#009900">PATH</font><font color="#990000">=</font><font color="#009900">$PATH</font><font color="#990000">:</font><font color="#009900">$M2_HOME</font>/bin</tt></pre></td></tr></table>
<p>OK, now that that brief detour is over, we can get back to building GateIn. We need to set up a directory where the build will pull the JBoss servers that it will package GateIn with. Then we can do the build.</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><font color="#990000">[</font>jboss@wxyz src<font color="#990000">]</font>$ pwd
/opt/jboss/src
<font color="#990000">[</font>jboss@wxyz src<font color="#990000">]</font>$ mkdir servers
<font color="#990000">[</font>jboss@wxyz src<font color="#990000">]</font>$ cd servers
<font color="#990000">[</font>jboss@wxyz servers<font color="#990000">]</font>$ tar zxf <font color="#990000">..</font>/jboss-as-<font color="#993399">7.1</font><font color="#990000">.</font><font color="#993399">3</font><font color="#990000">.</font>Final/dist/target/jboss-as-<font color="#993399">7.1</font><font color="#990000">.</font><font color="#993399">3</font> <font color="#990000">.</font>Final<font color="#990000">.</font>tar<font color="#990000">.</font>gz
<font color="#990000">[</font>jboss@wxyz servers<font color="#990000">]</font>$ <b><font color="#0000FF">export</font></b> <font color="#009900">SERVERS_DIR</font><font color="#990000">=</font><font color="#009900">$(pwd)</font>
<font color="#990000">[</font>jboss@wxyz servers<font color="#990000">]</font>$ cd <font color="#990000">..</font>/gatein-portal-<font color="#993399">3.6</font><font color="#990000">.</font><font color="#993399">3</font><font color="#990000">.</font>Final<font color="#990000">/</font>
<font color="#990000">[</font>jboss@wxyz gatein-portal-<font color="#993399">3.6</font><font color="#990000">.</font><font color="#993399">3</font><font color="#990000">.</font>Final<font color="#990000">]</font>$ <font color="#990000">\</font>
mvn install -DskipTests -Dservers<font color="#990000">.</font><font color="#009900">dir</font><font color="#990000">=</font><font color="#009900">$SERVERS_DIR</font> -Dgatein<font color="#990000">.</font><font color="#009900">dev</font><font color="#990000">=</font>jbossas713
<font color="#990000">[</font>jboss@wxyz <font color="#990000">~]</font>$ cd
<font color="#990000">[</font>jboss@wxyz <font color="#990000">~]</font>$ mkdir jboss-as-<font color="#993399">7.1</font><font color="#990000">.</font><font color="#993399">3</font><font color="#990000">.</font>Final-gatein-<font color="#993399">3.6</font><font color="#990000">.</font><font color="#993399">3</font><font color="#990000">.</font> Final
<font color="#990000">[</font>jboss@wxyz <font color="#990000">~]</font>$ cd jboss-as-<font color="#993399">7.1</font><font color="#990000">.</font><font color="#993399">3</font><font color="#990000">.</font>Final-gatein-<font color="#993399">3.6</font><font color="#990000">.</font><font color="#993399">3</font><font color="#990000">.</font>Final<font color="#990000">/</font>
<font color="#990000">[</font>jboss@wxyz jboss-as-<font color="#993399">7.1</font><font color="#990000">.</font><font color="#993399">3</font><font color="#990000">.</font>Final-gatein-<font color="#993399">3.6</font><font color="#990000">.</font><font color="#993399">3</font><font color="#990000">.</font>Final<font color="#990000">]</font>$ cp -r <font color="#990000">\</font>
<font color="#990000">~</font>/src/gatein-portal-<font color="#993399">3.6</font><font color="#990000">.</font><font color="#993399">3</font><font color="#990000">.</font>Final/packaging/jboss-as<font color="#993399">7</font>/pkg/target/jboss<font color="#990000">/*</font> <font color="#990000">.</font></tt></pre></td></tr></table>
<p>Above we have copied the result of the build from <tt>packaging/jboss-as7/pkg/target/jboss</tt> into a directory under <tt>~jboss</tt>. Now we can follow the remaining steps from <a href="/2013/10/build-and-install-jboss-720-on-centos-64.html">my 7.2.0 build</a> to install this version of JBoss with GateIn as a service in CentOS.</p>
RayDeCampohttp://www.blogger.com/profile/00893357454992134962noreply@blogger.com0tag:blogger.com,1999:blog-6427287440000636763.post-77162084391298048742013-10-20T09:30:00.000-04:002013-10-20T09:30:00.202-04:00Build and Install JBoss 7.2.0 on CentOS 6.4<p>As you may or may not be aware, a great many changes have been happening to the JBoss application server since being purchased by Red Hat. Most importantly, the application server is being rebranded as <a href="http://www.wildfly.org/">WildFly</a> for version 8. ("Why?" is the first entry on the <a href="http://www.wildfly.org/faq/">WildFly FAQ</a> if you are curious.) But since WildFly is not quite ready as of this writing (but looks real close), we are going to deal with the latest community release, JBoss AS 7.2.0.</p>
<p>Before the name change to WildFly, there was a split in JBoss into a 7.x community edition and a 6.x EAP edition. The community edition remains the open source version free to use as before. The EAP edition requires a subscription to use for production purposes (but is free for development). The EAP edition is based on the community edition, typically taking the "Final" version of the community edition as the "Alpha" of the corresponding EAP edition (although keep in mind that the community edition versions are 7.x while the EAP is 6.x). This appears to be a split in the mold of Red Hat Linux begetting Fedora and Red Hat Enterprise.</p>
<p>Whew, that is a lot of change and I haven’t even mentioned that JBoss AS 7 appears to be a complete rewrite. The configuration files and tools are completely different, so if are coming from JBoss 5 or 6, be prepared to invest a little time to get familiar with the new JBoss, er, WildFly.</p>
<p>OK, we are getting closer to the good stuff. In addition to all the changes mentioned above, Red Hat (or JBoss.org or WildFly.org whoever is responsible for the community editions of JBoss AS 7) has stopped providing builds of the JBoss AS 7 line after 7.1.1. Since then there have been versions 7.1.2, 7.1.3 and 7.2.0 but no corresponding build on the <a href="http://www.jboss.org/jbossas/downloads">JBoss AS download page</a>. Fortunately it is easy to get the source and build JBoss yourself.</p>
<p>We will be using a new CentOS 6.4 box created using the CentOS minimal DVD. We’ll start by installing Java; instead of going to Oracle, I decided to try the OpenJDK from the CentOS repositories to see how that goes:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" style="margin:0.2em 0;">
<tr><td style="padding:0.5em;">
<pre style="margin:0; padding:0;">[root@wxyz ~]# yum install java-1.7.0-openjdk java-1.7.0-openjdk-devel wget</pre>
</td></tr>
</table>
<p>You’ll notice I threw in <tt>wget</tt> since we will need it shortly.</p>
<p>Next we create a <tt>jboss</tt> user on the server to build and run JBoss as. (You may want to call the user <tt>jboss-as</tt> since the JBoss scripts reference this user by default. I already have a convention of using the user <tt>jboss</tt> and I want to stick with it.)</p>
<table border="0" bgcolor="#e8e8e8" width="100%" style="margin:0.2em 0;">
<tr><td style="padding:0.5em;">
<pre style="margin:0; padding:0;">[root@wxyz ~]# useradd --system --comment JBossAS --create-home \
--home /opt/jboss --user-group jboss</pre>
</td></tr>
</table>
<p>Now we are ready to download the JBoss source. Fortunately for us, github provides tarballs of tags so we can easily download the JBoss source for 7.2.0:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><font color="#990000">[</font>jboss@wxyz <font color="#990000">~]</font>$ wget https<font color="#990000">:</font>//github<font color="#990000">.</font>com/jbossas/jboss-as/archive<font color="#990000">/</font><font color="#993399">7.2</font><font color="#990000">.</font><font color="#993399">0</font><font color="#990000">.</font>Final<font color="#990000">.</font>tar<font color="#990000">.</font>gz
<font color="#990000">[</font>jboss@wxyz <font color="#990000">~]</font>$ mv <font color="#993399">7.2</font><font color="#990000">.</font><font color="#993399">0</font><font color="#990000">.</font>Final /opt/jboss/JBoss-<font color="#993399">7.2</font><font color="#990000">.</font> <font color="#993399">0</font><font color="#990000">.</font>Final<font color="#990000">.</font>tar<font color="#990000">.</font>gz
<font color="#990000">[</font>jboss@wxyz <font color="#990000">~]</font>$ mkdir src
<font color="#990000">[</font>jboss@wxyz <font color="#990000">~]</font>$ cd src
<font color="#990000">[</font>jboss@wxyz src<font color="#990000">]</font>$ tar xzf JBoss-<font color="#993399">7.2</font><font color="#990000">.</font><font color="#993399">0</font><font color="#990000">.</font>Final<font color="#990000">.</font>tar<font color="#990000">.</font>gz
<font color="#990000">[</font>jboss@wxyz src<font color="#990000">]</font>$ cd jboss-as-<font color="#993399">7.2</font><font color="#990000">.</font><font color="#993399">0</font><font color="#990000">.</font>Final<font color="#990000">/</font>
<font color="#990000">[</font>jboss@wxyz jboss-as-<font color="#993399">7.2</font><font color="#990000">.</font><font color="#993399">0</font><font color="#990000">.</font>Final<font color="#990000">]</font>$ <i><font color="#9A1900"># This next command kicks off the build</font></i>
<font color="#990000">[</font>jboss@wxyz jboss-as-<font color="#993399">7.2</font><font color="#990000">.</font><font color="#993399">0</font><font color="#990000">.</font>Final<font color="#990000">]</font>$ <font color="#990000">.</font>/build<font color="#990000">.</font>sh -DskipTests -Drelease<font color="#990000">=</font><b><font color="#0000FF">true</font></b></tt></pre></td></tr></table>
<p>If you take a look at the <tt>README.md</tt> file in the download there are some basic instructions on how to do the build. One pleasant surprise is that there is no need to install maven. We do want a couple of tweaks to the command line they suggest however in order to skip the unit tests and get a release tarball. After running the command above you will find the tarball in the <tt>dist/target</tt> directory.</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><font color="#990000">[</font>jboss@wxyz jboss-as-<font color="#993399">7.2</font><font color="#990000">.</font><font color="#993399">0</font><font color="#990000">.</font>Final<font color="#990000">]</font>$ ls dist/target
archive-tmp jboss-as-<font color="#993399">7.2</font><font color="#990000">.</font><font color="#993399">0</font><font color="#990000">.</font>Final-src<font color="#990000">.</font>tar<font color="#990000">.</font>gz jboss-as-<font color="#993399">7.2</font><font color="#990000">.</font><font color="#993399">0</font><font color="#990000">.</font>Final-src<font color="#990000">.</font>zip
jboss-as-<font color="#993399">7.2</font><font color="#990000">.</font><font color="#993399">0</font><font color="#990000">.</font>Final<font color="#990000">.</font>tar<font color="#990000">.</font>gz jboss-as-<font color="#993399">7.2</font><font color="#990000">.</font><font color="#993399">0</font><font color="#990000">.</font>Final<font color="#990000">.</font>zip
<font color="#990000">[</font>jboss@wxyz jboss-as-<font color="#993399">7.2</font><font color="#990000">.</font><font color="#993399">0</font><font color="#990000">.</font>Final<font color="#990000">]</font>$ cd
<font color="#990000">[</font>jboss@wxyz <font color="#990000">~]</font>$ tar zxvf src/jboss-as-<font color="#993399">7.2</font><font color="#990000">.</font><font color="#993399">0</font><font color="#990000">.</font>Final/dist/target/jboss-as-<font color="#993399">7.2</font><font color="#990000">.</font><font color="#993399">0</font><font color="#990000">.</font>Final<font color="#990000">.</font>tar<font color="#990000">.</font>gz</tt></pre></td></tr></table>
<p>Now that we have a build of JBoss AS 7.2.0 on the system, we need to configure CentOS to treat it like a service. JBoss comes with some scripts in the <tt>bin/init.d</tt> directory that will help with this. I am using the standalone server, but it is not difficult to modify the instructions for the domain server. First up is the <tt>/etc/jboss-as/jboss-as.conf</tt> file.</p>
<table border="0" bgcolor="#e8e8e8" width="100%" style="margin:0.2em 0;">
<tr><td style="padding:0.5em;">
<pre style="margin:0; padding:0;">[root@wxyz ~]# cd /etc
[root@wxyz etc]# mkdir jboss-as
[root@wxyz etc]# cd jboss-as/
[root@wxyz jboss-as]# cp /opt/jboss/jboss-as-7.2.0.Final/bin/init.d/jboss-as.conf ./
[root@wxyz jboss-as]# # We'll just create an empty properties file for now
[root@wxyz jboss-as]# touch jboss-as.properties</pre>
</td></tr>
</table>
<p>Next edit the file. We need to define a few environment variables:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><i><font color="#9A1900"># General configuration for the init.d scripts,</font></i>
<i><font color="#9A1900"># not necessarily for JBoss AS itself.</font></i>
<i><font color="#9A1900"># The username who should own the process.</font></i>
<i><font color="#9A1900">#</font></i>
<font color="#009900">JBOSS_USER</font><font color="#990000">=</font>jboss
<i><font color="#9A1900"># The amount of time to wait for startup</font></i>
<i><font color="#9A1900">#</font></i>
<i><font color="#9A1900"># STARTUP_WAIT=30</font></i>
<i><font color="#9A1900"># The amount of time to wait for shutdown</font></i>
<i><font color="#9A1900">#</font></i>
<i><font color="#9A1900"># SHUTDOWN_WAIT=30</font></i>
<i><font color="#9A1900"># Location to keep the console log</font></i>
<i><font color="#9A1900">#</font></i>
<font color="#009900">JBOSS_CONSOLE_LOG</font><font color="#990000">=</font>/var/log/jboss-as/console<font color="#990000">.</font>log
<i><font color="#9A1900"># JBoss installation directory (default is /usr/share/jboss)</font></i>
<font color="#009900">JBOSS_HOME</font><font color="#990000">=</font>/opt/jboss/jboss-as-<font color="#993399">7.2</font><font color="#990000">.</font><font color="#993399">0</font><font color="#990000">.</font>Final
<i><font color="#9A1900"># Server configuration file, using full JEE 6 profile</font></i>
<font color="#009900">JBOSS_CONFIG</font><font color="#990000">=</font>standalone-full<font color="#990000">.</font>xml
<i><font color="#9A1900"># Need to modify the init script to account for these</font></i>
<font color="#009900">JBOSS_OPTS</font><font color="#990000">=</font><font color="#FF0000">"--properties=/etc/jboss-as/jboss-as.properties"</font></tt></pre></td></tr></table>
<p>Just in case you are confused on the two files, <tt>jboss-as.conf</tt> is a bash script that is sourced by the JBoss init script; use it to set environment variables for the scripts. As for <tt>jboss-as.properties</tt>, it is a Java properties file that is read by JBoss on start up. Use it to set JBoss system properties (we will get to an example shortly).</p>
<p>Next up we will deposit the init script in <tt>/etc/init.d</tt> and set the server to start on boot:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" style="margin:0.2em 0;">
<tr><td style="padding:0.5em;">
<pre style="margin:0; padding:0;">[root@wxyz jboss-as]# cd /etc/ini t.d/
[root@wxyz init.d]# cp /opt/jboss/jboss-as-7.2.0.Final/bin/init.d/jboss-as-standalone.sh ./
[root@wxyz init.d]# mv jboss-as-standalone.sh jboss-as
[root@wxyz init.d]# chkconfig --add jboss-as
[root@wxyz init.d]# chkconfig --level 345 jboss-as on
[root@wxyz init.d]# chkconfig --list jboss-as
jboss-as 0:off 1:off 2:off 3:on 4:on 5:on 6:off</pre>
</td></tr>
</table>
<p>As-is the scripts do not allow passing any additional options to the JBoss process, so we need to edit the <tt>/etc/init.d/jboss-as</tt> script to add the <tt>$JBOSS_OPTS</tt> variable whenever JBoss is starting. Here is the edited snippet (I’ve added some line breaks for readability):</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt> <b><font color="#0000FF">if</font></b> <font color="#990000">[</font> <font color="#990000">!</font> -z <font color="#FF0000">"$JBOSS_USER"</font> <font color="#990000">];</font> <b><font color="#0000FF">then</font></b>
<b><font color="#0000FF">if</font></b> <font color="#990000">[</font> -r /etc/rc<font color="#990000">.</font>d/init<font color="#990000">.</font>d/functions <font color="#990000">];</font> <b><font color="#0000FF">then</font></b>
daemon --user <font color="#009900">$JBOSS_USER</font> <font color="#009900">LAUNCH_JBOSS_IN_BACKGROUND</font><font color="#990000">=</font><font color="#993399">1</font> <font color="#990000">\</font>
<font color="#009900">JBOSS_PIDFILE</font><font color="#990000">=</font><font color="#009900">$JBOSS_PIDFILE</font> <font color="#009900">$JBOSS_SCRIPT</font> -c <font color="#009900">$JBOSS_CONFIG</font> <font color="#990000">\</font>
<font color="#009900">$JBOSS_OPTS</font> <font color="#993399">2</font><font color="#990000">>&</font><font color="#993399">1</font> <font color="#990000">></font> <font color="#009900">$JBOSS_CONSOLE_LOG</font> <font color="#990000">&</font>
<b><font color="#0000FF">else</font></b>
su - <font color="#009900">$JBOSS_USER</font> -c <font color="#FF0000">"LAUNCH_JBOSS_IN_BACKGROUND=1 \</font>
<font color="#FF0000"> JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT -c $JBOSS_CONFIG \</font>
<font color="#FF0000"> $JBOSS_OPTS"</font> <font color="#993399">2</font><font color="#990000">>&</font><font color="#993399">1</font> <font color="#990000">></font> <font color="#009900">$JBOSS_CONSOLE_LOG</font> <font color="#990000">&</font>
<b><font color="#0000FF">fi</font></b>
<b><font color="#0000FF">fi</font></b></tt></pre></td></tr></table>
<p>Next up we create the log directories and redirect the JBoss log directory to <tt>/var/log/jboss-as</tt> and the tmp directory to <tt>/tmp/jboss-as</tt></p>
<table border="0" bgcolor="#e8e8e8" width="100%" style="margin:0.2em 0;">
<tr><td style="padding:0.5em;">
<pre style="margin:0; padding:0;">[root@wxyz ~]# mkdir /var/log/jboss-as
[root@wxyz ~]# chown jboss:jboss /var/log/jboss-as/</pre>
</td></tr>
</table>
<p>To get JBoss to use these directories, we set the system properties for them in <tt>/etc/jboss-as/jboss-as.properties</tt>:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><i><font color="#9A1900"># System properties for jboss-as</font></i>
<font color="#009900">jboss.server.log.dir</font><font color="#990000">=</font>/var/log/jboss-as
<font color="#009900">jboss.server.temp.dir</font><font color="#990000">=</font>/tmp/jboss-as</tt></pre></td></tr></table>
<p>At this point you can start the server using the command <tt>service jboss-as start</tt>. You won’t be able to do much however, unless you like browsing via <tt>wget</tt> since the server is bound to the localhost interface only (and we are working on a headless server, i.e. no GUI web browser). So we’ll need to bind JBoss to all interfaces and open up the CentOS firewall to allow browsing to JBoss and the management console. Keep in mind that this may not be exactly what you want in a production environment or in environment where unknown users might access your server (like shared hosting).</p>
<p>First we’ll edit the <tt>/etc/jboss-as/jboss-as.properties</tt> file:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><i><font color="#9A1900"># System properties for jboss-as</font></i>
<font color="#009900">jboss.bind.address</font><font color="#990000">=</font>0.0.0.0
<font color="#009900">jboss.bind.address.management</font><font color="#990000">=</font>0.0.0.0
<font color="#009900">jboss.server.log.dir</font><font color="#990000">=</font>/var/log/jboss-as
<font color="#009900">jboss.server.temp.dir</font><font color="#990000">=</font>/tmp/jboss-as</tt></pre></td></tr></table>
<p>Depending on how your local network is setup you may need further configuration for JBoss to be completely happy binding to all interfaces. If your DNS recognizes the name of the CentOS server you are working on, congratulations, you are all set. On the other hand, if DNS is not configured for the server, you will need to add an entry to the <tt>/etc/hosts</tt> file pointing the name of the server to the external IP.</p>
<p>Next we need to open the firewall for ports 8080 (regular JBoss) and 9990 (the management console). <strong>Be careful</strong> when adjusting the firewall. The commands below use hard-coded line numbers that may not be appropriate for whatever system you are using. If you think you have screwed up your firewall use <tt>service iptables restart</tt> to reset it. Of course, this won’t work after you issue <tt>service iptables save</tt> so be extra sure before you save the rules. You will also need to replace 10.0.0.0 with your subnet below.</p>
<table border="0" bgcolor="#e8e8e8" width="100%" style="margin:0.2em 0;">
<tr><td style="padding:0.5em;">
<pre style="margin:0; padding:0;">[root@wxyz ~]# # 8080 for JBoss applications
[root@wxyz ~]# iptables --insert INPUT 5 \
--match state \
--state NEW \
--protocol tcp \
--destination-port 8080 \
--source 10.0.0.0/24 \
--jump ACCEPT
[root@wxyz ~]# # 9990 for JBoss management
[root@wxyz ~]# iptables --insert INPUT 6 \
--match state \
--state NEW \
--protocol tcp \
--destination-port 9990 \
--source 10.0.0.0/24 \
--jump ACCEPT
[root@wxyz ~]# # Verify the state of the firewall
[root@wxyz ~]# iptables -L --line-numbers
[root@wxyz ~]# # Go and test it out before doing the following
[root@wxyz ~]# service iptables save</pre>
</td></tr>
</table>
<p>At this point you should be ready to go. Start up JBoss and try accessing it from your desktop.</p>
RayDeCampohttp://www.blogger.com/profile/00893357454992134962noreply@blogger.com0tag:blogger.com,1999:blog-6427287440000636763.post-60463433023158637502013-09-22T09:30:00.000-04:002013-10-25T14:29:06.992-04:00RESTful Web Services on JBossAS 7<p>Deploying RESTful web services on JBossAS 7 is relatively painless and straightforward. Thanks to the extensive support of annotations vs configuration in JEE 6, creating RESTful web services is almost XML-free.</p>
<p>Let’s start with the good stuff: the code you want to run as a web service. We will use as an example a web service supplying random number as inspired by the classic <a href="http://xkcd.com/221/">xkcd comic</a>:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><b><font color="#000080">import</font></b> javax<font color="#990000">.</font>ws<font color="#990000">.</font>rs<font color="#990000">.</font>GET<font color="#990000">;</font>
<b><font color="#000080">import</font></b> javax<font color="#990000">.</font>ws<font color="#990000">.</font>rs<font color="#990000">.</font>Path<font color="#990000">;</font>
@<b><font color="#000000">Path</font></b><font color="#990000">(</font><font color="#FF0000">"random"</font><font color="#990000">)</font>
<b><font color="#0000FF">public</font></b> <b><font color="#0000FF">class</font></b> <font color="#008080">RandomResource</font>
<font color="#FF0000">{</font>
@GET
@<b><font color="#000000">Path</font></b><font color="#990000">(</font><font color="#FF0000">"xkcd"</font><font color="#990000">)</font>
<b><font color="#0000FF">public</font></b> <font color="#008080">String</font> <b><font color="#000000">xkcd</font></b><font color="#990000">()</font>
<font color="#FF0000">{</font>
<i><font color="#9A1900">// Chosen by a fair dice roll</font></i>
<i><font color="#9A1900">// Guaranteed to be random</font></i>
<b><font color="#0000FF">return</font></b> <font color="#FF0000">"4"</font><font color="#990000">;</font>
<font color="#FF0000">}</font>
<font color="#FF0000">}</font></tt></pre></td></tr></table>
<p>Here we have assigned paths both to the entire class and the specific method. That means the resource will be available at the path "random/xkcd" relative to the path for RESTful web services (more details on that to follow).</p>
<p>From here we can go in two directions: supply an implementation of <tt>javax.ws.rs.core.Application</tt> and let our web services be found automatically or configure a bunch of things in the <tt>web.xml</tt>. We’ll take the easy way:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><b><font color="#000080">import</font></b> javax<font color="#990000">.</font>ws<font color="#990000">.</font>rs<font color="#990000">.</font>ApplicationPath<font color="#990000">;</font>
<b><font color="#000080">import</font></b> javax<font color="#990000">.</font>ws<font color="#990000">.</font>rs<font color="#990000">.</font>core<font color="#990000">.</font>Application<font color="#990000">;</font>
@<b><font color="#000000">ApplicationPath</font></b><font color="#990000">(</font><font color="#FF0000">"/jaxrs"</font><font color="#990000">)</font>
<b><font color="#0000FF">public</font></b> <b><font color="#0000FF">class</font></b> <font color="#008080">RestApplication</font> <b><font color="#0000FF">extends</font></b> Application
<font color="#FF0000">{</font>
<font color="#FF0000">}</font></tt></pre></td></tr></table>
<p>Note that we do not override the methods in <tt>javax.ws.rs.core.Application</tt>. The specification indicates that the default implementation will return empty sets; furthermore if an implementation of <tt>Application</tt> returns empty sets then all root resource classes and providers in the WAR will be included. Which is all a fancy way of saying that this is exactly what we want: the container will scan the WAR and find all the resource classes by annotation.</p>
<p>Notice we used the <tt>ApplicationPath</tt> annotation; this tells the container the root URI for RESTful web services. So our <tt>xkcd()</tt> method now has URI "jaxrs/random/xkcd" relative to the deployment of the WAR.</p>
<p>Finally we have the small piece of XML necessary. We need to include a <tt>web.xml</tt> file in order to indicate that we are using servlet version 3.0. If all we have are the RESTful web services in the application, the <tt>web.xml</tt> can be empty aside from the root element:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><b><font color="#0000FF"><web-app</font></b> <font color="#009900">xmlns</font><font color="#990000">=</font><font color="#FF0000">"http://java.sun.com/xml/ns/javaee"</font>
<font color="#009900">xmlns:xsi</font><font color="#990000">=</font><font color="#FF0000">"http://www.w3.org/2001/XMLSchema-instance"</font>
<font color="#009900">xsi:schemaLocation</font><font color="#990000">=</font><font color="#FF0000">"http://java.sun.com/xml/ns/javaee</font>
<font color="#FF0000"> http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"</font>
<font color="#009900">version</font><font color="#990000">=</font><font color="#FF0000">"3.0"</font><b><font color="#0000FF">></font></b>
<b><font color="#0000FF"></web-app></font></b></tt></pre></td></tr></table>
<p>OK, now we are ready to package it up and deploy to JBossAS 7. We are going to create a WAR file named <tt>rest.war</tt>. Just to refresh your memory, the Java classes are compiled and placed in the <tt>WEB-INF/classes</tt> directory and the <tt>web.xml</tt> is placed in the <tt>WEB-INF</tt> directory. You may also want to include a "Hello world" HTML file in the WAR as well for debugging.</p>
<p>Copy the <tt>rest.war</tt> file into the <tt>$JBOSS_HOME/standalone/deployments</tt> directory and start JBoss if you have not already. Now you can get a random number (xkcd-style) via the URL <a href="http://localhost:8080/rest/jaxrs/random/xkcd">http://localhost:8080/rest/jaxrs/random/xkcd</a>.</p>
<p>Resources:</p>
<ul>
<li>
<a href="https://jsr311.java.net/nonav/releases/1.1/index.html">https://jsr311.java.net/nonav/releases/1.1/index.html</a>
</li>
<li>
<a href="http://jcp.org/aboutJava/communityprocess/mrel/jsr311/index.html">http://jcp.org/aboutJava/communityprocess/mrel/jsr311/index.html</a>
</li>
<li>
<a href="http://docs.jboss.org/resteasy/docs/3.0.4.Final/userguide/html_single/index.html#d4e40">http://docs.jboss.org/resteasy/docs/3.0.4.Final/userguide/html_single/index.html#d4e40</a>
</li>
<li>
<a href="http://xkcd.com/221/">http://xkcd.com/221/</a>
</li>
</ul>
RayDeCampohttp://www.blogger.com/profile/00893357454992134962noreply@blogger.com0tag:blogger.com,1999:blog-6427287440000636763.post-47827368305496297522013-09-20T07:30:00.000-04:002013-09-20T07:30:06.127-04:00Trac Plugins vs Python VersionsJust a quick and dirty reminder than when you are trying to make Trac plugins work, you need to make sure you are using the correct python version of the egg. For example, I recently wanted to add the <a href="http://trac-hacks.org/wiki/RegexLinkPlugin" target="_blank">RegexLinkPlugin</a> to one of my Trac instances. However, when I downloaded the provided egg and installed it, nothing happened. Upon further inspection, I realized that the egg was for Python 2.5 and I was running 2.6 on my server. I downloaded the source and recompiled and was rewarded with a (working) Python 2.6 egg.<br />
<br />
By the way, the <a href="http://trac-hacks.org/wiki/RegexLinkPlugin" target="_blank">RegexLinkPlugin</a> is a nice way to map wiki text to links in your Trac installation. For example, I am using it on an IT wiki where each server has its own page but the servers are all referred to by all lowercase hostnames. Using <a href="http://trac-hacks.org/wiki/RegexLinkPlugin" target="_blank">RegexLinkPlugin</a> I can map each hostname to link to the page for the server with no extra wiki markup, ensuring my users always generate the links when using the hostnames.RayDeCampohttp://www.blogger.com/profile/00893357454992134962noreply@blogger.com0tag:blogger.com,1999:blog-6427287440000636763.post-49178985654775077082013-09-08T09:30:00.000-04:002013-09-08T09:30:00.281-04:00Joining a CentOS server to Active Directory<p>As the number of CentOS (or Red Hat) machines in your environment grows, you begin to appreciate the need for a central login mechanism. Most workplaces already have a such a login for their Windows workstations in the form of an Active Directory domain. By joining your CentOS machines to the Active Directory domain, you allow users to login with the same credentials as on their Windows machines. Furthermore you do not need to add or remove users when new people join the team or others drop off the team.</p>
<p>For the purposes of these instructions, we will assume the Active Directory server is ad.example.com and the CentOS server is centos.example.com.</p>
<p>As a first step, we install Samba, kerberos and ntpd.</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>yum install samba samba-client samba-winbind krb5-workstation ntp
chkconfig smb on
chkconfig nmb on
service smb start
service nmb start
chkconfig ntpd on
ntpdate ad<font color="#990000">.</font>example<font color="#990000">.</font>com</tt></pre></td></tr></table>
<p>We need to install and configure an ntp client because the Kerberos protocol will not work if the two machines' clocks are too far apart. Edit <tt>/etc/ntpd.conf</tt> remove all the existing <tt>server</tt> lines and replace them with:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" style="margin:0.2em 0;">
<tr><td style="padding:0.5em;">
<pre style="margin:0; padding:0;">server ad.example.com</pre>
</td></tr>
</table>
<p>Next start the <tt>ntpd</tt> server with the command <tt>service ntpd start</tt>.</p>
<p>I have had issues down the road with trying to synchronize the clocks against the Active Directory server; in those cases I configured the two servers to synchronize against the same third-party server. I suspect the problem was a (presumably temporary) issue with time.windows.com, the default Windows NTP server.</p>
<p>Next we want to be able to refer to machines on the local network using their short names. Add the following to <tt>/etc/resolv.conf</tt>:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" style="margin:0.2em 0;">
<tr><td style="padding:0.5em;">
<pre style="margin:0; padding:0;">search example.com</pre>
</td></tr>
</table>
<p>This may not be necessary depending on how the networking of the CentOS server is configured. For example, I have set up all the servers to use DHCP with reservations to keep all the IP configuration in one place. The DHCP server already is configured to have the clients append .example.com to bare host names so the <tt>/etc/resolv.conf</tt> already contains this line.</p>
<p>If you are using a static IP, add the following to <tt>/etc/hosts</tt>, replacing the IP address with the IP for your CentOS server and the host names with the proper values:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" style="margin:0.2em 0;">
<tr><td style="padding:0.5em;">
<pre style="margin:0; padding:0;">192.168.0.10 centos centos.example.com</pre>
</td></tr>
</table>
<p>If you do not have a static IP, add the host entries to the existing line for localhost (127.0.0.1).</p>
<p>Next we need to configure Kerberos by making the following edits to <tt>/etc/krb5.conf</tt> (note that the capitalization is important in this file):</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><b><font color="#000000">[libdefaults]</font></b>
<font color="#009900"> default_realm </font><font color="#990000">=</font> EXAMPLE<font color="#990000">.</font>COM
<font color="#009900"> dns_lookup_realm </font><font color="#990000">=</font> true
<font color="#009900"> dns_lookup_kdc </font><font color="#990000">=</font> true
<font color="#009900"> allow_weak_crypto </font><font color="#990000">=</font> yes
<b><font color="#000000">[realms]</font></b>
<font color="#009900"> EXAMPLE.COM </font><font color="#990000">=</font> {
<font color="#009900"> default_domain </font><font color="#990000">=</font> example<font color="#990000">.</font>com
<font color="#009900"> kdc </font><font color="#990000">=</font> ad<font color="#990000">.</font>EXAMPLE<font color="#990000">.</font>COM
<font color="#009900"> admin-server </font><font color="#990000">=</font> ad<font color="#990000">.</font>EXAMPLE<font color="#990000">.</font>COM
}
<b><font color="#000000">[domain_realm]</font></b>
<font color="#009900"> .example.com </font><font color="#990000">=</font> EXAMPLE<font color="#990000">.</font>COM
<font color="#009900"> example.com </font><font color="#990000">=</font> EXAMPLE<font color="#990000">.</font>COM</tt></pre></td></tr></table>
<p>Next edit <tt>/etc/samba.conf</tt>, changing or adding the following:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><i><font color="#9A1900"># Use the value of your workgroup/domain here</font></i>
<font color="#009900">workgroup </font><font color="#990000">=</font> MY_WORKGROUP
<font color="#009900">password server </font><font color="#990000">=</font> ad<font color="#990000">.</font>example<font color="#990000">.</font>com
<font color="#009900">realm </font><font color="#990000">=</font> EXAMPLE<font color="#990000">.</font>COM
<font color="#009900">security </font><font color="#990000">=</font> ads
<font color="#009900">winbind use default domain </font><font color="#990000">=</font> true
<font color="#009900">winbind offline logon </font><font color="#990000">=</font> false
<font color="#009900">encrypt passwords </font><font color="#990000">=</font> yes</tt></pre></td></tr></table>
<p>Finally we can initialize Kerberos and join the domain. You will need the credentials of a user allowed to make changes in the domain (in the example we use <tt>administrator</tt>).</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>kinit administrator@EXAMPLE<font color="#990000">.</font>COM
<i><font color="#9A1900"># Enter the password at the prompt and expect no other output</font></i>
authconfig --update <font color="#990000">\</font>
--kickstart <font color="#990000">\</font>
--enablewinbind <font color="#990000">\</font>
--enablewinbindauth <font color="#990000">\</font>
--smbsecurity<font color="#990000">=</font>ads <font color="#990000">\</font>
--smbrealm<font color="#990000">=</font>EXAMPLE<font color="#990000">.</font>COM <font color="#990000">\</font>
--winbindjoin<font color="#990000">=</font>administrator@EXAMPLE<font color="#990000">.</font>COM <font color="#990000">\</font>
--winbindtemplatehomedir<font color="#990000">=</font>/home<font color="#990000">/%</font>U <font color="#990000">\</font>
--winbindtemplateshell<font color="#990000">=</font>/bin/bash <font color="#990000">\</font>
--enablewinbindusedefaultdomain <font color="#990000">\</font>
--enablelocauthorize <font color="#990000">\</font>
--smbservers<font color="#990000">=</font>ad<font color="#990000">.</font>example<font color="#990000">.</font>com <font color="#990000">\</font>
--enablemkhomedir</tt></pre></td></tr></table>
<p>At this point you should be done. You should be able to log into the machine using your Windows credentials.</p>
<p>Once in a while I find it is necessary to re-join the domain. Use the following commands:</p>
<table border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td><!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><i><font color="#9A1900"># Restart all relevant services</font></i>
service smb stop
service nmb stop
service winbind stop
service winbind start
service nmb start
service smb start
<i><font color="#9A1900"># Re-join the domain</font></i>
net ads join -S ad<font color="#990000">.</font>example<font color="#990000">.</font>com -U administrator
<i><font color="#9A1900"># Restart winbind</font></i>
service winbind stop
service winbind start
<i><font color="#9A1900"># Test the credentials</font></i>
wbinfo -t
<i><font color="#9A1900"># List the users</font></i>
wbinfo -u</tt></pre></td></tr></table>
<p>If the last two tests do not come out the way you expect (<tt>wbinfo -t</tt> should report success and <tt>wbinfo -u</tt> should list all the users in your domain), you have some googling to do. Let me know how it turns out.</p>
RayDeCampohttp://www.blogger.com/profile/00893357454992134962noreply@blogger.com0