Wednesday, 15 March 2017

Enable Access logs in Wildfly 8.1

In order to enable access logs in Wildfly 8.1,Please refer below steps:

  1. Go to WILDFLY_HOME/standalone/configuration folder.
  2. Open Standalone.xml and put following snippet under <subsystem xmlns="urn:jboss:domain:undertow:1.2">

 <subsystem xmlns="urn:jboss:domain:undertow:1.2">  
       <buffer-cache name="default"/>  
       <server name="default-server">  
         <http-listener name="default" socket-binding="http" record-request-start-time="true"/>  
         <host name="default-host" alias="localhost">  
           <location name="/" handler="welcome-content"/>  
           <access-log pattern="%h&#x9;%p&#x9;%l&#x9;%u&#x9;%t&#x9;&quot;%r&quot;&#x9;%s&#x9;%b&#x9;&quot;%{i,Referer}&quot;&#x9;&quot;%{i,User-Agent}&quot;&#x  
 9;%D&#x9;&quot;%{i,X-Forwarded-For}&quot;&#x9;&quot;%{i,True-Client-IP}&quot;&#x9;&quot;%{i,JSESSIONID}c&quot;" directory="${jboss.server.log.dir}" prefix="access-log"  
 worker="default" rotate="true"/>  
           <filter-ref name="server-header"/>  
           <filter-ref name="x-powered-by-header"/>  
       <servlet-container name="default">  
         <file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>  
         <response-header name="server-header" header-name="Server" header-value="WildFly/8"/>  
         <response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="Undertow/1"/>  

For access log pattern configuration, refer Access log Patterns

Enjoy Learning.

Enable Access logs in JBOSS 7.2.1

In order to enable access logs in JBOSS 7.2.1,Please refer below steps:

  1. Go to JBOSS_HOME/standalone/configuration folder.
  2. Open Standalone.xml and put following snippet under <subsystem xmlns="urn:jboss:domain:web:1.4">

 <subsystem xmlns="urn:jboss:domain:web:1.4" default-virtual-server="default-host" instance-id="${jboss.instance-id.jvmRoute}" native="false">  
       <connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http" max-connections="250"/>  
       <connector name="ajp" protocol="AJP/1.3" scheme="http" socket-binding="ajp" max-connections="250"/>  
       <connector name="https" protocol="HTTP/1.1" scheme="https" socket-binding="https" secure="true">  
         <ssl name="https" password="g04theau" certificate-key-file="/opt/jboss/certs/"/>  
       <virtual-server name="default-host" enable-welcome-root="false">  
         <alias name="localhost"/>  
         <alias name=""/>  
         <access-log pattern='%h&#9;%p&#9;%l&#9;%u&#9;%t&#9;"%r"&#9;%s&#9;%b&#9;"%{Referer}i"&#9;"%{User-Agent}i"&#9;%D&#9;"%{X-Forwarded-For}i"&#9;"%{True-Clien  
 t-IP}i"&#9;"%{JSESSIONID}c"' prefix="access-log-" rotate="true">  
           <directory path="." relative-to="jboss.server.log.dir"/>  

For access log pattern configuration, refer Access log Patterns

Enjoy Learning.

Tuesday, 14 March 2017

Tunneling with Local Port Forwarding

This diagram illustrates that our localhost is being blocked from connection to the Target Server(say Sharp Server) using a proxy filter in our corporate network.

We need a gateway server which would accept the requests from the localhost and fetch data and tunneling it back. Actually the gateway server should have a access to the Target server to perform the tunneling.
For example, the server has already got the access, to connect to the Target server, so it can act as a gateway to connect to the Target sever from the localhost .

To Create the SSH tunnel execute the following from Localhost.

1. First load the gateway server , which have the access to the Target server, in the putty

2. Select the Tunnels option from the category to add the binding port (this can be some arbitrary value) of localhost and remote host ip and port (sharp server ip and active ports).

The ‘L’ switch indicates that a local port forward is need to be created. The switch syntax is as follows.
-L <local-port-to-listen>:<remote-host>:<remote-port>

Refer the below diagram for understanding

Now the SSH client at localhost will connect to SSH server running at (usually running at port 22) binding port 4444 of localhost to listen for local requests thus creating a SSH tunnel between and localhost. At the end it will create a connection to Target Server at port 17030. So localhost doesn’t need to know how to connect to Target Server. Only needs to worry about that. The channel between localhost and will be encrypted while the connection between and localhost will be unencrypted.
Now it is possible to connect to target server by localhost:4444  at localhost computer. The computer will act as a gateway which would accept requests from localhost machine and fetch data and tunneling it back.
3. Then click Open and enter the login credentials and keep it open.

Now the server is open to connect to Target server for the localhost

To test this replace the hardcoded target server details from the code with the binding port (4444)

The same can be modified in the xml or properties file( for ex:sharpserverconfig.xml) if the server details are taking from it.

After this the connection can be make from localhost to Target Server through tunneling.

Enjoy Learning.

Rotate an array to the right by a given number of steps

Given an list of integers of Strings.We need to rotate the list in right direction.
There are few approaches to accomplish the Solution:

  • We can use two for loops and rotate the elements one by one.
  • We can use Collections utility class rotate method.

Sample Program:

import java.util.ArrayList;  
 import java.util.Collections;  
 import java.util.List;  
  * @author Dixit  
 public class RotateElement {  
       * @param args  
      public static void main(String[] args) {  
           List<String> list = new ArrayList<String>();  
           System.out.println("Before Rotating :" + list);  
           Collections.rotate(list, 2);  
           System.out.println("After Rotating :" + list);  


 Before Rotating :[1, 2, 3, 4, 5, 6]  
 After Rotating :[5, 6, 1, 2, 3, 4]  

Enjoy Learning.

Find value that occurs in odd number of times in array of elements.

Given an array of Integers.Some Integers occurs even number of times and some odd.We need to find the number which occurs odd number of times.




Sample Program:

import java.util.HashSet;  
 import java.util.Set;  
 public class OddElements {  
      public static void main(String[] args) {  
           int[] integerArray={1,2,3,2,3,2,3};  
      private static void printOddElementOccurence(int[] integerArray) {  
        Set<Integer> unpaired = new HashSet<Integer>();  
        for (int i = 0; i<integerArray.length; i++){  
          if (unpaired.contains(integerArray[i])){  
            unpaired.remove(new Integer(integerArray[i]));  
        // all printed out values are odd  
        for (Integer result : unpaired){  



Enjoy Learning.