-
Notifications
You must be signed in to change notification settings - Fork 582
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix display of StepExecutionContext. (#5604)
* Fix StepExecutionControllers and add AllInOneExecutionContextSerializer to support Jackson and other serialization options. Fixes #5557
- Loading branch information
Corneil du Plessis
authored
Dec 14, 2023
1 parent
e972661
commit 2b3c13b
Showing
8 changed files
with
114 additions
and
40 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
...a/org/springframework/cloud/dataflow/server/batch/AllInOneExecutionContextSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2023 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.cloud.dataflow.server.batch; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.batch.core.repository.dao.Jackson2ExecutionContextStringSerializer; | ||
|
||
import java.io.*; | ||
import java.util.Base64; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Implements the same logic as used in Batch 5.x | ||
* @author Corneil du Plessis | ||
*/ | ||
public class AllInOneExecutionContextSerializer extends Jackson2ExecutionContextStringSerializer { | ||
private final static Logger logger = LoggerFactory.getLogger(AllInOneExecutionContextSerializer.class); | ||
@SuppressWarnings({"unchecked", "NullableProblems"}) | ||
@Override | ||
public Map<String, Object> deserialize(InputStream inputStream) throws IOException { | ||
ByteArrayOutputStream buffer = new ByteArrayOutputStream(); | ||
IOUtils.copy(inputStream, buffer); | ||
Map<String, Object> result = new HashMap<>(); | ||
// Try Jackson | ||
try { | ||
return super.deserialize(new ByteArrayInputStream(buffer.toByteArray())); | ||
} catch (Throwable x) { | ||
result.put("context.deserialize.error.jackson", x.toString()); | ||
} | ||
InputStream decodingStream = new ByteArrayInputStream(buffer.toByteArray()); | ||
try { | ||
// Try decode base64 | ||
decodingStream = Base64.getDecoder().wrap(decodingStream); | ||
} catch (Throwable x) { | ||
// Use original input for java deserialization | ||
decodingStream = new ByteArrayInputStream(buffer.toByteArray()); | ||
result.put("context.deserialize.error.base64.decode", x.toString()); | ||
} | ||
try { | ||
ObjectInputStream objectInputStream = new ObjectInputStream(decodingStream); | ||
return (Map<String, Object>) objectInputStream.readObject(); | ||
} catch (Throwable x) { | ||
result.put("context.deserialize.error.java.deserialization", x.toString()); | ||
} | ||
// They may have a custom serializer or custom classes. | ||
logger.warn("deserialization failed:{}", result); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters