I created a small service that receives images from an Android device and saves them in Buzz Amazon S3. The code is pretty simple, but it is very slow. This happens as follows:
public synchronized static Response postCommentPicture(Response response, Request request){
JsonObject ret = new JsonObject();
OutputStream outputStream;
String meepId = request.params(":id");
System.out.println("1");
if(meepId == null){
ret.addProperty("Error", "Missing meep id");
response.body(ret.getAsString());
return response;
}
try {
System.out.println("2");
Map<String, String> urlData = Utils.splitQuery(request.queryString());
if(!urlData.containsKey("senderName") || !urlData.containsKey("senderId"))
throw new Exception("senderName or senderId missing");
System.out.println("3");
MultipartConfigElement multipartConfigElement = new MultipartConfigElement("/temp");
System.out.println("3.1");
request.raw().setAttribute("org.eclipse.jetty.multipartConfig", multipartConfigElement);
System.out.println("3.2");
Collection<Part> files = request.raw().getParts();
System.out.println("3.3");
if(files.size() == 0 || files.size() > 1){
throw new Exception("No files or more than 1 file detected");
}
} catch (Exception e2){
System.out.println(e2.getMessage());
ret.addProperty("Error", e2.getMessage());
} finally {
response.body(ret.toString());
return response;
}
So, as you can see, I print magazines at certain stages. The code runs smoothly to "3.2", where it begins to transfer the file from the client device. Thus, it takes some time to complete the transfer, but after the download is complete (as I can say using Android Studio Network Monitor) the server takes 3 o for another 4 minutes before it processes the next line and prints β3.3β. The rest of the code runs smoothly and I can finally get a client-side response.
, : request.raw().getParts()
6 , .