logo
down
shadow

Spring REST returning PDF - Response status 406 (not acceptable)


Spring REST returning PDF - Response status 406 (not acceptable)

By : ynesterenko
Date : November 22 2020, 02:42 PM
it fixes the issue Basically there is no need to add produces = "application/pdf" in RequestMapping as it seems to try to convert the ResponeBody internally. You can just add MediaType to response headers which is what you need.
code :
@ResponseBody
@RequestMapping(value = "get/pdf/{id}", headers="Accept=*/*", method = RequestMethod.GET)
public ResponseEntity<InputStreamResource> getPdfContractById(@PathVariable("id") Long id){
        // Get the remove file based on the fileaddress
        RemoteFile remotefile = new RemoteFile(id);

        // Set the input stream
        InputStream inputstream = remotefile.getInputStream();
        // asume that it was a PDF file
        HttpHeaders responseHeaders = new HttpHeaders();
        InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
        responseHeaders.setContentLength(contentLengthOfStream);
        responseHeaders.setContentType(MediaType.valueOf("application/pdf"));
        // just in case you need to support browsers
        responseHeaders.put("Content-Disposition", Collections.singletonList("attachment; filename=somefile.pdf"))
        return new ResponseEntity<InputStreamResource> (inputStreamResource,
                                   responseHeaders,
                                   HttpStatus.OK);
}


Share : facebook icon twitter icon
Spring REST consumption results in HTTP Status 406 - Not Acceptable

Spring REST consumption results in HTTP Status 406 - Not Acceptable


By : NYLDN
Date : March 29 2020, 07:55 AM
To fix the issue you can do I get this error when i try to consume a REST API: , You're sending an Accept= header instead of an Accept: header.
Yii2 rest api is not returning response code and status

Yii2 rest api is not returning response code and status


By : Jasmine Li
Date : March 29 2020, 07:55 AM
Hope that helps I am trying to get (StatusCode) in response of REST api while its just return field name and error message like this , Try that way, it works for me:
Java Spring REST API Status 400 response on POST / PUT

Java Spring REST API Status 400 response on POST / PUT


By : user5473005
Date : March 29 2020, 07:55 AM
With these it helps I built a REST API Service using Java Spring Cloud / Boot. Firstly, I made a simple class connected to a MongoDB and a controller with service that should allow me to add, delete, update and get all the objects. When using POSTMAN these all work, however when I want to add or update an object using redux and fetch API I get a status 400 and "bad request" error. This seems to have something to do with the JSON I'm sending in the body but it is the exact same format of JSON that is working with for example POSTMAN. , your error message says :
type=Not Acceptable, status=406 Error In Spring Rest For Producing XML

type=Not Acceptable, status=406 Error In Spring Rest For Producing XML


By : Ashwani
Date : March 29 2020, 07:55 AM
Hope this helps I'm working on Spring Rest and in my Spring Rest app, if I try to produce json everything is OK. I can see it on browser. There is no error. , You need to add jackson-dataformat-xml's dependency:
Document response status with Spring REST Docs

Document response status with Spring REST Docs


By : viony veronica
Date : March 29 2020, 07:55 AM
To fix this issue The feature you're looking for is not implemented and, in my opinion, it isn't needed.
When you're developing and documentation a RESTful API, you should try to make your API as consistent as possible in how it uses HTTP status codes and you should also use the standard, well-understood meanings of each status. If you follow these two guidelines you can either avoid documenting the status code altogether, or you can document them once in an overview section.
Related Posts Related Posts :
  • Remove background noise from image to make text more clear for OCR
  • PostgreSQL query always return true
  • How to connect FX controller with main app
  • Is there a difference between these two code snippets, and if so what?
  • When two interfaces have conflicting return types, why does one method become default?
  • Updating database throws errors in To Do List app
  • Where does the url come from?
  • Dagger 2 issue overriding single provides annotated method from a module in a library which app uses
  • Better way then If(x instanceof y) in Java?
  • how to debug maven enunciate plugin tomcat web service
  • Spring Context Initialization fails when upgrading to version 4.2.3
  • spring boot cannot connect to rabbitmq
  • How to Run Unit Test in Parallel Across All Modules Using Maven?
  • Getting the next Value in a ArrayList(Not working)
  • How to wait for a MouseListener mouse press?
  • Java RMI: Blocking for void method return?
  • Get Table Properties out of Hive using Java API
  • Read CSV file and write to another CSV - ArrayIndexOutOfBoundsException and pattern difficuties
  • Set LineChart(javafx) style to a child element
  • ArrayList how catch exception on one item from constructor
  • java.lang.NumberFormatException: For input string: " 1"
  • Dekker's Algorithm not working fine for three processes
  • Maven javadoc plugin - package does not exist
  • NotOLE2FileException: Invalid header signature; read 0x0000000000000000, expected 0xE11AB1A1E011CFD0
  • NullPointerExcpetion on findViewById
  • Java ArrayList initialization
  • Problems on making a Tic Tac Toe Game in Java
  • how to set proxy server details on WebServiceTemplate
  • How can I get a Class object form primitive?
  • How to count rows and Columns of excel sheet in Java
  • Should I split up texture atlas?
  • JavaFX freezing issue
  • What is the JavaFX equivalent of androids AsyncTask?
  • Zenity bash command not working with Java
  • GSON serialize multiple properties to sub object
  • How to convert some elements that satisfy a particular condition in a 2d array into a list in java?
  • Setting LinkedList nodes to null
  • Java Swing ignore text size on JButton
  • Collision detection for separate class instances - Processing Java
  • handle unreal numbers, jump to catch
  • Java - 100 decimal places in variable
  • Cancel previously shown toast before showing new toast
  • projectile motion sim - 'illegal start of type' error
  • How to print out the whole contents of a stack?
  • How to find variable name from a list of class in a package
  • how can i make this dialog close when socket is accepted?
  • I have created a small book program, I am new to java. Can't find what the error or mistake in this code?
  • How to get a variable from a php file and use it in a Android activity?
  • Creating an updater. Updating/downloading part
  • How can i print my array and my histogram on the same line?
  • Unknown error on if, else if, else statement
  • WebView crashing
  • Compare formatted dates to integers in Java
  • java sudoku why it doesnt show me the final result of sudoku
  • Json referring font to different font error
  • High-accuracy time syncing between Android (Java) and .NET DateTime?
  • Maven environment mac
  • What are these mystery characters
  • What is the proper way to say `#` to other developers?
  • How to make a Model attribute global?
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co