Skip to content
This repository was archived by the owner on Nov 23, 2022. It is now read-only.

Commit 668e680

Browse files
committed
Reformat, not functional changes
1 parent fa255c2 commit 668e680

File tree

2 files changed

+47
-52
lines changed

2 files changed

+47
-52
lines changed

src/main/java/org/sonatype/spice/jersey/client/ahc/AhcClientHandler.java

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,15 @@
1111
*******************************************************************************/
1212
package org.sonatype.spice.jersey.client.ahc;
1313

14-
import com.ning.http.client.AsyncHttpClient;
15-
import com.ning.http.client.Cookie;
16-
import com.ning.http.client.FluentCaseInsensitiveStringsMap;
17-
import com.ning.http.client.RequestBuilder;
18-
import com.ning.http.client.Response;
14+
import com.ning.http.client.*;
1915
import com.sun.jersey.api.client.ClientHandler;
2016
import com.sun.jersey.api.client.ClientHandlerException;
2117
import com.sun.jersey.api.client.ClientRequest;
2218
import com.sun.jersey.api.client.ClientResponse;
23-
import org.sonatype.spice.jersey.client.ahc.config.AhcConfig;
24-
import org.sonatype.spice.jersey.client.ahc.config.DefaultAhcConfig;
2519
import com.sun.jersey.core.header.InBoundHeaders;
2620
import com.sun.jersey.spi.MessageBodyWorkers;
21+
import org.sonatype.spice.jersey.client.ahc.config.AhcConfig;
22+
import org.sonatype.spice.jersey.client.ahc.config.DefaultAhcConfig;
2723

