4

I am trying to write a simple WebService Testing using HTTPClient. I have all my jars loaded up but get the above error message.

Why am I getting this error message?

Here is the code:

package HTTPClientTest;

import java.io.IOException;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.HttpClientBuilder;
import org.junit.Assert;


public class RESTTester {

    public static void main (String args[]) {

    String restURL_XML = "http://parabank.parasoft.com/parabank/services/bank/customers/12212/";


    try {

    testStatusCode(restURL_XML);

    } catch (ClientProtocolException e) {

    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    } 
}


public static void testStatusCode(String restURL) throws ClientProtocolException, IOException {
    HttpUriRequest request = new HttpGet(restURL);
    HttpResponse httpResponse = HttpClientBuilder.create().build().execute(request);
    Assert.assertEquals(httpResponse.getStatusLine().getStatusCode(),HttpStatus.SC_OK);
    }

}

Below is the error stacktrace,

Exception in thread "main" java.lang.NoSuchFieldError: INSTANCE
    at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:144)
    at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:966)
    at HTTPClientTest.RESTTester.testStatusCode(RESTTester.java:37)
    at HTTPClientTest.RESTTester.main(RESTTester.java:22)
Chuchoo
  • 823
  • 2
  • 17
  • 36

3 Answers3

11

I got above error because I had multiple older versions of HTTPClient in my project. I removed older versions of HTTPClient and now the error message is gone.

Chuchoo
  • 823
  • 2
  • 17
  • 36
1

By analysing your stack trace, I found out your program is written good. It seems that apache HTTP APIs were compiled wrong. Maybe the package org.apache.http.impl.clientwas compiled against different version of org.apache.http.conn.ssl than you are using? Upgrade both packages to their newest versions and retry. Report it to HTTPClient bug tracker.

Top Sekret
  • 748
  • 5
  • 21
-1

Ive come across this error(java.lang.NoSuchFieldError: INSTANCE) several times. With different reasons here it is INSTANCE. This error is conveying about the mismatch between the aws-java-sdk-core library and one of the service-specific SDKs aws-sdk-s3 or aws-java-sdk-sqs.

I faced this error while using aws-java-sdk-core(1.11.289) with aws-sdk-s3(1.11.428). Fixed it by using the following aws-java-sdk-core(1.11.289) with aws-sdk-s3(1.11.186).

akshaypmurgod
  • 77
  • 1
  • 3