public static void main(String[] args) {
        //Settings 
        String APIURL = "https://sandbox.thesecuregateway.com/rest/v1/transactions";
        String APIKEY = "fc594b6c6fd4493db932d7ae50f8c56e";
        int TIMEOUT = 15000; //Milliseconds
        String LANG_TYPE = "json"; //"xml" or "json"

        //Transaction info
        TransactionRequest transaction_request = new TransactionRequest();
        transaction_request.api_key = APIKEY;
        transaction_request.type = "SALE";
        transaction_request.card = "4111111111111111";
        transaction_request.csc = "123";
        transaction_request.exp_date = "1121";
        transaction_request.amount = "10.00";
        transaction_request.avs_address = "112 N. Orion Court";
        transaction_request.avs_zip = "20210";
        transaction_request.purchase_order = "10";
        transaction_request.invoice = "100";
        transaction_request.email = "email@tsg.com";
        transaction_request.customer_id = "25";
        transaction_request.order_number = "1000";
        transaction_request.client_ip = "";
        transaction_request.description = "Cel Phone";
        transaction_request.comments = "Electronic Product";

        transaction_request.billing = new Billing();
        transaction_request.billing.first_name = "Joe";
        transaction_request.billing.last_name = "Smith";
        transaction_request.billing.company = "Company Inc.";
        transaction_request.billing.street = "Street 1";
        transaction_request.billing.street2 = "Street 2";
        transaction_request.billing.city = "Jersey City";
        transaction_request.billing.state = "NJ";
        transaction_request.billing.zip = "07097";
        transaction_request.billing.country = "USA";
        transaction_request.billing.phone = "123456789";
        
        transaction_request.shipping = new Shipping();
        transaction_request.shipping.first_name = "Joe";
        transaction_request.shipping.last_name = "Smith";
        transaction_request.shipping.company = "Company 2 Inc.";
        transaction_request.shipping.street = "Street 1 2";
        transaction_request.shipping.street2 = "Street 2 2";
        transaction_request.shipping.city = "Colorado City";
        transaction_request.shipping.state = "TX";
        transaction_request.shipping.zip = "79512";
        transaction_request.shipping.country = "USA";
        transaction_request.shipping.phone = "123456789";
        
        String request;
        if("xml".equals(LANG_TYPE)){ //if XML is chosen, build a XML formatted transaction 
        	request = marshalJAXBObjectToXml(TransactionRequest.class,transaction_request);
        }else{ //if JSON is chosen, build a JSON formatted transaction 
        	//Server doesn't process next fields for JSON requests, so they are excluded from the request
        	transaction_request.avs_address=null;
        	transaction_request.avs_zip=null;
        	
        	Gson gson = new Gson();
        	request = gson.toJson(transaction_request);
        }   
        
        try  
        {
        	          
            //Execute request to gateway
            System.out.println("-----------------------------------------------------");
            System.out.println("REQUEST TO URL: " + APIURL);
            System.out.println("POST DATA: \n" + request);
            
            //Trust All certificates
            trustAllSSL();
            
            URL url = new URL(APIURL);  
            URLConnection uc = url.openConnection();  
            HttpsURLConnection conn = (HttpsURLConnection) uc;  
            conn.setDoInput(true);  
            conn.setDoOutput(true);  
            conn.setConnectTimeout(TIMEOUT);
            conn.setReadTimeout(TIMEOUT);
            conn.setRequestMethod("POST");  
            conn.setRequestProperty("Content-type", "application/"+LANG_TYPE);          
            PrintWriter pw = new PrintWriter(conn.getOutputStream());  
            pw.write(request);  
            pw.close();  
            BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
            String response = "";
            String inputLine;
            while ((inputLine = in.readLine()) != null) 
                response += inputLine;
            in.close();  
            
      //formatting response
            String formattedResponse;
            if("xml".equals(LANG_TYPE)){ // if the chosen language was XML, then the server will respond back with XML
            	formattedResponse = formatXml(response);   //Format string to xml indented         	
            }else{   // if the chosen language was JSON, then the server will respond back with JSON
            	formattedResponse = response;				//no need to format string to json indented
            }     
            
            System.out.println("-----------------------------------------------------");
            System.out.println("RESPONSE DATA: \n" + formattedResponse);
            
          //parse response according to its content
            if("xml".equals(LANG_TYPE)){
            	parseXMLResponse(conn, response);   //parse XML response          	
            }else{ 
            	parseJSONResponse(conn, response);	//parse JSON response
            }         
        }catch (Exception e){  
            System.out.println("-----------------------------------------------------");
            System.out.println("EXCEPTION: " + e.getMessage());
        }  
    }