The attempt to access a Spring Boot webservice using AngularJS and the GET method resulted in a 500 status error, indicating that the operation

I have successfully developed a webservice using springboot and angularjs to download an excel file from the server to my local machine. The URL is being generated correctly, however, I am encountering a 500 error. Below is the code snippet:

My Springboot class:

    class MyWebserviceClass
    
        {
@RequestMapping(method = RequestMethod.GET, value = "digital_data/{digital_file}", produces = "application/vnd.ms-excel")
        public getExcelFileFromServer((HttpServletResponse response, @PathVariable("digital_file") String digital_file) throws IOException {
        {
        // download logic implementation would be here
        }

AngularJS controller method

digitalService.getDigitalData(digital_file).then (function(res) {

                    var blob = new Blob([res.data], {type: "application/vnd.ms-excel"});
                    
                    saveDigitalData(blob, digital_file);

                }, function(errRes) {
                    $scope.showErrorMessage("Error");
                
                })
            };
        

AngularJS Service Layer

digitalService
{
 function getDigitalData(digital_file) {
            var url = 'digital_data/'+file_name;
            return $http.get(url,{
                        transformRequest: angular.identity,
                        headers: {'Content-Type': undefined},
                        responseType:"arraybuffer"
                    });
                        
        }
    }

Although the webservice URL is getting generated correctly, the issue lies in calling the springboot webservice.

Generated URL: http://localhost:8080/RMS/digital_data/user_review.xlsx

Error:

{resStatus: -3, appErrorMsg: "Could not find acceptable representation"}

Exception: com.media.MediaController.MyWebservice.getExcelFileFromServer(javax.servlet.http.HttpServletResponse,java.lang.String) throws java.io.IOException={[/digital_data/{digital_file}],methods=[GET],produces=[application/vnd.ms-excel]}}

If anyone could provide some assistance, as this is my first webservice project and I may have overlooked something. Apologies for any typing errors.

Answer №1

I recently made a small adjustment to the file URL by removing the file extension from the filename and incorporating it into the springboot functionality. For example, the URL now reads as http://localhost:8080/RMS/digital_data/user_review instead of http://localhost:8080/RMS/digital_data/user_review.xlsx.. and everything is functioning smoothly.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating a dropdown menu utilizing JavaScript/jQuery arrays

Looking to create an HTML select menu using a JavaScript array where the keys are used as values for options. The challenge is when entering numbers as keys, they should be accepted in the code. a([selected="No of rooms", 1="1", 2="2", 3="3", 4="4", 5="5" ...

The State of NgRX Entity is encountering undefined IDs

I decided to experiment with @ngrx/entity in a simple "Todo" project, where I had only one AppModule, one reducer, and a single component. However, as I delved into it, I encountered some challenges. The actions I defined were quite basic, focusing on CRU ...

Update the second dropdown menu depending on the selection made in the first dropdown menu

While I know this question has been posed previously, I'm struggling to apply it to my current situation. In my MySQL database, I have a table named "subject" that includes columns for subject name and subject level. Here's an example: Subject ...

The new data is not being fetched before *ngFor is updating

In the process of developing a "Meeting List" feature that allows users to create new meetings and join existing ones. My technology stack includes: FrontEnd: Angular API: Firebase Cloud Functions DB: Firebase realtime DB To display the list of meeting ...

What is the best way to extract the ID of an element that triggers an OnChange event?

Just a heads up: The solution to my problem ended up being CSS code that was triggered by clicking on a widget. Once I realized it was CSS, along with the widget name and hover action, I was able to handle it successfully. Previous question before the PS ...

Attempting to modify the color of a selected Three.js object causes all objects in the scene to have their colors altered

For example, check out this JSFiddle link. The interesting part occurs during the mousedown event: var hits = raycaster.intersectObjects( [object1, object2, object3] ); if ( hits.length > 0 ) { console.log(hits[ 0 ].object) hits[ 0 ].object.m ...

Pause until the existence of document.body is confirmed

Recently, I developed a Chrome extension that runs before the page fully loads by setting the attribute "run_at": "document_start". One issue I encountered is that I need to insert a div tag into the body of the webpage as soon as it is created. However, a ...

A guide on mapping an array and removing the associated element

I have an array called responseData, which is used to display the available card options on the screen. public responseData = [ { id: 1399, pessoa_id: 75898, created_at: '2022-11-08T16:59:59.000000Z', holder: 'LEONARDO ', validade: ...

Tips for increasing the size of Material-ui Rating icons

I am currently utilizing npm to develop a widget. I aim to utilize the material-ui Rating component and have successfully integrated it. However, when I embed the widget on a webpage, the html font-size is set at 62.5%, causing the component to appear too ...

Error: Attempting to access properties of an undefined object (specifically, the 'prototype' property) within a React application

I encountered an error while working on my React application: TypeError: Cannot read properties of undefined (reading 'prototype') (anonymous function) C:/Users/tatup/Desktop/GrowApp/frontend/node_modules/express/lib/response.js:42 39 | * @pub ...

.toggle function malfunctioning

Upon page load, I have a script that toggles the County menu. The goal is to hide the county menu if any country other than "United Kingdom" is selected on page load. If the user selects another country after the page has loaded, there is an issue where ...

Apply a custom filter to ng-repeat results

Asking for advice on how to iterate over an array using ng-repeat and filter the contained objects based on a function property. Find more details in this Plunker link. Let's say we have an object like this: vm.show1 = function(){ return true; }; ...

org.springframework.web.client.HttpClientErrorException: The RestTemplate encountered a 400 Bad Request

When using Rest Template to POST JSON data, testing with Postman shows it runs successfully and returns a 200 status code. This is the JSON format I'm using: { "senderUser": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__ ...

Mastering the art of constantly monitoring data changes in a Firebase real-time database using Vue.js

I am currently utilizing vue.js version 2 in CDN mode. I have designed 2 vue components - one that pushes data to a database and another that displays it. Here is the code snippet: firebase.database().ref().on('value', function (data) { c ...

Retrieve a Play Scala variable in the $scope of an AngularJS application

After trying various methods recommended on StackOverflow, I am still struggling to retrieve a Play Scala variable within my Javascript $scope. The line of initialization in an HTML file is as follows: @(playVariable: String)(implicit request: play.api.mv ...

Issues with link behavior when using Angular UI-Router

I am just starting to learn AngularJS and I'm trying to figure out how to pass a parameter using anchor tags within the $stateProvider code. I've been attempting to do so, but it doesn't seem to be working. Can someone guide me on the correc ...

Creating an array based on specific conditions being satisfied (Using Javascript)

I am struggling with a coding problem involving adding users to groups. The goal is to add each user to a group array, with a maximum of 3 users per group. If a group reaches 3 users, it should be moved to another array that collects all the groups. I then ...

Update the class name by utilizing template literals

I'm currently in the process of mastering template literals as I have a project where I need to utilize them. However, I seem to be encountering an issue that I can't quite figure out. Here is the code that is currently working: const classes = ...

Eliminating any spaces in the password prior to finalizing the form submission

After submitting the Form, I am trying to remove all spaces from the Password field. This is my current code: $(document).on("submit", "form#user-login", function(e){ e.preventDefault(); var emailAdd = $("#edit-pass").val().replace(/ / ...

What is the best way to trigger a function exclusively upon clicking a particular element?

My goal is to enable the user to interact with the model by positioning cubes in space upon clicking the "Cubes Mode" button. I currently have a script from the three.js website that achieves this, but I want it to only run when the mentioned button is cli ...