Sunday, August 31, 2014

Torquebox 3.1 - Injectable Resources demystified!

Hello, guys!

During the last week I had the chance to attend RubyconfBR, a great Ruby conference that happens every year here in Sao Paulo. I also could present a bit about Torquebox, a great tool to mix Java and Ruby languages into the same container. Torquebox is a pretty great tool IMHO, but it lacks of marketing and better examples. The first time I tried Torquebox was in 2011 and now in 2014 it is much more mature, fast and reliable.

Torquebox has a very interesting feature - you can deploy a JAR file inside a Ruby application and invoke a Java class inside Ruby code. Nothing new for JRuby users, but it makes a 'box' that makes the code much more simple:

 @m = TorqueBox.fetch(Java::test.torquebox.MemberRegistration)  

Well, a similar example is listed in the documentation. The problem is that it is not into a 'for dummies' format, so it gets pretty hard to execute. First thing we need to know is that Torquebox 3 has two operation modes:


  • A 'Slim' one - a format where you do not have all JBoss/JEE features embedded on it, turning the container lighter and faster, but incomplete in terms of JEE implementations. (Download here)
  • A 'Full' mode - You need to download JBoss AS 7.1 (or higher) or JBoss EAP (6.1 or higher - I am using JBoss EAP 6.3, that you can download here) and then download Torquebox Overlay Package (here). After that, you need to add Overlay files into JBoss AS or EAP, *respecting the proper directories*! Think about Overlay package as a JBoss Patch. This will give you all JEE implementations with full power of a Java Application Server. *THIS* is the only mode that Injectable resources will work properly, since CDI libs will be loaded here!
After that, another problem - I could not fin an example of Java application + Ruby application that I could deploy into Torquebox. Argh. So I created one example here. The only part that you should build with mvn clean install is the EJB project, that will generate a JAR for you. This project has a single Java class for test:

 package test.torquebox;  
 import javax.enterprise.context.ApplicationScoped;  
 import javax.inject.Inject;  
 @ApplicationScoped  
 public class MemberRegistration {  
      @Inject  
      public MemberRegistration() {  
           // TODO Auto-generated constructor stub  
      }  
   public String minhaRegraDeNegocio() {  
        return "LOLOLOLOLOL";  
   }  
 }  

Clone the project from Github, go to ejb/ folder and run
mvn clean install

After that, you should obtain a JAR file with the class.

Then create your Rails application using JRuby (1.7.12 or higher). Paste the JAR into the lib/ folder of the Rails app. You should end up with something like this project.

Now you can call the Java classes inside the JAR just the way like the initial example in the post. You can also call the into the ERB files:
 <html>  
 <head></head>  
 <body>  
  <%= @m %>  
  <%= @m.minhaRegraDeNegocio %>  
 </body>  
 </html>  


Cheers!

Thursday, August 28, 2014

How to configure a JDBC driver on Wildfly / JBoss AS7

Hi guys! Welcome back to this series of blog post that aims to teach you something new  on every post =)

So in this post we are going to configure an JDBC driver on Wildfly / JBoss AS 7. I mention the JBoss AS as there still many people using it. Remember that Wildfly is the continuation of JBoss AS project, it just renamed it and now Wildfly is the upstream, having all the bleeding edge technologies and fixes.

I will try to make some very simple and specify steps how to do this with an example, drop a comment if you need any more help or if something went wrong, I will help you =)

For this tutorial, let's suppose we have a Oracle Database that we want to use in our WAR/EAR project. First things we need to know the specific version of the database (you can ask to the DBA or if you already have access to the database using a tool, just do a query like 'select * from v$version;' to check the Oracle DB version).

Now you need the JDBC Driver, which implements a many interfaces defined to abstract the database vendor to an easy to use API. So for this example, to get the JDBC driver from Oracle's website (which will require you to have an account) you will got to http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html .

Now that we have the driver, it would be interesting to push that jar into your local maven repository (or you private repository), so if you need some classes from that JAR in your project and you use Maven (or some other technology that  can read the maven repository), that would help to control the JDBC version and type as well. To install it, run the following command (changing the parameters, like the 'ojdbc6.jar ' to the path of your JDBC jar file) and put it as dependency in the pom.xml with provided scope.
mvn install:install-file -Dfile=ojdbc6.jar -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0-4 -Dpackaging=jar

Now using Wildfly you have two options, you can drop the JDBC driver file into the deployment folder OR you can also create a module for this JDBC drive.

Then you have to setup the JDBC conection pool. Again, this can be done by two different ways, one you can use the web management console to create the connection (would look like this jdbc:oracle:thin:@HOST:PORT:SID ) or you can use the CLI (a command-line interface that comes with Wildfly) to connect to your remote server (or locally) and create the connection pool. Below an example of the CLI commands:    
[standalone@localhost:9990 /] data-source add --name=OracleDS --driver-name=ojdbc6.jar --connection-url=jdbc:oracle:thin:@HOST:PORT:SID --jndi-name=java:jboss/jdbc/OracleDS --user-name=u --password=p
[standalone@localhost:9990 /] reload
[standalone@localhost:9990 /] /subsystem=datasources/data-source=OracleDS:enable()
[standalone@localhost:9990 /] /subsystem=datasources/data-source=OracleDS:test-connection-in-pool()

