microsoftgraph / microsoftgraph/msgraph-sdk-java
ClassCastException while uploading content to OneDrive using Graph API
Chưa có ai nhận issue này.
- 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
Mô tả
Describe the bug
We are trying to upload content to OneDrive root and getting following error consistently.
java.lang.ClassCastException: class java.io.BufferedInputStream cannot be cast to class com.microsoft.graph.models.extensions.UploadSession (java.io.BufferedInputStream is in module java.base of loader 'bootstrap'; com.microsoft.graph.models.extensions.UploadSession is in unnamed module of loader 'app')
at com.ptc.cloudstorage.onedrive.OneDriveStorageService$1.success(OneDriveStorageService.java:103)
at com.microsoft.graph.concurrency.DefaultExecutors$1.run(DefaultExecutors.java:92)
at com.microsoft.graph.concurrency.SynchronousExecutor.execute(SynchronousExecutor.java:45)
at com.microsoft.graph.concurrency.DefaultExecutors.performOnForeground(DefaultExecutors.java:89)
at com.microsoft.graph.http.CoreHttpProvider$1.run(CoreHttpProvider.java:155)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
Expected behavior
Upload should work as expected.
How to reproduce
try {
IAuthenticationProvider authProvider = new AuthenticationProvider(accessToken);
// Build a Graph client
final IGraphServiceClient graphServiceClient = GraphServiceClient.builder()
.authenticationProvider(authProvider)
.buildClient();
final BlockingQueue queue = new LinkedBlockingQueue<>(1);
DriveItemUploadableProperties itemProperties = new DriveItemUploadableProperties();
graphServiceClient
.me()
.drive()
.root()
.itemWithPath(escapeSpace(filename))
.createUploadSession(itemProperties)
.buildRequest()
.post(new ICallback() {
@Override
public void failure(final ClientException ex) {
logger.error("createUploadSession.failure: Error occured durring post " + ex);
if (logger.isTraceEnabled()) {
ex.printStackTrace();
}
try {
queue.put("");
} catch (InterruptedException ie) {
}
}
@Override
public void success(final UploadSession result) {
if (logger.isDebugEnabled()) {
logger.debug("createUploadSession.success: UploadSession= " + result);
}
try {
ChunkedUploadProvider<DriveItem> chunkedUploadProvider = new ChunkedUploadProvider<DriveItem>(
result, graphServiceClient, inputStream, streamSize, DriveItem.class);
chunkedUploadProvider.upload(new IProgressCallback<DriveItem>() {
@Override
public void failure(ClientException ce) {
logger.error("failure: Error occured durring upload " + ce);
if (logger.isTraceEnabled()) {
ce.printStackTrace();
}
try {
queue.put("");
} catch (InterruptedException ie) {
}
}
@Override
public void success(DriveItem driveItem) {
if (logger.isDebugEnabled()) {
logger.debug("success: driveItem = " + driveItem);
}
try {
queue.put(driveItem.webUrl);
} catch (InterruptedException ie) {
}
}
@Override
public void progress(long current, long max) {
if (logger.isDebugEnabled()) {
logger.debug("progress: current=" + current + ", max=" + max);
}
}
}, new int[] { finalChunkSize });
} catch (Exception e) {
logger.error("Exception occured in upload to One Drive", e);
try {
queue.put("");
} catch (InterruptedException ie) {
}
}
SDK Version
microsoft-graph-core 1.0.9 microsoft-graph 1.9.0
Latest version known to work for scenario above?
No response
Known Workarounds
No response
Debug output
Click to expand log
```</details>
### Configuration
_No response_
### Other information
_No response_
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.
Hướng nghiên cứu
Bắt đầu với lệnh gọi createUploadSession đã tái hiện và ClassCastException tại OneDriveStorageService.java:103, sử dụng microsoft-graph 1.9.0 và microsoft-graph-core 1.0.9. Xác minh lý do callback nhận được một BufferedInputStream thay vì một UploadSession; hoàn tất khi cùng một luồng tải lên hoàn thành mà không xảy ra lỗi cast.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- java
- Lĩnh vực
- api, cloud
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 30/100