Author: fmui
Date: Fri Mar 10 10:16:34 2017
New Revision: 1786320
URL: http://svn.apache.org/viewvc?rev=1786320&view=rev
Log:
code clean up
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/DefaultHttpInvoker.java
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/AbstractApacheClientHttpInvoker.java
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/DefaultHttpInvoker.java
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/OkHttpHttpInvoker.java
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/exceptions/CmisConnectionException.java
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/DefaultHttpInvoker.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/DefaultHttpInvoker.java?rev=1786320&r1=1786319&r2=1786320&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/DefaultHttpInvoker.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/DefaultHttpInvoker.java
Fri Mar 10 10:16:34 2017
@@ -18,6 +18,8 @@
*/
package org.apache.chemistry.opencmis.client.bindings.spi.http;
+import static
org.apache.chemistry.opencmis.commons.impl.CollectionsHelper.isNotEmpty;
+
import java.io.BufferedOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
@@ -94,7 +96,9 @@ public class DefaultHttpInvoker implemen
conn.setDoOutput(writer != null);
conn.setAllowUserInteraction(false);
conn.setUseCaches(false);
- conn.setRequestProperty("User-Agent",
ClientVersion.OPENCMIS_CLIENT);
+
+ conn.setRequestProperty("User-Agent",
+ (String) session.get(SessionParameter.USER_AGENT,
ClientVersion.OPENCMIS_USER_AGENT));
// timeouts
int connectTimeout = session.get(SessionParameter.CONNECT_TIMEOUT,
-1);
@@ -124,7 +128,7 @@ public class DefaultHttpInvoker implemen
Map<String, List<String>> httpHeaders =
authProvider.getHTTPHeaders(url.toString());
if (httpHeaders != null) {
for (Map.Entry<String, List<String>> header :
httpHeaders.entrySet()) {
- if (header.getKey() != null && header.getValue() !=
null && !header.getValue().isEmpty()) {
+ if (header.getKey() != null &&
isNotEmpty(header.getValue())) {
String key = header.getKey();
if (key.equalsIgnoreCase("user-agent")) {
conn.setRequestProperty("User-Agent",
header.getValue().get(0));
@@ -153,7 +157,7 @@ public class DefaultHttpInvoker implemen
}
// range
- if ((offset != null) || (length != null)) {
+ if (offset != null || length != null) {
StringBuilder sb = new StringBuilder("bytes=");
if ((offset == null) || (offset.signum() == -1)) {
@@ -163,7 +167,7 @@ public class DefaultHttpInvoker implemen
sb.append(offset.toString());
sb.append('-');
- if ((length != null) && (length.signum() == 1)) {
+ if (length != null && length.signum() == 1) {
sb.append(offset.add(length.subtract(BigInteger.ONE)).toString());
}
@@ -172,7 +176,7 @@ public class DefaultHttpInvoker implemen
// compression
Object compression = session.get(SessionParameter.COMPRESSION);
- if ((compression != null) &&
Boolean.parseBoolean(compression.toString())) {
+ if (compression != null &&
Boolean.parseBoolean(compression.toString())) {
conn.setRequestProperty("Accept-Encoding", "gzip,deflate");
}
@@ -199,11 +203,7 @@ public class DefaultHttpInvoker implemen
OutputStream out = new BufferedOutputStream(connOut,
BUFFER_SIZE);
writer.write(out);
- out.flush();
-
- if (connOut instanceof GZIPOutputStream) {
- ((GZIPOutputStream) connOut).finish();
- }
+ out.close();
}
// connect
@@ -218,8 +218,8 @@ public class DefaultHttpInvoker implemen
// log after connect
if (LOG.isTraceEnabled()) {
- LOG.trace("Session {}: {} {} > Headers: {}",
session.getSessionId(), method, url, conn
- .getHeaderFields().toString());
+ LOG.trace("Session {}: {} {} > Headers: {}",
session.getSessionId(), method, url,
+ conn.getHeaderFields().toString());
}
// forward response HTTP headers
@@ -231,8 +231,7 @@ public class DefaultHttpInvoker implemen
return new Response(respCode, conn.getResponseMessage(),
conn.getHeaderFields(), inputStream,
conn.getErrorStream());
} catch (Exception e) {
- String status = respCode > 0 ? " (HTTP status code " + respCode +
")" : "";
- throw new CmisConnectionException("Cannot access \"" + url + "\""
+ status + ": " + e.getMessage(), e);
+ throw new CmisConnectionException(url.toString(), respCode, e);
}
}
}
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/AbstractApacheClientHttpInvoker.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/AbstractApacheClientHttpInvoker.java?rev=1786320&r1=1786319&r2=1786320&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/AbstractApacheClientHttpInvoker.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/AbstractApacheClientHttpInvoker.java
Fri Mar 10 10:16:34 2017
@@ -316,8 +316,7 @@ public abstract class AbstractApacheClie
return new Response(respCode,
response.getStatusLine().getReasonPhrase(), responseHeaders, inputStream,
errorStream);
} catch (Exception e) {
- String status = (respCode > 0 ? " (HTTP status code " + respCode +
")" : "");
- throw new CmisConnectionException("Cannot access \"" + url + "\""
+ status + ": " + e.getMessage(), e);
+ throw new CmisConnectionException(url.toString(), respCode, e);
}
}
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/DefaultHttpInvoker.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/DefaultHttpInvoker.java?rev=1786320&r1=1786319&r2=1786320&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/DefaultHttpInvoker.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/DefaultHttpInvoker.java
Fri Mar 10 10:16:34 2017
@@ -216,8 +216,8 @@ public class DefaultHttpInvoker implemen
// log after connect
if (LOG.isTraceEnabled()) {
- LOG.trace("Session {}: {} {} > Headers: {}",
session.getSessionId(), method, url, conn
- .getHeaderFields().toString());
+ LOG.trace("Session {}: {} {} > Headers: {}",
session.getSessionId(), method, url,
+ conn.getHeaderFields().toString());
}
// forward response HTTP headers
@@ -229,8 +229,7 @@ public class DefaultHttpInvoker implemen
return new Response(respCode, conn.getResponseMessage(),
conn.getHeaderFields(), inputStream,
conn.getErrorStream());
} catch (Exception e) {
- String status = respCode > 0 ? " (HTTP status code " + respCode +
")" : "";
- throw new CmisConnectionException("Cannot access \"" + url + "\""
+ status + ": " + e.getMessage(), e);
+ throw new CmisConnectionException(url.toString(), respCode, e);
}
}
}
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/OkHttpHttpInvoker.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/OkHttpHttpInvoker.java?rev=1786320&r1=1786319&r2=1786320&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/OkHttpHttpInvoker.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/OkHttpHttpInvoker.java
Fri Mar 10 10:16:34 2017
@@ -32,12 +32,6 @@ import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.X509TrustManager;
-import okhttp3.MediaType;
-import okhttp3.OkHttpClient;
-import okhttp3.Request;
-import okhttp3.RequestBody;
-import okio.BufferedSink;
-
import org.apache.chemistry.opencmis.client.bindings.impl.ClientVersion;
import org.apache.chemistry.opencmis.client.bindings.impl.CmisBindingsHelper;
import
org.apache.chemistry.opencmis.client.bindings.spi.AbstractAuthenticationProvider;
@@ -50,6 +44,12 @@ import org.apache.chemistry.opencmis.com
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import okhttp3.MediaType;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.RequestBody;
+import okio.BufferedSink;
+
public class OkHttpHttpInvoker implements HttpInvoker {
private static final Logger LOG =
LoggerFactory.getLogger(OkHttpHttpInvoker.class);
@@ -248,8 +248,7 @@ public class OkHttpHttpInvoker implement
// get the response
return new Response(respCode, okResponse.message(),
responseHeaders, inputStream, errorStream);
} catch (Exception e) {
- String status = (respCode > 0 ? " (HTTP status code " + respCode +
")" : "");
- throw new CmisConnectionException("Cannot access \"" + url + "\""
+ status + ": " + e.getMessage(), e);
+ throw new CmisConnectionException(url.toString(), respCode, e);
}
}
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/exceptions/CmisConnectionException.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/exceptions/CmisConnectionException.java?rev=1786320&r1=1786319&r2=1786320&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/exceptions/CmisConnectionException.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/exceptions/CmisConnectionException.java
Fri Mar 10 10:16:34 2017
@@ -158,6 +158,34 @@ public class CmisConnectionException ext
super(message, BigInteger.ZERO);
}
+ /**
+ * Constructor.
+ *
+ * @param url
+ * failing URL
+ * @param respCode
+ * HTTP response code (0 if unknown)
+ * @param cause
+ * the cause
+ */
+ public CmisConnectionException(String url, int respCode, Throwable cause) {
+ super("Cannot access \"" + url + "\"" + (respCode > 0 ? " (HTTP status
code " + respCode + ")" : "") + ": "
+ + formatMessage(cause), BigInteger.ZERO, cause);
+ }
+
+ private static String formatMessage(Throwable cause) {
+ if (cause == null) {
+ return "(no exception)";
+ }
+
+ String msg = cause.getMessage();
+ if (msg == null || msg.length() == 0) {
+ msg = cause.getClass().getSimpleName();
+ }
+
+ return msg;
+ }
+
@Override
public final String getExceptionName() {
return EXCEPTION_NAME;