rest - Exception in thread "AWT-EventQueue-0" java.lang.NoSuchFieldError: DEF_CONTENT_CHARSET -


i trying call login api java swing desktop application (implemented on jersey web app) user id , password in header using code below.

  string authstring = username + ":" + password;   string authstringenc = new base64encoder().encode(authstring.getbytes());   system.out.println("base64 encoded auth string: " + authstringenc);    defaulthttpclient httpclient = new defaulthttpclient();   httpget getrequest = new httpget(fvconstants.loginapi);   getrequest.addheader("authorization", "basic " + authstringenc);    httpresponse response = null;   try {     response = httpclient.execute(getrequest);      if (response.getstatusline().getstatuscode() != 200) {         throw new runtimeexception("failed : http error code : "            + response.getstatusline().getstatuscode());       }      bufferedreader br = new bufferedreader(new inputstreamreader((response.getentity().getcontent())));      string output;     system.out.println("output server .... \n");     while ((output = br.readline()) != null) {             system.out.println(output);     }      httpclient.getconnectionmanager().shutdown();  } catch (clientprotocolexception e) {     // todo auto-generated catch block     e.printstacktrace(); } catch (ioexception e) {     // todo auto-generated catch block     e.printstacktrace(); } 

it gives me error below on line response = httpclient.execute(getrequest);

exception in thread "awt-eventqueue-0" java.lang.nosuchfielderror: def_content_charset @ org.apache.http.impl.client.defaulthttpclient.setdefaulthttpparams(defaulthttpclient.java:175) @ org.apache.http.impl.client.defaulthttpclient.createhttpparams(defaulthttpclient.java:158) @ org.apache.http.impl.client.abstracthttpclient.getparams(abstracthttpclient.java:448) @ org.apache.http.impl.client.abstracthttpclient.createclientconnectionmanager(abstracthttpclient.java:309) @ org.apache.http.impl.client.abstracthttpclient.getconnectionmanager(abstracthttpclient.java:466) @ org.apache.http.impl.client.abstracthttpclient.createhttpcontext(abstracthttpclient.java:286) @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:851) @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:805) @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:784) @ login.login.callloginapi(login.java:67) @ login.login.actionperformed(login.java:101) @ javax.swing.abstractbutton.fireactionperformed(abstractbutton.java:2022) @ javax.swing.abstractbutton$handler.actionperformed(abstractbutton.java:2348) @ javax.swing.defaultbuttonmodel.fireactionperformed(defaultbuttonmodel.java:402) @ javax.swing.defaultbuttonmodel.setpressed(defaultbuttonmodel.java:259) @ javax.swing.plaf.basic.basicbuttonlistener.mousereleased(basicbuttonlistener.java:252) @ java.awt.component.processmouseevent(component.java:6533) @ javax.swing.jcomponent.processmouseevent(jcomponent.java:3324) 

i tried remove multiple version of same library build path , /.m2/repository/org/apache/ mentioned in httpclient def_content_chars , added again, still giving me same error. appreciated, thanks.

solved using code below.please make sure have following imports.

import org.apache.http.client.httpclient; import org.apache.http.client.methods.httpget; import org.apache.http.impl.client.httpclientbuilder; import org.apache.http.httpresponse; 

add library using import , go code below.

private void callloginapi(string username, string password) {   string authstring = username + ":" + password;   string authstringenc = new    base64encoder().encode(authstring.getbytes());   system.out.println("base64 encoded auth string: " + authstringenc);    httpclient client = httpclientbuilder.create().build();   httpget request = new httpget(fvconstants.loginapi);   request.addheader("authorization", "basic " + authstringenc);    try {       httpresponse response = client.execute(request);       system.out.println("response : "+response.getstatusline());    } catch (exception e) {       e.printstacktrace();    } } 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -