Permalink
Browse files

rfe11076 improve log and exceptions, javadoc links

Various code cleanup, no functional change.
Remove a log warn message, instead keeping the info in an exception.
Fix broken javadoc links and other compiler warnings.

tests-added:   none
tests-run:     prepush
performance:   no impact

<release-notes>
rfe11076 improve log and exceptions, javadoc links

Remove a log warning message, instead keeping the
information in an exception cause.

Fixed broken javadoc links.
</release-notes>

Change-Id: Ia6bcdd5fb69ea1691192afee7c38211747d7b295
Reviewed-on: https://gerrit.franz.com:9080/1718
Reviewed-by: John O'Rourke <jor@franz.com>
Tested-by: Kevin Layer <layer@franz.com>
  • Loading branch information...
1 parent 05e5b80 commit 660962131c9f40268f9a41cd3fded07bc0062cbd Mike Hinchey committed with dklayer Oct 21, 2011
@@ -8,19 +8,23 @@
package com.franz.agraph.http;
-public class AGErrorInfo {
+public class AGErrorInfo extends Exception {
+
+ private static final long serialVersionUID = -7109531872359055983L;
private AGErrorType errorType;
- private String errMSg;
+ public AGErrorInfo(String errMsg, Throwable cause) {
+ super(errMsg, cause);
+ assert errMsg != null : "errMsg must not be null";
+ }
public AGErrorInfo(String errMsg) {
- assert errMsg != null : "errMsg must not be null";
- this.errMSg = errMsg;
+ this(errMsg, null);
}
public AGErrorInfo(AGErrorType errorType, String errMsg) {
- this(errMsg);
+ this(errMsg, null);
this.errorType = errorType;
}
@@ -29,7 +33,7 @@ public AGErrorType getErrorType() {
}
public String getErrorMessage() {
- return errMSg;
+ return getMessage();
}
@Override
@@ -38,11 +42,11 @@ public String toString() {
StringBuilder sb = new StringBuilder(64);
sb.append(errorType);
sb.append(": ");
- sb.append(errMSg);
+ sb.append(getMessage());
return sb.toString();
}
else {
- return errMSg;
+ return getMessage();
}
}
@@ -86,7 +86,9 @@ public AGHTTPClient(String serverURL, HttpConnectionManager manager) {
manager.setParams(params);
}
httpClient = new HttpClient(manager);
- logger.debug("connect: " + serverURL + " " + httpClient + " " + manager);
+ if (logger.isDebugEnabled()) {
+ logger.debug("connect: " + serverURL + " " + httpClient + " " + manager);
+ }
}
@Override
@@ -137,13 +139,12 @@ public void post(String url, Header[] headers, NameValuePair[] params,
} else if (!HttpClientUtil.is2xx(httpCode)) {
AGErrorInfo errInfo = getErrorInfo(post);
if (errInfo.getErrorType() == AGErrorType.MALFORMED_DATA) {
- throw new RDFParseException(errInfo.getErrorMessage());
+ throw new RDFParseException(errInfo);
} else if (errInfo.getErrorType() == AGErrorType.UNSUPPORTED_FILE_FORMAT) {
- throw new UnsupportedRDFormatException(errInfo
- .getErrorMessage());
+ throw new UnsupportedRDFormatException(errInfo.getErrorMessage(), errInfo);
} else {
throw new RepositoryException("POST failed " + url + ": "
- + errInfo + " (" + httpCode + ")");
+ + errInfo + " (" + httpCode + ")", errInfo);
}
}
} catch (AGHttpException e) {
@@ -204,7 +205,7 @@ public void delete(String url, Header[] headers, NameValuePair[] params)
} else if (!HttpClientUtil.is2xx(httpCode)) {
AGErrorInfo errInfo = getErrorInfo(delete);
throw new RepositoryException("DELETE failed " + url + ": "
- + errInfo + " (" + httpCode + ")");
+ + errInfo + " (" + httpCode + ")", errInfo);
}
} catch (IOException e) {
throw handleIOException(e, url);
@@ -247,19 +248,15 @@ public void put(String url, Header[] headers, NameValuePair[] params, RequestEnt
*-------------------------*/
protected AGErrorInfo getErrorInfo(HttpMethod method) {
- AGErrorInfo errorInfo;
try {
// TODO: check the case where the server supplies
// no error message
AGStringHandler handler = new AGStringHandler();
handler.handleResponse(method);
- errorInfo = AGErrorInfo.parse(handler.getResult());
- logger.warn("Server reports problem: {}", errorInfo.getErrorMessage());
+ return AGErrorInfo.parse(handler.getResult());
} catch (Exception e) {
- logger.warn("Unable to retrieve error info from server");
- errorInfo = new AGErrorInfo("Unable to retrieve error info from server");
+ return new AGErrorInfo("Unable to retrieve error info from server", e);
}
- return errorInfo;
}
/**
@@ -273,20 +270,15 @@ protected AGErrorInfo getErrorInfo(HttpMethod method) {
public void setUsernameAndPassword(String username, String password) {
if (username != null && password != null) {
- logger.debug(
- "Setting username '{}' and password for server at {}.",
- username, serverURL);
+ logger.debug("Setting username '{}' and password for server at {}.", username, serverURL);
try {
URL server = new URL(serverURL);
authScope = new AuthScope(server.getHost(), AuthScope.ANY_PORT);
httpClient.getState().setCredentials(authScope,
new UsernamePasswordCredentials(username, password));
httpClient.getParams().setAuthenticationPreemptive(true);
} catch (MalformedURLException e) {
- logger
- .warn(
- "Unable to set username and password for malformed URL {}",
- serverURL);
+ logger.warn("Unable to set username and password for malformed URL " + serverURL, e);
}
} else {
authScope = null;
@@ -15,13 +15,14 @@
private final AGErrorInfo errorInfo;
AGHttpException(AGErrorInfo errorInfo) {
- super(errorInfo.getErrorMessage());
+ super(errorInfo.getErrorMessage(), errorInfo);
this.errorInfo = errorInfo;
}
public AGHttpException(String message) {
super(message);
errorInfo = new AGErrorInfo(message);
+ initCause(errorInfo);
}
public AGHttpException(String message, Throwable cause) {
@@ -33,7 +33,6 @@
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.json.JSONArray;
import org.json.JSONObject;
-import org.openrdf.OpenRDFException;
import org.openrdf.OpenRDFUtil;
import org.openrdf.http.protocol.Protocol;
import org.openrdf.http.protocol.UnauthorizedException;
@@ -230,7 +229,7 @@ public RDFFormat getDefaultRDFFormat() {
* Gets the RDFFormat to use in making requests that return
* RDF statements.
*
- * Defaults to the format returned by {@link getDefaultRDFFormat()}
+ * Defaults to the format returned by {@link #getDefaultRDFFormat()}
*
* @return an RDFFormat, either NQUADS or TRIX
*/
@@ -243,7 +242,7 @@ public RDFFormat getPreferredRDFFormat() {
* RDF statements; the format should support contexts.
*
* AGRDFFormat.NQUADS and RDFFormat.TRIX are currently supported.
- * Defaults to the format returned by {@link getDefaultRDFFormat()}
+ * Defaults to the format returned by {@link #getDefaultRDFFormat()}
*
*/
public void setPreferredRDFFormat(RDFFormat preferredRDFFormat) {
@@ -586,8 +585,6 @@ public void uploadJSON(String url, JSONArray rows, Resource... contexts)
throw new RuntimeException(e);
} catch (RDFParseException e) {
throw new RuntimeException(e);
- } catch (IOException e) {
- throw new RepositoryException(e);
}
}
@@ -42,7 +42,6 @@
import com.hp.hpl.jena.shared.AddDeniedException;
import com.hp.hpl.jena.shared.DeleteDeniedException;
import com.hp.hpl.jena.shared.PrefixMapping;
-import com.hp.hpl.jena.shared.ReificationStyle;
import com.hp.hpl.jena.util.iterator.ClosableIterator;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
import com.hp.hpl.jena.util.iterator.NullIterator;
@@ -12,26 +12,17 @@
import tutorial.JenaTutorialExamples;
-import com.franz.agraph.jena.AGGraph;
import com.franz.agraph.jena.AGGraphMaker;
import com.franz.agraph.jena.AGInfModel;
import com.franz.agraph.jena.AGModel;
-import com.franz.agraph.jena.AGQuery;
-import com.franz.agraph.jena.AGQueryExecutionFactory;
-import com.franz.agraph.jena.AGQueryFactory;
import com.franz.agraph.jena.AGReasoner;
import com.franz.agraph.repository.AGCatalog;
-import com.franz.agraph.repository.AGQueryLanguage;
import com.franz.agraph.repository.AGRepositoryConnection;
import com.franz.agraph.repository.AGServer;
import com.franz.agraph.repository.AGVirtualRepository;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
-import com.hp.hpl.jena.query.QueryExecution;
-import com.hp.hpl.jena.query.QuerySolution;
-import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.rdf.model.InfModel;
-import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.RDFNode;
@@ -23,7 +23,6 @@
import org.junit.Test;
import org.junit.experimental.categories.Categories;
-import org.junit.experimental.categories.Category;
import org.junit.experimental.categories.Categories.ExcludeCategory;
import org.junit.experimental.categories.Categories.IncludeCategory;
import org.junit.runner.RunWith;

0 comments on commit 6609621

Please sign in to comment.