My receipt check program in Java in CentOs is Correct?

Question 1

For my receipt Chek program is comprised of a compilation error.

Error, the version of the library is different error.


Question 2

Program of my following Java, I think there is a bug?




In CentOs Server.



// ----------------------------------------


// BufferedReader is use

import java.io.BufferedReader;

import java.io.InputStream;


// for InputStreamReader is use

import java.io.InputStreamReader;


// WebApplicationException is use (liblary: forjavax.ws.rs-api-2.0.1.jar、javax.ws.rs-api-2.0.1-sources.jar)

import javax.ws.rs.WebApplicationException;


// JSONObject (for java-json.jar) is use

import org.json.JSONObject;


// Response.status(Status.BAD_REQUEST) is use (liblary: for javax.ws.rs-api-2.0.1.jar、javax.ws.rs-api-2.0.1-sources.jar)

import javax.ws.rs.GET;

import javax.ws.rs.Path;

import javax.ws.rs.QueryParam;

import javax.ws.rs.core.Response;

import javax.ws.rs.core.Response.Status;


// IOUtils is use (liblary: httpclient-win-4.5.1.jar、httpclient-cache-4.5.1.jar、httpclient-4.5.1.jar)

import org.apache.commons.io.IOUtils;


// HttpResponse is use (liblary: httpclient-win-4.5.1.jar、httpclient-cache-4.5.1.jar、httpclient-4.5.1.jar、httpcore-4.4.3.jar)

import org.apache.http.HttpResponse;


// HttpClient is use (liblary: httpclient-win-4.5.1.jar、httpclient-cache-4.5.1.jar、httpclient-4.5.1.jar)

import org.apache.http.client.HttpClient;


// HttpPost is use (liblary: httpclient-win-4.5.1.jar、httpclient-cache-4.5.1.jar、httpclient-4.5.1.jar)

import org.apache.http.client.methods.HttpPost;


// HttpClientParams is use (liblary: httpclient-win-4.5.1.jar、httpclient-cache-4.5.1.jar、httpclient-4.5.1.jar)

import org.apache.http.client.params.HttpClientParams;


//StringEntity is use (liblary: ishttpclient-win-4.5.1.jar、httpclient-cache-4.5.1.jar、httpclient-4.5.1.jar、httpcore-4.4.3.jar)

import org.apache.http.entity.StringEntity;


// DefaultHttpClient is use (liblary: httpclient-win-4.5.1.jar、httpclient-cache-4.5.1.jar、httpclient-4.5.1.jar)

import org.apache.http.impl.client.DefaultHttpClient;



public class Appstore_Itunes_Receipt_Validator extends Object implements java.io.Serializable

{

public boolean check_appstore_itunes_receipt_in_app_purchase(String strReceipt)

{

try {

String url = "https://sandbox.itunes.apple.com/verifyReceipt";

// String url = "https://buy.itunes.apple.com/verifyReceipt";

HttpClient httpClient = new DefaultHttpClient();


DefaultHttpClient client = null;


try {

String input = IOUtils.toString( String strReceipt );

// log.info("THE INPUTSTREAM: " + input);

JSONObject receipt = new JSONObject();

receipt.put("receipt-data", input);


client = new DefaultHttpClient();

HttpPost post = new HttpPost(url);

StringEntity entity = new StringEntity(receipt.toString());

entity.setContentType("application/json");

post.setEntity(entity);

HttpClientParams.setRedirecting(post.getParams(), false);


HttpResponse response = client.execute(post);

if (300 <= response.getStatusLine().getStatusCode()) {

throw new RuntimeException("No response from iTune store. status code: " + response.getStatusLine().getStatusCode());

}


if (null == response.getEntity()) {

// log.info("Response is null");

throw new Exception("Response is null");

}


StringBuilder sb = new StringBuilder();

BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

for (String line; null != (line = reader.readLine());) {

sb.append(line);

}

JSONObject json = new JSONObject(sb.toString());

//Then work with json below


return true;

} catch (Exception e) {

throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build());

} finally {

if (null != client) {

client.getConnectionManager().shutdown();

}

}

}

catch (Exception e) {

}

finally {

}

return false;

}

}

My receipt check program in Java in CentOs is Correct?
 
 
Q