-
Notifications
You must be signed in to change notification settings - Fork 932
Replace deprecated SSLConnectionSocketFactory with recommended API #6281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
joviegas
merged 12 commits into
feature/master/apache5x
from
joviegas/apache5_replace_DeprecatedAPIs
Aug 1, 2025
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
034f7b6
Replace deprecated SSLConnectionSocketFactory with recommended API
joviegas 4e60a0d
Fixed checkstyle issues
joviegas 126b428
Changed name tlsSocketStrategy on builder
joviegas e055dcb
Removed warning log
joviegas 4c48f27
Merge branch 'master' into joviegas/apache5_replace_DeprecatedAPIs
joviegas abc984b
added more test cases
joviegas 9472ac8
updated after review
joviegas a94cd3e
Added ConnectionSocketFactory to Apache5Client builder same as Apache4
joviegas dcaaaf6
handled PR comments
joviegas dfeff16
Removed ConnectionSocketFactory API since its deprecated and mentione…
joviegas 018873d
Removed unused classes after moving to SSL sockets
joviegas 9e21fa7
Rebase
joviegas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
70 changes: 70 additions & 0 deletions
70
...amazon/awssdk/http/apache5/internal/conn/ConnectionSocketFactoryToTlsStrategyAdapter.java
This file contains hidden or 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,70 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file 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 software.amazon.awssdk.http.apache5.internal.conn; | ||
|
||
import java.io.IOException; | ||
import java.net.Socket; | ||
import javax.net.ssl.SSLSocket; | ||
import org.apache.hc.client5.http.socket.ConnectionSocketFactory; | ||
import org.apache.hc.client5.http.socket.LayeredConnectionSocketFactory; | ||
import org.apache.hc.client5.http.ssl.TlsSocketStrategy; | ||
import org.apache.hc.core5.http.protocol.HttpContext; | ||
import software.amazon.awssdk.annotations.SdkInternalApi; | ||
|
||
/** | ||
* Adapter to wrap ConnectionSocketFactory as TlsSocketStrategy. | ||
* Supports both plain and layered (SSL/TLS) socket factories. | ||
*/ | ||
@SdkInternalApi | ||
public class ConnectionSocketFactoryToTlsStrategyAdapter implements TlsSocketStrategy { | ||
|
||
private final ConnectionSocketFactory socketFactory; | ||
|
||
public ConnectionSocketFactoryToTlsStrategyAdapter(ConnectionSocketFactory socketFactory) { | ||
this.socketFactory = socketFactory; | ||
} | ||
|
||
@Override | ||
public SSLSocket upgrade(Socket socket, | ||
String target, | ||
int port, | ||
Object attachment, | ||
HttpContext context) throws IOException { | ||
|
||
// Only LayeredConnectionSocketFactory can upgrade to SSL | ||
if (socketFactory instanceof LayeredConnectionSocketFactory) { | ||
LayeredConnectionSocketFactory layeredFactory = (LayeredConnectionSocketFactory) socketFactory; | ||
Socket upgradedSocket = layeredFactory.createLayeredSocket(socket, target, port, context); | ||
|
||
if (upgradedSocket == null) { | ||
throw new IOException("LayeredConnectionSocketFactory.createLayeredSocket returned null"); | ||
} | ||
if (!(upgradedSocket instanceof SSLSocket)) { | ||
throw new IOException("LayeredConnectionSocketFactory.createLayeredSocket did not return an SSLSocket. " + | ||
"Returned type: " + upgradedSocket.getClass().getName()); | ||
} | ||
|
||
return (SSLSocket) upgradedSocket; | ||
} | ||
|
||
// For plain socket factories (like PlainConnectionSocketFactory), | ||
// we can't upgrade to TLS, but we shouldn't throw an exception | ||
// Return null to indicate no TLS upgrade is possible/needed | ||
return null; | ||
} | ||
|
||
|
||
} |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we explain that this is here to ease migration from 4.5.x?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done