Andy
Andy

Reputation: 5379

Calling spring boot webservice from angularjs with get method, is not working is giving 500 status error

I have created a webservice to get the excel file from server location to my local machine. with the help of springboot and angularjs. Now my URL is generating well, but i am getting 500 error. my code is given below ..

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 {
        {
        // my download logic will we 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"
                    });
                        
        }
    }

After running this code, web service URL generating properly but code is not able to call 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]}}

could you guys please help me, as this is my first webservice . it might be possible i am doing some silly mistake.. And sorry for typo mistake...

Upvotes: 1

Views: 55

Answers (1)

Andy
Andy

Reputation: 5379

I removed the file extension from the filename for URL, and added into springboot functionality. Example: URL would be http://localhost:8080/RMS/digital_data/user_review instead of http://localhost:8080/RMS/digital_data/user_review.xlsx.. and it is working fine.

Upvotes: 1

Related Questions