Skip to content

Commit

Permalink
SapienzaBioHandler: now getStudentPhoto() is cringe
Browse files Browse the repository at this point in the history
  • Loading branch information
leosarra committed Jul 26, 2019
1 parent 4e8caf7 commit da2bf74
Showing 1 changed file with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import okhttp3.ResponseBody;
import okio.BufferedSink;
import okio.Okio;
import org.apache.commons.io.IOUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand All @@ -27,6 +28,8 @@
import java.io.IOException;
import java.io.OutputStream;
import java.net.SocketException;
import java.net.URL;
import java.net.URLConnection;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
Expand Down Expand Up @@ -263,15 +266,10 @@ public byte[] getStudentPhoto(Student student) throws OpenstudConnectionExceptio

private byte[] _getStudentPhoto(Student student) throws OpenstudInvalidResponseException, OpenstudConnectionException {
try {
Request req = new Request.Builder().url(String.format("%s/cartastudente/%s/foto?ingresso=%s", os.getEndpointAPI(), student.getStudentID(), os.getToken()))
.addHeader("Accept", "application/json, text/plain, */*")
.addHeader("Connection", "keep-alive").build();
Response resp = os.getClient().newCall(req).execute();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
BufferedSink bs = Okio.buffer(Okio.sink(outputStream));
bs.writeAll(resp.body().source());
bs.close();
return outputStream.toByteArray();
URL url = new URL(String.format("%s/cartastudente/%s/foto?ingresso=%s", os.getEndpointAPI(), student.getStudentID(), os.getToken()));
URLConnection conn = url.openConnection();
conn.setRequestProperty("User-Agent", "Firefox");
return IOUtils.toByteArray(conn.getInputStream());
} catch (IOException e) {
if (e instanceof SSLException || e.getMessage().contains("reset")) {
OpenstudInvalidResponseException invalidResponseException = new OpenstudInvalidResponseException(e);
Expand Down

0 comments on commit da2bf74

Please sign in to comment.