@Override public void onMatch(RestCall rc, Matcher m) throws RestCallException { throw new RestCallException("Failure pattern detected."); } }
@Override public void onMatch(RestCall rc, Matcher m) throws RestCallException { throw new RestCallException("Failure pattern detected."); } }
@Override public void onNoMatch(RestCall rc) throws RestCallException { throw new RestCallException("Success pattern not detected."); } }
@Override public void onNoMatch(RestCall rc) throws RestCallException { throw new RestCallException("Success pattern not detected."); } }
@Override public void onMatch(RestCall rc, Matcher m) throws RestCallException { throw new RestCallException("Failure pattern detected."); } }
@Override public void onNoMatch(RestCall rc) throws RestCallException { throw new RestCallException("Success pattern not detected."); } }
/** * Make this call retryable if an error response (>=400) is received. * * @param retries The number of retries to attempt. * @param interval The time in milliseconds between attempts. * @param retryOn * Optional object used for determining whether a retry should be attempted. * If <jk>null</jk>, uses {@link RetryOn#DEFAULT}. * @return This object (for method chaining). * @throws RestCallException If current entity is not repeatable. */ public RestCall retryable(int retries, long interval, RetryOn retryOn) throws RestCallException { if (request instanceof HttpEntityEnclosingRequestBase) { if (input != null && input instanceof HttpEntity) { HttpEntity e = (HttpEntity)input; if (e != null && ! e.isRepeatable()) throw new RestCallException("Attempt to make call retryable, but entity is not repeatable."); } } this.retries = retries; this.retryInterval = interval; this.retryOn = (retryOn == null ? RetryOn.DEFAULT : retryOn); return this; }
/** * Make this call retryable if an error response (>=400) is received. * * @param retries The number of retries to attempt. * @param interval The time in milliseconds between attempts. * @param retryOn * Optional object used for determining whether a retry should be attempted. * If <jk>null</jk>, uses {@link RetryOn#DEFAULT}. * @return This object (for method chaining). * @throws RestCallException If current entity is not repeatable. */ public RestCall retryable(int retries, long interval, RetryOn retryOn) throws RestCallException { if (request instanceof HttpEntityEnclosingRequestBase) { if (input != null && input instanceof HttpEntity) { HttpEntity e = (HttpEntity)input; if (e != null && ! e.isRepeatable()) throw new RestCallException("Attempt to make call retryable, but entity is not repeatable."); } } this.retries = retries; this.retryInterval = interval; this.retryOn = (retryOn == null ? RetryOn.DEFAULT : retryOn); return this; }
/** * Make this call retryable if an error response (>=400) is received. * * @param retries The number of retries to attempt. * @param interval The time in milliseconds between attempts. * @param retryOn * Optional object used for determining whether a retry should be attempted. * If <jk>null</jk>, uses {@link RetryOn#DEFAULT}. * @return This object (for method chaining). * @throws RestCallException If current entity is not repeatable. */ public RestCall retryable(int retries, long interval, RetryOn retryOn) throws RestCallException { if (request instanceof HttpEntityEnclosingRequestBase) { if (input != null && input instanceof HttpEntity) { HttpEntity e = (HttpEntity)input; if (e != null && ! e.isRepeatable()) throw new RestCallException("Attempt to make call retryable, but entity is not repeatable."); } } this.retries = retries; this.retryInterval = interval; this.retryOn = (retryOn == null ? RetryOn.DEFAULT : retryOn); return this; }
/** * Sets the URI for this call. * * <p> * Can be any of the following types: * <ul> * <li>{@link URI} * <li>{@link URL} * <li>{@link URIBuilder} * <li>Anything else converted to a string using {@link Object#toString()}. * </ul> * * <p> * Relative URL strings will be interpreted as relative to the root URL defined on the client. * * @param uri * The URI to use for this call. * This overrides the URI passed in from the client. * @return This object (for method chaining). * @throws RestCallException */ public RestCall uri(Object uri) throws RestCallException { try { if (uri != null) uriBuilder = new URIBuilder(client.toURI(uri)); return this; } catch (URISyntaxException e) { throw new RestCallException(e); } }
/** * Sets the URI for this call. * * <p> * Can be any of the following types: * <ul> * <li>{@link URI} * <li>{@link URL} * <li>{@link URIBuilder} * <li>Anything else converted to a string using {@link Object#toString()}. * </ul> * * <p> * Relative URL strings will be interpreted as relative to the root URL defined on the client. * * @param uri * The URI to use for this call. * This overrides the URI passed in from the client. * @return This object (for method chaining). * @throws RestCallException */ public RestCall uri(Object uri) throws RestCallException { try { if (uri != null) uriBuilder = new URIBuilder(client.toURI(uri)); return this; } catch (URISyntaxException e) { throw new RestCallException(e); } }
/** * Sets the URI for this call. * * <p> * Can be any of the following types: * <ul> * <li>{@link URI} * <li>{@link URL} * <li>{@link URIBuilder} * <li>Anything else converted to a string using {@link Object#toString()}. * </ul> * * <p> * Relative URL strings will be interpreted as relative to the root URL defined on the client. * * @param uri * The URI to use for this call. * This overrides the URI passed in from the client. * @return This object (for method chaining). * @throws RestCallException */ public RestCall uri(Object uri) throws RestCallException { try { if (uri != null) uriBuilder = new URIBuilder(client.toURI(uri)); return this; } catch (URISyntaxException e) { throw new RestCallException(e); } }
void match(RestCall rc) throws RestCallException { try { Matcher m = pattern.matcher(rc.getCapturedResponse()); boolean found = false; while (m.find()) { onMatch(rc, m); found = true; } if (! found) onNoMatch(rc); } catch (IOException e) { throw new RestCallException(e); } }
void match(RestCall rc) throws RestCallException { try { Matcher m = pattern.matcher(rc.getCapturedResponse()); boolean found = false; while (m.find()) { onMatch(rc, m); found = true; } if (! found) onNoMatch(rc); } catch (IOException e) { throw new RestCallException(e); } }
void match(RestCall rc) throws RestCallException { try { Matcher m = pattern.matcher(rc.getCapturedResponse()); boolean found = false; while (m.find()) { onMatch(rc, m); found = true; } if (! found) onNoMatch(rc); } catch (IOException e) { throw new RestCallException(e); } }
int sc = status.getStatusCode(); if (sc >= 400 && ! ignoreErrors) throw new RestCallException(sc, status.getReasonPhrase(), request.getMethod(), request.getURI(), getResponseAsString()).setHttpResponse(response); if (outputStreams.size() > 0 || writers.size() > 0) getReader(); } catch (IOException e) { isFailed = true; throw new RestCallException(e).setHttpResponse(response); } finally { close();
int sc = status.getStatusCode(); if (sc >= 400 && ! ignoreErrors) throw new RestCallException(sc, status.getReasonPhrase(), request.getMethod(), request.getURI(), getResponseAsString()).setHttpResponse(response); if (outputStreams.size() > 0 || writers.size() > 0) getReader(); } catch (IOException e) { isFailed = true; throw new RestCallException(e).setHttpResponse(response); } finally { close();
@Override /* BasicHttpEntity */ public void writeTo(OutputStream os) throws IOException { os = new NoCloseOutputStream(os); if (output instanceof InputStream) { IOPipe.create(output, os).run(); } else if (output instanceof Reader) { try (OutputStreamWriter osw = new OutputStreamWriter(os, UTF8)) { IOPipe.create(output, osw).run(); } } else { try { if (serializer == null) { // If no serializer specified, just close the stream. os.close(); } else { SerializerSessionArgs sArgs = new SerializerSessionArgs(null, null, null, null, null, schema, false, null, null); SerializerSession session = serializer.createSession(sArgs); try (Closeable c = session.isWriterSerializer() ? new OutputStreamWriter(os, UTF8) : os) { session.serialize(output, c); } } } catch (SerializeException e) { throw new org.apache.juneau.rest.client.RestCallException(e); } } }
@Override /* BasicHttpEntity */ public void writeTo(OutputStream os) throws IOException { os = new NoCloseOutputStream(os); if (output instanceof InputStream) { IOPipe.create(output, os).run(); } else if (output instanceof Reader) { try (OutputStreamWriter osw = new OutputStreamWriter(os, UTF8)) { IOPipe.create(output, osw).run(); } } else { try { if (serializer == null) { // If no serializer specified, just close the stream. os.close(); } else { SerializerSessionArgs sArgs = new SerializerSessionArgs(null, null, null, null, null, schema, false, null, null); SerializerSession session = serializer.createSession(sArgs); try (Closeable c = session.isWriterSerializer() ? new OutputStreamWriter(os, UTF8) : os) { session.serialize(output, c); } } } catch (SerializeException e) { throw new org.apache.juneau.rest.client.RestCallException(e); } } }
@Override /* BasicHttpEntity */ public void writeTo(OutputStream os) throws IOException { os = new NoCloseOutputStream(os); if (output instanceof InputStream) { IOPipe.create(output, os).run(); } else if (output instanceof Reader) { try (OutputStreamWriter osw = new OutputStreamWriter(os, UTF8)) { IOPipe.create(output, osw).run(); } } else { try { if (serializer == null) { // If no serializer specified, just close the stream. os.close(); } else { SerializerSessionArgs sArgs = new SerializerSessionArgs(null, null, null, null, null, schema, false, null, null); SerializerSession session = serializer.createSession(sArgs); try (Closeable c = session.isWriterSerializer() ? new OutputStreamWriter(os, UTF8) : os) { session.serialize(output, c); } } } catch (SerializeException e) { throw new org.apache.juneau.rest.client.RestCallException(e); } } }