Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Monday, 17 August 2015

Remote JMX Connection Issue

Recently I tried to remotely connect to Liferay 6.2 's tomcat bundle on JMX via JConsole and JVisualVM with no success. Both applications repeatedly unable to connect via rmi. This boggled me as this never happened to me if the same to be done on Windows or my OSX macbook.

The only difference this time is I have Centos 7 running on my macbook. Yes, Centos 7, trying to get my hands dirty back on Linux. Installing Centos 7 on Macbook is another story. It took me a few days of misery and frustration until LiveCD saved me. OK, enough about me.

So, as usual you would need to supply VM arguments as follow:

-Dcom.sun.management.jmxremote 
-Dcom.sun.management.jmxremote.port=9999
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false


Tips: You can quickly kill the process that is listening to port 9999 with "fuser -k 9999/tcp" command.

Normally this is would suffice, but not this time.
Further tests to narrow down to possible root cause includes:

1. Telnet to port - OK
# telnet <host-ip> 9999

2. Run local JConsole and JVisualVM - OK (although unneccessary)

Tips: You may completely disable firewall in Centos 7 with "sudo systemctl disable firewall-d" or
open up specific port with "sudo firewall-cmd --zone=public --add-port=9999/tcp && sudo firewall-cmd --reload"

After exhaustively searching through google and stackoverflow finally I found a blog page that suggest additional argument. Ironically, the blog post entry has nothing to do with my problem, duhh...additionally I found this via a comment in stackoverflow entry.

So, the additional argument that make it work is -Dcom.sun.management.jmxremote.rmi.port=9999
Feel me? yeah, how silly is that and I don't know why and how that works. So, help me god if anyone would generously want to explain.
'
-Dcom.sun.management.jmxremote 
-Dcom.sun.management.jmxremote.port=9999
-Dcom.sun.management.jmxremote.rmi.port=9999
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false


Made the changes then, I fired JConsole/JVisualVM and it works!

I hope that helps some one outthere.

Happy Godek'king!!

FYI "Godek" slang means "hack" in Malay :)




java.io.IOException: Cannot recover key

For those who are NOT familiar with configuring tomcat HTTPS connector (I had apache-tomcat-7.0.34), like me, this error can be frustrating. It turned out to be a simple fix. I am assuming you have properly generated a tomcat key, a keystore and imported them successfully into JAVA cacerts keystore. As for my case I chose my own keystore filename, my own kesytore pass(word) and my own tomcat key pass(word). Unfortunately, these require explicitly be entered in your tomcat's server.xml. 

Consider the following template in the tomcat's server.xml file after you uncommented it.



If you named your keystore as ".keystore" with key and keystore pass(word) as "changeit" and left it reside in your home dir (i.e.: /home/hamid) , then above setup would work happily just like that.

Unfortunately, for most of the time it is not the case as you would name your keystore to some other name, located to some other location (folder) and both key & keystore with some other pass(word).
For example:

Keystore name: keystore.jks
Keystore folder: /home/hamid/secret/store
Keystore password: password1
Key password: password2

Then you would want to do the following:



I hope that helps.

Happy Godek'king!

FYI "Godek" slang means "hack" in Malay :)

Thursday, 12 June 2014

Setting up Spring MVC flavor of AppFuse 3.0.1-SNAPSHOT stack in Eclipse IDE

Hello again! I was lucky enough to review some of the web application stacks and have found AppFuse Stack a comprehensive starter kit with well-written tutorials to continue with. I have used them in couple of projects in past successfully especially with Spring MVC Flavor and I thought I would write some tutorials dedicated to this Stack. To learn more on AppFuse, click on.

In this tutorial, I will show in 5 steps to generate, import and start up Spring MVC flavor of AppFuse ready for development in your Eclipse IDE with the following pre-requisites:

1. Eclipse IDE  (JUNO or later) with m2e plugin installed.
2. Maven 3.x
3. MySQL 5.x
4. JDK 7.x
5.  An awesome Macbook Pro on Maverick OSX or whatever OSX Version you currently have.
6. and of course Internet Connection


