Permalink
Browse files

rfe10622: HTTP response handlers now have their own package

<release-note>
rfe10622: HTTP response handlers now have their own package

With this change, the Java client's HTTP response handlers have
been refactored and moved into a com.franz.agraph.http.handler
package.
</release-note>

make prepush passes.
ant tutorial runs.
make javadoc runs clean.

Change-Id: I00aa1887cdcff7c4152c22af101ee416805eefd5
Reviewed-on: https://gerrit.franz.com:9080/1555
Reviewed-by: Ahmon Dancy <dancy@franz.com>
Reviewed-by: John O'Rourke <jor@franz.com>
Tested-by: Kevin Layer <layer@franz.com>
  • Loading branch information...
1 parent ae1f3a1 commit 5734c4498c2bed85f9915346c525f76c70459957 Bill Millar committed with dklayer Jun 16, 2011
@@ -50,6 +50,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.franz.agraph.http.handler.AGResponseHandler;
+import com.franz.agraph.http.handler.AGStringHandler;
+import com.franz.agraph.http.handler.AGTQRHandler;
import com.franz.util.Closeable;
import com.franz.util.Util;
@@ -98,7 +101,7 @@ public HttpClient getHttpClient() {
}
public void post(String url, Header[] headers, NameValuePair[] params,
- RequestEntity requestEntity, AGResponseHandlerInf handler) throws HttpException, IOException,
+ RequestEntity requestEntity, AGResponseHandler handler) throws HttpException, IOException,
RepositoryException, RDFParseException {
PostMethod post = new PostMethod(url);
setDoAuthentication(post);
@@ -128,6 +131,8 @@ public void post(String url, Header[] headers, NameValuePair[] params,
+ errInfo + " (" + httpCode + ")");
}
}
+ } catch (AGHttpException e) {
+ throw new RepositoryException(e);
} finally {
if (handler == null || handler.releaseConnection()) {
releaseConnection(post);
@@ -136,7 +141,7 @@ public void post(String url, Header[] headers, NameValuePair[] params,
}
public void get(String url, Header[] headers, NameValuePair[] params,
- AGResponseHandlerInf handler) throws IOException, RepositoryException,
+ AGResponseHandler handler) throws IOException, RepositoryException,
AGHttpException {
GetMethod get = new GetMethod(url);
setDoAuthentication(get);
@@ -224,9 +229,9 @@ protected AGErrorInfo getErrorInfo(HttpMethod method) {
try {
// TODO: check the case where the server supplies
// no error message
- AGResponseHandler handler = new AGResponseHandler("");
+ AGStringHandler handler = new AGStringHandler();
handler.handleResponse(method);
- errorInfo = AGErrorInfo.parse(handler.getString());
+ errorInfo = AGErrorInfo.parse(handler.getResult());
logger.warn("Server reports problem: {}", errorInfo.getErrorMessage());
} catch (Exception e) {
logger.warn("Unable to retrieve error info from server");
@@ -321,7 +326,7 @@ public TupleQueryResult getTupleQueryResult(String url) throws RepositoryExcepti
Repository repo = new SailRepository( new MemoryStore() );
repo.initialize();
TupleQueryResultBuilder builder = new TupleQueryResultBuilder();
- AGResponseHandler handler = new AGResponseHandler(repo,builder);
+ AGTQRHandler handler = new AGTQRHandler(TupleQueryResultFormat.SPARQL,builder,repo.getValueFactory());
try {
get(url, headers, params, handler);
} catch (IOException e) {
@@ -339,28 +344,28 @@ public TupleQueryResult getTupleQueryResult(String url) throws RepositoryExcepti
NameValuePair[] data = { new NameValuePair(AMOUNT_PARAM_NAME, Integer
.toString(amount)) };
- AGResponseHandler handler = new AGResponseHandler("");
+ AGStringHandler handler = new AGStringHandler();
try {
post(url, headers, data, null, handler);
} catch (RDFParseException e) {
// bug.
throw new RuntimeException(e);
}
- return handler.getString().split("\n");
+ return handler.getResult().split("\n");
}
public String getString(String url) throws AGHttpException {
Header[] headers = new Header[0];
NameValuePair[] data = {};
- AGResponseHandler handler = new AGResponseHandler("");
+ AGStringHandler handler = new AGStringHandler();
try {
get(url, headers, data, handler);
} catch (RepositoryException e) {
throw new AGHttpException(e.getMessage());
} catch (IOException e) {
throw new AGHttpException(e.getMessage());
}
- return handler.getString();
+ return handler.getResult();
}
public String openSession(String spec, boolean autocommit) throws RepositoryException {
@@ -371,15 +376,15 @@ public String openSession(String spec, boolean autocommit) throws RepositoryExce
Boolean.toString(autocommit)),
new NameValuePair(AGProtocol.LIFETIME_PARAM_NAME,
Long.toString(3600)) }; // TODO have some kind of policy for this
- AGResponseHandler handler = new AGResponseHandler("");
+ AGStringHandler handler = new AGStringHandler();
try {
post(url, headers, data, null, handler);
} catch (HttpException e) {
throw new RepositoryException(e);
} catch (IOException e) {
throw new RepositoryException(e);
} catch (RDFParseException e) {}
- return handler.getString();
+ return handler.getResult();
}
@Override
@@ -394,13 +399,13 @@ public void close() {
Header[] headers = new Header[0];
NameValuePair[] data = { new NameValuePair("prefix", namespace),
new NameValuePair(AMOUNT_PARAM_NAME, Integer.toString(amount)) };
- AGResponseHandler handler = new AGResponseHandler("");
+ AGStringHandler handler = new AGStringHandler();
try {
post(url, headers, data, null, handler);
} catch (RDFParseException e) {
throw new RepositoryException(e);
}
- return handler.getString().split("\n");
+ return handler.getResult().split("\n");
}
Oops, something went wrong.

0 comments on commit 5734c44

Please sign in to comment.