Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 8023C200C52 for ; Mon, 27 Mar 2017 03:28:08 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 7B79B160B87; Mon, 27 Mar 2017 01:28:08 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 834D7160B9D for ; Mon, 27 Mar 2017 03:28:06 +0200 (CEST) Received: (qmail 90390 invoked by uid 500); 27 Mar 2017 01:28:05 -0000 Mailing-List: contact commits-help@juneau.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@juneau.incubator.apache.org Delivered-To: mailing list commits@juneau.incubator.apache.org Received: (qmail 90381 invoked by uid 99); 27 Mar 2017 01:28:05 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Mar 2017 01:28:05 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 3695BC0B7C for ; Mon, 27 Mar 2017 01:28:05 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.222 X-Spam-Level: X-Spam-Status: No, score=-4.222 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id 3NLZXKavUiZ2 for ; Mon, 27 Mar 2017 01:27:57 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id E52555FE4B for ; Mon, 27 Mar 2017 01:27:53 +0000 (UTC) Received: (qmail 88191 invoked by uid 99); 27 Mar 2017 01:21:11 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Mar 2017 01:21:11 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id B8D12E038D; Mon, 27 Mar 2017 01:21:11 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jamesbognar@apache.org To: commits@juneau.incubator.apache.org Date: Mon, 27 Mar 2017 01:21:19 -0000 Message-Id: <6699e0ce0d224c97b944abc2124c2360@git.apache.org> In-Reply-To: <221181c0d4b94f1c8007ba38d3731012@git.apache.org> References: <221181c0d4b94f1c8007ba38d3731012@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [09/37] incubator-juneau-website git commit: Update javadocs archived-at: Mon, 27 Mar 2017 01:28:08 -0000 http://git-wip-us.apache.org/repos/asf/incubator-juneau-website/blob/236aea45/content/site/apidocs/src-html/org/apache/juneau/rest/client/RestCallException.html ---------------------------------------------------------------------- diff --git a/content/site/apidocs/src-html/org/apache/juneau/rest/client/RestCallException.html b/content/site/apidocs/src-html/org/apache/juneau/rest/client/RestCallException.html index a5d51e2..f17a320 100644 --- a/content/site/apidocs/src-html/org/apache/juneau/rest/client/RestCallException.html +++ b/content/site/apidocs/src-html/org/apache/juneau/rest/client/RestCallException.html @@ -23,140 +23,199 @@ 015import static java.lang.String.*; 016 017import java.io.*; -018import java.net.*; -019import java.util.regex.*; -020 -021import org.apache.http.*; -022import org.apache.http.client.*; -023import org.apache.http.util.*; -024import org.apache.juneau.internal.*; -025 -026/** -027 * Exception representing a <code>400+</code> HTTP response code against a remote resource. -028 */ -029public final class RestCallException extends IOException { -030 -031 private static final long serialVersionUID = 1L; -032 -033 private int responseCode; -034 private String response, responseStatusMessage; -035 HttpResponseException e; -036 private HttpResponse httpResponse; -037 +018import java.lang.reflect.*; +019import java.net.*; +020import java.util.regex.*; +021 +022import org.apache.http.*; +023import org.apache.http.client.*; +024import org.apache.http.util.*; +025import org.apache.juneau.internal.*; +026 +027/** +028 * Exception representing a <code>400+</code> HTTP response code against a remote resource. +029 */ +030public final class RestCallException extends IOException { +031 +032 private static final long serialVersionUID = 1L; +033 +034 private int responseCode; +035 private String response, responseStatusMessage; +036 HttpResponseException e; +037 private HttpResponse httpResponse; 038 -039 /** -040 * Constructor. -041 * -042 * @param msg The exception message. -043 */ -044 public RestCallException(String msg) { -045 super(msg); -046 } -047 -048 /** -049 * Constructor. -050 * -051 * @param e The inner cause of the exception. -052 */ -053 public RestCallException(Exception e) { -054 super(e.getLocalizedMessage(), e); -055 if (e instanceof FileNotFoundException) { -056 responseCode = 404; -057 } else if (e.getMessage() != null) { -058 Pattern p = Pattern.compile("[^\\d](\\d{3})[^\\d]"); -059 Matcher m = p.matcher(e.getMessage()); -060 if (m.find()) -061 responseCode = Integer.parseInt(m.group(1)); -062 } -063 setStackTrace(e.getStackTrace()); -064 } -065 -066 /** -067 * Create an exception with a simple message and the status code and body of the specified response. -068 * -069 * @param msg The exception message. -070 * @param response The HTTP response object. -071 * @throws ParseException -072 * @throws IOException -073 */ -074 public RestCallException(String msg, HttpResponse response) throws ParseException, IOException { -075 super(format("%s%nstatus='%s'%nResponse: %n%s%n", msg, response.getStatusLine().getStatusCode(), EntityUtils.toString(response.getEntity(), IOUtils.UTF8))); -076 } -077 -078 /** -079 * Constructor. -080 * -081 * @param responseCode The response code. -082 * @param responseMsg The response message. -083 * @param method The HTTP method (for message purposes). -084 * @param url The HTTP URL (for message purposes). -085 * @param response The reponse from the server. -086 */ -087 public RestCallException(int responseCode, String responseMsg, String method, URI url, String response) { -088 super(format("HTTP method '%s' call to '%s' caused response code '%s,%s'.%nResponse: %n%s%n", method, url, responseCode, responseMsg, response)); -089 this.responseCode = responseCode; -090 this.responseStatusMessage = responseMsg; -091 this.response = response; -092 } -093 -094 /** -095 * Sets the HTTP response object that caused this exception. -096 * -097 * @param httpResponse The HTTP respose object. -098 * @return This object (for method chaining). -099 */ -100 protected RestCallException setHttpResponse(HttpResponse httpResponse) { -101 this.httpResponse = httpResponse; -102 return this; -103 } -104 -105 /** -106 * Returns the HTTP response object that caused this exception. -107 * -108 * @return The HTTP response object that caused this exception, or <jk>null</jk> if no response was created yet when the exception was thrown. -109 */ -110 public HttpResponse getHttpResponse() { -111 return this.httpResponse; -112 } -113 -114 /** -115 * Returns the HTTP response status code. -116 * -117 * @return The response status code. If a connection could not be made at all, returns <code>0</code>. -118 */ -119 public int getResponseCode() { -120 return responseCode; -121 } -122 -123 /** -124 * Returns the HTTP response message body text. -125 * -126 * @return The response message body text. -127 */ -128 public String getResponseMessage() { -129 return response; -130 } -131 -132 /** -133 * Returns the response status message as a plain string. -134 * -135 * @return The response status message. -136 */ -137 public String getResponseStatusMessage() { -138 return responseStatusMessage; -139 } -140 -141 /** -142 * Sets the inner cause for this exception. -143 * @param cause The inner cause. -144 * @return This object (for method chaining). -145 */ -146 @Override /* Throwable */ -147 public synchronized RestCallException initCause(Throwable cause) { -148 super.initCause(cause); -149 return this; -150 } -151} +039 @SuppressWarnings("unused") +040 private String serverExceptionName, serverExceptionMessage, serverExceptionTrace; +041 +042 +043 /** +044 * Constructor. +045 * +046 * @param msg The exception message. +047 */ +048 public RestCallException(String msg) { +049 super(msg); +050 } +051 +052 /** +053 * Constructor. +054 * +055 * @param e The inner cause of the exception. +056 */ +057 public RestCallException(Exception e) { +058 super(e.getLocalizedMessage(), e); +059 if (e instanceof FileNotFoundException) { +060 responseCode = 404; +061 } else if (e.getMessage() != null) { +062 Pattern p = Pattern.compile("[^\\d](\\d{3})[^\\d]"); +063 Matcher m = p.matcher(e.getMessage()); +064 if (m.find()) +065 responseCode = Integer.parseInt(m.group(1)); +066 } +067 setStackTrace(e.getStackTrace()); +068 } +069 +070 /** +071 * Create an exception with a simple message and the status code and body of the specified response. +072 * +073 * @param msg The exception message. +074 * @param response The HTTP response object. +075 * @throws ParseException +076 * @throws IOException +077 */ +078 public RestCallException(String msg, HttpResponse response) throws ParseException, IOException { +079 super(format("%s%nstatus='%s'%nResponse: %n%s%n", msg, response.getStatusLine().getStatusCode(), EntityUtils.toString(response.getEntity(), IOUtils.UTF8))); +080 } +081 +082 /** +083 * Constructor. +084 * +085 * @param responseCode The response code. +086 * @param responseMsg The response message. +087 * @param method The HTTP method (for message purposes). +088 * @param url The HTTP URL (for message purposes). +089 * @param response The reponse from the server. +090 */ +091 public RestCallException(int responseCode, String responseMsg, String method, URI url, String response) { +092 super(format("HTTP method '%s' call to '%s' caused response code '%s,%s'.%nResponse: %n%s%n", method, url, responseCode, responseMsg, response)); +093 this.responseCode = responseCode; +094 this.responseStatusMessage = responseMsg; +095 this.response = response; +096 } +097 +098 /** +099 * Sets the server-side exception details. +100 * +101 * @param exceptionName The <code>Exception-Name:</code> header specifying the full name of the exception. +102 * @param exceptionMessage The <code>Exception-Message:</code> header specifying the message returned by {@link Throwable#getMessage()}. +103 * @param exceptionTrace The stack trace of the exception returned by {@link Throwable#printStackTrace()}. +104 * @return This object (for method chaining). +105 */ +106 protected RestCallException setServerException(Header exceptionName, Header exceptionMessage, Header exceptionTrace) { +107 if (exceptionName != null) +108 serverExceptionName = exceptionName.getValue(); +109 if (exceptionMessage != null) +110 serverExceptionMessage = exceptionMessage.getValue(); +111 if (exceptionTrace != null) +112 serverExceptionTrace = exceptionTrace.getValue(); +113 return this; +114 } +115 +116 /** +117 * Tries to reconstruct and re-throw the server-side exception. +118 * <p> +119 * The exception is based on the following HTTP response headers: +120 * <ul> +121 * <li><code>Exception-Name:</code> - The full class name of the exception. +122 * <li><code>Exception-Message:</code> - The message returned by {@link Throwable#getMessage()}. +123 * <li><code>Exception-Trace:</code> - The stack trace of the exception returned by {@link Throwable#printStackTrace()}. +124 * </ul> +125 * <p> +126 * Does nothing if the server-side exception could not be reconstructed. +127 * <p> +128 * Currently only supports <code>Throwables</code> with either a public no-arg constructor +129 * or a public constructor that takes in a simple string message. +130 * +131 * @param cl The classloader to use to resolve the throwable class name. +132 * @throws Throwable If the throwable could be reconstructed. +133 */ +134 protected void throwServerException(ClassLoader cl) throws Throwable { +135 if (serverExceptionName != null) { +136 Throwable t = null; +137 try { +138 Class<?> exceptionClass = cl.loadClass(serverExceptionName); +139 Constructor<?> c = ClassUtils.findPublicConstructor(exceptionClass, String.class); +140 if (c != null) +141 t = (Throwable)c.newInstance(serverExceptionMessage); +142 if (t == null) { +143 c = ClassUtils.findPublicConstructor(exceptionClass); +144 if (c != null) +145 t = (Throwable)c.newInstance(); +146 } +147 } catch (Exception e2) { /* Ignore */ } +148 if (t != null) +149 throw t; +150 } +151 } +152 +153 /** +154 * Sets the HTTP response object that caused this exception. +155 * +156 * @param httpResponse The HTTP respose object. +157 * @return This object (for method chaining). +158 */ +159 protected RestCallException setHttpResponse(HttpResponse httpResponse) { +160 this.httpResponse = httpResponse; +161 return this; +162 } +163 +164 /** +165 * Returns the HTTP response object that caused this exception. +166 * +167 * @return The HTTP response object that caused this exception, or <jk>null</jk> if no response was created yet when the exception was thrown. +168 */ +169 public HttpResponse getHttpResponse() { +170 return this.httpResponse; +171 } +172 +173 /** +174 * Returns the HTTP response status code. +175 * +176 * @return The response status code. If a connection could not be made at all, returns <code>0</code>. +177 */ +178 public int getResponseCode() { +179 return responseCode; +180 } +181 +182 /** +183 * Returns the HTTP response message body text. +184 * +185 * @return The response message body text. +186 */ +187 public String getResponseMessage() { +188 return response; +189 } +190 +191 /** +192 * Returns the response status message as a plain string. +193 * +194 * @return The response status message. +195 */ +196 public String getResponseStatusMessage() { +197 return responseStatusMessage; +198 } +199 +200 /** +201 * Sets the inner cause for this exception. +202 * @param cause The inner cause. +203 * @return This object (for method chaining). +204 */ +205 @Override /* Throwable */ +206 public synchronized RestCallException initCause(Throwable cause) { +207 super.initCause(cause); +208 return this; +209 } +210} http://git-wip-us.apache.org/repos/asf/incubator-juneau-website/blob/236aea45/content/site/apidocs/src-html/org/apache/juneau/rest/client/RestCallLogger.html ---------------------------------------------------------------------- diff --git a/content/site/apidocs/src-html/org/apache/juneau/rest/client/RestCallLogger.html b/content/site/apidocs/src-html/org/apache/juneau/rest/client/RestCallLogger.html index 9a47f37..0741b42 100644 --- a/content/site/apidocs/src-html/org/apache/juneau/rest/client/RestCallLogger.html +++ b/content/site/apidocs/src-html/org/apache/juneau/rest/client/RestCallLogger.html @@ -40,92 +40,98 @@ 032 */ 033public class RestCallLogger extends RestCallInterceptor { 034 -035 private Level level; -036 private Logger log; -037 -038 /** -039 * Constructor. -040 * -041 * @param level The log level to log messages at. -042 * @param log The logger to log to. -043 */ -044 protected RestCallLogger(Level level, Logger log) { -045 this.level = level; -046 this.log = log; -047 } -048 -049 @Override /* RestCallInterceptor */ -050 public void onInit(RestCall restCall) { -051 if (log.isLoggable(level)) -052 restCall.captureResponse(); +035 /** +036 * Default HTTP request logger. +037 * Logs outgoing HTTP requests to the <code>org.apache.juneau.rest.client</code> logger at <jsf>WARNING</jsf> level. +038 */ +039 public static final RestCallLogger DEFAULT = new RestCallLogger(Level.WARNING, Logger.getLogger("org.apache.juneau.rest.client")); +040 +041 private Level level; +042 private Logger log; +043 +044 /** +045 * Constructor. +046 * +047 * @param level The log level to log messages at. +048 * @param log The logger to log to. +049 */ +050 protected RestCallLogger(Level level, Logger log) { +051 this.level = level; +052 this.log = log; 053 } 054 055 @Override /* RestCallInterceptor */ -056 public void onConnect(RestCall restCall, int statusCode, HttpRequest req, HttpResponse res) { -057 // Do nothing. -058 } -059 -060 @Override /* RestCallInterceptor */ -061 public void onRetry(RestCall restCall, int statusCode, HttpRequest req, HttpResponse res, Exception ex) { -062 if (log.isLoggable(level)) { -063 if (ex == null) -064 log.log(level, MessageFormat.format("Call to {0} returned {1}. Will retry.", req.getRequestLine().getUri(), statusCode)); //$NON-NLS-1$ -065 else -066 log.log(level, MessageFormat.format("Call to {0} caused exception {1}. Will retry.", req.getRequestLine().getUri(), ex.getLocalizedMessage()), ex); //$NON-NLS-1$ -067 } -068 } -069 -070 @Override /* RestCallInterceptor */ -071 public void onClose(RestCall restCall) throws RestCallException { -072 try { -073 if (log.isLoggable(level)) { -074 String output = restCall.getCapturedResponse(); -075 StringBuilder sb = new StringBuilder(); -076 HttpUriRequest req = restCall.getRequest(); -077 HttpResponse res = restCall.getResponse(); -078 if (req != null) { -079 sb.append("\n=== HTTP Call =================================================================="); -080 -081 sb.append("\n=== REQUEST ===\n").append(req); -082 sb.append("\n---request headers---"); -083 for (Header h : req.getAllHeaders()) -084 sb.append("\n").append(h); -085 if (req instanceof HttpEntityEnclosingRequestBase) { -086 sb.append("\n---request entity---"); -087 HttpEntityEnclosingRequestBase req2 = (HttpEntityEnclosingRequestBase)req; -088 HttpEntity e = req2.getEntity(); -089 if (e == null) -090 sb.append("\nEntity is null"); -091 else { -092 if (e.getContentType() != null) -093 sb.append("\n").append(e.getContentType()); -094 if (e.getContentEncoding() != null) -095 sb.append("\n").append(e.getContentEncoding()); -096 if (e.isRepeatable()) { -097 try { -098 sb.append("\n---request content---\n").append(EntityUtils.toString(e)); -099 } catch (Exception ex) { -100 throw new RuntimeException(ex); -101 } -102 } -103 } -104 } -105 } -106 if (res != null) { -107 sb.append("\n=== RESPONSE ===\n").append(res.getStatusLine()); -108 sb.append("\n---response headers---"); -109 for (Header h : res.getAllHeaders()) -110 sb.append("\n").append(h); -111 sb.append("\n---response content---\n").append(output); -112 sb.append("\n=== END ========================================================================"); -113 } -114 log.log(level, sb.toString()); -115 } -116 } catch (IOException e) { -117 log.log(Level.SEVERE, e.getLocalizedMessage(), e); -118 } -119 } -120} +056 public void onInit(RestCall restCall) { +057 if (log.isLoggable(level)) +058 restCall.captureResponse(); +059 } +060 +061 @Override /* RestCallInterceptor */ +062 public void onConnect(RestCall restCall, int statusCode, HttpRequest req, HttpResponse res) { +063 // Do nothing. +064 } +065 +066 @Override /* RestCallInterceptor */ +067 public void onRetry(RestCall restCall, int statusCode, HttpRequest req, HttpResponse res, Exception ex) { +068 if (log.isLoggable(level)) { +069 if (ex == null) +070 log.log(level, MessageFormat.format("Call to {0} returned {1}. Will retry.", req.getRequestLine().getUri(), statusCode)); //$NON-NLS-1$ +071 else +072 log.log(level, MessageFormat.format("Call to {0} caused exception {1}. Will retry.", req.getRequestLine().getUri(), ex.getLocalizedMessage()), ex); //$NON-NLS-1$ +073 } +074 } +075 +076 @Override /* RestCallInterceptor */ +077 public void onClose(RestCall restCall) throws RestCallException { +078 try { +079 if (log.isLoggable(level)) { +080 String output = restCall.getCapturedResponse(); +081 StringBuilder sb = new StringBuilder(); +082 HttpUriRequest req = restCall.getRequest(); +083 HttpResponse res = restCall.getResponse(); +084 if (req != null) { +085 sb.append("\n=== HTTP Call (outgoing) ======================================================="); +086 +087 sb.append("\n=== REQUEST ===\n").append(req); +088 sb.append("\n---request headers---"); +089 for (Header h : req.getAllHeaders()) +090 sb.append("\n\t").append(h); +091 if (req instanceof HttpEntityEnclosingRequestBase) { +092 sb.append("\n---request entity---"); +093 HttpEntityEnclosingRequestBase req2 = (HttpEntityEnclosingRequestBase)req; +094 HttpEntity e = req2.getEntity(); +095 if (e == null) +096 sb.append("\nEntity is null"); +097 else { +098 if (e.getContentType() != null) +099 sb.append("\n").append(e.getContentType()); +100 if (e.getContentEncoding() != null) +101 sb.append("\n").append(e.getContentEncoding()); +102 if (e.isRepeatable()) { +103 try { +104 sb.append("\n---request content---\n").append(EntityUtils.toString(e)); +105 } catch (Exception ex) { +106 throw new RuntimeException(ex); +107 } +108 } +109 } +110 } +111 } +112 if (res != null) { +113 sb.append("\n=== RESPONSE ===\n").append(res.getStatusLine()); +114 sb.append("\n---response headers---"); +115 for (Header h : res.getAllHeaders()) +116 sb.append("\n\t").append(h); +117 sb.append("\n---response content---\n").append(output); +118 sb.append("\n=== END ========================================================================"); +119 } +120 log.log(level, sb.toString()); +121 } +122 } catch (IOException e) { +123 log.log(Level.SEVERE, e.getLocalizedMessage(), e); +124 } +125 } +126}