邮件请求上的NoSuchMethodError(Jersey-client)

时间:2016-05-24 09:16:12

标签: java json jersey-client

我正在开发一个Jersey客户端来测试API。我正在使用Jersey客户端2.22和Cucumber。

build.gradle

version 'unspecified'

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'idea'

sourceCompatibility = 1.8

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        // if you use the version of cucumber-jvm that the plugin was built with
        classpath "info.cukes:cucumber-core:1.2.4"
    }
}

repositories {
    mavenCentral()
    maven { url "http://download.java.net/maven/2/" }
    maven { url "http://repo.maven.apache.org/maven2" }
    maven { url "http://repository.jboss.org/nexus/content/groups/public/" }
    maven { url "http://repository.primefaces.org" }
    flatDir {
        dirs 'libs'
    }
    maven {
        url "http://dl.bintray.com/bmuschko/gradle-plugins"
    }
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.11'

    testCompile 'info.cukes:cucumber-core:1.2.4'
    testCompile 'info.cukes:cucumber-html:0.2.3'
    testCompile 'info.cukes:cucumber-java:1.2.4'
    testCompile 'info.cukes:cucumber-junit:1.2.4'
    testCompile 'info.cukes:cucumber-jvm-deps:1.0.5'
    testCompile 'info.cukes:gherkin:2.12.2'
    testCompile 'info.cukes:cucumber-picocontainer:1.2.4'
    testCompile 'org.picocontainer:picocontainer:2.15'

    testCompile 'org.glassfish.jersey.core:jersey-client:2.22.2'

    // JAX-RS
    //providedCompile 'javax.ws.rs:javax.ws.rs-api:2.0.1'

    // Jersey
    compile 'org.glassfish.jersey.containers:jersey-container-servlet-core:2.22.2'
    compile 'org.glassfish.jersey.containers:jersey-container-servlet:2.22.2'
    compile 'org.glassfish.jersey.media:jersey-media-json-jackson:2.22.2'

    compile 'javax.servlet:javax.servlet-api:3.1.0'
    compile 'mysql:mysql-connector-java:5.1.35'
    compile 'org.slf4j:slf4j-simple:1.7.12'
    compile 'org.javassist:javassist:3.15.0-GA'
    compile 'org.apache.commons:commons-lang3:3.1'
    compile 'commons-collections:commons-collections:3.2.1'
    compile 'javax.ws.rs:javax.ws.rs-api:2.0.1'

    compile 'org.hibernate:hibernate-validator-annotation-processor:4.1.0.Final'

    compile 'log4j:log4j:1.2.17'

    compile name: 'primefaces-4.0'
    compile(group: 'org.primefaces.extensions', name: 'primefaces-extensions', version: '2.0.0') {
        exclude(module: 'primefaces')
    }

    compile 'org.atmosphere:atmosphere-runtime:2.0.1'

    // MesView Core
    compile project(':MonitorizadorComun')
}

我正在尝试使用JSON格式序列化POJO并执行发布请求。 MedidaAtributoRecursoAtributoRecurso都实现了Serializable。

@When( "^El cliente realiza una petición POST /medida/atributo$" )
    public void elClienteRealizaUnaPeticiónPOSTMedidaAtributo() throws Throwable {
        try {
            Client client = ClientBuilder.newClient();
            WebTarget target = client.target("http://localhost:8080/api").path("medida/atributo");

            MedidaAtributoRecurso medida = new MedidaAtributoRecurso();

            List<AtributoRecurso> atributos = new ArrayList<>();
            atributos.add(new AtributoRecurso("agrupacion", "76483"));

            medida.setVariableIndustrialId(1L);
            medida.setValor(11.0);
            medida.setFecha(1462348800L);
            medida.setAtributos(atributos);

            Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE);
            postResponse = invocationBuilder.post(Entity.entity(medida, MediaType.APPLICATION_JSON));

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

        } catch (Exception e) {

        }
        Assert.assertEquals("No se ha recibido la respuesta OK: ", HttpURLConnection.HTTP_OK, postResponse.getStatus());
    }

但它抛出NoSuchMethodError异常:

javax.ws.rs.ProcessingException: com.fasterxml.jackson.databind.ObjectWriter.getFactory()Lcom/fasterxml/jackson/core/JsonFactory;
    at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:264)
    at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:684)
    at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:681)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
    at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:444)
    at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:681)
    at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:437)
    at org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:343)
    at es.mesview.api.servicio.rest.MedidaAtributoRestSteps.elClienteRealizaUnaPeticiónPOSTMedidaAtributo(MedidaAtributoRestSteps.java:50)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at cucumber.runtime.Utils$1.call(Utils.java:37)
    at cucumber.runtime.Timeout.timeout(Timeout.java:13)
    at cucumber.runtime.Utils.invoke(Utils.java:31)
    at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:38)
    at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37)
    at cucumber.runtime.Runtime.runStep(Runtime.java:299)
    at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)
    at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)
    at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:44)
    at cucumber.runtime.model.CucumberFeature.run(CucumberFeature.java:165)
    at cucumber.runtime.Runtime.run(Runtime.java:121)
    at cucumber.api.cli.Main.run(Main.java:36)
    at cucumber.api.cli.Main.main(Main.java:18)
Caused by: java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.ObjectWriter.getFactory()Lcom/fasterxml/jackson/core/JsonFactory;
    at com.fasterxml.jackson.jaxrs.base.ProviderBase._createGenerator(ProviderBase.java:696)
    at com.fasterxml.jackson.jaxrs.base.ProviderBase.writeTo(ProviderBase.java:602)
    at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.invokeWriteTo(WriterInterceptorExecutor.java:265)
    at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:250)
    at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162)
    at org.glassfish.jersey.message.internal.MessageBodyFactory.writeTo(MessageBodyFactory.java:1130)
    at org.glassfish.jersey.client.ClientRequest.doWriteEntity(ClientRequest.java:517)
    at org.glassfish.jersey.client.ClientRequest.writeEntity(ClientRequest.java:499)
    at org.glassfish.jersey.client.internal.HttpUrlConnector._apply(HttpUrlConnector.java:388)
    at org.glassfish.jersey.client.internal.HttpUrlConnector.apply(HttpUrlConnector.java:285)
    at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:255)
    ... 27 more

0 个答案:

没有答案