forked from spring-cloud/spring-cloud-dataflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix loading of StepExecutionContext.
Fixes spring-cloud#5557
- Loading branch information
Corneil du Plessis
committed
Dec 14, 2023
1 parent
e45fcd8
commit 0ca26b3
Showing
7 changed files
with
105 additions
and
47 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
...ava/org/springframework/cloud/dataflow/server/batch/Base64ExecutionContextSerializer.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,53 @@ | ||
/* | ||
* Copyright 2009-2019 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.DefaultExecutionContextSerializer; | ||
|
||
import java.io.*; | ||
import java.util.Base64; | ||
import java.util.Map; | ||
|
||
/** | ||
* Implements the same logic as used in Batch 5.x | ||
* @author Corneil du Plessis | ||
*/ | ||
public class Base64ExecutionContextSerializer extends DefaultExecutionContextSerializer { | ||
private final static Logger logger = LoggerFactory.getLogger(Base64ExecutionContextSerializer.class); | ||
@SuppressWarnings({"unchecked", "NullableProblems"}) | ||
@Override | ||
public Map<String, Object> deserialize(InputStream inputStream) throws IOException { | ||
ByteArrayOutputStream buffer = new ByteArrayOutputStream(); | ||
IOUtils.copy(inputStream, buffer); | ||
InputStream decodingStream = new ByteArrayInputStream(buffer.toByteArray()); | ||
try { | ||
decodingStream = Base64.getDecoder().wrap(decodingStream); | ||
} catch (Throwable x) { | ||
logger.info("Cannot decode input as base"); | ||
} | ||
try { | ||
ObjectInputStream objectInputStream = new ObjectInputStream(decodingStream); | ||
return (Map<String, Object>) objectInputStream.readObject(); | ||
} catch (IOException ex) { | ||
throw new IllegalArgumentException("Failed to deserialize object", ex); | ||
} catch (ClassNotFoundException ex) { | ||
throw new IllegalStateException("Failed to deserialize object type", ex); | ||
} | ||
} | ||
} |
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