Giter Site home page Giter Site logo

Exception on simple put request about etcd4j HOT 11 CLOSED

jurmous avatar jurmous commented on September 27, 2024
Exception on simple put request

from etcd4j.

Comments (11)

ghristov avatar ghristov commented on September 27, 2024

As far as I can see the constructor of the HttpPostRequestEncoder.java doesn't allow creation of the object if the method is different from POST

public HttpPostRequestEncoder(
            HttpDataFactory factory, HttpRequest request, boolean multipart, Charset charset,
            EncoderMode encoderMode)
            throws ErrorDataEncoderException {
        if (factory == null) {
            throw new NullPointerException("factory");
        }
        if (request == null) {
            throw new NullPointerException("request");
        }
        if (charset == null) {
            throw new NullPointerException("charset");
        }
        if (request.getMethod() != HttpMethod.POST) {
            throw new ErrorDataEncoderException("Cannot create a Encoder if not a POST");
        }

         .......
    }

As you can see in the implementation of setRequestParameters in the EtcdNettyClient you allow creation of this encoder even if the method is PUT.

 private static HttpRequest setRequestParameters(String uri, EtcdRequest<?> etcdRequest, HttpRequest httpRequest) throws Exception {
    // Set possible key value pairs
    Map<String, String> keyValuePairs = etcdRequest.getRequestParams();
    if (keyValuePairs != null && !keyValuePairs.isEmpty()) {
      HttpMethod etcdRequestMethod = etcdRequest.getMethod();
      if (etcdRequestMethod == HttpMethod.POST || etcdRequestMethod == HttpMethod.PUT) {
        HttpPostRequestEncoder bodyRequestEncoder = new HttpPostRequestEncoder(httpRequest, false);

       ....
  }

I think this should be fixed.

from etcd4j.

slintes avatar slintes commented on September 27, 2024

Hi,

I don't see the exception, and I see a different source for HttpPostRequestEncoder, where PUT is allowed:

public HttpPostRequestEncoder(
        HttpDataFactory factory, HttpRequest request, boolean multipart, Charset charset,
        EncoderMode encoderMode)
        throws ErrorDataEncoderException {
    if (factory == null) {
        throw new NullPointerException("factory");
    }
    if (request == null) {
        throw new NullPointerException("request");
    }
    if (charset == null) {
        throw new NullPointerException("charset");
    }
    HttpMethod method = request.method();
    if (!(method.equals(HttpMethod.POST) || method.equals(HttpMethod.PUT)
            || method.equals(HttpMethod.PATCH) || method.equals(HttpMethod.OPTIONS))) {
        throw new ErrorDataEncoderException("Cannot create a Encoder if not a POST");
    }

...

Do have another netty-codec-http version on your classpath? The one used in etcd4j is io.netty:netty-codec-http:4.1.0.Beta3, see build.gradle

Regards, Marc

from etcd4j.

ghristov avatar ghristov commented on September 27, 2024

Yeah I'm using 4.0.25 Final... And obviously in the newer version they changed the api. I changed it to 4.1.3Beta and it worked. Well i'm not using gradle. I'm using this library from Maven.

from etcd4j.

slintes avatar slintes commented on September 27, 2024

👍

from etcd4j.

ghristov avatar ghristov commented on September 27, 2024

Btw I think project must be packaged with all of it's dependencies because as you can see I can't know which version of the netty api is used. And since i use always final versions that was a problem in this case.

from etcd4j.

slintes avatar slintes commented on September 27, 2024

I don't agree with this. You can see the dependencies with version numbers in the build.gradle file: https://github.com/jurmous/etcd4j/blob/master/build.gradle#L42. If if you don't use gradle, you still can use that information to add the dependencies to your maven pom file (like you did obviously) or on any other way you prefer to your classpath.
If every library comes packaged with every dependency, you will have chaos on your classpath sooner or later, when different libraries use different versions of dependencies.

Oh wait, it's even easier: why do you not just add etcd4j to your pom file? That should resolve all dependencies automatically, not? http://search.maven.org/#artifactdetails%7Corg.mousio%7Cetcd4j%7C2.1.0%7Cjar

from etcd4j.

slintes avatar slintes commented on September 27, 2024

Oh, no, won't work. The pom of etcd4j does not contain all dependencies.
@jurmous I think the tooling for uploading to the maven repository does not understand the "clientCompile" you use in the build.gradle file... 😕

from etcd4j.

jurmous avatar jurmous commented on September 27, 2024

Oh dear. Something is indeed wrong with the gradle build. Gradle maven plugin by default only includes the dependencies of the main sourceSet which in this case does not include Netty. I have opened #27 with a more specific description and will look into it tomorrow. Thanks for reporting this issue in!

I will also look into back porting to the final Netty 4.0 release since those betas take much longer time to mature than I was expecting when I started this project.

from etcd4j.

ghristov avatar ghristov commented on September 27, 2024

Glad that i helped :)

from etcd4j.

jurmous avatar jurmous commented on September 27, 2024

Released in 2.1.1 :)

I could not easily convert back to Final because of the issue reported above which prevented to use the Post decoder with the Put. So I left the dependency at Beta for this moment. Maybe I will look into this issue later if I can solve it differently.

from etcd4j.

ghristov avatar ghristov commented on September 27, 2024

Now it works like a charm. No need to add any additional libraries.

Just added this one and all deps are resolved and included.

<dependency>
      <groupId>org.mousio</groupId>
      <artifactId>etcd4j</artifactId>
      <version>2.1.1</version>
    </dependency>

Thank you

from etcd4j.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.