Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Commit 3264d8b

Browse files
author
Michal Gajdos
committed
GitHub Pull Request #88: Minor refactorings.
Change-Id: Iffd92f75efbc7118f4d2e52318a34e8dc4f3b298 Signed-off-by: Michal Gajdos <[email protected]>
1 parent 4dbe88a commit 3264d8b

File tree

2 files changed

+21
-31
lines changed

2 files changed

+21
-31
lines changed

connectors/apache-connector/src/main/java/org/glassfish/jersey/apache/connector/ApacheConnectorProvider.java

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2013-2014 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2013-2015 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -111,7 +111,7 @@
111111
public class ApacheConnectorProvider implements ConnectorProvider {
112112

113113
@Override
114-
public Connector getConnector(Client client, Configuration runtimeConfig) {
114+
public Connector getConnector(final Client client, final Configuration runtimeConfig) {
115115
return new ApacheConnector(runtimeConfig);
116116
}
117117

@@ -129,14 +129,8 @@ public Connector getConnector(Client client, Configuration runtimeConfig) {
129129
* is not configured to use a {@code ApacheConnectorProvider}.
130130
* @since 2.8
131131
*/
132-
public static HttpClient getHttpClient(Configurable<?> component) {
133-
Connector connector = getConnector(component);
134-
135-
if (connector instanceof ApacheConnector) {
136-
return ((ApacheConnector) connector).getHttpClient();
137-
}
138-
139-
throw new IllegalArgumentException(LocalizationMessages.EXPECTED_CONNECTOR_PROVIDER_NOT_USED());
132+
public static HttpClient getHttpClient(final Configurable<?> component) {
133+
return getConnector(component).getHttpClient();
140134
}
141135

142136
/**
@@ -147,23 +141,16 @@ public static HttpClient getHttpClient(Configurable<?> component) {
147141
* @param component {@code JerseyClient} or {@code JerseyWebTarget} instance that is configured to use
148142
* {@code ApacheConnectorProvider}.
149143
* @return underlying Apache {@code CookieStore} instance.
150-
*
151144
* @throws java.lang.IllegalArgumentException in case the {@code component} is neither {@code JerseyClient}
152145
* nor {@code JerseyWebTarget} instance or in case the component
153146
* is not configured to use a {@code ApacheConnectorProvider}.
154-
* @since 2.10
147+
* @since 2.16
155148
*/
156-
public static CookieStore getCookieStore(Configurable<?> component) {
157-
Connector connector = getConnector(component);
158-
159-
if (connector instanceof ApacheConnector) {
160-
return ((ApacheConnector) connector).getCookieStore();
161-
}
162-
163-
throw new IllegalArgumentException(LocalizationMessages.EXPECTED_CONNECTOR_PROVIDER_NOT_USED());
149+
public static CookieStore getCookieStore(final Configurable<?> component) {
150+
return getConnector(component).getCookieStore();
164151
}
165152

166-
private static Connector getConnector(Configurable<?> component) {
153+
private static ApacheConnector getConnector(final Configurable<?> component) {
167154
if (!(component instanceof Initializable)) {
168155
throw new IllegalArgumentException(
169156
LocalizationMessages.INVALID_CONFIGURABLE_COMPONENT_TYPE(component.getClass().getName()));
@@ -175,6 +162,11 @@ private static Connector getConnector(Configurable<?> component) {
175162
initializable.preInitialize();
176163
connector = initializable.getConfiguration().getConnector();
177164
}
178-
return connector;
165+
166+
if (connector instanceof ApacheConnector) {
167+
return (ApacheConnector) connector;
168+
} else {
169+
throw new IllegalArgumentException(LocalizationMessages.EXPECTED_CONNECTOR_PROVIDER_NOT_USED());
170+
}
179171
}
180172
}

connectors/apache-connector/src/test/java/org/glassfish/jersey/apache/connector/UnderlyingCookieStoreAccessTest.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2014-2015 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -39,14 +39,14 @@
3939
*/
4040
package org.glassfish.jersey.apache.connector;
4141

42-
import org.apache.http.client.CookieStore;
43-
import org.glassfish.jersey.client.ClientConfig;
44-
import org.junit.Test;
45-
4642
import javax.ws.rs.client.Client;
4743
import javax.ws.rs.client.ClientBuilder;
4844
import javax.ws.rs.client.WebTarget;
4945

46+
import org.glassfish.jersey.client.ClientConfig;
47+
48+
import org.apache.http.client.CookieStore;
49+
import org.junit.Test;
5050
import static org.junit.Assert.assertNotNull;
5151
import static org.junit.Assert.assertSame;
5252

@@ -69,9 +69,7 @@ public void testCookieStoreInstanceAccess() {
6969

7070
assertNotNull("CookieStore instance set on JerseyClient should not be null.", csOnClient);
7171
assertNotNull("CookieStore instance set on JerseyWebTarget should not be null.", csOnTarget);
72-
assertSame("CookieStore instance set on JerseyClient should be the same instance as the one set on JerseyWebTarget" +
73-
"(provided the target instance has not been further configured).",
74-
csOnClient, csOnTarget
75-
);
72+
assertSame("CookieStore instance set on JerseyClient should be the same instance as the one set on JerseyWebTarget"
73+
+ "(provided the target instance has not been further configured).", csOnClient, csOnTarget);
7674
}
7775
}

0 commit comments

Comments
 (0)