Friday, December 28, 2012

Maven - How to deploy WAR to vFabric TC Server remotely using Maven build?

Four easy steps on How to deploy the WAR file to vFabric TC 2.8.* server  or Tomcat 7 remotely using Maven build (pom.xml)

Step 1: Open your tomcat-user.xml from your <CATALINA_HOME>/conf folder and insert the code:

Code:
  <?xml version="1.0" encoding="UTF-8"?>
  <tomcat-users>
     <role rolename="manager-gui" />
     <role rolename="manage-script" />
     <role rolename="manager-status" />
     <role rolename="manager-jmx" />
     <user username="adminuser" password="adminpwd" roles="manager-gui" />
  </tomcat-users>

Note: Role name script, status and jmx are optional. In previous version of tomcat, you can use role "manager" but for tomcat 7, it was divided into four role. For depolyment, we need only "manager-gui".

Step 2: Update your Maven settings.xml with the following code. To check where is your maven settings located, just open a command prompt and type maven -X and it will show the global settings and user settings. I choose global settings since I will be allowing other users to use the same settings.

Open <MAVEN_HOME>/conf/settings.xml then insert the code:

Code:
  <?xml version="1.0" encoding="UTF-8"?>
  <settings>
   <servers>
     <server>
        <id>remoteserver</id>
        <username>adminuser</username>
        <password>adminpwd</password>
     </server>
   </servers>
  </settings>


Step 3: Open your pom.xml and insert the following code

  Code:
  <plugin>
      <groupId>org.apache.tomcat.maven</groupId>
      <!-- for tomcat 6 -->
      <!--
      <artifactId>tomcat6-maven-plugin</artifactId>
      -->
      <artifactId>tomcat7-maven-plugin</artifactId>
      <configuration>
         <url>http://<remote_ip_address>:<port>/manager/html</url>
         <server>remoteserver</server>
         <path>/your_web_context_path_here</path>
      </configuration>
  </plugin>


Note: if you have a parent pom.xml you need to insert the following code to your parent pom.xml

Code:
  <plugin>
     <groupId>org.apache.tomcat.maven</groupId>
     <artifactId>tomcat7-maven-plugin</artifactId>
     <version>2.0</version>
  </plugin>


Step 4: Deploy or Redeploy
  Run maven command to deploy
  Code:
   mvn tomcat7:deploy
  For redeploy:
  Code:
   mvn tomcat7:redeploy

Wednesday, December 12, 2012

MuleSoft - Building the JKS for the HTTPS Services for ESB Standalone

After following this instruction https://docs.mulesoft.com/cloudhub/building-an-https-service to build a sample hello application. We need to replace the JKS file. Follow the instruction below:

1) Generate key with AES256
openssl genrsa -aes256 -out server.key 1024
2) Generate a Certificate Request for CA
openssl req -x509 -sha256 -new -key server.key -out server.csr
Enter pass phrase for server.key: <ENTER_YOUR_PASSWORD_YOU'VE_CREATED on STEP 1>
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:<ENTER THE COUNTRY 2 LETTER CODE i.e. US>
State or Province Name (full name) [Some-State]:<ENTER YOUR STATE IN FULL i.e. KANSAS>
Locality Name (eg, city) []:<ENTER YOUR CITY i.e. KANSAS CITY>
Organization Name (eg, company) [Internet Widgits Pty Ltd]:<ENTER YOUR COMPANY NAME i.e. MyCompany>
Organizational Unit Name (eg, section) []:<ENTER YOUR DEPARMENT i.e. Research>
Common Name (e.g. server FQDN or YOUR name) []:<ENTER YOUR DOMAIN NAME i.e. www.mywebsite.com or localhost>
Email Address []:<LEAVE IT BLANK just PRESS ENTER>

3) Generate a self signed certificate that will expire for 360 days
openssl x509 -sha256 -days 360 -in server.csr -signkey server.key -out selfsigned.crt
Getting Private key
Enter pass phrase for server.key:<ENTER_YOUR_PASSWORD_YOU'VE CREATED on STEP 1>

4) Create PKCS12 keystore from private key and public certificate
openssl pkcs12 -export -name servercert -in selfsigned.crt -inkey server.key -out keystore.p12
Enter pass phrase for server.key:
Enter Export Password:
Verifying - Enter Export Password:

5) Convert PKCS12 keystone into a JKS Keystore
keytool -importkeystore -destkeystore keystore.jks -srckeystore keystore.p12 -srcstoretype pkcs12 -alias servercert
Enter destination keystore password:  
Re-enter new password: 
Enter source keystore password:  

6) Verify the content of the JKS
keytool -list -v -keystore keystore.jks
Enter keystore password:  

Keystore type: JKS
Keystore provider: SUN

Your keystore contains 1 entry

Alias name: servercert
Creation date: Mar 15, 2016
Entry type: PrivateKeyEntry
Certificate chain length: 1
Certificate[1]:
Owner: O=Internet Widgits Pty Ltd, ST=Some-State, C=US
Issuer: O=Internet Widgits Pty Ltd, ST=Some-State, C=US
Serial number: a829076439b2c11f
Valid from: Tue Mar 15 08:31:22 CDT 2016 until: Fri Mar 10 07:31:22 CST 2017
Certificate fingerprints:
MD5:  0B:F0:2C:64:86:50:80:29:3F:41:09:80:9C:F0:FF:CA
SHA1: 8C:26:4A:4B:FA:55:49:B7:4E:FE:33:13:90:AA:6F:15:B7:A3:E6:DE
SHA256: BB:B2:7C:A2:A8:EF:F5:AE:E8:F1:2D:13:15:ED:46:F5:16:21:AF:18:9D:74:A0:AA:BE:2A:D2:55:68:27:68:D5
Signature algorithm name: SHA256withRSA
Version: 3

Extensions: 

#1: ObjectId: 2.5.29.35 Criticality=false
AuthorityKeyIdentifier [
KeyIdentifier [
0000: 2B C6 1B 1C 65 24 F4 95   F2 46 E0 1F 07 94 B8 C9  +...e$...F......
0010: F4 25 F0 1C                                        .%..
]
[O=Internet Widgits Pty Ltd, ST=Some-State, C=US]
SerialNumber: [    a8290764 39b2c11f]
]

#2: ObjectId: 2.5.29.19 Criticality=false
BasicConstraints:[
  CA:true
  PathLen:2147483647
]

#3: ObjectId: 2.5.29.14 Criticality=false
SubjectKeyIdentifier [
KeyIdentifier [
0000: 2B C6 1B 1C 65 24 F4 95   F2 46 E0 1F 07 94 B8 C9  +...e$...F......
0010: F4 25 F0 1C                                        .%..
]
]
*******************************************

7) Copy the keystore.jks file to MuleSoft Project /<PROJECT>/src/main/resources

8) Run the application and invoke your HTTPS://<IP>:<PORT> using browser