protected HttpMessage parseHead( final SessionInputBuffer sessionBuffer) throws IOException, HttpException, ParseException { this.lineBuf.clear(); int i = sessionBuffer.readLine(this.lineBuf); if (i == -1) { throw new NoHttpResponseException("The target server failed to respond"); } //create the status line from the status string ParserCursor cursor = new ParserCursor(0, this.lineBuf.length()); StatusLine statusline = lineParser.parseStatusLine(this.lineBuf, cursor); return this.responseFactory.newHttpResponse(statusline, null); }
super(buffer, parser, responseFactory, params); this.icyLineBuf = new CharArrayBuffer(128); icyResponseFactory = responseFactory; final int i = sessionBuffer.readLine(this.icyLineBuf); String tmp = icyLineBuf.substring(0, this.icyLineBuf.length()); if(tmp.contains("ICY ")){ tmp = tmp.replace("ICY", "HTTP/1.0"); this.icyLineBuf = new CharArrayBuffer(128); System.arraycopy(tmp.toCharArray(), 0, icyLineBuf.buffer(), 0, tmp.length()); icyLineBuf.setLength( tmp.length()); throw new NoHttpResponseException("The target server failed to respond");
final NoHttpResponseException updatedex = new NoHttpResponseException( route.getTargetHost().toHostString() + " failed to respond"); updatedex.setStackTrace(ex.getStackTrace()); throw updatedex; } else {
/** * Validate the given response as contained in the HttpPost object, * throwing an exception if it does not correspond to a successful HTTP response. * <p>Default implementation rejects any HTTP status code beyond 2xx, to avoid * parsing the response body and trying to deserialize from a corrupted stream. * @param config the HTTP invoker configuration that specifies the target service * @param response the resulting HttpResponse to validate * @throws java.io.IOException if validation failed */ protected void validateResponse(HttpInvokerClientConfiguration config, HttpResponse response) throws IOException { StatusLine status = response.getStatusLine(); if (status.getStatusCode() >= 300) { throw new NoHttpResponseException( "Did not receive successful HTTP response: status code = " + status.getStatusCode() + ", status message = [" + status.getReasonPhrase() + "]"); } }
/** * Method that captures all the {@link ServerErrorException} exceptions. * * @param response * {@link HttpServletResponse} * @param request * {@link HttpServletRequest} * @param exception * {@link Exception} * @return {@link ErroInfo}. */ @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) @ExceptionHandler(NoHttpResponseException.class) public @ResponseBody ErroInfo noHttpResponseExceptionServerError(HttpServletResponse response, HttpServletRequest request, NoHttpResponseException exception) { ErroInfo erroInfo = buildErrorInfoException(request, exception); log.error(exception.getMessage(), exception); return erroInfo; }
public CloseableHttpResponse getResponse(HttpRequestBase request,Proxy proxy) { request.setHeader("User-Agent", Constant.userAgentArray[new Random().nextInt(Constant.userAgentArray.length)]); HttpClientContext httpClientContext = HttpClientContext.create(); CloseableHttpResponse response = null; try { if (proxy == null) { response = createHttpClient().execute(request, httpClientContext); } else { response = createHttpClient(20000, proxy.toHttpHost(),null).execute(request, httpClientContext); } } catch (NoHttpResponseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return response; }
final NoHttpResponseException updatedex = new NoHttpResponseException( route.getTargetHost().toHostString() + " failed to respond"); updatedex.setStackTrace(ex.getStackTrace()); throw updatedex; } else {
/** * Validate the given response as contained in the HttpPost object, * throwing an exception if it does not correspond to a successful HTTP response. * <p>Default implementation rejects any HTTP status code beyond 2xx, to avoid * parsing the response body and trying to deserialize from a corrupted stream. * @param config the HTTP invoker configuration that specifies the target service * @param response the resulting HttpResponse to validate * @throws java.io.IOException if validation failed */ protected void validateResponse(HttpInvokerClientConfiguration config, HttpResponse response) throws IOException { StatusLine status = response.getStatusLine(); if (status.getStatusCode() >= 300) { throw new NoHttpResponseException( "Did not receive successful HTTP response: status code = " + status.getStatusCode() + ", status message = [" + status.getReasonPhrase() + "]"); } }
/** * Method that captures all the {@link ServerErrorException} exceptions. * * @param response * {@link HttpServletResponse} * @param request * {@link HttpServletRequest} * @param exception * {@link Exception} * @return {@link ErroInfo} */ @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) @ExceptionHandler(NoHttpResponseException.class) public @ResponseBody ErroInfo noHttpResponseExceptionServerError(HttpServletResponse response, HttpServletRequest request, NoHttpResponseException exception) { ErroInfo erroInfo = buildErrorInfoException(request, exception); log.error(exception.getMessage(), exception); return erroInfo; }
@Override protected HttpMessage parseHead( final SessionInputBuffer sessionBuffer) throws IOException, HttpException { // clear the buffer this.lineBuf.clear(); //read out the HTTP status string int count = 0; ParserCursor cursor = null; do { int i = sessionBuffer.readLine(this.lineBuf); if (i == -1 && count == 0) { // The server just dropped connection on us throw new NoHttpResponseException("The target server failed to respond"); } cursor = new ParserCursor(0, this.lineBuf.length()); if (lineParser.hasProtocolVersion(this.lineBuf, cursor)) { // Got one break; } else if (i == -1 || count >= this.maxGarbageLines) { // Giving up throw new ProtocolException("The server failed to respond with a " + "valid HTTP response"); } count++; } while(true); //create the status line from the status string StatusLine statusline = lineParser.parseStatusLine(this.lineBuf, cursor); return this.responseFactory.newHttpResponse(statusline, null); }
final NoHttpResponseException updatedex = new NoHttpResponseException( route.getTargetHost().toHostString() + " failed to respond"); updatedex.setStackTrace(ex.getStackTrace()); throw updatedex; } else {
private void validateResponse(HttpResponse response) throws IOException { StatusLine status = response.getStatusLine(); if (status.getStatusCode() == 403) { String messagePrefix = "The server returned status code 403. Possible reasons include:"; List<String> reasons = Arrays.asList( "This agent has been deleted from the configuration", "This agent is pending approval", "There is possibly a reverse proxy (or load balancer) that is terminating SSL. Hint: use port 8154 of the GoCD server. See " + docsUrl("/installation/configure-reverse-proxy.html#agents-and-reverse-proxies") + " for details." ); String delimiter = "\n - "; throw new ClientProtocolException(messagePrefix + delimiter + String.join(delimiter, reasons)); } if (status.getStatusCode() >= 300) { throw new NoHttpResponseException("Did not receive successful HTTP response: status code = " + status.getStatusCode() + ", status message = [" + status.getReasonPhrase() + "]"); } } }
/** * Method that captures all the {@link ServerErrorException} exceptions. * * @param response * {@link HttpServletResponse} * @param request * {@link HttpServletRequest} * @param exception * {@link Exception} * @return {@link ErroInfo} */ @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) @ExceptionHandler(CircuitBreakerException.class) public @ResponseBody ErroInfo handleCircuitBreakerException(HttpServletResponse response, HttpServletRequest request, NoHttpResponseException exception) { ErroInfo erroInfo = buildErrorInfo(request, exception); log.error(exception.getMessage(), exception); return erroInfo; }
protected HttpMessage parseHead( final SessionInputBuffer sessionBuffer) throws IOException, HttpException, ParseException { this.lineBuf.clear(); int i = sessionBuffer.readLine(this.lineBuf); if (i == -1) { throw new NoHttpResponseException("The target server failed to respond"); } //create the status line from the status string ParserCursor cursor = new ParserCursor(0, this.lineBuf.length()); StatusLine statusline = lineParser.parseStatusLine(this.lineBuf, cursor); return this.responseFactory.newHttpResponse(statusline, null); }
final NoHttpResponseException updatedex = new NoHttpResponseException( route.getTargetHost().toHostString() + " failed to respond"); updatedex.setStackTrace(ex.getStackTrace()); throw updatedex; } else {
@Override public CloseableHttpResponse answer(InvocationOnMock invocation) throws Throwable { iteration++; if (1 == iteration) { throw new NoHttpResponseException("The server didn't respond!"); } else { return goodResponse; } } };
@Override protected HttpMessage parseHead( final SessionInputBuffer sessionBuffer) throws IOException, HttpException, ParseException { this.lineBuf.clear(); final int i = sessionBuffer.readLine(this.lineBuf); if (i == -1) { throw new NoHttpResponseException("The target server failed to respond"); } //create the status line from the status string final ParserCursor cursor = new ParserCursor(0, this.lineBuf.length()); final StatusLine statusline = lineParser.parseStatusLine(this.lineBuf, cursor); return this.responseFactory.newHttpResponse(statusline, null); }
final NoHttpResponseException updatedex = new NoHttpResponseException( route.getTargetHost().toHostString() + " failed to respond"); updatedex.setStackTrace(ex.getStackTrace()); throw updatedex; } else {
@Override public CloseableHttpResponse answer(InvocationOnMock invocation) throws Throwable { iteration++; if (1 == iteration) { throw new NoHttpResponseException("The server didn't respond!"); } else { return goodResponse; } } };
@Override protected HttpResponse parseHead( final SessionInputBuffer sessionBuffer) throws IOException, HttpException, ParseException { this.lineBuf.clear(); final int i = sessionBuffer.readLine(this.lineBuf); if (i == -1) { throw new NoHttpResponseException("The target server failed to respond"); } //create the status line from the status string final ParserCursor cursor = new ParserCursor(0, this.lineBuf.length()); final StatusLine statusline = lineParser.parseStatusLine(this.lineBuf, cursor); return this.responseFactory.newHttpResponse(statusline, null); }