ingo@32: package de.intevation.flys.client.server; ingo@32: ingo@32: import org.w3c.dom.Document; ingo@32: ingo@1367: import org.apache.log4j.Logger; ingo@1367: ingo@32: import com.google.gwt.user.server.rpc.RemoteServiceServlet; ingo@32: ingo@32: import de.intevation.artifacts.common.ArtifactNamespaceContext; ingo@32: import de.intevation.artifacts.common.utils.ClientProtocolUtils; ingo@32: import de.intevation.artifacts.common.utils.XMLUtils; ingo@32: ingo@32: import de.intevation.artifacts.httpclient.exceptions.ConnectionException; ingo@32: import de.intevation.artifacts.httpclient.http.HttpClient; ingo@32: import de.intevation.artifacts.httpclient.http.HttpClientImpl; ingo@32: import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler; ingo@32: ingo@215: import de.intevation.flys.client.shared.exceptions.ServerException; ingo@32: import de.intevation.flys.client.shared.model.Artifact; ingo@32: import de.intevation.flys.client.client.services.AdvanceService; ingo@32: ingo@32: ingo@32: /** ingo@32: * This interface provides artifact specific operation ADVANCE. ingo@32: * ingo@32: * @author Ingo Weinzierl ingo@32: */ ingo@32: public class AdvanceServiceImpl ingo@32: extends RemoteServiceServlet ingo@32: implements AdvanceService ingo@32: { ingo@1367: private static final Logger logger = Logger.getLogger(AdvanceService.class); ingo@1367: ingo@1367: ingo@32: public static final String XPATH_RESULT = "/art:result/text()"; ingo@32: ingo@32: public static final String OPERATION_FAILURE = "FAILED"; ingo@32: ingo@215: public static final String ERROR_ADVANCE_ARTIFACT = "error_advance_artifact"; ingo@32: ingo@215: ingo@229: public Artifact advance( ingo@229: String locale, ingo@229: Artifact artifact, ingo@229: String target) ingo@215: throws ServerException ingo@215: { ingo@1367: logger.info("AdvanceServiceImpl.advance"); ingo@229: raimund@1425: String url = getServletContext().getInitParameter("server-url"); raimund@1425: ingo@32: Document advance = ClientProtocolUtils.newAdvanceDocument( ingo@32: artifact.getUuid(), ingo@32: artifact.getHash(), ingo@32: target); ingo@32: raimund@1425: HttpClient client = new HttpClientImpl(url, locale); ingo@32: ingo@32: try { ingo@32: Document description = (Document) client.advance( ingo@32: new de.intevation.artifacts.httpclient.objects.Artifact( ingo@32: artifact.getUuid(), ingo@32: artifact.getHash()), ingo@32: advance, ingo@32: new DocumentResponseHandler()); ingo@32: ingo@32: if (description == null) { ingo@215: throw new ServerException(ERROR_ADVANCE_ARTIFACT); ingo@32: } ingo@32: ingo@32: String result = XMLUtils.xpathString( ingo@32: description, ingo@32: XPATH_RESULT, ingo@32: ArtifactNamespaceContext.INSTANCE); ingo@32: ingo@32: if (result == null || !result.equals(OPERATION_FAILURE)) { ingo@32: return (Artifact) new FLYSArtifactCreator().create(description); ingo@32: } ingo@32: } ingo@32: catch (ConnectionException ce) { ingo@1367: logger.error(ce, ce); ingo@32: } ingo@32: ingo@215: throw new ServerException(ERROR_ADVANCE_ARTIFACT); ingo@32: } ingo@32: } ingo@32: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :