ingo@221: package de.intevation.flys.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: ingo@221: import de.intevation.artifacts.common.ArtifactNamespaceContext; ingo@221: import de.intevation.artifacts.common.utils.ClientProtocolUtils; ingo@221: import de.intevation.artifacts.common.utils.XMLUtils; ingo@221: ingo@221: import de.intevation.artifacts.httpclient.exceptions.ConnectionException; ingo@221: import de.intevation.artifacts.httpclient.http.HttpClient; ingo@221: import de.intevation.artifacts.httpclient.http.HttpClientImpl; ingo@221: import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler; ingo@221: ingo@221: import de.intevation.flys.client.shared.exceptions.ServerException; ingo@221: import de.intevation.flys.client.shared.model.Artifact; ingo@221: import de.intevation.flys.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 url, 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: 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( ingo@221: new de.intevation.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 :