-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
src/main/java/de/taimos/httputils/callbacks/HTTPByteCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package de.taimos.httputils.callbacks; | ||
|
||
import org.apache.http.HttpResponse; | ||
|
||
import de.taimos.httputils.WS; | ||
|
||
public abstract class HTTPByteCallback extends HTTPStatusCheckCallback { | ||
|
||
@Override | ||
protected void checkedResponse(HttpResponse response) { | ||
this.byteResponse(WS.getResponseAsBytes(response), response); | ||
} | ||
|
||
protected abstract void byteResponse(byte[] body, HttpResponse response); | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/de/taimos/httputils/callbacks/HTTPStatusCheckCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package de.taimos.httputils.callbacks; | ||
|
||
import org.apache.http.HttpResponse; | ||
|
||
import de.taimos.httputils.HTTPResponseCallback; | ||
|
||
public abstract class HTTPStatusCheckCallback implements HTTPResponseCallback { | ||
|
||
@Override | ||
public final void response(HttpResponse response) { | ||
int statusCode = response.getStatusLine().getStatusCode(); | ||
if (statusCode != this.expectedStatus()) { | ||
this.invalidStatus(statusCode, response); | ||
} | ||
this.checkedResponse(response); | ||
} | ||
|
||
protected abstract void checkedResponse(HttpResponse response); | ||
|
||
protected abstract void invalidStatus(int status, HttpResponse response); | ||
|
||
/** | ||
* @return the expected status code of the {@link HttpResponse} | ||
*/ | ||
protected int expectedStatus() { | ||
return 200; | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/de/taimos/httputils/callbacks/HTTPStringCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package de.taimos.httputils.callbacks; | ||
|
||
import org.apache.http.HttpResponse; | ||
|
||
import de.taimos.httputils.WS; | ||
|
||
public abstract class HTTPStringCallback extends HTTPStatusCheckCallback { | ||
|
||
@Override | ||
protected void checkedResponse(HttpResponse response) { | ||
this.stringResponse(WS.getResponseAsString(response), response); | ||
} | ||
|
||
protected abstract void stringResponse(String body, HttpResponse response); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters