Sunday, August 8, 2010

JBoss Seam UTF-8 encoding

UTF-8 encoding of JBoss Seam can cause a lot of the problem. I went through of everything that's probably possible cases, and try to show you how to properly configure Seam to UTF-8 to work properly.
At the beginning of some of the tools used to work. The most important is probably installed Eclipse with JBoss Tools. Next ... Well no more, Eclipse itself is enough :-)
Okay, so yes, there are several cases to consider:
  1. We want to do a connection to the database in UTF-8
  2. We want to display a static XHTML in UTF-8
  3. We want to have URLs in UTF-8
Let us take the first point. The case is quite simple, open the file hibernate-console.properties and set the URL so that it is in UTF-8. If you are using a PostgreSQL database is a matter of even more simplified, because the default is UTF. Remember that a database was created in UTF too.
Second point.
Here you can help Eclipse. To display a static XHTML in JavaServer Faces (UTF-8), which is built on JBoss Seam, you must file with the JSF is to encode to UTF-8. Now you can put this file in UTF. Oh, one more thing - how to encode in Eclipse? It's easy, from the main menu click File, then Properties, from section Text file properties choose Other and UTF-8 select. Click Apply and OK. Oh, and do it with an open file that you want to encode.
And the last, URL encoding in UTF-8. Here are more combinations. Open a file components.xml and add tag:
<web:character-encoding-filter encoding="UTF-8" override-client="true" url-pattern="*.html" />
Instead, *. html, use your own pattern (default is *. seam). I use the JBoss application server, and it is for this server will further tip. One must set the connector support the processing of URLs with UTF. Generally, this is a setting for Tomcat, so if you have another application server, you probably also will use Tomcat, and the configuration process is similar. Open the file server.xml located in $JBOSS_HOME / server / (your server configuration) / deploy / jbossweb.sar.
See for this part of the file:

<Connector protocol="HTTP/1.1" SSLEnabled="true"
   port="8443" address="${jboss.bind.address}"
   enableLookups="true" disableUploadTimeout="true"
   useBodyEncodingForURI="true" URIEncoding="UTF-8"
   scheme="https" secure="true" clientAuth="false"
   sslProtocol = "TLS" SSLCertificateKeyFile="${jboss.server.home.dir}/conf/459659.crt"
   SSLCertificateFile="${jboss.server.home.dir}/conf/privatekey.pem" />

In your file is certainly a little different this entry, but the two most important fields that you need to add are those that have mark red. Add them, and restart the JBoss AS.

IT Systems Java Developers

Thursday, August 5, 2010

SSL CA on JBoss AS application server

Recently I create a registraion system to the conference, of course JBoss Seam and JBoss platform based on (stable and everything works without a problem at all.)
There have however a problem, namely the SSL encrypted connection. Everywhere, the solution is given using keytool utility. The problem is that there just create the certificate to be signed by an authorized company. (Self signed out of the question). I received a certificate signed ready. Well, how can it run on JBoss AS?

The solution is not so obvious to the end, but as we read it, it will look. So, copy your private key file and certificate file to the conf directory in your JBoss configuration. In this configuration, enter the directory deploy \ jbossweb.sar and open the file server.xml. Edit the connector as follows:

<Connector protocol="HTTP/1.1" SSLEnabled="true"
   port="8443" address="${jboss.bind.address}"
   enableLookups="true" disableUploadTimeout="true"
   scheme="https" secure="true" clientAuth="false"
   sslProtocol = "TLS"
   SSLCertificateKeyFile="${jboss.server.home.dir}/conf/459659.pem"
   SSLCertificateFile="${jboss.server.home.dir}/conf/privatekey.crt" />

Sorry, but that's not all. Now a bit more difficult case, you must install JBoss Native Library to download from JBoss web page. After unpacking, copy the contents of the directory - they are dll files to the bin directory of our server. It was for Windows. If you have a Unix / Linux is the standard again you have anything else, or the bin directory create a directory "native", copy all files with the extensions "so", remembering to copy the file openssl.


