return;
}
ServiceStrategy strategy = null;
Response serviceResponse = null;
try {
strategy = getServiceStrategy();
LOGGER.fine("strategy is: " + strategy);
serviceResponse = getResponseHandler();
} catch (Throwable t) {
sendError(response, t);
return;
}
Service s = null;
if ("WFS".equals(serviceRequest.getService())) {
s = serviceRequest.getWFS();
} else {
s = serviceRequest.getWMS();
}
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(response, serviceException);
return;
} catch (Throwable t) {
//we can safelly send errors here, since we have not touched response yet
serviceResponse.abort(s);
sendError(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(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
serviceResponse.abort(s);
strategy.abort();
sendError(response, ioException);
return;
} catch (ServiceException writeToFailure) { // writeTo Failure
serviceResponse.abort(s);
strategy.abort();
sendError(response, writeToFailure);
return;
} catch (Throwable help) { // This is an unexpected error(!)
help.printStackTrace();
serviceResponse.abort(s);
strategy.abort();
sendError(response, help);
return;
}