2824
import javax.ws.rs.core.Context;
2925
import java.util.ArrayList;
@@ -104,6 +100,7 @@ public AsyncHttpClient getHttpClient() {
104100

105101
/**
106102
* Translate the {@link ClientRequest} into a AsyncHttpClient request, and execute it.
103+
*
107104
* @param cr the HTTP request.
108105
* @return the {@link ClientResponse}
109106
* @throws ClientHandlerException
@@ -134,58 +131,59 @@ public ClientResponse handle(final ClientRequest cr)
134131
throw new ClientHandlerException(e);
135132
}
136133
}
137-
134+
138135
/**
139136
* append request cookies and override existing cookies
140-
*
137+
*
141138
* @param responseCookies list of cookies from response
142139
*/
143-
private void applyResponseCookies(List<Cookie> responseCookies){
144-
if ( responseCookies != null ){
145-
for ( Cookie rc : responseCookies ){
146-
// remove existing cookie
147-
Iterator<Cookie> it = cookies.iterator();
148-
while ( it.hasNext() ){
149-
Cookie c = it.next();
150-
if ( isSame(rc, c) )
151-
{
152-
it.remove();
153-
break;
140+
private void applyResponseCookies(List<Cookie> responseCookies) {
141+
if (responseCookies != null) {
142+
for (Cookie rc : responseCookies) {
143+
// remove existing cookie
144+
Iterator<Cookie> it = cookies.iterator();
145+
while (it.hasNext()) {
146+
Cookie c = it.next();
147+
if (isSame(rc, c)) {
148+
it.remove();
149+
break;
150+
}
151+
}
152+
// add new cookie
153+
cookies.add(rc);
154154
}
155-
}
156-
// add new cookie
157-
cookies.add(rc);
158155
}
159-
}
160156
}
161-
162-
private boolean isSame(Cookie c, Cookie o){
163-
return isEquals(c.getDomain(), o.getDomain()) &&
164-
isEquals(c.getPath(), o.getPath()) &&
165-
isEquals(c.getName(), o.getName());
157+
158+
private boolean isSame(Cookie c, Cookie o) {
159+
return isEquals(c.getDomain(), o.getDomain()) &&
160+
isEquals(c.getPath(), o.getPath()) &&
161+
isEquals(c.getName(), o.getName());
166162
}
167-
168-
private boolean isEquals( Object o, Object o2 ){
169-
return (o == null && o2 == null) || o != null && o.equals(o2);
163+
164+
private boolean isEquals(Object o, Object o2) {
165+
return (o == null && o2 == null) || o != null && o.equals(o2);
170166
}
171167

172168
/**
173169
* Check if a body needs to be constructed based on a method's name.
170+
*
174171
* @param method An HTTP method
175172
* @return true if s body can be allowed.
176173
*/
177174
private boolean allowBody(String method) {
178-
if ( method.equalsIgnoreCase("GET") || method.equalsIgnoreCase("OPTIONS")
179-
&& method.equalsIgnoreCase("TRACE")
180-
&& method.equalsIgnoreCase("HEAD")) {
175+
if (method.equalsIgnoreCase("GET") || method.equalsIgnoreCase("OPTIONS")
176+
&& method.equalsIgnoreCase("TRACE")
177+
&& method.equalsIgnoreCase("HEAD")) {
181178
return false;
182179
} else {
183180
return true;
184181
}
185182
}
186183

187184
/**
188-
* Return the {@link RequestBuilder} based on a method
185+
* Return the {@link RequestBuilder} based on a method
186+
*
189187
* @param cr the HTTP request.
190188
* @return {@link RequestBuilder}
191189
*/
@@ -222,9 +220,10 @@ private InBoundHeaders getInBoundHeaders(Response response) {
222220
/**
223221
* Return the instance of {@link com.sun.jersey.api.client.RequestWriter}. This instance will be injected
224222
* within Jersey so it cannot be null.
223+
*
225224
* @return the instance of {@link com.sun.jersey.api.client.RequestWriter}.
226225
*/
227-
public AhcRequestWriter getAhcRequestWriter(){
226+
public AhcRequestWriter getAhcRequestWriter() {
228227
return requestWriter;
229228
}
230229

@@ -233,5 +232,5 @@ private void handleCookie(RequestBuilder requestBuilder) {
233232
requestBuilder.addCookie(c);
234233
}
235234
}
236-
235+
237236
}

src/test/java/org/sonatype/spice/jersey/client/ahc/tests/tests/CookieTest.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,9 @@
5050
import javax.ws.rs.GET;
5151
import javax.ws.rs.POST;
5252
import javax.ws.rs.Path;
53-
import javax.ws.rs.core.Context;
54-
import javax.ws.rs.core.Cookie;
55-
import javax.ws.rs.core.HttpHeaders;
56-
import javax.ws.rs.core.NewCookie;
57-
import javax.ws.rs.core.Response;
53+
import javax.ws.rs.core.*;
5854

5955
/**
60-
*
6156
* @author Paul.Sandoz@Sun.Com
6257
*/
6358
public class CookieTest extends AbstractGrizzlyServerTester {
@@ -70,17 +65,18 @@ public Response get(@Context HttpHeaders h) {
7065
return Response.ok(e).
7166
cookie(new NewCookie("name", "value")).build();
7267
}
68+
7369
@POST
74-
public Response get(){
75-
// return response without cookie
76-
return Response.ok("wo-cookie").build();
70+
public Response get() {
71+
// return response without cookie
72+
return Response.ok("wo-cookie").build();
7773
}
7874
}
79-
75+
8076
public CookieTest(String testName) {
8177
super(testName);
8278
}
83-
79+
8480
public void testCookie() {
8581
ResourceConfig rc = new DefaultResourceConfig(CookieResource.class);
8682
rc.getProperties().put(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS,
@@ -111,13 +107,13 @@ public void testCookieWithState() {
111107
assertEquals("value", r.get(String.class));
112108

113109
}
114-
115-
public void testSessionCookie(){
110+
111+
public void testSessionCookie() {
116112
ResourceConfig rc = new DefaultResourceConfig(CookieResource.class);
117113
rc.getProperties().put(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS,
118114
LoggingFilter.class.getName());
119115
startServer(rc);
120-
116+
121117
DefaultAhcConfig config = new DefaultAhcConfig();
122118
AhcHttpClient c = AhcHttpClient.create(config);
123119

0 commit comments

Comments
 (0)