0

I am using httpClient to call a web service. code is as follows:

    public static void main(String args[]) {

    if (connection!=null) {

      String url = "some url";
    String result = null;
    Statement statement = null;
    HttpClient client = HttpClientBuilder.create().build();
    HttpGet requestFinal = new HttpGet(url);
    requestFinal.addHeader("Connection", "Keep-Alive");
    requestFinal.addHeader("Content-Type", "application/xml");
    requestFinal.addHeader("Accept", "application/xml");

    HttpResponse responseFinal = null;
    StringBuilder responseBuilderFinal = new StringBuilder();
    BufferedReader bufferedReader = null;

    try {
        responseFinal = client.execute(requestFinal);
        int statusCode = responseFinal.getStatusLine().getStatusCode();

        statement = connection.createStatement();
        bufferedReader = new BufferedReader(new InputStreamReader(responseFinal.getEntity().getContent()));
        String lines = "";
        while ((lines = bufferedReader.readLine()) != null) {
            responseBuilderFinal.append(lines);
        }
        requestFinal.abort();
    } catch (IOException ioException) {

        logger.error("HttpCall class third catch block---" + ioException);
   }}

When eclipse executes line-- responseFinal = client.execute(requestFinal);

it gives the following error:

Exception in thread "main" java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;Ljava/lang/Throwable;)V
    at org.apache.commons.logging.impl.SLF4JLocationAwareLog.debug(SLF4JLocationAwareLog.java:99)
    at org.apache.http.client.protocol.RequestAuthCache.process(RequestAuthCache.java:75)
    at org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:131)
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:193)
    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85)
    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)

Please help me with this. Thanks in advance.

Vikrant Kashyap
  • 6,398
  • 3
  • 32
  • 52
Jag
  • 17
  • 1
  • 5
  • Please check that slf4j jar is at your calsspath. If yes the n set the war policy to parent last. It will solve the problem. – Ahmed May 27 '16 at 05:28
  • Yess it in my class path. It gives problem when I run it from main method(as independent java class). It does not give any issue when I make it a static method and call it from frontEnd on a button event. I am getting why it is happening so. – Jag May 27 '16 at 06:36

1 Answers1

0

It's only a compatibility issue of .jar that you used in your project.

You have used any old version of slf4j.jar . Please replace your jar with any earlier released .jars.

add new .jar and clean your project then try to re-build your project.

Thanks

Vikrant Kashyap
  • 6,398
  • 3
  • 32
  • 52