Skip to content

Commit 7e87b02

Browse files
committed
Fixing observable behavior so that onerror and oncomplete are mutually exclusive, and adding license headers
1 parent 03bcb31 commit 7e87b02

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

extras/rxjava/src/main/java/org/asynchttpclient/extras/rxjava/AsyncHttpClientErrorException.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/*
2+
* Copyright (c) 2015 Target, Inc. All rights reserved.
3+
*
4+
* This program is licensed to you under the Apache License Version 2.0,
5+
* and you may not use this file except in compliance with the Apache License Version 2.0.
6+
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
7+
*
8+
* Unless required by applicable law or agreed to in writing,
9+
* software distributed under the Apache License Version 2.0 is distributed on an
10+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
12+
*/
113
package org.asynchttpclient.extras.rxjava;
214

315
/**

extras/rxjava/src/main/java/org/asynchttpclient/extras/rxjava/AsyncHttpObservable.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/*
2+
* Copyright (c) 2015 Target, Inc. All rights reserved.
3+
*
4+
* This program is licensed to you under the Apache License Version 2.0,
5+
* and you may not use this file except in compliance with the Apache License Version 2.0.
6+
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
7+
*
8+
* Unless required by applicable law or agreed to in writing,
9+
* software distributed under the Apache License Version 2.0 is distributed on an
10+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
12+
*/
113
package org.asynchttpclient.extras.rxjava;
214

315
import org.asynchttpclient.AsyncCompletionHandler;
@@ -59,8 +71,10 @@ public State onStatusReceived(HttpResponseStatus status) throws Exception {
5971

6072
@Override
6173
public Void onCompleted(Response response) throws Exception {
62-
subscriber.onNext(response);
63-
subscriber.onCompleted();
74+
if (!(abortOnErrorStatus && response.getStatusCode() >= 400)) {
75+
subscriber.onNext(response);
76+
subscriber.onCompleted();
77+
}
6478
return null;
6579
}
6680

extras/rxjava/src/test/java/org/asynchttpclient/extras/rxjava/AsyncHttpObservableTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/*
2+
* Copyright (c) 2015 Target, Inc. All rights reserved.
3+
*
4+
* This program is licensed to you under the Apache License Version 2.0,
5+
* and you may not use this file except in compliance with the Apache License Version 2.0.
6+
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
7+
*
8+
* Unless required by applicable law or agreed to in writing,
9+
* software distributed under the Apache License Version 2.0 is distributed on an
10+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
12+
*/
113
package org.asynchttpclient.extras.rxjava;
214

315
import org.asynchttpclient.AsyncHttpClient;
@@ -59,6 +71,7 @@ public BoundRequestBuilder call() {
5971
tester.awaitTerminalEvent();
6072
tester.assertTerminalEvent();
6173
tester.assertCompleted();
74+
tester.assertNoErrors();
6275
List<Response> responses = tester.getOnNextEvents();
6376
assertNotNull(responses);
6477
assertEquals(responses.size(), 1);
@@ -106,6 +119,7 @@ public BoundRequestBuilder call() {
106119
o1.subscribe(tester);
107120
tester.awaitTerminalEvent();
108121
tester.assertTerminalEvent();
122+
tester.assertNotCompleted();
109123
tester.assertError(AsyncHttpClientErrorException.class);
110124
List<Response> responses = tester.getOnNextEvents();
111125
assertNotNull(responses);
@@ -155,6 +169,7 @@ public BoundRequestBuilder call() {
155169
tester.awaitTerminalEvent();
156170
tester.assertTerminalEvent();
157171
tester.assertCompleted();
172+
tester.assertNoErrors();
158173
List<Response> responses = tester.getOnNextEvents();
159174
assertNotNull(responses);
160175
assertEquals(responses.size(), 1);
@@ -202,6 +217,7 @@ public BoundRequestBuilder call() {
202217
o1.subscribe(tester);
203218
tester.awaitTerminalEvent();
204219
tester.assertTerminalEvent();
220+
tester.assertNotCompleted();
205221
tester.assertError(AsyncHttpClientErrorException.class);
206222
List<Response> responses = tester.getOnNextEvents();
207223
assertNotNull(responses);

0 commit comments

Comments
 (0)