0
votes

I have implemented http client to communicate with my rest server which I have implemented using Apache CXF. when I use url at browser, evrything is fine but when I use client then I got an exception. The exception is

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) at ABC.XYZ(ABC.java:45) at ABC.XYZ(ABC.java:93)

I have written following code at my client side

    HttpClient client = HttpClientBuilder.create().build();
    HttpGet getRequest = new HttpGet(path);
    getRequest.addHeader("accept", "application/xml");
    HttpResponse response = client.execute(getRequest);//here I have an exception
2
How are you running your client code? It looks like you have multiple, conflicting versions of SLF4J on your classpath. If you posted the classpath someone can probably help, but at the moment there is insufficient information to answer your questionDonald_W
The problem is with your classpath - how are you invoking your main class - via java on the command line, via an IDE like Eclipse, via Ant? / Maven? / Gradle?Donald_W
i have maven project in eclipse ideJerry

2 Answers

0
votes

I suggest you to use maven and add apache http client dependency. May be an incompatible version of slf4j.jar exist which is causing the issue. maven will be able handle the compatible version.

0
votes

I think that the request are somehow different and for the second one a logger is needed. You should add dependency to slf4j correctly and see the error