Skip to main content

Posts

Using Apache as (SSL) proxy server

If you are a using any Java web server (such as Tomcat) or app server (such as Wildfly, JBoss or Glassfish), then you know that they dont listen on http port 80. Well, why does it have to listen on port 80? because if you want your user to specify only the url and not the port; for example, http://mydomain.com and not http://mydomain:8080 Note: throughout this article mydomain.com can be replaced with localhost, if your product is in development stage. Software used: Ubuntu apache2 Any Java web/app server What we want to achieve We are going to divert all user requests coming on port 80 to Tomcat running 8080 on the same host. Installation Run the following commands sudo apt-get install apache2 sudo apt-get install libxml2-dev sudo apt-get install libapache2-mod-proxy-html Note: If your ubuntu OS is latest, then you may not have libapache2-mod-proxy-html package. Instead run the following command. sudo a2enmod proxy_html Configuration 1. Append t...

How to install (K)Ubuntu alongside Yosemite and Windows 8 on Mac Book Pro?

Here let's see how we can install Windows 8 and (K)ubuntu 15.10 (Wily Werewolf) along side Mac Yosemite as triple boot. Software/Hardware required Mac book Pro 11,1 (instruction might be similar for newer models) Yosemite Windows 8 (K)Ubuntu 15.10  Wily Werewolf (might work with 15.04 as well) Refind (not reEFIt) Here is the summary of what we are going to do. Partition mac to have windows boot-camp partition  Install windows 8 Create two new partitions from mac partition for Linux Install (K)ubuntu Fix GPT-MBR Install Refind Step-0 In case you want to backup your mac:  Restart mac and hold  This will boot Mac in recovery mode as shown below    Plugin an external drive and choose Disk Utility option Select the mac partition (not your hard disk root) and go to restore tab Choose your external drive as the destination as shown below Important: ensure that your mac partition is the Source Click Restore to take a cop...

Installing GoDaddy certificate in Wildfly/Keycloak

In the previous post we saw how to set up Keycloak . Here we will see how to generate and install GoDaddy.com certificate in Keycloak. The steps are similar for Wildfly as well. Step 1: Generate CSR file Run the following commands in your terminal. <mydomain.com> has to be replaced with your actual domain name. keytool -genkey -alias mydomain_com -keyalg RSA -keysize 2048 -keystore mydomain_com.jks keytool -certreq -alias mydomain_com -file mydomain_com.csr -keystore mydomain_com.jks Step 2: Generate certificate Upload  mydomain_com . csr  file content into GoDaddy.com, generate and download certificate for tomcat server (steps to generating SSL certificate is beyond the scope of this article). If you unzip the file, you will see the following files. gd_bundle-g2-g1.crt ..5f8c...3a89.crt   #some file with alphanumeric name gdig2.crt Files 1 and 2 are of our interest. Third file is not required. Step 3: Import certificate to key...

Configuring and using Keycloak

In this article we will see how to use Keycloak , one of the popular SSO software. Here is the excerpt from the official website. Integrated SSO and IDM for browser apps and RESTful web services.  Built on top of the OAuth 2.0, Open ID Connect, JSON Web Token (JWT) and SAML 2.0 specifications.  Keycloak has tight integration with a variety of platforms and has a HTTP security proxy service where we don't have tight integration.  Options are to deploy it with an existing app server, as a black-box appliance, or as an Openshift cloud service and/or cartridge. Installation Download the software from   here . Let's use  keycloak-1.4.0.Final   for the purpose of demonstration in this article and we will try to set it as a standalone server. To install first download either the zip or tar.gz and extract. Then start by running either: keycloak-1.4.0.Final/bin/standalone.sh or: keycloak-1.4.0.Final/bin/standalone.bat That's it. you are do...

How to execute a singleton task in a cluster?

Have you come across a situation where you wanted a singleton to execute a task in a cluster of servers (such as running a clean up task every day, sending a report everyday etc)? You know that these type of tasks should be executed by exactly only one of many servers you have. Here you go. Following simple program will let you do that exactly. import java.util.logging.Level; import java.util.logging.Logger; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import org.jgroups.Address; import org.jgroups.JChannel; import org.jgroups.ReceiverAdapter; import org.jgroups.View; import org.springframework.stereotype.Component; /** * * @author Pragalathan M */ @Component public class ClusteredSingletonManager { private JChannel channel; private Address ownAddress; private static final Logger logger = Logger.getLogger(ClusteredSingletonManager.class.getName()); @PostConstruct private void init() { try { logger.info(...

Transform Object into XML using JAXB (Part 2)

In one of the posts  we had seen how to convert Java objects into XML. This was done using JAXB and XSD .  What if you don't like to write XSD by hand. Well, you can use any online or offline tools available, to generate the desired XSD from XML. Most of the times the generated XSD will be nearly accurate and you have to hand edit them to make it 100% perfect. Alright. What if you don't know XSD at all. Is there a simpler way? Yes there is. Here we are going to use a different approach to achieve exactly the same result that we have got in the  old  post. Open Netbeans and create a Java Application File->New Project->Java Application Enter "XMLBinding2" in the Project Name field Click Finish Create the following Java classes Replace the Java files with the following contents appropriately. package xmlbinding2; import java.util.List; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrappe...

Dynamic SOAP Service Client

If you have written SOAP service client, you might know that you need the WSDL file; need to generate Java code for that,compile that Java classes and add it as dependency for your module. What would you do if you have to incorporate your code with a new SOAP service every now and then? What would you do if all you need is to consume the service and do a little processing on the output, i.e., you need the data in XML format? What would you do if you don't have a complete WSDL? What would you do if your service is in .NET whose WSDL is having problem while generating Java classes? Is there a way to write a dynamic client which can consume any SOAP service? .... YES!... there is a way. Let's quickly write a web (SOAP) service. Software used: Java 7 NetBeans IDE 7.4 GlassFish 4.0 Maven Create a web project and choose Glassfish as server. Now add web service (not a rest service) as below. Edit the SimpleService.java as follows. package com.mycom...