-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow for providing Jetty HttpClient to Jetty Connector (#4089)
Signed-off-by: Jan Supol <jan.supol@oracle.com>
- Loading branch information
Showing
4 changed files
with
126 additions
and
9 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
33 changes: 33 additions & 0 deletions
33
...connector/src/main/java/org/glassfish/jersey/jetty/connector/JettyHttpClientContract.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,33 @@ | ||
/* | ||
* Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0, which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
|
||
package org.glassfish.jersey.jetty.connector; | ||
|
||
import org.eclipse.jetty.client.HttpClient; | ||
import org.glassfish.jersey.spi.Contract; | ||
|
||
/** | ||
* A contract that allows for an optional registration of user predefined Jetty {@code HttpClient} | ||
* that is consequently used by {@link JettyConnector} | ||
*/ | ||
@Contract | ||
public interface JettyHttpClientContract { | ||
/** | ||
* Supply a user predefined HttpClient | ||
* @return a user predefined HttpClient | ||
*/ | ||
HttpClient getHttpClient(); | ||
} |
56 changes: 56 additions & 0 deletions
56
...connector/src/main/java/org/glassfish/jersey/jetty/connector/JettyHttpClientSupplier.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,56 @@ | ||
/* | ||
* Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0, which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
package org.glassfish.jersey.jetty.connector; | ||
|
||
import org.eclipse.jetty.client.HttpClient; | ||
|
||
/** | ||
* Jetty HttpClient supplier to be registered into Jersey configuration to be used by {@link JettyConnector}. | ||
* Not every possible configuration option is covered by the Jetty Connector and this supplier offers a way to provide | ||
* an HttpClient that has configured the options not covered by the Jetty Connector. | ||
* <p> | ||
* Typical usage: | ||
* </p> | ||
* <pre> | ||
* {@code | ||
* HttpClient httpClient = ... | ||
* | ||
* ClientConfig config = new ClientConfig(); | ||
* config.connectorProvider(new JettyConnectorProvider()); | ||
* config.register(new JettyHttpClientSupplier(httpClient)); | ||
* Client client = ClientBuilder.newClient(config); | ||
* } | ||
* </pre> | ||
* <p> | ||
* The {@code HttpClient} is configured as if it was created by {@link JettyConnector} the usual way. | ||
* </p> | ||
*/ | ||
public class JettyHttpClientSupplier implements JettyHttpClientContract { | ||
private final HttpClient httpClient; | ||
|
||
/** | ||
* {@code HttpClient} supplier to be optionally registered to a {@link org.glassfish.jersey.client.ClientConfig} | ||
* @param httpClient a HttpClient to be supplied when {@link JettyConnector#getHttpClient()} is called. | ||
*/ | ||
public JettyHttpClientSupplier(HttpClient httpClient) { | ||
this.httpClient = httpClient; | ||
} | ||
|
||
@Override | ||
public HttpClient getHttpClient() { | ||
return httpClient; | ||
} | ||
} |
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