Skip to content

Commit

Permalink
rfe11076 improve log and exceptions, javadoc links
Browse files Browse the repository at this point in the history
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
Mike Hinchey authored and dklayer committed Oct 25, 2011
1 parent 05e5b80 commit 6609621
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 44 deletions.
20 changes: 12 additions & 8 deletions src/com/franz/agraph/http/AGErrorInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -29,7 +33,7 @@ public AGErrorType getErrorType() {
}

public String getErrorMessage() {
return errMSg;
return getMessage();
}

@Override
Expand All @@ -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();
}
}

Expand Down
30 changes: 11 additions & 19 deletions src/com/franz/agraph/http/AGHTTPClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/com/franz/agraph/http/AGHttpException.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ public class AGHttpException extends Exception {
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) {
Expand Down
7 changes: 2 additions & 5 deletions src/com/franz/agraph/http/AGHttpRepoClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*/
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
}

Expand Down
1 change: 0 additions & 1 deletion src/com/franz/agraph/jena/AGGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 0 additions & 9 deletions src/test/AGMoreJenaExamples.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/test/AGRepositoryConnectionTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6609621

Please sign in to comment.