Log in or register to post comments

Jar file required for VWS API

April 19, 2013 - 5:11am #1

Hi Experts,

I'm trying to execute the sample implementation in Java for getting the list of targets using the VWS API.

Probably this requires a jar to included in the build path for classes like org.apache.http.client.HttpClient, org.apache.http.util.EntityUtils.

Please help me with the path to the jar file for this.

Best regards,

Harsh

 

 

Jar file required for VWS API

April 20, 2013 - 1:07pm #4

Hi, you must add (as external JARs) all the jar files that are located in the directory of the Apache Http client (once you have extracted the zip file).

 

Jar file required for VWS API

April 19, 2013 - 11:26pm #3

Thanks for your inputs!

I included two jar files, commons-codec-1.6.jar and httpclient-4.2.3.jar. This solved most of the build errors except two in SignatureBuilder.java. It is unable to find method getFirstHeader in HTTPUriRequest object and getEntity method in HttpEntityEnclosingRequestBase object. (Code snippets enclosed).

 

Please suggest if I need to include some other jar file as well.

 

	public String tmsSignature(HttpUriRequest request, String secretKey) {
		String method = request.getMethod();
		String contentType = "";
		String hexDigest = "d41d8cd98f00b204e9800998ecf8427e"; // Hex digest of an empty string

		if (method.equalsIgnoreCase("GET") || method.equalsIgnoreCase("DELETE")) {
			// Do nothing because the strings are already set correctly
		} else if (method.equalsIgnoreCase("POST") || method.equalsIgnoreCase("PUT")) {
			contentType = "application/json";
			// If this is a POST or PUT the request should have a request body
			hexDigest = contentMD5((HttpEntityEnclosingRequestBase) request);
		} else {
			System.out.println("ERROR: Invalid content type passed to Sig Builder");
		}

		// Date in the header and date used to calculate the hash must be the same
		String dateValue = request.getFirstHeader("Date").getValue();
		String requestPath = request.getURI().getPath();
		String toDigest = new String(method + "\n" + hexDigest + "\n" + contentType + "\n" + dateValue + "\n" + requestPath);
		String shaHashed = "";
		try {
			System.out.println(toDigest);
			shaHashed = calculateRFC2104HMAC(secretKey, toDigest);
		} catch (SignatureException e) {
			e.printStackTrace();
		}
		return new String(shaHashed);
	}

	private String contentMD5(HttpEntityEnclosingRequestBase httpMethod) {
		ByteArrayOutputStream requestOutputStream = new ByteArrayOutputStream();
		try {
			httpMethod.getEntity().writeTo(requestOutputStream);
		} catch (IOException e) {
			System.out.println("ERROR: IOException caught when writing Content MD5 hash");
			e.printStackTrace();
		}
		return DigestUtils.md5Hex(requestOutputStream.toByteArray()).toLowerCase();
	}

 

Jar file required for VWS API

April 19, 2013 - 7:02am #2

Hi,

you need to download the Apache Http client 4.2.3 from here:

http://hc.apache.org/downloads.cgi

(go to the download page)

Then, once you ahve unzipped the package, you can just add the JARs as external JARs to your project in Eclipse

(click on Project - > Properties -> Java Build Path, select the Libraries Tab and click on Add external jars...)

Log in or register to post comments