-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: jansupol <jan.supol@oracle.com>
- Loading branch information
Showing
4 changed files
with
149 additions
and
1 deletion.
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
52 changes: 52 additions & 0 deletions
52
core-client/src/main/java/org/glassfish/jersey/client/spi/ClientBuilderListener.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,52 @@ | ||
/* | ||
* Copyright (c) 2020 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.client.spi; | ||
|
||
import org.glassfish.jersey.Beta; | ||
|
||
import javax.ws.rs.client.ClientBuilder; | ||
|
||
/** | ||
* <p> | ||
* Implementations of this interface will be notified when new ClientBuilder | ||
* instances are being constructed. This will allow implementations to register | ||
* providers on the ClientBuilder, and is intended for global providers. | ||
* </p> | ||
* <p> | ||
* In order for the ClientBuilder to call implementations of this interface, | ||
* the implementation must be specified such that a ServiceLoader can find it - | ||
* i.e. it must be specified in the <code> | ||
* META-INF/services/org.glassfish.jersey.client.spi.ClientBuilderListener | ||
* </code> file in an archive on the current thread's context classloader's | ||
* class path. | ||
* </p> | ||
* <p> | ||
* Note that the <code>onNewBuilder</code> method will be called when the | ||
* ClientBuilder is constructed, not when it's <code>build</code> method is | ||
* invoked. This allows the caller to override global providers if they desire. | ||
* </p> | ||
* <p> | ||
* The ClientBuilderListener are invoked in an order given by it's {@code @Priority}. | ||
* The default is {@code Priorities.USER}. | ||
* </p> | ||
* @since 2.32 | ||
*/ | ||
// Must not be annotated with @Contract | ||
@Beta | ||
public interface ClientBuilderListener { | ||
void onNewBuilder(ClientBuilder builder); | ||
} |
61 changes: 61 additions & 0 deletions
61
core-client/src/test/java/org/glassfish/jersey/client/spi/ClientBuilderListenerTest.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,61 @@ | ||
/* | ||
* Copyright (c) 2020 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.client.spi; | ||
|
||
import org.glassfish.jersey.client.ClientConfig; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import javax.annotation.Priority; | ||
import javax.ws.rs.Priorities; | ||
import javax.ws.rs.client.Client; | ||
import javax.ws.rs.client.ClientBuilder; | ||
|
||
public class ClientBuilderListenerTest { | ||
|
||
public static final String PROPERTY_NAME = "ClientBuilderListenerProperty"; | ||
|
||
@Priority(Priorities.USER + 1000) | ||
public static class FirstClientBuilderListener implements ClientBuilderListener { | ||
@Override | ||
public void onNewBuilder(ClientBuilder builder) { | ||
builder.withConfig(new ClientConfig().property(PROPERTY_NAME, 60)); | ||
} | ||
} | ||
|
||
public static class SecondClientBuilderListener implements ClientBuilderListener { | ||
@Override | ||
public void onNewBuilder(ClientBuilder builder) { | ||
builder.withConfig(new ClientConfig().property(PROPERTY_NAME, 50)); | ||
} | ||
} | ||
|
||
@Priority(Priorities.USER + 2000) | ||
public static class ThirdClientBuilderListener implements ClientBuilderListener { | ||
@Override | ||
public void onNewBuilder(ClientBuilder builder) { | ||
builder.withConfig(new ClientConfig().property(PROPERTY_NAME, 70)); | ||
} | ||
} | ||
|
||
@Test | ||
public void testClientBuilderListener() { | ||
Client client = ClientBuilder.newClient(); | ||
Assert.assertEquals(70, client.getConfiguration().getProperty(PROPERTY_NAME)); | ||
} | ||
|
||
} |
3 changes: 3 additions & 0 deletions
3
...rc/test/resources/META-INF/services/org.glassfish.jersey.client.spi.ClientBuilderListener
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,3 @@ | ||
org.glassfish.jersey.client.spi.ClientBuilderListenerTest$ThirdClientBuilderListener | ||
org.glassfish.jersey.client.spi.ClientBuilderListenerTest$FirstClientBuilderListener | ||
org.glassfish.jersey.client.spi.ClientBuilderListenerTest$SecondClientBuilderListener |