-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DXE-2981 Merge pull request #49 from akamai/release/5.1.0
DXE-2981 Release/5.1.0
- Loading branch information
Showing
26 changed files
with
237 additions
and
29 deletions.
There are no files selected for viewing
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
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
33 changes: 25 additions & 8 deletions
33
...a/com/akamai/edgegrid/signer/apachehttpclient5/ApacheHttpClient5EdgeGridRoutePlanner.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 |
---|---|---|
@@ -1,34 +1,51 @@ | ||
package com.akamai.edgegrid.signer.apachehttpclient5; | ||
|
||
import com.akamai.edgegrid.signer.ClientCredential; | ||
import org.apache.hc.client5.http.impl.routing.SystemDefaultRoutePlanner; | ||
import org.apache.hc.client5.http.HttpRoute; | ||
import org.apache.hc.client5.http.routing.HttpRoutePlanner; | ||
import org.apache.hc.core5.annotation.Contract; | ||
import org.apache.hc.core5.annotation.ThreadingBehavior; | ||
import org.apache.hc.core5.http.HttpException; | ||
import org.apache.hc.core5.http.HttpHost; | ||
import org.apache.hc.core5.http.protocol.HttpContext; | ||
|
||
import java.net.ProxySelector; | ||
|
||
public class ApacheHttpClient5EdgeGridRoutePlanner extends SystemDefaultRoutePlanner { | ||
/** | ||
* Apache HTTP Client binding for EdgeGrid route planner for computing {@link HttpRoute}. | ||
* | ||
*/ | ||
@Contract(threading = ThreadingBehavior.STATELESS) | ||
public class ApacheHttpClient5EdgeGridRoutePlanner implements HttpRoutePlanner { | ||
|
||
private final ClientCredential clientCredential; | ||
|
||
/** | ||
* Creates an EdgeGrid route planner using {@link ClientCredential}. | ||
* | ||
* @param clientCredential a {@link ClientCredential} | ||
*/ | ||
public ApacheHttpClient5EdgeGridRoutePlanner(ClientCredential clientCredential) { | ||
super(ProxySelector.getDefault()); | ||
this.clientCredential = clientCredential; | ||
} | ||
|
||
@Override | ||
protected HttpHost determineProxy(HttpHost target, HttpContext context) { | ||
public HttpRoute determineRoute(HttpHost target, HttpContext context) throws HttpException { | ||
var hostname = clientCredential.getHost(); | ||
int port = -1; | ||
int port = 443; | ||
final int pos = hostname.lastIndexOf(":"); | ||
if (pos > 0) { | ||
try { | ||
port = Integer.parseInt(hostname.substring(pos + 1)); | ||
if (port <= 0 || port > 65535) { | ||
throw new NumberFormatException(); | ||
} | ||
} catch (NumberFormatException ex) { | ||
throw new IllegalArgumentException("Host contains invalid port number: " + hostname); | ||
} | ||
hostname = hostname.substring(0, pos); | ||
} | ||
return new HttpHost("https", hostname, port); | ||
HttpHost host = new HttpHost("https", hostname, port); | ||
return new HttpRoute(host, null, true); | ||
} | ||
} | ||
|
||
|
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
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
Oops, something went wrong.