[Geoserver-devel] Speed Strategy Only? [geoserver-scm] [geoserver] [5323] trunk/wcs/src/main/java/org/vfny/geoserver/wcs/servlets: WCSService -> SPEED Strategy no matter what is the configuration

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&gt;
    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():wink: {
    + 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

Hi Chris, this is only a first very quick hack, I have to better think how to solve this problem but I need a deeper study and analysis. I committed the code in order to continue working at home … at this time I haven’t all the responses I’m thinking to a good way to solve the issue. First of all I have to understand why the plugins work bad with other strategies.

On 10/20/06, Chris Holmes <cholmes@anonymised.com> wrote:

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](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.
    • This method has very strict requirements, please see the class
    • description for the specifics.
    • 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.
    • @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():wink: {

  • 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

Eng. Alessio Fabiani
Vice President/CTO GeoSolutions

http://www.geo-solutions.it


Cool. I'm just trying to make sure what we do on trunk is high quality. I guess the one thing I would say is that if you're doing quick hacks on trunks, then label them as such, either with a HACK comment in the code or in the commit, so others know and don't do a code review (I'm hoping to encourage more code reviews in general).

Chris

Alessio Fabiani wrote:

Hi Chris, this is only a first very quick hack, I have to better think how to solve this problem but I need a deeper study and analysis. I committed the code in order to continue working at home ... at this time I haven't all the responses I'm thinking to a good way to solve the issue. First of all I have to understand why the plugins work bad with other strategies.

On 10/20/06, *Chris Holmes* <cholmes@anonymised.com <mailto:cholmes@anonymised.com>> wrote:

    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>
     > <mailto: afabiani@anonymised.com <mailto:afabiani@anonymised.com>>*
    <afabiani@anonymised.com <mailto:afabiani@anonymised.com>
     > <mailto:afabiani@anonymised.com>> wrote:
     >
     > Revision
     > 5323
    <http://fisheye.codehaus.org/changelog/geoserver/?cs=5323&gt;
     > 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():wink: {
     > + 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
     >

    --
    Chris Holmes
    The Open Planning Project
    http://topp.openplans.org

--
-------------------------------------------------------
Eng. Alessio Fabiani
Vice President/CTO GeoSolutions

http://www.geo-solutions.it

--------------------------------------------------------- !DSPAM:1003,45393543117141510810322!

------------------------------------------------------------------------

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

!DSPAM:1003,45393543117141510810322!

------------------------------------------------------------------------

_______________________________________________
Geoserver-devel mailing list
Geoserver-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-devel

!DSPAM:1003,45393543117141510810322!

--
Chris Holmes
The Open Planning Project
http://topp.openplans.org