@Test public void testFail_With_400() throws Exception { GenericCommand<String> command = getCommand("http: try { command.run(); } catch (Exception e) { assertThat(e.getCause(), is(lastException)); assertThat(lastException, isA(TDPException.class)); assertThat(lastException.getCode().getCode(), is(BaseErrorCodes.MISSING_ACTION_SCOPE.getCode())); assertThat(lastException.getCode().getHttpStatus(), is(400)); } }
@Override protected T run() throws Exception { final HttpRequestBase request = httpCall.get(); addCommandHeaders(request); addAuthorizationHeaders(request); addLocaleHeaders(request); final Span requestSpan = addTrackingHeaders(request); try { final HttpResponse response; try { LOGGER.trace("Requesting {} {}", request.getMethod(), request.getURI()); response = client.execute(request); } catch (Exception e) { throw onError.apply(e); } commandResponseHeaders = response.getAllHeaders(); status = HttpStatus.valueOf(response.getStatusLine().getStatusCode()); Header cookies = response.getFirstHeader("Set-Cookie"); if (cookies != null) { LOGGER.warn( "request {} {}: Cookie detected in responseHeaders (check security.oauth2.resource.uri settings)", request.getMethod(), request.getURI()); } BiFunction<HttpRequestBase, HttpResponse, T> function = behavior.get(status); if (function != null) { try { return function.apply(request, response); } catch (Exception e) { throw onError.apply(e); } } if (status.is4xxClientError() || status.is5xxServerError()) { LOGGER.debug("request {} {} : response on error {}", request.getMethod(), request.getURI(), response.getStatusLine()); return callOnError(onError).apply(request, response); } else { return behavior.getOrDefault(status, missingBehavior()).apply(request, response); } } finally { tracer.close(requestSpan); } }
GenericCommand extends HystrixCommand<T> { @Override protected T run() throws Exception { final HttpRequestBase request = httpCall.get(); addCommandHeaders(request); addAuthorizationHeaders(request); addLocaleHeaders(request); final Span requestSpan = addTrackingHeaders(request); try { final HttpResponse response; try { LOGGER.trace("Requesting {} {}", request.getMethod(), request.getURI()); response = client.execute(request); } catch (Exception e) { throw onError.apply(e); } commandResponseHeaders = response.getAllHeaders(); status = HttpStatus.valueOf(response.getStatusLine().getStatusCode()); Header cookies = response.getFirstHeader("Set-Cookie"); if (cookies != null) { LOGGER.warn( "request {} {}: Cookie detected in responseHeaders (check security.oauth2.resource.uri settings)", request.getMethod(), request.getURI()); } BiFunction<HttpRequestBase, HttpResponse, T> function = behavior.get(status); if (function != null) { try { return function.apply(request, response); } catch (Exception e) { throw onError.apply(e); } } if (status.is4xxClientError() || status.is5xxServerError()) { LOGGER.debug("request {} {} : response on error {}", request.getMethod(), request.getURI(), response.getStatusLine()); return callOnError(onError).apply(request, response); } else { return behavior.getOrDefault(status, missingBehavior()).apply(request, response); } } finally { tracer.close(requestSpan); } } }
GenericCommand extends HystrixCommand<T> { @Override protected T run() throws Exception { final HttpRequestBase request = httpCall.get(); addCommandHeaders(request); addAuthorizationHeaders(request); addLocaleHeaders(request); final Span requestSpan = addTrackingHeaders(request); try { final HttpResponse response; try { LOGGER.trace("Requesting {} {}", request.getMethod(), request.getURI()); response = client.execute(request); } catch (Exception e) { throw onError.apply(e); } commandResponseHeaders = response.getAllHeaders(); status = HttpStatus.valueOf(response.getStatusLine().getStatusCode()); Header cookies = response.getFirstHeader("Set-Cookie"); if (cookies != null) { LOGGER.warn( "request {} {}: Cookie detected in responseHeaders (check security.oauth2.resource.uri settings)", request.getMethod(), request.getURI()); } BiFunction<HttpRequestBase, HttpResponse, T> function = behavior.get(status); if (function != null) { try { return function.apply(request, response); } catch (Exception e) { throw onError.apply(e); } } if (status.is4xxClientError() || status.is5xxServerError()) { LOGGER.debug("request {} {} : response on error {}", request.getMethod(), request.getURI(), response.getStatusLine()); return callOnError(onError).apply(request, response); } else { return behavior.getOrDefault(status, missingBehavior()).apply(request, response); } } finally { tracer.close(requestSpan); } } protected  GenericCommand(final HystrixCommandGroupKey group); protected  GenericCommand(final HystrixCommandGroupKey group, final Map<String, String> headers); }
GenericCommand extends HystrixCommand<T> { @Override protected T run() throws Exception { final HttpRequestBase request = httpCall.get(); addCommandHeaders(request); addAuthorizationHeaders(request); addLocaleHeaders(request); final Span requestSpan = addTrackingHeaders(request); try { final HttpResponse response; try { LOGGER.trace("Requesting {} {}", request.getMethod(), request.getURI()); response = client.execute(request); } catch (Exception e) { throw onError.apply(e); } commandResponseHeaders = response.getAllHeaders(); status = HttpStatus.valueOf(response.getStatusLine().getStatusCode()); Header cookies = response.getFirstHeader("Set-Cookie"); if (cookies != null) { LOGGER.warn( "request {} {}: Cookie detected in responseHeaders (check security.oauth2.resource.uri settings)", request.getMethod(), request.getURI()); } BiFunction<HttpRequestBase, HttpResponse, T> function = behavior.get(status); if (function != null) { try { return function.apply(request, response); } catch (Exception e) { throw onError.apply(e); } } if (status.is4xxClientError() || status.is5xxServerError()) { LOGGER.debug("request {} {} : response on error {}", request.getMethod(), request.getURI(), response.getStatusLine()); return callOnError(onError).apply(request, response); } else { return behavior.getOrDefault(status, missingBehavior()).apply(request, response); } } finally { tracer.close(requestSpan); } } protected  GenericCommand(final HystrixCommandGroupKey group); protected  GenericCommand(final HystrixCommandGroupKey group, final Map<String, String> headers); String getAuthenticationToken(); Header[] getCommandResponseHeaders(); Header getHeader(String name); HttpStatus getStatus(); }
GenericCommand extends HystrixCommand<T> { @Override protected T run() throws Exception { final HttpRequestBase request = httpCall.get(); addCommandHeaders(request); addAuthorizationHeaders(request); addLocaleHeaders(request); final Span requestSpan = addTrackingHeaders(request); try { final HttpResponse response; try { LOGGER.trace("Requesting {} {}", request.getMethod(), request.getURI()); response = client.execute(request); } catch (Exception e) { throw onError.apply(e); } commandResponseHeaders = response.getAllHeaders(); status = HttpStatus.valueOf(response.getStatusLine().getStatusCode()); Header cookies = response.getFirstHeader("Set-Cookie"); if (cookies != null) { LOGGER.warn( "request {} {}: Cookie detected in responseHeaders (check security.oauth2.resource.uri settings)", request.getMethod(), request.getURI()); } BiFunction<HttpRequestBase, HttpResponse, T> function = behavior.get(status); if (function != null) { try { return function.apply(request, response); } catch (Exception e) { throw onError.apply(e); } } if (status.is4xxClientError() || status.is5xxServerError()) { LOGGER.debug("request {} {} : response on error {}", request.getMethod(), request.getURI(), response.getStatusLine()); return callOnError(onError).apply(request, response); } else { return behavior.getOrDefault(status, missingBehavior()).apply(request, response); } } finally { tracer.close(requestSpan); } } protected  GenericCommand(final HystrixCommandGroupKey group); protected  GenericCommand(final HystrixCommandGroupKey group, final Map<String, String> headers); String getAuthenticationToken(); Header[] getCommandResponseHeaders(); Header getHeader(String name); HttpStatus getStatus(); static final HystrixCommandGroupKey DATASET_GROUP; static final HystrixCommandGroupKey PREPARATION_GROUP; static final HystrixCommandGroupKey TRANSFORM_GROUP; static final HystrixCommandGroupKey FULLRUN_GROUP; static final HystrixCommandGroupKey ASYNC_GROUP; static final HystrixCommandGroupKey USER_GROUP; }