0

Hello, I am currently trying to build a spring boot backend to match with Syncfusion's Datamanager (their documentation for backend construction is purely for .NET as far as I can see.) I have managed to get the GET functionality working so my data type mapping is correct but posting is causing some issues. Specifically, it appears that DataManager posts a multipart/mixed that includes the JSON object i'm trying to persist as well as some sort of batch file (which I don't care about). Since I can't modify datamanager, I need to figure out a way in spring to purely pull out the JSON. I'm sure it's really simple but I'm fairly new to this and couldn't find any other previously asked questions that matched my current situation. Here is a copy of the Request details as listed in Chrome Developer tools.

General

***Request URL: http://localhost:8082/schedule/$batch

Request Method: POST

Status Code: 415

Remote Address: [::1]:8082

Referrer Policy: no-referrer-when-downgrade

Response Headers

Access-Control-Allow-Headers: Authorization, Content-Type

Access-Control-Allow-Methods: POST, PUT, GET, OPTIONS, DELETE

Access-Control-Allow-Origin: *

Access-Control-Max-Age: 3600

Content-Type: application/json

Date: Fri, 22 Nov 2019 14:38:39 GMT

Transfer-Encoding: chunked

Vary: Origin

Vary: Access-Control-Request-Method

Vary: Access-Control-Request-Headers

Request Headers

Accept: application/json, text/javascript, /; q=0.01, application/json

Accept-Encoding: gzip, deflate, br

Accept-Language: en-US,en;q=0.9

Connection: keep-alive

Content-Length: 358

Content-Type: multipart/mixed; boundary=batch_dddabc0b-930c-47fc-b7e5-934999f0adc9

Host: localhost:8082

Origin: http://localhost:4200

Referer: http://localhost:4200/main/schedule

Sec-Fetch-Mode: cors

Sec-Fetch-Site: same-site

User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36

Request Payload

--batch_dddabc0b-930c-47fc-b7e5-934999f0adc9

Content-Type: application/http; msgtype=request

POST /api/null HTTP/1.1

Content-Type: application/json; charset=utf-8

Host: localhost:4200

{"Subject":"m","Id":4,"StartTime":"2019-11-21T06:30:00.000Z","EndTime":"2019-11-21T07:00:00.000Z","IsAllDay":false}

--batch_dddabc0b-930c-47fc-b7e5-934999f0adc9--***

And here is a copy of my Controller as it currently stands. (Basically was built to accept regular application/json POSTS)

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.quietmodebackend.models.Appointment;
import com.quietmodebackend.repos.ScheduleRepository;

@CrossOrigin
@RestController
@RequestMapping("/schedule")
public class ScheduleController {

    @Autowired
    ScheduleRepository myRepo;

    @GetMapping
    public List<Appointment> getAppointments(HttpServletResponse response){

        response.setStatus(200);
        return myRepo.findAll();
    }

    @PostMapping("/$batch")
    public Appointment postAppointments(HttpServletResponse response, @RequestBody Appointment appointment){
        return myRepo.save(appointment);
    }


}

Any help would be greatly appreciated.

1 Answers1

0
Dear Customer,

Syncfusion Greetings

Scheduler CRUD actions support is not provided for WebApiAdaptor which could be the cause and for the same we already logged the below feature request.

https://www.syncfusion.com/feedback/2373/batch-handler-support-for-asp-net-core-while-using-webapi-adaptor

Kindly use UrlAdaptor like below sample.

Sample: https://stackblitz.com/edit/angular-ysiqa8-9s3lef?file=app.component.ts
Service: https://www.syncfusion.com/downloads/support/directtrac/general/ze/ej2-schedule-crud-1800404263 

 private dataManger: DataManager = new DataManager({
    url: "http://localhost:25255/api/Batch", 
    crossDomain: true, 
    adaptor: new UrlAdaptor 
  });

Note: Keep the Service project in runnable state.

Regards,
M.Vinitha devi
vinitha m
  • 81
  • 3