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@599: ingo@599: import org.w3c.dom.Document; ingo@599: ingo@1367: import org.apache.log4j.Logger; ingo@1367: ingo@599: import com.google.gwt.user.server.rpc.RemoteServiceServlet; ingo@599: teichmann@5835: import org.dive4elements.artifacts.common.ArtifactNamespaceContext; teichmann@5835: import org.dive4elements.artifacts.common.utils.XMLUtils; ingo@599: 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@599: teichmann@5835: import org.dive4elements.river.client.shared.exceptions.ServerException; teichmann@5835: import org.dive4elements.river.client.shared.model.Collection; ingo@599: ingo@599: ingo@599: /** ingo@599: * @author Ingo Weinzierl ingo@599: */ ingo@599: public class DoCollectionAction extends RemoteServiceServlet { ingo@599: ingo@1367: private static final Logger logger = ingo@1367: Logger.getLogger(DoCollectionAction.class); ingo@1367: ingo@1367: ingo@599: public static final String XPATH_RESULT = "/art:result/text()"; ingo@599: public static final String OPERATION_FAILURE = "FAILED"; ingo@599: public static final String FAILURE_EXCEPTION = "collection_action_failed"; ingo@599: ingo@599: ingo@599: protected void doAction(Collection c, Document action, String url) ingo@599: throws ServerException ingo@599: { ingo@1367: logger.info("DoCollectionAction.doAction"); ingo@1367: ingo@599: HttpClient client = new HttpClientImpl(url); ingo@599: ingo@599: try { ingo@599: Document res = (Document) client.doCollectionAction( ingo@599: action, c.identifier(), ingo@599: new DocumentResponseHandler()); ingo@599: ingo@599: String result = XMLUtils.xpathString( ingo@599: res, ingo@599: XPATH_RESULT, ingo@599: ArtifactNamespaceContext.INSTANCE); ingo@599: ingo@599: if (result == null || result.equals(OPERATION_FAILURE)) { ingo@1367: logger.error("Operation failed."); ingo@599: throw new ServerException(FAILURE_EXCEPTION); ingo@599: } ingo@599: } ingo@599: catch (ConnectionException ce) { ingo@1367: logger.error(ce, ce); ingo@599: throw new ServerException(FAILURE_EXCEPTION); ingo@599: } ingo@599: } ingo@599: }