Done! Now you can get your datasource using @Resource or configuring with your JPA or even using JNDI, for example:

InitialContext context = new InitialContext();
DataSource a = (DataSource) context.lookup("java:jboss/jdbc/OracleDS");

Well, hope it helped a bit to setup your JDBC driver and connection. I will put some useful links in the end of the post.

Thank for reading! Let me know any question.

Links:

https://community.jboss.org/wiki/DataSourceConfigurationInAS7
https://docs.jboss.org/author/display/AS71/CLI+Recipes#CLIRecipes-AddaNewDatasource
https://docs.jboss.org/author/display/WFLY8/Developer+Guide#DeveloperGuide-InstalltheJDBCdriverasadeployment
https://github.com/arun-gupta/wildfly-lab/blob/master/docs/chapters/jboss-cli.adoc
http://www.orafaq.com/wiki/JDBC
https://stackoverflow.com/questions/1074869/find-oracle-jdbc-driver-in-maven-repository
https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope

Tuesday, June 3, 2014

Getting more secure with End-to-end and more advices for your privacy!

Hi, I would like to help people to install the end-to-end project (you can read the overview in the google security blog here). For those how want 10,000 feet overview, it basically it will make you encrypt your emails, which is much more secure, you can even put a password that only the recipients will be able to read.

To install, you need to get the contents from project wiki and use the following instructions (after resolving the dependencies (like git, svc, wget, java and etc) in case you don't have them installed before hand):

To install (get the source):
vim install.sh
chmod a+x install.sh
./install.sh

To compile:
cd e2e_dev/
vim compile.sh
chmod a+x compile.sh
shopt -s expand_aliases
./compile.sh

Then just install the unpacked extension using the path  e2e_dev/end-to-end/javascript/crypto/e2e/extension/
(More details about it in
https://developer.chrome.com/extensions/getstarted )

Congratulations for the amazing project Google and  end-to-end project team =)

Guys, checkout other projects in https://prism-break.org ,so you can find things like disconnect that can help to avoid those advertisements and some undesired contents and other useful things to have more privacy.

Kindest regards,
Luan

Monday, June 2, 2014

PostgreSQL working on Mac OS Mavericks

Hello, all!

Installing PostgreSQL and make it up and running usually is a mess to me.
So, some simple and few steps worked pretty well to me.

1. Download and Install Postgres.app - http://postgresapp.com/
2. Install brew (http://brew.sh/)
3. brew install postgresql

Fine! You have postgreSQL installed. However, it may generate the following error if you try to run a migration from Rails:

 Is the server running locally and accepting connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?  

Now you have to follow these steps:

4. sudo mkdir /var/pgsql_socket/
5. ln -s /private/tmp/.s.PGSQL.5432 /var/pgsql_socket/
(steps described here - http://www.fullybaked.co.uk/articles/getting-postgresql-running-on-osx-mountain-lion - on section named "No Socket" )

Almost there! Now it's time for (if it happens)

 rake aborted!  
 FATAL: role "postgres" does not exist  

So, finally,
6. Access PostgreSQL command Line (if Postgres.app is running, click on the elephant on the menu bar, then Open psql, as shown on the image below)
Click on "Open psql" option
7. Now, on the terminal, type
\du
It will show you a list of SUPERUSERS. If you don't have postgres a SUPERUSER, simply add one:
8.  CREATE USER postgres SUPERUSER;

And doonnee! Finally you have PostgreSQL up and running!

Saturday, May 17, 2014

Helios - iOS apps Backend made easy

Hi All!

Some time ago I found a precious tool to build backend apps for iOS world - Helios framework!
https://github.com/helios-framework/helios . This guy is a ruby gem that allows you to do Data Mapping and Push Notifications in a very, very easy way.

If you like to build backends in Ruby and uses Heroku, this gem can be very useful if you need an iOS backend.

I have made some talks about it - http://www.slideshare.net/hannelita/rubyconf-ar-2013pdf  .

Warning - this guy is Beta yet. However, it's very stable - I have tried it with no disappointments!

Sunday, February 16, 2014

Fedora 20 release party at Red Hat São Paulo Office



Hi Guys!

I discovered a new event these days.On January 18th happened Fedora 20 Release Party at Red Hat São Paulo Office (here in Brazil). This event is a very special opportunity to get in touch to the contributors and subject matter expert which can answer almost anything about Fedora (and other Open Source stuff). You can also learn about the new features that Fedora is about to release, like Leonardo Vaz (the organizer of this event and a very cool metal open source friend =) ) talked about . And you can also learn some bleeding edge technologies, for example in this time  Ricardo talked about Openshift, a PaaS solution.

This event is really cool and everybody can go:

  • If you are just starting to use Linux;
  • If you are SysAdmin;
  • If you are a developer;
  • and so on.
Feel free to reach the people from the Fedora 20 Release Party close to you and let's share and learn information =D.


Below some photos of that day:






Monday, January 27, 2014

Quick tricky tip about JBoss CLI - stop a single server

Hello, guys.

I really like JBoss CLI, but sometime its syntax is pretty tricky and Google does not help. So, once for all: "How do you stop a single server instance in domain mode??" Yeah, not a group or a full host, but just a single server instance.

There it goes!

/host=master/server-config=server-one:stop

JUST LIKE THAT.

Hope it helps you!