Hey Alessio, I just noticed this commit, and have a couple comments.
First, I don't think it's necessarily wise to _just_ use the speed strategy. The point of the different strategies is to return proper OGC exceptions. If you're already streaming out there's no way to then return an exception, so the various strategies make it so it writes to a partial memory buffer or to disk first before sending it out, so as to catch errors when writing and to be able to report them properly. So if at all possible I'd recommend trying to use them, or else the server may not be spec compliant. Unless there's no chance of anything messing up at the point you're writing out?
Second, the full on copy and paste of doService is a recipe for maintenance nightmare. If the parent class changes people won't know to also update this. If it's necessary to have WCS always pick the speed strategy then I'd abstract out that line in to a method
Instead I'd override getServiceStrategy and just have that call Speed Strategy there instead of using the strategy class set on init.
best regards,
Chris
Chris Holmes wrote:
On 20 Oct 2006 15:53:59 -0000, *afabiani@anonymised.com <mailto:afabiani@anonymised.com>* <afabiani@anonymised.com <mailto:afabiani@anonymised.com>> wrote:
Revision
5323 <http://fisheye.codehaus.org/changelog/geoserver/?cs=5323>
Author
afabiani
Date
2006-10-20 10:53:59 -0500 (Fri, 20 Oct 2006)Log Message
WCSService -> SPEED Strategy no matter what is the configuration
Modified Paths
* trunk/wcs/src/main/java/org/vfny/geoserver/wcs/responses/coverage/GeoTIFFCoverageResponseDelegate.java
<#10e666dd481d30ef_trunkwcssrcmainjavaorgvfnygeoserverwcsresponsescoverageGeoTIFFCoverageResponseDelegatejava>
* trunk/wcs/src/main/java/org/vfny/geoserver/wcs/servlets/WCService.java
<#10e666dd481d30ef_trunkwcssrcmainjavaorgvfnygeoserverwcsservletsWCServicejava>Diff
Modified:
trunk/wcs/src/main/java/org/vfny/geoserver/wcs/responses/coverage/GeoTIFFCoverageResponseDelegate.java
(5322 => 5323)--- trunk/wcs/src/main/java/org/vfny/geoserver/wcs/responses/coverage/GeoTIFFCoverageResponseDelegate.java 2006-10-20 15:16:23 UTC (rev 5322)
+++ trunk/wcs/src/main/java/org/vfny/geoserver/wcs/responses/coverage/GeoTIFFCoverageResponseDelegate.java 2006-10-20 15:53:59 UTC (rev 5323)@@ -4,7 +4,6 @@
*/
package org.vfny.geoserver.wcs.responses.coverage;
-import java.io.File;
import java.io.IOException;
import java.io.OutputStream
;
Modified:
trunk/wcs/src/main/java/org/vfny/geoserver/wcs/servlets/WCService.java
(5322 => 5323)--- trunk/wcs/src/main/java/org/vfny/geoserver/wcs/servlets/WCService.java 2006-10-20 15:16:23 UTC (rev 5322)
+++ trunk/wcs/src/main/java/org/vfny/geoserver/wcs/servlets/WCService.java 2006-10-20 15:53:59 UTC (rev 5323)@@ -4,11 +4,26 @@
*/
package org.vfny.geoserver.wcs.servlets;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.SocketException;+import java.util.Iterator;
+import java.util.Map;
+import java.util.logging.Level;
+
+import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import org.vfny.geoserver.ExceptionHandler;
+import org.vfny.geoserver.Request;
+import org.vfny.geoserver.Response;
+import org.vfny.geoserver.ServiceException
;
+import org.vfny.geoserver.global.Service;
import org.vfny.geoserver.global.WCS;
import org.vfny.geoserver.servlets.AbstractService;
+import org.vfny.geoserver.servlets.ServiceStrategy
;
+import org.vfny.geoserver.servlets.SpeedStrategy;
import org.vfny.geoserver.wcs.WcsExceptionHandler;
/**
@@ -50,6 +65,194 @@
}
/**+ * Peforms service according to ServiceStrategy.
+ * + * <p>
+ * This method has very strict requirements, please see the class
+ * description for the specifics.
+ * </p>+ * + * <p>
+ * It has a lot of try/catch blocks, but they are fairly necessary to
+ * handle things correctly and to avoid as many ugly servlet responses, so
+ * that everything is wrapped correctly.+ * </p>
+ *
+ * @param request The httpServlet of the request.
+ * @param response The response to be returned.
+ * @param serviceRequest The OGC request to service.
+ *+ * @throws ServletException if the strategy can't be instantiated
+ */
+ protected void doService(HttpServletRequest request,
+ HttpServletResponse response, Request serviceRequest)
+ throws ServletException {+ LOGGER.info("handling request: " + serviceRequest);
+
+ if (!isServiceEnabled(request)) {
+ try {
+ sendDisabledServiceError(response);
+ } catch(IOException e) {+ LOGGER.log(Level.WARNING, "Error writing service unavailable response", e);
+ }
+ return;
+ }
+
+ ServiceStrategy strategy = null;
+ Response serviceResponse = null;+
+ try {
+ strategy = new SpeedStrategy();
+ LOGGER.fine("strategy is: " + strategy.getId());
+ serviceResponse = getResponseHandler();
+ } catch (Throwable t) {+ sendError(request, response, t);
+
+ return;
+ }
+
+ Map services = getApplicationContext().getBeansOfType(Service.class);
+ Service s = null;
+ for (Iterator itr = services.entrySet().iterator(); itr.hasNext() {
+ Map.Entry entry = (Map.Entry) itr.next();
+ String id = (String) entry.getKey();
+ Service service = (Service) entry.getValue();
++ if (id.equalsIgnoreCase(serviceRequest.getService())) {
+ s = service;
+ break;
+ }
+
+ }
+
+ if (s == null) {
+ String msg = "No service found matching: " ++ serviceRequest.getService();
+ sendError(request, response,new ServiceException ( msg ));
+ return;
+ }
+
+ try {
+ // execute request+ LOGGER.finer("executing request");
+ serviceResponse.execute(serviceRequest);
+ LOGGER.finer("execution succeed");
+ } catch (ServiceException serviceException) {+ LOGGER.warning("service exception while executing request: "
+ + serviceRequest + "\ncause: " + serviceException.getMessage());
+ serviceResponse.abort(s);+ sendError(request, response, serviceException);
+
+ return;
+ } catch (Throwable t) {
+ //we can safelly send errors here, since we have not touched response yet+ serviceResponse.abort(s);
+ sendError(request, response, t);
+
+ return;
+ }
+
+ OutputStream strategyOuput = null;
+
+ //obtain the strategy output stream+ try {
+ LOGGER.finest("getting strategy output");
+ strategyOuput = strategy.getDestination(response);
+ LOGGER.finer("strategy output is: "
+ + strategyOuput.getClass().getName());
+
+ String mimeType = serviceResponse.getContentType(s.getGeoServer());
+ LOGGER.fine("mime type is: " + mimeType);
+ response.setContentType
(mimeType);
+
+ String encoding = serviceResponse.getContentEncoding();
+
+ if (encoding != null) {
+ LOGGER.fine("content encoding is: " + encoding);
+ response.setHeader("Content-Encoding", encoding);
+ }
+ } catch (SocketException socketException) {
+ LOGGER.fine(
+ "it seems that the user has closed the request stream: "+ + socketException.getMessage());
+
+ // It seems the user has closed the request stream
+ // Apparently this is a "cancel" and will quietly go away
+ //+ // I will still give strategy and serviceResponse
+ // a chance to clean up
+ //
+ serviceResponse.abort(s);
+ strategy.abort();
+
+ return;+ } catch (IOException ex) {
+ serviceResponse.abort(s);
+ strategy.abort();
+ sendError(request, response, ex);
+
+ return;
+ }
+
+ try {+ // gather response
+ serviceResponse.writeTo(strategyOuput);
+ strategyOuput.flush();
+ strategy.flush();
+ } catch (java.net.SocketException sockEx) { // user cancel+ serviceResponse.abort(s);
+ strategy.abort();
+
+ return;
+ } catch (IOException ioException) { // strategyOutput error
+ LOGGER.log(Level.SEVERE, "Error writing out " + ioException.getMessage(), ioException);
+ serviceResponse.abort(s);
+ strategy.abort();
+ sendError(request, response, ioException);
+
+ return;
+ } catch (ServiceException writeToFailure) { // writeTo Failure+ serviceResponse.abort(s);
+ strategy.abort();
+ sendError(request, response, writeToFailure);
+
+ return;
+ } catch (Throwable help) { // This is an unexpected error(!)+ help.printStackTrace();
+ serviceResponse.abort(s);
+ strategy.abort();
+ sendError(request, response, help);
+
+ return;
+ }
+
+ // Finish Response+ // I have moved closing the output stream out here, it was being
+ // done by a few of the ServiceStrategy
+ //
+ // By this time serviceResponse has finished successfully
+ // and strategy is also finished+ //
+ try {
+ response.getOutputStream().flush();
+ response.getOutputStream().close();
+ } catch (SocketException sockEx) { // user cancel
+ LOGGER.warning
("Could not send completed response to user:"
+ + sockEx);
+
+ return;
+ } catch (IOException ioException) {
+ // This is bad, the user did not get the completed response+ LOGGER.warning("Could not send completed response to user:"
+ + ioException);
+
+ return;
+ }
+
+ LOGGER.info("Service handled");+ }
+ + /**
* a Web Coverage ServiceConfig exception handler
*
* @return an instance of WcsExceptionHandler------------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email
!DSPAM:1003,4538fa3479047731818748!
--
Chris Holmes
The Open Planning Project
http://topp.openplans.org