private ContentResponse response(byte[] content) { return new HttpContentResponse(null, content, ANY_TYPE.type(), UTF_8.name()); }
@Override public String toString() { return String.format("%s[%s %d %s - %d bytes]", HttpContentResponse.class.getSimpleName(), getVersion(), getStatus(), getReason(), getContent().length); } }
@Before public void setup() throws InterruptedException, ExecutionException, TimeoutException { when(loadBalancer.getHealthyInstance()).thenReturn(createServiceEndpoint()); when(loadBalancer.getHealthyInstanceExclude(anyListOf(ServiceEndpoint.class))) .thenReturn(createServiceEndpoint()); when(rpcClient.getRetries()).thenReturn(NUMBER_OF_RETRIES); when(rpcClient.getTimeout()).thenReturn(0); httpClientWrapper.setLoadBalancer(loadBalancer); when(rpcClientMetrics.getMethodTimer(any(), any())).thenReturn(new GoTimer("timer")); when(tracer.buildSpan(any())).thenReturn(spanBuilder); when(spanBuilder.start()).thenReturn(span); when(httpClient.newRequest(any(URI.class))).thenReturn(request); when(httpClient.newRequest(any(String.class))).thenReturn(request); when(request.content(any(ContentProvider.class))).thenReturn(request); when(request.method(anyString())).thenReturn(request); when(request.timeout(anyLong(), any(TimeUnit.class))).thenReturn(request); when(request.send()).thenReturn(httpContentResponse); when(httpContentResponse.getStatus()).thenReturn(100); dependencyHealthCheck = mock(ServiceDependencyHealthCheck.class); }
@Override public String getContentAsString() { String encoding = this.encoding; if (encoding == null) { return new String(getContent(), StandardCharsets.UTF_8); } else { try { return new String(getContent(), encoding); } catch (UnsupportedEncodingException e) { throw new UnsupportedCharsetException(encoding); } } }
LOG.warn("Error: Failed to submit nonce to pool: " + httpContentResponse.getContentAsString());
@Override public String getContentAsString() { String encoding = this.encoding; try { return new String(getContent(), encoding == null ? "UTF-8" : encoding); } catch (UnsupportedEncodingException e) { throw new UnsupportedCharsetException(encoding); } }
@Override public String toString() { return String.format("%s[%s %d %s - %d bytes]", HttpContentResponse.class.getSimpleName(), getVersion(), getStatus(), getReason(), getContent().length); } }
@Override public void onComplete(Result result) { resultRef.set(new Result(result.getRequest(), result.getRequestFailure(), new HttpContentResponse(result.getResponse(), getContent(), getMediaType(), getEncoding()), result.getResponseFailure())); latch.countDown(); } });
@Override public String getContentAsString() { String encoding = this.encoding; try { return new String(getContent(), encoding == null ? "UTF-8" : encoding); } catch (UnsupportedEncodingException e) { throw new UnsupportedCharsetException(encoding); } }
@Override public String toString() { return String.format("%s[%s %d %s - %d bytes]", HttpContentResponse.class.getSimpleName(), getVersion(), getStatus(), getReason(), getContent().length); } }
@Override public void onComplete(Result result) { response = new HttpContentResponse(result.getResponse(), getContent(), getEncoding()); failure = result.getFailure(); latch.countDown(); }
@Override public void onComplete(Result result) { response = new HttpContentResponse(result.getResponse(), getContent(), getEncoding()); failure = result.getFailure(); latch.countDown(); }
@Override public void onComplete(Result result) { response = new HttpContentResponse(result.getResponse(), getContent(), getMediaType(), getEncoding()); failure = result.getFailure(); latch.countDown(); }
@Override public void onFailure(Response response, Throwable failure) { HttpConversation conversation = client.getConversation(response.getConversationID(), false); // Mark the 100 Continue response as handled conversation.setAttribute(ATTRIBUTE, Boolean.TRUE); // Reset the conversation listeners to allow the conversation to be completed conversation.updateResponseListeners(null); HttpExchange exchange = conversation.getExchanges().peekLast(); assert exchange.getResponse() == response; List<Response.ResponseListener> listeners = exchange.getResponseListeners(); HttpContentResponse contentResponse = new HttpContentResponse(response, getContent(), getEncoding()); notifier.forwardFailureComplete(listeners, exchange.getRequest(), exchange.getRequestFailure(), contentResponse, failure); }
@Override public void onFailure(Response response, Throwable failure) { HttpConversation conversation = client.getConversation(response.getConversationID(), false); // Mark the 100 Continue response as handled conversation.setAttribute(ATTRIBUTE, Boolean.TRUE); // Reset the conversation listeners to allow the conversation to be completed conversation.updateResponseListeners(null); HttpExchange exchange = conversation.getExchanges().peekLast(); assert exchange.getResponse() == response; List<Response.ResponseListener> listeners = exchange.getResponseListeners(); HttpContentResponse contentResponse = new HttpContentResponse(response, getContent(), getEncoding()); notifier.forwardFailureComplete(listeners, exchange.getRequest(), exchange.getRequestFailure(), contentResponse, failure); }
@Override public void onFailure(Response response, Throwable failure) { HttpConversation conversation = ((HttpRequest)response.getRequest()).getConversation(); // Mark the 100 Continue response as handled conversation.setAttribute(ATTRIBUTE, Boolean.TRUE); // Reset the conversation listeners to allow the conversation to be completed conversation.updateResponseListeners(null); HttpExchange exchange = conversation.getExchanges().peekLast(); assert exchange.getResponse() == response; List<Response.ResponseListener> listeners = exchange.getResponseListeners(); HttpContentResponse contentResponse = new HttpContentResponse(response, getContent(), getMediaType(), getEncoding()); notifier.forwardFailureComplete(listeners, exchange.getRequest(), exchange.getRequestFailure(), contentResponse, failure); }
response = new HttpContentResponse(response,content,null, getEncoding());
HttpContentResponse contentResponse = new HttpContentResponse(response, getContent(), getEncoding()); notifier.forwardSuccess(listeners, contentResponse); exchange.proceed(false);
HttpContentResponse contentResponse = new HttpContentResponse(response, getContent(), getEncoding()); notifier.forwardSuccess(listeners, contentResponse); exchange.proceed(false);
@Override public void onSuccess(Response response) { // Handling of success must be done here and not from onComplete(), // since the onComplete() is not invoked because the request is not completed yet. Request request = response.getRequest(); HttpConversation conversation = ((HttpRequest)request).getConversation(); // Mark the 100 Continue response as handled request.attribute(ATTRIBUTE, Boolean.TRUE); // Reset the conversation listeners, since we are going to receive another response code conversation.updateResponseListeners(null); HttpExchange exchange = conversation.getExchanges().peekLast(); if (response.getStatus() == HttpStatus.CONTINUE_100) { // All good, continue. exchange.resetResponse(); exchange.proceed(null); onContinue(request); } else { // Server either does not support 100 Continue, // or it does and wants to refuse the request content, // or we got some other HTTP status code like a redirect. List<Response.ResponseListener> listeners = exchange.getResponseListeners(); HttpContentResponse contentResponse = new HttpContentResponse(response, getContent(), getMediaType(), getEncoding()); notifier.forwardSuccess(listeners, contentResponse); exchange.proceed(new HttpRequestException("Expectation failed", request)); } }