2
I’m having a problem using the library httpclient, the exception is happening:
Caused by: java.lang.Classnotfoundexception: org.apache.Commons.httpclient.Httpexception
I don’t know if I am also using the right library, I found that there are other libraries that treat the problem as the Apache Httpclient 4.3.6 API and Defaulthttpclient (which I think is from jboss). I use the Httpclient 3.1 API.
Error Stack
11:10:47,773 INFO [org.jboss.weld.ClassLoading] (MSC service thread 1-3) catching: org.jboss.weld.resources.spi.ResourceLoadingException: Error loading class br.gov.ro.portovelho.semfaz.sisfiscal.persistence.EnderecoDAO at org.jboss.Weld.resources.Classtransformer.loadClass(Classtransformer.java:167) [Weld-core-1.1.13.Final-Redhat-1.jar:1.1.13.Final-Redhat-1] at org.jboss.Weld.bootstrap.Beandeployer.loadWeldClass(Beandeployer.java:116) [Weld-core-1.1.13.Final-Redhat-1.jar:1.1.13.Final-Redhat-1] at org.jboss.Weld.bootstrap.Beandeployer.addClass(Beandeployer.java:79) [Weld-core-1.1.13.Final-Redhat-1.jar:1.1.13.Final-Redhat-1] at org.jboss.Weld.bootstrap.Beandeployer.addClasses(Beandeployer.java:135) [Weld-core-1.1.13.Final-Redhat-1.jar:1.1.13.Final-Redhat-1] at org.jboss.Weld.bootstrap.Beandeployment.createBeans(Beandeployment.java:184) [Weld-core-1.1.13.Final-Redhat-1.jar:1.1.13.Final-Redhat-1] at org.jboss.Weld.bootstrap.Weldbootstrap.deployBeans(Weldbootstrap.java:349) [Weld-core-1.1.13.Final-Redhat-1.jar:1.1.13.Final-Redhat-1] at org.jboss.as.weld.Weldstartservice.start(Weldstartservice.java:63) [jboss-as-Weld-7.2.0.Final-Redhat-8.jar:7.2.0.Final-Redhat-8] at org.jboss.Msc.service.Servicecontrollerimpl$Starttask.startService(Servicecontrollerimpl.java:1811) at org.jboss.Msc.service.Servicecontrollerimpl$Starttask.run(Servicecontrollerimpl.java:1746) at java.util.Concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_71] at java.util.Concurrent.Threadpoolexecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_71] at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_71] Caused by: java.lang.Noclassdeffounderror: org/apache/Commons/httpclient/Httpexception at java.lang.Class.getDeclaredFields0(Native Method) [rt.jar:1.7.0_71] at java.lang.Class.privateGetDeclaredFields(Unknown Source) [rt.jar:1.7.0_71] at java.lang.Class.getDeclaredFields(Unknown Source) [rt.jar:1.7.0_71] at org.jboss.Weld.util.Reflection.Securereflections$4.work(Securereflections.java:105) [Weld-core-1.1.13.Final-Redhat-1.jar:1.1.13.Final-Redhat-1] at org.jboss.Weld.util.Reflection.Securereflections$4.work(Securereflections.java:102) [Weld-core-1.1.13.Final-Redhat-1.jar:1.1.13.Final-Redhat-1] at org.jboss.Weld.util.Reflection.SecureReflectionAccess.run(Securereflectionaccess.java:52) [Weld-core-1.1.13.Final-Redhat-1.jar:1.1.13.Final-Redhat-1] at org.jboss.Weld.util.Reflection.SecureReflectionAccess.runAndWrap(Securereflectionaccess.java:63) [Weld-core-1.1.13.Final-Redhat-1.jar:1.1.13.Final-Redhat-1] at org.jboss.Weld.util.Reflection.SecureReflections.getDeclaredFields(Securereflections.java:102) [Weld-core-1.1.13.Final-Redhat-1.jar:1.1.13.Final-Redhat-1] at org.jboss.Weld.introspector.jlr.WeldClassImpl.(Weldclassimpl.java:155) [Weld-core-1.1.13.Final-Redhat-1.jar:1.1.13.Final-Redhat-1] at org.jboss.Weld.introspector.jlr.WeldClassImpl.of(Weldclassimpl.java:121) [Weld-core-1.1.13.Final-Redhat-1.jar:1.1.13.Final-Redhat-1] at org.jboss.Weld.resources.Classtransformer$Transformtypetoweldclass.apply(Classtransformer.java:59) [Weld-core-1.1.13.Final-Redhat-1.jar:1.1.13.Final-Redhat-1] at org.jboss.Weld.resources.Classtransformer$Transformtypetoweldclass.apply(Classtransformer.java:50) [Weld-core-1.1.13.Final-Redhat-1.jar:1.1.13.Final-Redhat-1] at com.google.common.collect.Computingconcurrenthashmap$Computingvaluereference.Compute(Computingconcurrenthashmap.java:358) at com.google.common.collect.Computingconcurrenthashmap$Computingsegment.Compute(Computingconcurrenthashmap.java:184) at com.google.common.collect.Computingconcurrenthashmap$Computingsegment.getOrCompute(Computingconcurrenthashmap.java:153) at com.google.common.collect.Computingconcurrenthashmap.getOrCompute(Computingconcurrenthashmap.java:69) at com.google.common.collect.Computingconcurrenthashmap$Computingmapadapter.get(Computingconcurrenthashmap.java:396) at org.jboss.Weld.resources.Classtransformer.loadClass(Classtransformer.java:163) [Weld-core-1.1.13.Final-Redhat-1.jar:1.1.13.Final-Redhat-1] ... 11 more Caused by: java.lang.Classnotfoundexception: org.apache.Commons.httpclient.Httpexception from [Module "Deployment.sisfiscal.War:main" from Service Module Loader] at org.jboss.modules.ModuleClassLoader.findClass(Moduleclassloader.java:196) [jboss-modules.jar:1.2.0.Final-Redhat-1] at org.jboss.modules.ConcurrentClassLoader.performLoadassClassUnchecked(Concurrentclassloader.java:444) [jboss-modules.jar:1.2.0.Final-Redhat-1] at org.jboss.modules.ConcurrentClassLoader.performLoadassChecked(Concurrentclassloader.java:432) [jboss-modules.jar:1.2.0.Final-Redhat-1] at org.jboss.modules.ConcurrentClassLoader.performLoadClass(Concurrentclassloader.java:374) [jboss-modules.jar:1.2.0.Final-Redhat-1] at org.jboss.modules.ConcurrentClassLoader.loadClass(Concurrentclassloader.java:119) [jboss-modules.jar:1.2.0.Final-Redhat-1] ... 29 more
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven- v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>br.gov.ro.portovelho.semfaz</groupId>
<artifactId>sisfiscal</artifactId>
<version>1.0.5</version>
<packaging>war</packaging>
<name></name>
<description></description>
<url></url>
<parent>
<groupId>br.gov.frameworkdemoiselle</groupId>
<artifactId>demoiselle-jsf-parent</artifactId>
<version>2.4.2</version>
</parent>
<repositories>
<repository>
<id>prime-repo</id>
<name>PrimeFaces Maven Repository</name>
<url>http://repository.primefaces.org</url>
<layout>default</layout>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>br.gov.frameworkdemoiselle</groupId>
<artifactId>demoiselle-jpa</artifactId>
<scope>compile</scope>
</dependency>
<!-- If you are using a JTA transaction then use this extension -->
<dependency>
<groupId>br.gov.frameworkdemoiselle</groupId>
<artifactId>demoiselle-jta</artifactId>
<scope>compile</scope>
</dependency>
<!-- Demoiselle Components -->
<dependency>
<groupId>br.gov.frameworkdemoiselle.component</groupId>
<artifactId>demoiselle-report</artifactId>
<version>2.2.0</version>
<scope>compile</scope>
</dependency>
<!-- <dependency> <groupId>br.gov.frameworkdemoiselle.component</groupId>
<artifactId>demoiselle-authorization</artifactId> <version>2.0.2</version>
<scope>compile</scope> </dependency> -->
<dependency>
<groupId>br.gov.frameworkdemoiselle.component</groupId>
<artifactId>demoiselle-validation</artifactId>
<version>2.0.0</version>
<scope>compile</scope>
</dependency>
<!-- Bibliotecas específicas da aplicação -->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>br.gov.frameworkdemoiselle.component</groupId>
<artifactId>demoiselle-junit</artifactId>
<version>2.3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.primefaces.themes</groupId>
<artifactId>all-themes</artifactId>
<version>1.0.10</version>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces-mobile</artifactId>
<version>0.9.3</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
<scope>provided</scope>
</dependency>
<!-- <dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.6</version>
</dependency> -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
<version>1.9.13</version>
</dependency>
<!-- <dependency>
<groupId>javax.security</groupId>
<artifactId>jacc</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>3.1.0.RELEASE</version>
</dependency> -->
<!-- <dependency>
<groupId>com.google.code.geocoder-java</groupId>
<artifactId>geocoder-java</artifactId>
<version>0.16</version>
</dependency>
<dependency>
<groupId>org.jboss.aerogear</groupId>
<artifactId>unifiedpush-java-client</artifactId>
<version>1.0.0</version>
</dependency> -->
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-installed-adapter</artifactId>
<version>1.0-beta-2</version>
<exclusions>
<exclusion>
<artifactId>httpclient</artifactId>
<groupId>org.apache.httpcomponents</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-core</artifactId>
<version>1.0.4.Final</version>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-admin-client</artifactId>
<version>1.0.4.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-envers</artifactId>
<version>4.1.8.Final</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.7</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
EnderecoDAO
package br.gov.ro.portovelho.semfaz.sisfiscal.persistence;
import java.io.IOException;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;
import org.codehaus.jackson.map.ObjectMapper;
import br.gov.frameworkdemoiselle.stereotype.PersistenceController;
import br.gov.frameworkdemoiselle.template.JPACrud;
import br.gov.ro.portovelho.semfaz.sisfiscal.domain.Endereco;
@PersistenceController
public class EnderecoDAO extends JPACrud<Endereco, Long> {
private static final long serialVersionUID = 1L;
Endereco endereco;
public Endereco getBuscaEndPorCEP(String cep) {
HttpClient httpClient = new HttpClient();
HttpMethod method = new GetMethod("http://correiosapi.apphb.com/cep/" + cep);
try {
httpClient.executeMethod(method);
} catch (HttpException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
String responseBody;
try {
if(method.getStatusLine().getStatusCode()==HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED){
return endereco = getBuscaEndPorCepComProxy(cep);
}
responseBody = method.getResponseBodyAsString();
//2. Convert JSON to Java object
ObjectMapper mapper = new ObjectMapper();
endereco = mapper.readValue(responseBody, Endereco.class);
} catch (IOException e) {
e.printStackTrace();
}
return endereco;
}
private Endereco getBuscaEndPorCepComProxy(String cep){
HttpClient httpClient = new HttpClient();
httpClient.getParams().setAuthenticationPreemptive(true);
//httpClient.getState().setProxyCredentials(new AuthScope("PROXY_ADDRESS", 8080, "PROXY_ADDRESS"), new NTCredentials("LOGIN", "PASS","LOCAL_MACHINE_IP","PROXY_ADDRESS"));
httpClient.getState().setProxyCredentials(new AuthScope("10.1.1.2", 3128, "10.1.1.2"), null);
//httpClient.getState().setProxyCredentials(new AuthScope("10.101.1.250", 3128, "10.101.1.250"), new NTCredentials("261537", "260603","10.200.3.47","10.101.1.250"));
httpClient.getHostConfiguration().setProxy("10.1.1.2", 3128);
HttpMethod method = new GetMethod(
"http://correiosapi.apphb.com/cep/" + cep);
try {
httpClient.executeMethod(method);
} catch (HttpException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
String responseBody;
try {
responseBody = method.getResponseBodyAsString();
//2. Convert JSON to Java object
ObjectMapper mapper = new ObjectMapper();
endereco = mapper.readValue(responseBody, Endereco.class);
} catch (IOException e) {
e.printStackTrace();
}
return endereco;
}
}
EnderecoBC
package br.gov.ro.portovelho.semfaz.sisfiscal.business;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.faces.model.SelectItem;
import org.apache.commons.httpclient.HttpException;
import br.gov.frameworkdemoiselle.stereotype.BusinessController;
import br.gov.frameworkdemoiselle.template.DelegateCrud;
import br.gov.ro.portovelho.semfaz.sisfiscal.domain.Endereco;
import br.gov.ro.portovelho.semfaz.sisfiscal.domain.EnumTipoEndereco;
import br.gov.ro.portovelho.semfaz.sisfiscal.persistence.EnderecoDAO;
@BusinessController
public class EnderecoBC extends DelegateCrud<Endereco, Long, EnderecoDAO> {
private static final long serialVersionUID = 1L;
public List<SelectItem> getEnumTipoEndereco() {
List<SelectItem> varEnumTipoEndereco = new ArrayList<SelectItem>();
for (EnumTipoEndereco eachEnumTipoEndereco : EnumTipoEndereco.values()) {
varEnumTipoEndereco.add(new SelectItem(eachEnumTipoEndereco));
}
return varEnumTipoEndereco;
}
/** @param cep
* <P> Este método busca um cep de um serviço rest
* @throws IOException
*/
public Endereco getBuscaEndPorCEP(String cep){
return getDelegate().getBuscaEndPorCEP(cep);
}
}
EnderecoEditMB
package br.gov.ro.portovelho.semfaz.sisfiscal.view;
import java.io.IOException;
import java.util.List;
import javax.faces.model.SelectItem;
import javax.inject.Inject;
import org.apache.commons.httpclient.HttpException;
import br.gov.frameworkdemoiselle.annotation.PreviousView;
import br.gov.frameworkdemoiselle.stereotype.ViewController;
import br.gov.frameworkdemoiselle.template.AbstractEditPageBean;
import br.gov.frameworkdemoiselle.util.Beans;
import br.gov.ro.portovelho.semfaz.sisfiscal.business.EnderecoBC;
import br.gov.ro.portovelho.semfaz.sisfiscal.domain.Endereco;
@ViewController
@PreviousView("./endereco_list.jsf")
public class EnderecoEditMB extends AbstractEditPageBean<Endereco, Long> {
private static final long serialVersionUID = 1L;
@Inject
private EnderecoBC enderecoBC;
@Inject
private Endereco endereco;
public Endereco getEndereco() {
return endereco;
}
public void setEndereco(Endereco endereco) {
this.endereco = endereco;
}
public List<SelectItem> getTipoEndereco() {
return enderecoBC.getEnumTipoEndereco();
}
public void buscaEnderecoPorCep(){
String cep = endereco.getCep();
//String cep = getEndereco().getCep();
//this.endereco = enderecoBC.getBuscaEndPorCEP("76821348");
if(cep.length() == 8) this.endereco = enderecoBC.getBuscaEndPorCEP(cep);
}
@Override
public String delete() {
this.enderecoBC.delete(getId());
return getPreviousView();
}
@Override
public String insert() {
this.enderecoBC.insert(this.getBean());
return getPreviousView();
}
@Override
public String update() {
this.enderecoBC.update(this.getBean());
return getPreviousView();
}
@Override
protected Endereco handleLoad(Long id) {
return this.enderecoBC.load(id);
}
}
You are including all the libraries that come along with the Httpcomponents? For beyond the . jar
HttpClient
, there are several other dependencies as you can see in that image.– Renan Gomes