1111 *******************************************************************************/
1212package 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 .*;
1915import com .sun .jersey .api .client .ClientHandler ;
2016import com .sun .jersey .api .client .ClientHandlerException ;
2117import com .sun .jersey .api .client .ClientRequest ;
2218import 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 ;
2519import com .sun .jersey .core .header .InBoundHeaders ;
2620import 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
2824import javax .ws .rs .core .Context ;
2925import 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}
0 commit comments