Step 1: Generate your choice of stack with AppFuse QuickStart
If you have read AppFuse QuickStart and chosen your stack as Spring MVC you will end up with the following command line to generate your stack.

mvn archetype:generate -B -DarchetypeGroupId=org.appfuse.archetypes -DarchetypeArtifactId=appfuse-basic-spring-archetype -DarchetypeVersion=3.0.1-SNAPSHOT -DgroupId=com.mycompany -DartifactId=myproject -DarchetypeRepository=http://oss.sonatype.org/content/repositories/appfuse

Go ahead and paste them into you chosen working (workspace) folder in the command line window.
It will goes on generating about sometimes and mostly downloading the required java libraries.
Once done, depending your choice of "ArtifactId" a folder with that name will be created. In this case, "myproject".

[INFO] project created from Archetype in dir: /Users/hamid/Documents/workspace/myproject
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.162s
[INFO] Finished at: Fri Jun 13 08:54:43 MYT 2014
[INFO] Final Memory: 18M/228M
[INFO] ------------------------------------------------------------------------


Step 2: Generate Full Source (Service Layer modules - models, daos, managers, tests) of your stack
I like my stack as verbose as possible especially when it comes to service layer and AppFuse has plugin called appfuse to do as such. Now that you have generated your stack, navigate to "myproject" folder in your command line tool and executed the following command:

mvn appfuse:full-source


During this process you will see the following output to confirm that your service layer is being generated...

[INFO] --- appfuse-maven-plugin:3.0.0:full-source (default-cli) @ myproject ---
[INFO] [AppFuse] Installing source from data-common module...
[INFO] [AppFuse] Installing source from hibernate module...
[INFO] [AppFuse] Installing source from service module...
[INFO] [AppFuse] Source successfully exported, modifying pom.xml...
[INFO] [AppFuse] Adding dependencies from root module...

Step 3: Import into Eclipse IDE
Importing into Eclipse is easy, go ahead startup your eclipse IDE.
Now that your IDE is ready, click on File -> Import -> Maven -> Existing Maven Projects -> [Browse to your project folder with Browse button] -> Finish

Yep I know, the are some errors, we will get to that in the next steps.

Step 4: Quick and dirty way clearing off the errors in Eclipse IDE
 I have identified few errors in the imported maven projects and let clear them one by one:

1. JavaScript Source error - Exclude them!
Navigate to "Include Path"  from your project.
Right Click on your project root myproject -> Properties -> JavaScript -> Include Path.
Then under "Source" tab,  select "Excluded:" and then click "Edit" button.
Add "src/main/webapp/scripts" folder in the "Exclusion Pattern" using Add -> Browse button.

2. Replace the "ne" to != in src/main/webapp/decorators/default.jsp file

3. pom.xml error
Enclose <plugins>..</plugins> node with <pluginManagement> element, like the following:

<pluginManagement>
    <plugins>
    ....
   </plugins>
</pluginManagement>

4. sample-data.xsd error
Open the same file of src/rest/resources/sample-data.xsd in your favorite text editor (mine is textmate),
select all, copy and paste them in the same file in your IDE.

Rebuild your project with Project -> Clean or if you have the "Build Automatically" selected, your project should been instantenously re-built and the errors should have been gone.

Step 5: First run of your stack
Now that the errors have disappeared, it is time to maiden run of your stack.
before that, just make sure your MySQL 5.x Server is installed and running
In the command line window execute the following:

mvn jetty:run

for, the eager beavers who don't want to wait for all tests to be completed, you may run with skipped test as the following:

mvn -Dmaven.test.skip=true jetty:run

Next : Continue on your development...
Extends the stack with exciting frameworks such as Spring Security ACL for fine-grained access to your web resources or whatever your have in mind.

That's it! I hope you have had a perfect run of your first stack and until next time...