ingo@599: package de.intevation.flys.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: ingo@599: import de.intevation.artifacts.common.ArtifactNamespaceContext; ingo@599: import de.intevation.artifacts.common.utils.XMLUtils; ingo@599: ingo@599: import de.intevation.artifacts.httpclient.exceptions.ConnectionException; ingo@599: import de.intevation.artifacts.httpclient.http.HttpClient; ingo@599: import de.intevation.artifacts.httpclient.http.HttpClientImpl; ingo@599: import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler; ingo@599: ingo@599: import de.intevation.flys.client.shared.exceptions.ServerException; ingo@599: import de.intevation.flys.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: }