Saturday, May 6, 2017

Start stop apache in Red Hat 7

Start apache in RHL 7

service httpd start

Stop apache in RHL 7

stop  httpd start

How to install Apache in Ubuntu

How to install Apache web server in ubuntu

1. Update package

apt-get upgrade

2. Install apache2

apt-get install apache2 apache2-utils

3. Start apache

service apache2 start

Find the version of apache

apache2  -V

Friday, December 30, 2016

Avoid SSL in Apache HTTP client

Avoid SSL in Apache HTTP client. 

Sometimes,  you need to do REST call from Apache HTTP client where the REST endpoint has https. HTTPS may block your request since you are not a trusted party. To avoid such situation you can use following code ( This code should be only used in development and QA environment, not for production).


try
 {
    DefaultHttpClient client = new DefaultHttpClient();
 HostnameVerifier hostnameVerifier=
org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; SchemeRegistry registry = new SchemeRegistry(); SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory(); socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier); registry.register(new Scheme("https", socketFactory, 443)); SingleClientConnManager mgr =
new SingleClientConnManager(client.getParams(), registry); DefaultHttpClient httpClient = new DefaultHttpClient(mgr, client.getParams()); HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier); HttpGet requestAPI = new HttpGet(url); HttpResponse responseAPI = httpClient.execute(requestAPI); HttpEntity entity = responseAPI.getEntity(); int responseCode = responseAPI.getStatusLine().getStatusCode(); } catch(Exception e) { }

How to get size of disc and size of RAM in JAVA

Following code can help you to find size of the disc and size of the RAM. 
import java.lang.management.*;
import java.io.*;

class Main
{
    public static void main(String... a)
    {
        long diskSize = new File("/").getTotalSpace();

        long maxMemory = Runtime.getRuntime().maxMemory();
        long memorySize = ((com.sun.management.OperatingSystemMXBean) 
ManagementFactory.getOperatingSystemMXBean())
.getTotalPhysicalMemorySize();
        System.out.println("Size of C:="+diskSize+" Bytes");


        System.out.println("RAM Size="+memorySize+" Bytes");
   }
}

Create and Build a Maven Project in Codenvy

Creating and building project with Maven in Codenvy is very simple. The new IDE interface provides some easy steps that helps you to build your POM file in a very easy manner.

Go to workspace and create project




Create a maven project
Give a name to project , description is optional.




Fill these entries as per your requirement. 
For demo purpose we are just leaving them blank.




After the project is created you can see this in your project explorer .




Build project




You can verify the build message in the console






Apache HttpClient example with Maven [JAVA]

Step one.
<dependencies>
 <dependency>
  <groupId>org.apache.httpcomponents</groupId>
  <artifactId>httpclient</artifactId>
  <version>4.5.2</version>
</dependency>
  </dependencies>

Update pom.xml with following entry



Step two

Execute following code


import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicNameValuePair;

public class Main 
{

    public static void main(String[] args) 
    {
        try
        {
        String url = "http://wikipedia.org";

        HttpClient client = HttpClientBuilder.create().build();
        HttpGet request = new HttpGet(url);


        request.addHeader("User-Agent", "USER_AGENT");
        HttpResponse response = client.execute(request);

            System.out.println("Response Code : "
                + response.getStatusLine().getStatusCode());
       }
       catch(Exception e)
       {
          System.out.println(e); 
       }
    }
}

Thursday, December 29, 2016

How to check if modules are enabled in php or not

To check if some particular modules such as PDO, XML, SQLLITE, FTP enabled in your PHP or not, we can use get_loaded_extensions() method.




<?php
echo "<pre>";
print_r(get_loaded_extensions());
?>



This will show you following modules are enabled


Array
(
    [0] => Core
    [1] => bcmath
    [2] => calendar
    [3] => ctype
    [4] => date
    [5] => filter
    [6] => hash
    [7] => iconv
    [8] => json
    [9] => mcrypt
    [10] => SPL
    [11] => pcre
    [12] => Reflection
    [13] => session
    [14] => standard
    [15] => mysqlnd
    [16] => tokenizer
    [17] => zip
    [18] => zlib
    [19] => libxml
    [20] => dom
    [21] => PDO
    [22] => bz2
    [23] => SimpleXML
    [24] => xml
    [25] => wddx
    [26] => xmlreader
    [27] => xmlwriter
    [28] => apache2handler
    [29] => openssl
    [30] => curl
    [31] => fileinfo
    [32] => gd
    [33] => gettext
    [34] => mbstring
    [35] => exif
    [36] => mysqli
    [37] => pdo_mysql
    [38] => pdo_sqlite
    [39] => Phar
    [40] => ftp
)