Well now you can run JBoss. Access to page through https, and how you have set the port connector, which is the 8443. On Linux can be a problem with permissions to port 443, well unless it is our and we have access to the root.

Servers Administration

Speed up JBoss Seam debug cycle

By creating an application in the JBoss Seam framework, it appears that hotdeployment not working well. After setting up all the environmental variables such as (JAVA_HOME, JBOSS_HOME, SEAM_HOME) run the tool developer, I use the Eclipse and JBoss Tools.
To fully implement the JBoss Seam application on the server when compressed archives such as the EAR or WAR file, you must restart the server. When the machine around 2GHz, and 2GB of RAM it will take about 2 minutes (for the JBoss application server 5 or 6).
If we create an exploded archive, you can do a trick in Eclipse:
  1. Select the directory "exploded-archives" in your project
  2. Click F5 key (refresh)
  3. Select your project directory, which is in the above directory
  4. Click Delete key
Now, wait about 20 seconds, is redeploy application.

JBoss Seam Projects

Wednesday, August 4, 2010

JBoss Seam Excel export as HttpServletResponse

JBoss Seam provides the ability to export to excel using the built-in libraries. Everything good until they want to do something custom. Then the trouble begins.


The solution is to use external library we know. One of the best is JExcelApi. We join in the usual way jxl.jar file to your project. Now we can start to write code for an Excel file generation. I will not describe the details of this lib. However I would like to show how the JBoss Seam display in the browser to download a file generated by the user.

Write a method which generates a file:
 
public void downloadXLSExport() {
   HttpServletResponse response = (HttpServletResponse) extCtx.getResponse();
   response.setContentType("application/vnd.ms-excel");
   response.addHeader("Content-disposition","attachment; filename=export.xls");
   OutputStream outputStream = null;
   try {
      outputStream = response.getOutputStream();
      WritableWorkbook workbook = Workbook.createWorkbook(outputStream);
      WritableSheet sheet = workbook.createSheet("First Sheet", 0);
      sheet.addCell(new Label(i, 0, "Something"));
      workbook.write();
      workbook.close();
      outputStream.flush();
   } catch (Exception e) {
      e.printStackTrace();
   } finally {
      if (outputStream != null) {
         try {
            outputStream.close();
         } catch (IOException e) {
            e.printStackTrace();
         }
         facesContext.responseComplete();
       }
   }
}

Now what left for us is calling from the xhtml file as shown below:


<h:form id="excelExport">
<h:commandLink value="Excel export"
action="#{exportModelStdHome.downloadXLSExport()}" />
</h:form>
 
Remember to place a call to form a <h:form>

Monday, August 2, 2010

JBoss Seam performance

Hey, 
long time I was not here, but I had a lot of work. Over the last two years, I created applications on the JBoss Seam framework and Liferay PortalNeedless to say that both are powerful machines. Today I say a little bit about Seam and Liferay for a few days. This article is for people who are already doing something in the Seam. Probably, if you did you do something advanced in the JSF, which is standard in the Seam 2.0, you noticed that in certain situation rendering of the page takes a long time.Overall, JBoss Seam is a very thought, component frameworks, however, it is important to skillfully use their benefits.Below are a few rules that I managed to get out of the created projects.

  1. Do not place in the methods getters and setters of any logic, because these methods are repeatedly invoked in the page of generations. Imagine the situation that you have a loop that iterates over a million times and something counts. If you put it in getters, call this loop several times. In Seam such invokes are most common forms generated by JBoss Tools. For example, a form list presenting the results of a database. Once getter is called to download the collection, once to check whether it is empty, etc.
  2. Avoid creating bi-directional relationships in entity classes, because it will further slow the Seam. Seam uses HibernateMore efficient is to write additional query rather than creating a bi-directional relationship.
  3. If you do not have advanced tables, you shoul use <h:table>  instead of <rich:table>. This will speed up the rendering of the page.
  4. Use the defined scope of component( Application, Conversation, Session etc.). This will reduce memory used.
  5. If you are creating a small project, do not need advanced tools for Java EE, EJB components offered, create Seam project as an war archive.You will need much less resources application server, and additionally you can run the project on Tomcat.