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@221: ingo@221: import org.w3c.dom.Document; ingo@221: ingo@1367: import org.apache.log4j.Logger; ingo@1367: ingo@221: import com.google.gwt.user.server.rpc.RemoteServiceServlet; ingo@221: teichmann@5835: import org.dive4elements.artifacts.common.ArtifactNamespaceContext; teichmann@5835: import org.dive4elements.artifacts.common.utils.ClientProtocolUtils; teichmann@5835: import org.dive4elements.artifacts.common.utils.XMLUtils; ingo@221: 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@221: teichmann@5835: import org.dive4elements.river.client.shared.exceptions.ServerException; teichmann@5835: import org.dive4elements.river.client.shared.model.Artifact; teichmann@5835: import org.dive4elements.river.client.client.services.GetArtifactService; ingo@221: ingo@221: ingo@221: /** ingo@221: * This service provides a method that returns an artifact based on its ingo@221: * identifier. ingo@221: * ingo@221: * @author Ingo Weinzierl ingo@221: */ ingo@221: public class GetArtifactServiceImpl ingo@221: extends RemoteServiceServlet ingo@221: implements GetArtifactService ingo@221: { ingo@1367: private static final Logger logger = ingo@1367: Logger.getLogger(GetArtifactServiceImpl.class); ingo@1367: ingo@1367: ingo@221: public static final String ERROR_DESCRIBE_ARTIFACT = ingo@221: "error_describe_artifact"; ingo@221: ingo@221: public static final String XPATH_RESULT = "/art:result/text()"; ingo@221: ingo@221: public static final String OPERATION_FAILURE = "FAILED"; ingo@221: ingo@221: ingo@229: public Artifact getArtifact( ingo@229: String locale, ingo@229: String uuid, ingo@229: String hash) ingo@221: throws ServerException ingo@221: { ingo@1367: logger.info("GetArtifactServiceImpl.getArtifact"); ingo@229: raimund@1425: String url = getServletContext().getInitParameter("server-url"); raimund@1425: ingo@221: Document describe = ClientProtocolUtils.newDescribeDocument( ingo@221: uuid, hash, true); ingo@221: ingo@229: HttpClient client = new HttpClientImpl(url, locale); ingo@221: ingo@221: try { ingo@221: Document description = (Document) client.describe( teichmann@5835: new org.dive4elements.artifacts.httpclient.objects.Artifact( ingo@221: uuid, hash), ingo@221: describe, ingo@221: new DocumentResponseHandler()); ingo@221: ingo@221: if (description == null) { ingo@221: throw new ServerException(ERROR_DESCRIBE_ARTIFACT); ingo@221: } ingo@221: ingo@221: String result = XMLUtils.xpathString( ingo@221: description, ingo@221: XPATH_RESULT, ingo@221: ArtifactNamespaceContext.INSTANCE); ingo@221: ingo@221: if (result == null || !result.equals(OPERATION_FAILURE)) { ingo@221: return (Artifact) new FLYSArtifactCreator().create(description); ingo@221: } ingo@221: } ingo@221: catch (ConnectionException ce) { ingo@1367: logger.error(ce, ce); ingo@221: } ingo@221: ingo@221: throw new ServerException(ERROR_DESCRIBE_ARTIFACT); ingo@221: } ingo@221: } ingo@221: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :