/** * Write a {@link HTTPTrackerErrorMessage} to the response with the given * HTTP status code. * * @param status The HTTP status code to return. * @param error The error reported by the tracker. */ private void serveError(Status status, HTTPTrackerErrorMessage error, RequestHandler requestHandler) throws IOException { requestHandler.serveResponse(status.getCode(), status.getDescription(), error.getData()); }
private void writeEmptyResponse(HTTPAnnounceRequestMessage announceRequest, RequestHandler requestHandler) throws IOException { HTTPAnnounceResponseMessage announceResponse; try { announceResponse = HTTPAnnounceResponseMessage.craft( myAnnounceInterval, 0, 0, Collections.<Peer>emptyList(), announceRequest.getHexInfoHash()); requestHandler.serveResponse(Status.OK.getCode(), Status.OK.getDescription(), announceResponse.getData()); } catch (Exception e) { serveError(Status.INTERNAL_SERVER_ERROR, e.getMessage(), requestHandler); } }
private void writeAnnounceResponse(TrackedTorrent torrent, Peer peer, boolean isSeeder, RequestHandler requestHandler) throws IOException { HTTPAnnounceResponseMessage announceResponse; try { announceResponse = HTTPAnnounceResponseMessage.craft( isSeeder ? SEEDER_ANNOUNCE_INTERVAL : myAnnounceInterval, torrent.seeders(), torrent.leechers(), isSeeder ? Collections.<Peer>emptyList() : torrent.getSomePeers(peer), torrent.getHexInfoHash()); requestHandler.serveResponse(Status.OK.getCode(), Status.OK.getDescription(), announceResponse.getData()); } catch (Exception e) { serveError(Status.INTERNAL_SERVER_ERROR, e.getMessage(), requestHandler); } }
@Override public OutputStream writeResponseStatusAndHeaders(final long contentLength, final ContainerResponse context) throws ContainerException { final javax.ws.rs.core.Response.StatusType statusInfo = context.getStatusInfo(); final int code = statusInfo.getStatusCode(); final String reason = statusInfo.getReasonPhrase() == null ? Status.getDescription(code) : statusInfo.getReasonPhrase(); response.setCode(code); response.setDescription(reason); if (contentLength != -1) { response.setContentLength(contentLength); } for (final Map.Entry<String, List<String>> e : context.getStringHeaders().entrySet()) { for (final String value : e.getValue()) { response.addValue(e.getKey(), value); } } try { return response.getOutputStream(); } catch (final IOException ioe) { throw new ContainerException("Error during writing out the response headers.", ioe); } }
public void setStatus(Status status) { this.code = status.getCode(); this.text = status.getDescription(); } }
public void setStatus(Status status) { this.code = status.getCode(); this.text.text = status.getDescription(); }
public OutputStream writeStatusAndHeaders(long contentLength, ContainerResponse cResponse) throws IOException { int code = cResponse.getStatus(); String text = Status.getDescription(code); String method = request.getMethod(); response.setCode(code); response.setDescription(text); if (!method.equalsIgnoreCase("HEAD") && contentLength != -1 && contentLength < Integer.MAX_VALUE) { response.setContentLength((int) contentLength); } for (Map.Entry<String, List<Object>> e : cResponse.getHttpHeaders().entrySet()) { for (Object value : e.getValue()) { response.setValue(e.getKey(), ContainerResponse.getHeaderValue(value)); } } return response.getOutputStream(); }
@Override public OutputStream writeResponseStatusAndHeaders(final long contentLength, final ContainerResponse context) throws ContainerException { final javax.ws.rs.core.Response.StatusType statusInfo = context.getStatusInfo(); final int code = statusInfo.getStatusCode(); final String reason = statusInfo.getReasonPhrase() == null ? Status.getDescription(code) : statusInfo.getReasonPhrase(); response.setCode(code); response.setDescription(reason); if (contentLength != -1) { response.setContentLength(contentLength); } for (final Map.Entry<String, List<String>> e : context.getStringHeaders().entrySet()) { for (final String value : e.getValue()) { response.addValue(e.getKey(), value); } } try { return response.getOutputStream(); } catch (final IOException ioe) { throw new ContainerException("Error during writing out the response headers.", ioe); } }