java.lang.UnsupportedOperationException using GetSchedulePostResponse
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
Bắt đầu tại dòng 223 của MicrosoftGraphClient.java và lần theo BatchResponseContentCollection.getResponseById qua BatchResponseContent và ResponseBodyHandler, sử dụng ngoại lệ TextParseNode được báo cáo làm điểm bắt đầu. Tái hiện yêu cầu batch với các phiên bản Graph SDK được liệt kê và xác định tại sao một số phản hồi được phân tích cú pháp dưới dạng văn bản; hoàn tất nghĩa là đã giải thích được lỗi và hành vi xử lý phản hồi bị ảnh hưởng được bao phủ bởi một regression test phù hợp.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
I have a scheduler that runs every hour that gets schedule for all our users and saves them in the db. But alot of calls (more than 50%) throws weird error. I haven't found anything on google that could fix this error and i am unable to fix it for days now.
Expected behavior
I am using following dependencies:
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>msal4j</artifactId>
<!--<version>1.17.1</version>-->
<version>1.18.0</version>
</dependency>
<dependency>
<groupId>com.microsoft.kiota</groupId>
<artifactId>microsoft-kiota-serialization-form</artifactId>
<version>1.8.2</version>
</dependency>
<dependency>
<groupId>com.microsoft.graph</groupId>
<artifactId>microsoft-graph</artifactId>
<version>6.25.1</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.13.3</version>
</dependency>
<dependency>
<groupId>com.microsoft.graph</groupId>
<artifactId>microsoft-graph-auth</artifactId>
<version>0.3.0</version>
</dependency>
This is my code:
public List<CalendarAvailabilityView> getUserCalendarFreeSlots(String userid, List<String> calendarIds, LocalDate startDate, LocalDate endDate){
logger.info("getUserCalendarFreeSlots()");
if (userid == null)
userid = defaultUserId;
StopWatch sw = new StopWatch("getUserCalendarFreeSlots");
LocalDateTime startDateTime = LocalDateTime.of(startDate, LocalTime.of(0, 0));
LocalDateTime endDateTime = LocalDateTime.of(endDate, LocalTime.of(23, 59));
List<LocalDate> dates = new ArrayList<>();
for (LocalDate d = startDate; !d.isAfter(endDate); d = d.plusDays(1)) {
dates.add(d);
}
int availabilityViewInterval = 30;
List<List<String>> partitions = Lists.partition(calendarIds, 50);
BatchRequestContentCollection batchRequestContent = new BatchRequestContentCollection(graphClient);
List<String> responseIds = new ArrayList<>();
for (List<String> schedulesList : partitions) {
logger.info("Creating request for partition: " + StringUtils.join(schedulesList, ", "));
sw.start("get data");
DateTimeTimeZone startTime = new DateTimeTimeZone();
startTime.setDateTime(dtf.format(startDateTime));
startTime.setTimeZone(timeZone);
DateTimeTimeZone endTime = new DateTimeTimeZone();
endTime.setDateTime(dtf.format(endDateTime));
endTime.setTimeZone(timeZone);
com.microsoft.graph.users.item.calendar.getschedule.GetSchedulePostRequestBody scheduleReq = new com.microsoft.graph.users.item.calendar.getschedule.GetSchedulePostRequestBody();
scheduleReq.setSchedules(schedulesList);
scheduleReq.setEndTime(endTime);
scheduleReq.setStartTime(startTime);
scheduleReq.setAvailabilityViewInterval(availabilityViewInterval);
RequestInformation request = graphClient.users().byUserId(userid).calendar().getSchedule().toPostRequestInformation(scheduleReq, requestConfiguration -> {
requestConfiguration.headers.add("Prefer", "outlook.timezone=\"" + timeZone + "\"");
requestConfiguration.headers.add("Content-Type", "application/json");
requestConfiguration.headers.add("Accept", "application/json");
});
// RequestInformation request = graphClient.me().calendar().getSchedule().toPostRequestInformation(scheduleReq, requestConfiguration -> {
// requestConfiguration.headers.add("Prefer", "outlook.timezone=\"" + timeZone + "\"");
// requestConfiguration.headers.add("Content-Type", "application/json");
// });
String responseId = batchRequestContent.addBatchRequestStep(request);
responseIds.add(responseId);
logger.info("responseId: " + responseId + " contains emails: " + schedulesList);
sw.stop();
}
// BatchResponseContent batchResponseContent = null;
BatchResponseContentCollection batchResponseContent = null;
try {
batchResponseContent = graphClient.getBatchRequestBuilder().post(batchRequestContent, null);
} catch (IOException e) {
logger.error("Error executing batch request: " + e.getMessage(), e);
}
List<CalendarAvailabilityView> availability = new ArrayList<>();
for (String responseId : responseIds) {
GetSchedulePostResponse response = null;
try {
response = batchResponseContent.getResponseById(responseId, GetSchedulePostResponse::createFromDiscriminatorValue);
} catch (UnsupportedOperationException e) {
logger.error("Failed to parse response for request ID: " + responseId + " due to unsupported content type.", e);
logger.error("response code: " + e.hashCode() + e.getStackTrace().hashCode());
continue;
} catch (Exception e) {
logger.error("Error while processing response for request ID: " + responseId, e);
continue;
}
if(response != null) {
List<ScheduleInformation> allSchedules = new ArrayList<>(response.getValue());
if (response.getOdataNextLink() != null && !response.getOdataNextLink().isEmpty()) {
handlePagination(response, allSchedules);
}
for (ScheduleInformation si : allSchedules) {
String availabilityView = si.getAvailabilityView();
WorkingHours workingHours =si.getWorkingHours();
if (si.getAvailabilityView() != null) {
CalendarAvailabilityView calav = new CalendarAvailabilityView();
// calav.setAvailabilityView(si.getAvailabilityView());
calav.setAvailabilityView(availabilityView);
calav.setIdCalendar(si.getScheduleId());
// calav.setWorkingHours(convert(si.getWorkingHours()));
calav.setWorkingHours(convert(workingHours));
calav.setDates(dates);
availability.add(calav);
}
}
}
}
logger.info(sw.prettyPrint());
return availability;
}
private void handlePagination(GetSchedulePostResponse initialResponse, List<ScheduleInformation> allSchedules) {
PageIterator<ScheduleInformation, GetSchedulePostResponse> pageIterator = null;
try {
pageIterator = new PageIterator.Builder<ScheduleInformation, GetSchedulePostResponse>()
.client(graphClient)
.collectionPage(initialResponse)
.collectionPageFactory(GetSchedulePostResponse::createFromDiscriminatorValue)
.processPageItemCallback(allSchedules::add)
.build();
} catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
logger.error("Error in creating PageIterator: " + e.getMessage(), e);
}
try {
if (pageIterator != null) {
pageIterator.iterate();
}
} catch (ApiException | ReflectiveOperationException e) {
logger.error("Error in iterating through pages: " + e.getMessage(), e);
}
}
private Map<String, WorkingHour> convert(WorkingHours wh) {
Map<String, WorkingHour> workingHoursMap = new LinkedHashMap<String, WorkingHour>();
if (wh==null)
return null;
//List<com.microsoft.graph.models.generated.DayOfWeek> daysOfWeek = wh.daysOfWeek;
List<DayOfWeek> daysOfWeek = wh.getDaysOfWeek();
for (com.microsoft.graph.models.DayOfWeek dow: daysOfWeek) {
WorkingHour workingHour = new WorkingHour();
LocalTime endTime = wh.getEndTime();
workingHour.setEndTime(LocalTime.of(endTime.getHour(), endTime.getMinute()));
LocalTime startTime = wh.getStartTime();
workingHour.setStartTime(LocalTime.of(startTime.getHour(), startTime.getMinute()));
workingHoursMap.put(dow.name().toUpperCase(), workingHour);
}
return workingHoursMap;
}
This is the error that i get:
I think the error happens at this line of code:
response = batchResponseContent.getResponseById(responseId, GetSchedulePostResponse::createFromDiscriminatorValue);
java.lang.UnsupportedOperationException: text does not support structured data
at com.microsoft.kiota.serialization.TextParseNode.getObjectValue(TextParseNode.java:125)
at com.microsoft.graph.core.requests.ResponseBodyHandler.handleFailedResponse(ResponseBodyHandler.java:94)
at com.microsoft.graph.core.requests.ResponseBodyHandler.handleResponse(ResponseBodyHandler.java:61)
at com.microsoft.graph.core.content.BatchResponseContent.getResponseById(BatchResponseContent.java:122)
at com.microsoft.graph.core.content.BatchResponseContent.getResponseById(BatchResponseContent.java:133)
at com.microsoft.graph.core.content.BatchResponseContentCollection.getResponseById(BatchResponseContentCollection.java:83)
at si.triglav.booking.microsoftgraph.MicrosoftGraphClient.getUserCalendarFreeSlots(MicrosoftGraphClient.java:223)
at si.triglav.booking.service.DataCacheService.getAvailability(DataCacheService.java:198)
at si.triglav.booking.service.DataCacheService.refreshAvailability(DataCacheService.java:179)
at si.triglav.booking.service.DataCacheService.refreshAvailabilityWithLocks(DataCacheService.java:91)
at si.triglav.booking.service.DataCacheRefresher.refreshAvailabilityCache(DataCacheRefresher.java:32)
at sun.reflect.GeneratedMethodAccessor177.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:503)
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:84)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:95)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:826)
How to reproduce
Can anyone please help me why am i constantly getting this errors and maybe some tips on how to fix it?
SDK Version
No response
Latest version known to work for scenario above?
6.25.1
Known Workarounds
No response
Debug output
Click to expand log
```</details>
### Configuration
_No response_
### Other information
_No response_
- Ngôn ngữ chính
- Java
- Star
- 444
- Fork
- 154
- Merge trung bình
- 18 giờ 28 phút
- Pull request đã merge (30 ngày)
- 4
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoftgraph/msgraph-sdk-java
-
status:waiting-for-triage type:bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
microsoftgraph/msgraph-sdk-java#2610 ·
-
status:waiting-for-triage type:bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
microsoftgraph/msgraph-sdk-java#2656 ·
-
status:waiting-for-triage type:bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 38/100
microsoftgraph/msgraph-sdk-java#2654 ·
-
status:waiting-for-triage
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
microsoftgraph/msgraph-sdk-java#2639 ·
-
Error in PATCH onlineMeeting Đang mởstatus:waiting-for-triage type:bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
microsoftgraph/msgraph-sdk-java#2589 · 1 bình luận ·
Tất cả issue của microsoftgraph/msgraph-sdk-java
Issue tương tự
-
Bug Java Platform: Java
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
getsentry/sentry-java#6138 · 1 bình luận ·
-
bug needs triage p2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
GoogleCloudPlatform/DataflowTemplates#4273 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
bug needs triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100