logo
down
shadow

Jersey 2.0 Content-Length not set


Jersey 2.0 Content-Length not set

Content Index :

Jersey 2.0 Content-Length not set
Tag : java , By : keird
Date : November 24 2020, 05:47 AM


Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Content-Length-Header not set in Jersey Client request


Tag : java , By : James Lupiani
Date : March 29 2020, 07:55 AM
seems to work fine The content length of a call is computed by Jersey Client, it cannot be set. Paul Sandoz — a well known commiter on the project — have answered a similar question:

Jersey Client doesn't set Content-Length


Tag : java , By : Star Gryphon
Date : March 29 2020, 07:55 AM
Hope that helps This is known "issue" and actually intended behavior.
Problem here is that entity is processed AFTER headers are written out to "the wire", thus Content-Length header value is not know when headers are serialized. If you need to have it, you have several options (with various complexity):

Jersey Client (2.4) - PUT InputStream but Content-Length = 0


Tag : java , By : woxorz
Date : March 29 2020, 07:55 AM
like below fixes the issue Just to answer this:
This is a problem with the ApacheConnector, which will always return -1 for the size of the content, ensuring this value is never set. (This is hardcoded in the getHttpEntity method)

Best way to make Jersey 2.x refuse requests with incorrect Content-Length?


Tag : java , By : user183825
Date : March 29 2020, 07:55 AM
Does that help If you don't want to buffer the incoming entity (input stream) I'd take a look at ReaderInterceptor interface. Instances of this contract are invoked only in cases when incoming requests contain an entity (typically POST, PUT). In the interceptor you can pretty much do anything with entity. A simple snippet (not covering all cases) could look like:
public class MyInterceptor implements ReaderInterceptor {

    @Override
    public Object aroundReadFrom(final ReaderInterceptorContext context) throws IOException, WebApplicationException {
        final InputStream old = context.getInputStream();
        final String first = context.getHeaders().getFirst("Content-Length");
        final Long declared = first == null ? -1 : Long.valueOf(first);

        context.setInputStream(new InputStream() {

            private long length = 0;
            private int mark = 0;

            @Override
            public int read() throws IOException {
                final int read = old.read();
                readAndCheck(read != -1 ? 1 : 0);
                return read;
            }

            @Override
            public int read(final byte[] b) throws IOException {
                final int read = old.read(b);
                readAndCheck(read != -1 ? read : 0);
                return read;
            }

            @Override
            public int read(final byte[] b, final int off, final int len) throws IOException {
                final int read = old.read(b, off, len);
                readAndCheck(read != -1 ? read : 0);
                return read;
            }

            @Override
            public long skip(final long n) throws IOException {
                final long skip = old.skip(n);
                readAndCheck(skip != -1 ? skip : 0);
                return skip;
            }

            @Override
            public int available() throws IOException {
                return old.available();
            }

            @Override
            public void close() throws IOException {
                old.close();
            }

            @Override
            public synchronized void mark(final int readlimit) {
                mark += readlimit;
                old.mark(readlimit);
            }

            @Override
            public synchronized void reset() throws IOException {
                this.length = 0;
                readAndCheck(mark);
                old.reset();
            }

            @Override
            public boolean markSupported() {
                return old.markSupported();
            }

            private void readAndCheck(final long read) {
                this.length += read;

                if (this.length > declared) {
                    throw new WebApplicationException(
                            Response.status(Response.Status.LENGTH_REQUIRED)
                                    .entity("No content-length provided.")
                                    .build());
                }
            }
        });

        final Object entity = context.proceed();

        context.setInputStream(old);

        return entity;
    }
}

How do I set Content-Length when returning large objects in Jersey JAX-RS server


Tag : development , By : DotNetWise
Date : March 29 2020, 07:55 AM
Related Posts Related QUESTIONS :
  • IllegalArgumentException or NullPointerException for a null parameter?
  • How do I configure and communicate with a serial port?
  • What are the different methods to parse strings in Java?
  • Android Broadcastreceiver for other apps install/delete not working
  • Android Studio onClick not working in BindViewHolder
  • How to use Spring Converter for some controllers only?
  • How verify that 3 numbers in sequence are equals?
  • When using .compareTo to compare dates, why doesn't it take Months into account?
  • Does the perfomance of "filter then map" and "map then filter" differ in a Stream?
  • How can I set the initial Delay after pressing the start Button to a specific time (HH:mm:ss) format
  • How to switch between Android devices during the tests
  • How to configure java.util.logging via properties to use standard output?
  • How to iterate through array in order
  • Is there better way of iteration to find the evenly divisible number?
  • How do I avoid using if statements with a large amount of variables in java
  • Writing JUnit test cases for a Spring Boot Service Application with autowired components
  • Cors for GET with Postman not showing headers
  • Printing values in different column same row using APACHE POI
  • Fully decompile java6 web application
  • Passing keycloak configuration parameters in the code rather than reading from application.properties
  • setDataSource() IO exception
  • Unexpected Output while retrieving Data from mongodb and displaying in a csv file?
  • Algorithm for searching a value in two arrays
  • How to avoid casting with generic return values?
  • Java/RegEx - Negation of pattern not working
  • How to split a string to non empty words if it might include a separator like tab on first place
  • Supplier<Sequence<String>> cannot be iterated more than once
  • Why there is only one thread can actually started in @PostConstruct method?
  • Manage CompletionStage inside of Netty handler
  • Url Problem while Developing on Localhost and deploy on Remote Virtual Server
  • How to identify the missing type id in Jackson error?
  • android data binding error: cannot find symbol
  • Spring Boot application with a jar dependency does not run after maven build
  • Spring Data JPA query , filter ? search engine ? JPQL?
  • Why LiveData returns null in ViewModel?
  • what this line of code mean....new URLClassLoader(new URL[0],getClass().getClassLoader());
  • Why do need to use new Random() instead of just Random Randomnum?
  • I want to access zk components from the java file
  • How do I cast FieldValue.serverTimestamp() to Kotlin/Java Date Class
  • Insertion Sort Double Array with User Input - JAVA
  • Creating 2 dimesional array with user input and find sum of specific columns
  • can not get Advertising ID Provider in android
  • Convert list of Objects to map of properties
  • How to represent an undirected weighted graph in java
  • Return values as array from collection
  • ByteBuddy generic method return cast to concrete type
  • ImageView hides the round corners of the parent
  • Is there a way to find setter method by its getter method or vice versa in a class?
  • Get aggregated list of properties from list of Objects(Java 8)
  • Unable to find a document in Mongodb where exact date match in java
  • UsernamePasswordAuthenticationFilter skips success handler
  • Use Java filter on stream with in a stream filter
  • Default Login not successful in spring boot 2.1.7
  • Adding key value pairs from a file to a Hashmap
  • Rub regex: matching a char except when after by another char
  • Convert Base64 String to String Array
  • Escape Unicode Character 'POPCORN' to HTML Entity
  • An empty JSON field which is a boolean/nullable field in Java model, is getting converted as null
  • Mongo java driver cannot find public constructor for interface
  • How to unit test writing a file to AWS Lambda output stream?
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com