ingo@1365: package de.intevation.flys.client.server; ingo@1365: ingo@1365: import java.io.InputStream; ingo@1365: import java.io.IOException; ingo@1365: raimund@1510: import java.util.Map; raimund@1510: ingo@1365: import org.w3c.dom.Document; ingo@1365: ingo@1367: import org.apache.log4j.Logger; ingo@1367: ingo@1365: import com.google.gwt.user.server.rpc.RemoteServiceServlet; ingo@1365: ingo@1365: import de.intevation.artifacts.common.utils.ClientProtocolUtils; ingo@1365: import de.intevation.artifacts.common.utils.XMLUtils; ingo@1365: ingo@1365: import de.intevation.artifacts.httpclient.http.HttpClient; ingo@1365: import de.intevation.artifacts.httpclient.http.HttpClientImpl; ingo@1365: import de.intevation.artifacts.httpclient.exceptions.ConnectionException; ingo@1365: ingo@1365: import de.intevation.flys.client.shared.exceptions.ServerException; ingo@1365: import de.intevation.flys.client.shared.model.Collection; ingo@1376: import de.intevation.flys.client.shared.model.MapConfig; raimund@1510: import de.intevation.flys.client.shared.model.OutputMode; ingo@1365: import de.intevation.flys.client.client.services.MapOutputService; ingo@1365: ingo@1365: ingo@1365: public class MapOutputServiceImpl ingo@1365: extends RemoteServiceServlet ingo@1365: implements MapOutputService ingo@1365: { ingo@1365: ingo@1367: private static final Logger logger = ingo@1367: Logger.getLogger(MapOutputServiceImpl.class); ingo@1367: ingo@1367: ingo@1376: public static final String ERROR_NO_MAP_CONFIG = "error_no_map_config"; ingo@1376: raimund@1510: public static final String ERROR_NO_MAP_OUTPUT_TYPE = "error_no_map_output_type"; ingo@1376: ingo@1376: public MapConfig doOut(Collection collection) ingo@1365: throws ServerException ingo@1365: { ingo@1367: logger.info("MapOutputServiceImpl.doOut"); ingo@1365: ingo@1370: String url = getServletContext().getInitParameter("server-url"); ingo@1365: String uuid = collection.identifier(); ingo@1365: raimund@1510: Map modes = collection.getOutputModes(); raimund@1510: String requestMode = ""; raimund@1510: if (modes.containsKey("floodmap")) { raimund@1510: requestMode = "floodmap"; raimund@1510: } raimund@1510: else if (modes.containsKey("map")) { raimund@1510: requestMode = "map"; raimund@1510: } raimund@1510: else { raimund@1510: throw new ServerException(ERROR_NO_MAP_OUTPUT_TYPE); raimund@1510: } raimund@1510: ingo@1365: try { ingo@1365: Document request = ClientProtocolUtils.newOutCollectionDocument( raimund@1510: uuid, requestMode, requestMode); ingo@1365: ingo@1370: HttpClient client = new HttpClientImpl(url); raimund@1510: InputStream is = client.collectionOut(request, uuid, requestMode); ingo@1365: ingo@1365: Document response = XMLUtils.parseDocument(is); ingo@1365: ingo@1376: return MapHelper.parseConfig(response); ingo@1365: } ingo@1365: catch (ConnectionException e) { ingo@1367: logger.error(e, e); ingo@1365: } ingo@1365: catch (IOException ioe) { ingo@1367: logger.error(ioe, ioe); ingo@1365: } ingo@1376: ingo@1376: throw new ServerException(ERROR_NO_MAP_CONFIG); ingo@1365: } ingo@1365: } ingo@1365: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :