teichmann@5861: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5861: * Software engineering by Intevation GmbH teichmann@5861: * teichmann@5861: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5861: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5861: * documentation coming with Dive4Elements River for details. teichmann@5861: */ teichmann@5861: teichmann@5835: package org.dive4elements.river.client.server; ingo@99: ingo@99: import org.w3c.dom.Document; ingo@99: ingo@1367: import org.apache.log4j.Logger; ingo@1367: ingo@99: import com.google.gwt.user.server.rpc.RemoteServiceServlet; ingo@99: teichmann@5835: import org.dive4elements.artifacts.common.utils.ClientProtocolUtils; ingo@99: teichmann@5835: import org.dive4elements.artifacts.httpclient.exceptions.ConnectionException; teichmann@5835: import org.dive4elements.artifacts.httpclient.http.HttpClient; teichmann@5835: import org.dive4elements.artifacts.httpclient.http.HttpClientImpl; teichmann@5835: import org.dive4elements.artifacts.httpclient.http.response.DocumentResponseHandler; ingo@99: teichmann@5835: import org.dive4elements.river.client.shared.exceptions.ServerException; teichmann@5835: import org.dive4elements.river.client.shared.model.Collection; ingo@905: teichmann@5835: import org.dive4elements.river.client.client.services.DescribeCollectionService; ingo@99: ingo@99: ingo@99: /** ingo@99: * This service implements a method that queries the DESCRIBE document of a ingo@99: * specific collection and returns a Collection object with the information of ingo@99: * the document. ingo@99: * ingo@99: * @author Ingo Weinzierl ingo@99: */ ingo@99: public class DescribeCollectionServiceImpl ingo@99: extends RemoteServiceServlet ingo@99: implements DescribeCollectionService ingo@99: { ingo@1367: private static final Logger logger = ingo@1367: Logger.getLogger(DescribeCollectionServiceImpl.class); ingo@1367: ingo@1367: ingo@215: /** The error message key that is thrown if an error occured while ingo@215: * describe() a Collection.*/ ingo@215: public static final String ERROR_DESCRIBE_COLLECTION = ingo@215: "error_describe_collection"; ingo@215: ingo@215: raimund@1425: public Collection describe(String uuid, String locale) ingo@215: throws ServerException ingo@215: { ingo@1367: logger.info("DescribeCollectionServiceImpl.describe"); ingo@99: raimund@1425: String url = getServletContext().getInitParameter("server-url"); raimund@1425: ingo@99: Document describe = ClientProtocolUtils.newDescribeCollectionDocument( ingo@99: uuid); ingo@99: raimund@1425: HttpClient client = new HttpClientImpl(url, locale); ingo@99: ingo@99: try { ingo@99: Document response = (Document) client.doCollectionAction( ingo@99: describe, uuid, new DocumentResponseHandler()); ingo@99: ingo@905: Collection c = CollectionHelper.parseCollection(response); ingo@99: ingo@99: if (c == null) { ingo@215: throw new ServerException(ERROR_DESCRIBE_COLLECTION); ingo@99: } ingo@99: ingo@1367: logger.debug("Collection successfully parsed."); ingo@524: ingo@99: return c; ingo@99: } ingo@99: catch (ConnectionException ce) { ingo@1367: logger.error(ce, ce); ingo@99: } ingo@99: ingo@215: throw new ServerException(ERROR_DESCRIBE_COLLECTION); ingo@99: } ingo@99: } ingo@99: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :