Hello Syncfusion Support Team,
I am currently working on a project using Syncfusion's Scheduler component, which is designed to handle batch operations for appointments (insert, update, and delete). However, I'm facing challenges with multipart/mixed requests when trying to perform these operations through a Spring Boot backend.
Description of the Issue:
When I check the network requests in the browser’s developer tools, I can see that the request is being sent as multipart/mixed. However, upon reaching the Spring Boot controller, the request body is empty, and I am unable to retrieve any data.
Steps to Reproduce:
Perform a batch operation in the Syncfusion Scheduler (insert/update/delete).
Observe the request sent to the backend in the browser’s network tab.
@PostMapping(value = "/$batch", consumes = "multipart/mixed")
public ResponseEntity<?> handleBatchOperations(MultipartHttpServletRequest request) {
System.out.println("Inside handleBatchOperations");
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream()));
String line;
StringBuilder batchPart = new StringBuilder();
boolean isPostPart = false;
System.out.println(reader.readLine());
while ((line = reader.readLine()) != null) {
System.out.println("Read line: " + line);
if (line.startsWith("POST ")) {
if (isPostPart && batchPart.length() > 0) {
System.out.println("Processing batch part: " + batchPart);
processBatchPart(batchPart.toString());
batchPart.setLength(0);
}
isPostPart = true;
} else if (isPostPart) {
batchPart.append(line).append("\n");
}
}
if (isPostPart && batchPart.length() > 0) {
processBatchPart(batchPart.toString());
}
return ResponseEntity.ok("Batch request processed successfully");
} catch (Exception e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Error processing batch request: " + e.getMessage());
}
}
private Appointment processBatchPart(String jsonPart) throws IOException {
String json = jsonPart.substring(jsonPart.indexOf("{"));
ObjectMapper objectMapper = new ObjectMapper();
Appointment appointment = objectMapper.readValue(json, Appointment.class);
System.out.println("Parsed Appointment: " + appointment);
Appointment savedAppointment = appointmentService.save(appointment);
System.out.println("Saved Appointment: " + savedAppointment);
return savedAppointment;
}
Error Encountered:
While I haven’t received a specific error related to parsing the request, the backend log indicates that the request body is empty.
What I have tried:
I've explored the use of MultipartHttpServletRequest in my Spring controller to handle multipart requests, but it does not resolve the issue.
I am considering changing the request format sent by the frontend, but I am unsure how to modify the default behavior of the Syncfusion Scheduler.
Questions:
Is there a recommended way to configure the Syncfusion Scheduler to send requests in a format that the Spring Boot backend can easily parse? I dont really need to send batch requests in my case
Are there specific settings in Syncfusion that could help facilitate proper multipart request handling?
Edit: This is my angular app
import {Component, ViewChild} from '@angular/core';
import {EventSettingsModel, ScheduleComponent, View} from "@syncfusion/ej2-angular-schedule";
import {DataManager, ODataV4Adaptor, Query, UrlAdaptor, WebApiAdaptor, WebMethodAdaptor} from "@syncfusion/ej2-data";
import {AppointmentService} from "../appointment.service";
import {CustomAdaptor} from "./CustomAdaptor";
@Component({
selector: 'app-calendar',
templateUrl: './calendar.component.html',
styleUrl: './calendar.component.css'
})
export class CalendarComponent {
@ViewChild("scheduleObj")
public scheduleObj?: ScheduleComponent;
public scheduleViews: View[] = ['Day', 'Week', 'WorkWeek', 'Month'];
private dataManager: DataManager = new DataManager({
url: "http://localhost:8080/api/appointments/",
// crudUrl: "http://localhost:8080/api/appointments/",
insertUrl: "insert",
adaptor: new WebApiAdaptor(),
crossDomain: true,
});
public selectedDate: Date = new Date();
public eventSettings: EventSettingsModel = {
// includeFiltersInQuery: true,
dataSource: this.dataManager,
fields: {
id: 'id',
subject: { name: 'subject' },
description: { name: 'note' },
startTime: { name: 'startTime' },
endTime: { name: 'endTime' }
}};
constructor(private appointmentService: AppointmentService) {
}
}
<ejs-schedule #scheduleObj [selectedDate]="selectedDate" [eventSettings]="eventSettings" [views]="scheduleViews" ></ejs-schedule>
Hi Yacine,
We understand the challenges you are facing with multipart/mixed requests in the Syncfusion Scheduler component when interfacing with a Spring Boot backend.
If you are using WebApiAdaptor and facing issues related to multipart/mixed requests, it is most likely due to backend configuration. We recommend checking the OData backend service configuration in the .NET framework to understand the necessary configurations.
Angular sample: https://stackblitz.com/edit/angular-s3w94n
Odata Service : https://github.com/SyncfusionExamples/scheduler-web-services/tree/master/asp.net%20core/odata%20service
Microsoft Official Documentation: https://learn.microsoft.com/en-us/odata/webapi/batch
These resources provide detailed examples and configurations that you can adapt to your Spring Boot application.
Alternatively, you can use
UrlAdaptor instead of WebApiAdaptor. With UrlAdaptor, you can get the events as
added, changed, deleted in the payload, which you can then retrieve on the
backend for further processing.
Angular sample: https://stackblitz.com/edit/angular-s3w94n-ehupju
Regards,
Ram