# HG changeset patch # User Thomas Arendsen Hein # Date 1348827313 -7200 # Node ID 31e71085748a1db98dd2acfcec86150f1a8e65fa # Parent cb6e23d3c752ae992258fedfa819fba7644e2941# Parent f3441dc6853f806d871e58e6c0bdb79a8c8e0760 dummy merge for repo head diff -r f3441dc6853f -r 31e71085748a ChangeLog --- a/ChangeLog Fri May 13 10:40:53 2011 +0000 +++ b/ChangeLog Fri Sep 28 12:15:13 2012 +0200 @@ -1,3 +1,115 @@ +2012-09-17 Ingo Weinzierl + + Taggd RELEASE 2.9.1 + +2012-09-10 Sascha L. Teichmann + + * pom.xml: Java 1.5 -> 1.6 + +2012-09-07 Ingo Weinzierl + + Taggd RELEASE 2.9 + +2012-08-24 Björn Ricks + + * src/main/java/de/intevation/artifacts/httpclient/http/HttpClientImpl.java, + src/main/java/de/intevation/artifacts/httpclient/http/HttpClient.java: + Added new method findUser. With the new method it is possible to get a + user document by an account name. + +2012-07-27 Ingo Weinzierl + + Taggd RELEASE 2.8.1 + +2012-07-16 Ingo Weinzierl + + Taggd RELEASE 2.8 + +2012-07-13 Björn Ricks + + * src/main/java/de/intevation/artifacts/httpclient/http/HttpClientImpl.java + src/main/java/de/intevation/artifacts/httpclient/http/HttpClient.java: + Implemented a createUser method for HttpClient. + With the new method its possible to create new users via the HttpClient. + +2012-04-16 Sascha L. Teichmann + + * src/main/java/de/intevation/artifacts/httpclient/http/response/StringResponseHandler.java, + src/main/java/de/intevation/artifacts/httpclient/http/response/StreamResponseHandler.java, + src/main/java/de/intevation/artifacts/httpclient/http/response/DocumentResponseHandler.java: + Added Override annotations. + +2011-09-19 Ingo Weinzierl + + Tagged pre2.7-2012-03-16 + +2011-09-19 Ingo Weinzierl + + Taggd RELEASE 0.5 + + * Changes: Prepared changes for the release. + +2011-08-23 Sascha L. Teichmann + + * src/main/java/de/intevation/artifacts/httpclient/utils/ArtifactProtocolUtils.java + (createFeedDocument): Directly iterate over the entry set of the map. Do not + use the more expensive 'for all key in keys: value = get(key)' + +2011-08-23 Sascha L. Teichmann + + * src/main/java/de/intevation/artifacts/httpclient/utils/ArtifactProtocolUtils.java: + Replaced some XPath attribute extraction by simple DOM getAttributeNS() calls. + +2011-07-04 Ingo Weinzierl + + * src/main/java/de/intevation/artifacts/httpclient/http/HttpClientImpl.java, + src/main/java/de/intevation/artifacts/httpclient/http/HttpClient.java: + Added a method to call a service with a ResponseHandler. This allows us + to access the InputStream directly. + +2011-06-28 Ingo Weinzierl + + Tagged RELEASE 0.4 + +2011-06-27 Ingo Weinzierl + + * Changes: Prepared changes for the upcoming release. + +2011-06-26 Sascha L. Teichmann + + * src/main/java/de/intevation/artifacts/httpclient/utils/XMLUtils.java, + src/main/java/de/intevation/artifacts/httpclient/ConsoleClient.java, + src/main/java/de/intevation/artifacts/httpclient/objects/Artifact.java: + Removed trailing whitespace. + +2011-06-01 Sascha L. Teichmann + + * src/main/java/de/intevation/artifacts/httpclient/http/HttpClientImpl.java: + Use thread local instances of the HTTP clients to foster + their re-use. Change some logging from INFO to DEBUG + because they are not so important. + + * pom.xml: Use the httpclient extension of Restlet to use the + Apache HTTP client as the the underlaying transport agent. + License Apache License, Version 2.0 + +2011-05-19 Ingo Weinzierl + + RELEASE 0.3 + +2011-05-19 Ingo Weinzierl + + * Changes: Prepared for release 0.3. + +2011-05-19 Sascha L. Teichmann + + * src/main/java/de/intevation/artifacts/httpclient/http/HttpClientImpl.java: + Improved the stream handling. + +2011-05-18 Sascha L. Teichmann + + * pom.xml: Bumped restlet version to 2.0.7 + 2011-05-13 Ingo Weinzierl * Changes, NEWS: For Release 0.2. diff -r f3441dc6853f -r 31e71085748a Changes --- a/Changes Fri May 13 10:40:53 2011 +0000 +++ b/Changes Fri Sep 28 12:15:13 2012 +0200 @@ -1,3 +1,31 @@ +2011-09-19 RELEASE 0.5 + + NEW: + + * Performance improvements in ArtifactProtocolUtils. + + * Improved the HttpClient interface and its default implementation: + enabled calling a service with a ResponseHandler. + + +2011-06-27 RELEASE 0.4 + + New: + + * Use thread local instances of the HTTP clients to re-use them. + + * Use the Apache HTTP client extension of Restlet to handle HTTP requests. + + +2011-05-13 RELEASE 0.3 + + New: + + * Bumped Restlet version to 2.0.7 + + * Improved stream handling. + + 2011-05-13 RELEASE 0.2 New: diff -r f3441dc6853f -r 31e71085748a pom.xml --- a/pom.xml Fri May 13 10:40:53 2011 +0000 +++ b/pom.xml Fri Sep 28 12:15:13 2012 +0200 @@ -21,8 +21,8 @@ maven-compiler-plugin 2.0.2 - 1.5 - 1.5 + 1.6 + 1.6 @@ -51,12 +51,17 @@ org.restlet.jse org.restlet - 2.0.4 + 2.0.7 org.restlet.jse org.restlet.ext.xml - 2.0.4 + 2.0.7 + + + org.restlet.jse + org.restlet.ext.httpclient + 2.0.7 diff -r f3441dc6853f -r 31e71085748a src/main/java/de/intevation/artifacts/httpclient/ConsoleClient.java --- a/src/main/java/de/intevation/artifacts/httpclient/ConsoleClient.java Fri May 13 10:40:53 2011 +0000 +++ b/src/main/java/de/intevation/artifacts/httpclient/ConsoleClient.java Fri Sep 28 12:15:13 2012 +0200 @@ -249,7 +249,7 @@ artifact, describe, new DocumentResponseHandler()); List pieces = Arrays.asList(text.split(",")); - List options = new ArrayList(pieces.size()); + List options = new ArrayList(pieces.size()); Node dynamic = XMLUtils.getNodeXPath(description, XPATH_DYNAMIC); diff -r f3441dc6853f -r 31e71085748a src/main/java/de/intevation/artifacts/httpclient/http/HttpClient.java --- a/src/main/java/de/intevation/artifacts/httpclient/http/HttpClient.java Fri May 13 10:40:53 2011 +0000 +++ b/src/main/java/de/intevation/artifacts/httpclient/http/HttpClient.java Fri Sep 28 12:15:13 2012 +0200 @@ -59,6 +59,13 @@ Document callService(String url, String service, Document input) throws ConnectionException; + Object callService( + String url, + String service, + Document input, + ResponseHandler handler) + throws ConnectionException; + /******************************* * Collections API @@ -99,5 +106,11 @@ Document listUserCollections(String userid) throws ConnectionException; + + Document createUser(Document doc) + throws ConnectionException; + + Document findUser(Document doc) + throws ConnectionException; } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: diff -r f3441dc6853f -r 31e71085748a src/main/java/de/intevation/artifacts/httpclient/http/HttpClientImpl.java --- a/src/main/java/de/intevation/artifacts/httpclient/http/HttpClientImpl.java Fri May 13 10:40:53 2011 +0000 +++ b/src/main/java/de/intevation/artifacts/httpclient/http/HttpClientImpl.java Fri Sep 28 12:15:13 2012 +0200 @@ -54,6 +54,12 @@ * user.*/ public static final String PATH_USER_COLLECTIONS = "/list-collections"; + /** The URL part og the resource to create a new user on the server.*/ + public static final String PATH_CREATE_USER = "/create-user"; + + /** The URL part og the resource to find an existing user on the server.*/ + public static final String PATH_FIND_USER = "/find-user"; + /** The URL part of the resource to call a specific service.*/ public static final String PATH_SERVICE = "/service"; @@ -70,6 +76,14 @@ private String localeString; + private static final ThreadLocal CLIENT = + new ThreadLocal() { + @Override + protected Client initialValue() { + logger.debug("create new HTTP client"); + return new Client(Protocol.HTTP); + } + }; public HttpClientImpl(String serverUrl) { this.serverUrl = serverUrl; @@ -213,11 +227,15 @@ ResponseHandler handler = new StreamResponseHandler(); InputStream stream = (InputStream) handler.handle(doPost(url, doc)); - - byte[] b = new byte[4096]; - int i = -1; - while ((i = stream.read(b)) > 0) { - out.write(b, 0, i); + try { + byte[] b = new byte[4096]; + int i; + while ((i = stream.read(b)) >= 0) { + out.write(b, 0, i); + } + } + finally { + stream.close(); } } catch (IOException ioe) { @@ -232,9 +250,11 @@ //============================== private Response doPost(String url, Document body) throws IOException { - logger.info("Start HTTP-POST request to: "+ url); + if (logger.isDebugEnabled()) { + logger.debug("Start HTTP-POST request to: " + url); + } - Client client = new Client(Protocol.HTTP); + Client client = getClient(); Request request = prepareRequest(Method.POST, url); Representation representation = new DomRepresentation( @@ -254,10 +274,17 @@ } + private static Client getClient() { + return CLIENT.get(); + } + + private Response doGet(String url) throws IOException { - logger.info("Start HTTP-POST request to: "+ url); + if (logger.isDebugEnabled()) { + logger.debug("Start HTTP-POST request to: "+ url); + } - Client client = new Client(Protocol.HTTP); + Client client = getClient(); Request request = prepareRequest(Method.GET, url); Response response = client.handle(request); @@ -309,7 +336,10 @@ Language lang = Language.valueOf(localeString); if (lang != null) { - logger.info("Set locale of the request object: " + lang.toString()); + if (logger.isDebugEnabled()) { + logger.debug( + "Set locale of the request object: " + lang.toString()); + } Preference pref = new Preference(); pref.setMetadata(lang); @@ -399,9 +429,14 @@ InputStream stream = collectionOut(doc, uuid, type); byte[] b = new byte[4096]; - int i = -1; - while ((i = stream.read(b)) > 0) { - out.write(b, 0, i); + try { + int i; + while ((i = stream.read(b)) >= 0) { + out.write(b, 0, i); + } + } + finally { + stream.close(); } } catch (IOException ioe) { @@ -446,19 +481,31 @@ public Document callService(String url, String service, Document input) throws ConnectionException { - logger.info("Start service call to '" + service + "'"); + DocumentResponseHandler handler = new DocumentResponseHandler(); - DocumentResponseHandler handler = new DocumentResponseHandler(); + return (Document) callService(url, service, input, handler); + } + + + public Object callService( + String url, + String service, + Document input, + ResponseHandler handler) + throws ConnectionException { + if (logger.isDebugEnabled()) { + logger.debug("Start service call to '" + service + "'"); + } try { String serverUrl = url + PATH_SERVICE + "/" + service; - return (Document) handler.handle(doPost(serverUrl, input)); + return handler.handle(doPost(serverUrl, input)); } catch (IOException ioe) { throw new ConnectionException( "Connection to server failed: " + ioe.getMessage()); } - } + } /******************************* @@ -494,5 +541,37 @@ throw new ConnectionException(ioe.getMessage(), ioe); } } + + @Override + public Document createUser(Document doc) + throws ConnectionException { + ResponseHandler handler = new DocumentResponseHandler(); + + String url = this.serverUrl + PATH_CREATE_USER; + + try { + return (Document) handler.handle(doPost(url, doc)); + } + catch (IOException ioe) { + throw new ConnectionException( + "Connection to server failed: " + ioe.getMessage()); + } + } + + @Override + public Document findUser(Document doc) + throws ConnectionException { + ResponseHandler handler = new DocumentResponseHandler(); + + String url = this.serverUrl + PATH_FIND_USER; + + try { + return (Document) handler.handle(doPost(url, doc)); + } + catch (IOException ioe) { + throw new ConnectionException( + "Connection to server failed: " + ioe.getMessage()); + } + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: diff -r f3441dc6853f -r 31e71085748a src/main/java/de/intevation/artifacts/httpclient/http/response/DocumentResponseHandler.java --- a/src/main/java/de/intevation/artifacts/httpclient/http/response/DocumentResponseHandler.java Fri May 13 10:40:53 2011 +0000 +++ b/src/main/java/de/intevation/artifacts/httpclient/http/response/DocumentResponseHandler.java Fri Sep 28 12:15:13 2012 +0200 @@ -23,6 +23,7 @@ public DocumentResponseHandler() { } + @Override public Object handle(Response response) throws IOException { Representation output = response.getEntity(); return XMLUtils.readDocument(output.getStream()); diff -r f3441dc6853f -r 31e71085748a src/main/java/de/intevation/artifacts/httpclient/http/response/StreamResponseHandler.java --- a/src/main/java/de/intevation/artifacts/httpclient/http/response/StreamResponseHandler.java Fri May 13 10:40:53 2011 +0000 +++ b/src/main/java/de/intevation/artifacts/httpclient/http/response/StreamResponseHandler.java Fri Sep 28 12:15:13 2012 +0200 @@ -21,6 +21,7 @@ public StreamResponseHandler() { } + @Override public Object handle(Response response) throws IOException { Representation output = response.getEntity(); return output.getStream(); diff -r f3441dc6853f -r 31e71085748a src/main/java/de/intevation/artifacts/httpclient/http/response/StringResponseHandler.java --- a/src/main/java/de/intevation/artifacts/httpclient/http/response/StringResponseHandler.java Fri May 13 10:40:53 2011 +0000 +++ b/src/main/java/de/intevation/artifacts/httpclient/http/response/StringResponseHandler.java Fri Sep 28 12:15:13 2012 +0200 @@ -22,6 +22,7 @@ public StringResponseHandler() { } + @Override public Object handle(Response response) throws IOException { InputStream in = (InputStream) super.handle(response); OutputStream out = new ByteArrayOutputStream(); diff -r f3441dc6853f -r 31e71085748a src/main/java/de/intevation/artifacts/httpclient/objects/Artifact.java --- a/src/main/java/de/intevation/artifacts/httpclient/objects/Artifact.java Fri May 13 10:40:53 2011 +0000 +++ b/src/main/java/de/intevation/artifacts/httpclient/objects/Artifact.java Fri Sep 28 12:15:13 2012 +0200 @@ -17,7 +17,7 @@ public class Artifact { /** - * The uuid of this Artifact which must be used to identify + * The uuid of this Artifact which must be used to identify * the artifact at the ArtifactDatabase. */ private String uuid = null; @@ -29,9 +29,9 @@ /** * Constructor - * @param uuid the uuid of this Artifact which must be used to identify + * @param uuid the uuid of this Artifact which must be used to identify * the artifact at the ArtifactDatabase - * @param hash the hash of the artifact which was send be the + * @param hash the hash of the artifact which was send be the * ArtifactDatabase */ public Artifact(String uuid, String hash) { diff -r f3441dc6853f -r 31e71085748a src/main/java/de/intevation/artifacts/httpclient/utils/ArtifactProtocolUtils.java --- a/src/main/java/de/intevation/artifacts/httpclient/utils/ArtifactProtocolUtils.java Fri May 13 10:40:53 2011 +0000 +++ b/src/main/java/de/intevation/artifacts/httpclient/utils/ArtifactProtocolUtils.java Fri Sep 28 12:15:13 2012 +0200 @@ -7,9 +7,7 @@ */ package de.intevation.artifacts.httpclient.utils; -import java.util.Iterator; import java.util.Map; -import java.util.Set; import javax.xml.xpath.XPathConstants; @@ -17,7 +15,6 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; -import org.w3c.dom.Node; import org.w3c.dom.NodeList; import de.intevation.artifacts.httpclient.objects.Artifact; @@ -42,12 +39,14 @@ ArtifactFactory[] facs = new ArtifactFactory[elements.getLength()]; - for (int idx = 0; idx < elements.getLength(); idx++) { - Node factory = elements.item(idx); - String desc = XMLUtils.getStringXPath(factory, "@art:description"); - String name = XMLUtils.getStringXPath(factory, "@art:name"); + String uri = ArtifactNamespaceContext.NAMESPACE_URI; - if (name != null) { + for (int idx = 0; idx < facs.length; idx++) { + Element factory = (Element)elements.item(idx); + String desc = factory.getAttributeNS(uri, "description"); + String name = factory.getAttributeNS(uri, "name"); + + if (name.length() != 0) { facs[idx] = new ArtifactFactory(name, desc); } } @@ -139,11 +138,11 @@ Element action = createArtifactAction(creator, artifact, "feed"); Element data = creator.create("data"); - Set keys = attr.keySet(); - Iterator iter = keys.iterator(); - while (iter.hasNext()) { - String key = (String) iter.next(); - Object values = attr.get(key); + for (Map.Entry entry: + ((Map)attr).entrySet()) { + + String key = entry.getKey(); + Object values = entry.getValue(); if (values instanceof Object[]) { appendInputNodes(creator, data, key, (Object[]) values); @@ -151,7 +150,6 @@ else { appendInputNodes(creator, data, key, values); } - } action.appendChild(data); diff -r f3441dc6853f -r 31e71085748a src/main/java/de/intevation/artifacts/httpclient/utils/XMLUtils.java --- a/src/main/java/de/intevation/artifacts/httpclient/utils/XMLUtils.java Fri May 13 10:40:53 2011 +0000 +++ b/src/main/java/de/intevation/artifacts/httpclient/utils/XMLUtils.java Fri Sep 28 12:15:13 2012 +0200 @@ -38,7 +38,7 @@ import org.xml.sax.SAXException; /** - * This class provides many helper-Methods for handling different kinds of + * This class provides many helper-Methods for handling different kinds of * XML-stuff. * @author Ingo Weinzierl * @author Sascha L. Teichmann @@ -102,7 +102,7 @@ } /** - * Adds a new attribute to the given element. + * Adds a new attribute to the given element. * @param element the element where the attribute should be placed in. * @param name the name of the attribute * @param value the value of the attribute @@ -152,7 +152,7 @@ } /** - * Fetch the value of an element or attribute from the given resource + * Fetch the value of an element or attribute from the given resource * using the query. * @param root the source where the value should be fetch from * @param query the query that should be used to fetch the value @@ -221,7 +221,7 @@ } /** - * Fetch a Nodeset value from a XML-Fragment or XML-Document using the + * Fetch a Nodeset value from a XML-Fragment or XML-Document using the * given query. * @param root the source where the String should be fetched from * @param query the query that should be used, @@ -232,7 +232,7 @@ } /** - * Fetch a Node from a XML-Fragment or XML-Document using the + * Fetch a Node from a XML-Fragment or XML-Document using the * given query. * @param root the source where the Node should be fetched from * @param query the query that should be used, @@ -243,7 +243,7 @@ } /** - * Fetch a String value from a XML-Fragment or XML-Document using the + * Fetch a String value from a XML-Fragment or XML-Document using the * given query. * @param root the source where the String should be fetched from * @param xpath the query that should be used, @@ -254,7 +254,7 @@ } /** - * Fetch a String value from a XML-Fragment or XML-Document using the + * Fetch a String value from a XML-Fragment or XML-Document using the * given query. * @param root the source where the String should be fetched from * @param query the query that should be used,