|
1 | 1 | /* |
2 | 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
3 | 3 | * |
4 | | - * Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. |
| 4 | + * Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved. |
5 | 5 | * |
6 | 6 | * The contents of this file are subject to the terms of either the GNU |
7 | 7 | * General Public License Version 2 only ("GPL") or the Common Development |
|
37 | 37 | * only if the new code is made subject to such option by the copyright |
38 | 38 | * holder. |
39 | 39 | */ |
40 | | - |
41 | 40 | package org.glassfish.jersey.jdk.connector; |
42 | 41 |
|
43 | 42 | import java.net.CookiePolicy; |
| 43 | +import java.util.Map; |
44 | 44 |
|
45 | | -import javax.ws.rs.client.Client; |
46 | | -import javax.ws.rs.core.Configuration; |
47 | | - |
48 | | -import org.glassfish.jersey.client.spi.Connector; |
49 | | -import org.glassfish.jersey.client.spi.ConnectorProvider; |
| 45 | +import org.glassfish.jersey.internal.util.PropertiesClass; |
| 46 | +import org.glassfish.jersey.internal.util.PropertiesHelper; |
50 | 47 |
|
51 | 48 | /** |
52 | | - * @author Petr Janouch (petr.janouch at oracle.com) |
| 49 | + * Configuration options specific to {@link org.glassfish.jersey.jdk.connector.internal.JdkConnector}. |
| 50 | + * |
| 51 | + * @author Adam Lindenthal (adam.lindenthal at oracle.com) |
53 | 52 | */ |
54 | | -public class JdkConnectorProvider implements ConnectorProvider { |
| 53 | +@PropertiesClass |
| 54 | +public final class JdkConnectorProperties { |
55 | 55 |
|
56 | 56 | /** |
57 | 57 | * Configuration of the connector thread pool. |
58 | 58 | * <p/> |
59 | | - * An instance of {@link ThreadPoolConfig} is expected. |
| 59 | + * An instance of {@link org.glassfish.jersey.jdk.connector.internal.ThreadPoolConfig} is expected. |
60 | 60 | */ |
61 | 61 | public static final String WORKER_THREAD_POOL_CONFIG = "jersey.config.client.JdkConnectorProvider.workerThreadPoolConfig"; |
62 | 62 |
|
@@ -86,7 +86,7 @@ public class JdkConnectorProvider implements ConnectorProvider { |
86 | 86 | * otherwise {@code MAX_HEADER_SIZE} is not applied. |
87 | 87 | * |
88 | 88 | * @see org.glassfish.jersey.client.ClientProperties#FOLLOW_REDIRECTS |
89 | | - * @see RedirectException |
| 89 | + * @see org.glassfish.jersey.jdk.connector.internal.RedirectException |
90 | 90 | */ |
91 | 91 | public static final String MAX_REDIRECTS = "jersey.config.client.JdkConnectorProvider.maxRedirects"; |
92 | 92 |
|
@@ -119,16 +119,53 @@ public class JdkConnectorProvider implements ConnectorProvider { |
119 | 119 | */ |
120 | 120 | public static final String CONNECTION_IDLE_TIMEOUT = "jersey.config.client.JdkConnectorProvider.connectionIdleTimeout"; |
121 | 121 |
|
122 | | - static final int DEFAULT_HTTP_CHUNK_SIZE = 4096; |
123 | | - static final int DEFAULT_MAX_HEADER_SIZE = 8192; |
124 | | - static final int DEFAULT_MAX_REDIRECTS = 5; |
125 | | - static final CookiePolicy DEFAULT_COOKIE_POLICY = CookiePolicy.ACCEPT_ORIGINAL_SERVER; |
126 | | - static final int DEFAULT_MAX_CONNECTIONS_PER_DESTINATION = 20; |
127 | | - static final int DEFAULT_CONNECTION_IDLE_TIMEOUT = 1000000; |
128 | | - static final int DEFAULT_CONNECTION_CLOSE_WAIT = 30_000; |
129 | | - |
130 | | - @Override |
131 | | - public Connector getConnector(Client client, Configuration config) { |
132 | | - return new JdkConnector(client, config); |
| 122 | + /** |
| 123 | + * Default value for the {@link org.glassfish.jersey.client.ClientProperties#CHUNKED_ENCODING_SIZE} property. |
| 124 | + */ |
| 125 | + public static final int DEFAULT_HTTP_CHUNK_SIZE = 4096; |
| 126 | + |
| 127 | + /** |
| 128 | + * Default value for the {@link #MAX_HEADER_SIZE} property. |
| 129 | + */ |
| 130 | + public static final int DEFAULT_MAX_HEADER_SIZE = 8192; |
| 131 | + |
| 132 | + /** |
| 133 | + * Default value for the {@link #MAX_REDIRECTS} property. |
| 134 | + */ |
| 135 | + public static final int DEFAULT_MAX_REDIRECTS = 5; |
| 136 | + |
| 137 | + /** |
| 138 | + * Default value for the {@link #COOKIE_POLICY} property. |
| 139 | + */ |
| 140 | + public static final CookiePolicy DEFAULT_COOKIE_POLICY = CookiePolicy.ACCEPT_ORIGINAL_SERVER; |
| 141 | + |
| 142 | + /** |
| 143 | + * Default value for the {@link #MAX_CONNECTIONS_PER_DESTINATION} property. |
| 144 | + */ |
| 145 | + public static final int DEFAULT_MAX_CONNECTIONS_PER_DESTINATION = 20; |
| 146 | + |
| 147 | + /** |
| 148 | + * Default value for the {@link #CONNECTION_IDLE_TIMEOUT} property. |
| 149 | + */ |
| 150 | + public static final int DEFAULT_CONNECTION_IDLE_TIMEOUT = 1000000; |
| 151 | + |
| 152 | + /** |
| 153 | + * Default value for the {@link #CONTAINER_IDLE_TIMEOUT} property. |
| 154 | + */ |
| 155 | + public static final int DEFAULT_CONNECTION_CLOSE_WAIT = 30_000; |
| 156 | + |
| 157 | + public static <T> T getValue(final Map<String, ?> properties, final String key, final Class<T> type) { |
| 158 | + return PropertiesHelper.getValue(properties, key, type, null); |
| 159 | + } |
| 160 | + |
| 161 | + public static <T> T getValue(final Map<String, ?> properties, final String key, T defaultValue, final Class<T> type) { |
| 162 | + return PropertiesHelper.getValue(properties, key, defaultValue, type, null); |
| 163 | + } |
| 164 | + |
| 165 | + /** |
| 166 | + * Prevents instantiation. |
| 167 | + */ |
| 168 | + private JdkConnectorProperties() { |
| 169 | + throw new AssertionError("No instances allowed."); |
133 | 170 | } |
134 | 171 | } |
0 commit comments