org.vfny.geoserver.wcs.WcsException Maven / Gradle / Ivy
/* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
* This code is licensed under the GPL 2.0 license, availible at the root
* application directory.
*/
package org.vfny.geoserver.wcs;
import org.vfny.geoserver.ServiceException;
import org.vfny.geoserver.global.GeoServer;
import org.vfny.geoserver.util.Requests;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;
/**
* This defines an exception that can be turned into a valid xml service
* exception that wcs clients will expect. All errors should be wrapped in this
* before returning to clients.
*
* @author $Author: Alessio Fabiani ([email protected]) $ (last
* modification)
* @author $Author: Simone Giannecchini ([email protected]) $ (last
* modification)
* @version $Id: WcsException.java 8479 2008-02-28 19:11:04Z aaime $
*/
public class WcsException extends ServiceException {
/** Class logger */
private static Logger LOGGER = org.geotools.util.logging.Logging.getLogger("org.vfny.geoserver.wcs");
/**
* The fixed MIME type of a WCS exception.
*/
private static final String SE_XML = "application/vnd.ogc.se_xml";
/**
* Empty constructor.
*/
public WcsException() {
super();
}
/**
* Message constructor.
*
* @param message The message for the .
*/
public WcsException(String message) {
super(message);
}
/**
* Throwable constructor.
*
* @param e The message for the .
*/
public WcsException(Throwable e) {
super(e);
}
/**
* Message Locator constructor.
*
* @param message The message for the .
* @param locator The java class that caused the problem
*/
public WcsException(String message, String locator) {
super(message, locator);
}
/**
* Message code and locator constructor.
*
* @param message The message for the .
* @param locator The java class that caused the problem
*/
public WcsException(String message, String locator, String code) {
super(message, locator);
setCode(code);
}
public WcsException(String message, Throwable cause) {
super(message, cause);
}
/**
* DOCUMENT ME!
*
* @param e The cause of failure
* @param preMessage The message to tack on the front.
* @param locator The java class that caused the problem
*/
public WcsException(Throwable e, String preMessage, String locator) {
super(e, preMessage, locator);
}
/**
* Return request type.
*
* @param printStackTrace whether the stack trace should be included.
* @param request DOCUMENT ME!
*
* @return The ServiceExceptionReport of this error.
*
* @task REVISIT: Our error handling should actually have knowledge of the
* app configuration, so that we can set the ogc error report to
* validate right (reference our own schema), and to put the correct
* mime type here.
*/
public String getXmlResponse(boolean printStackTrace, HttpServletRequest request,
GeoServer geoserver) {
//Perhaps not the best place to do this, but it's by far the best place to ensure
//that all logged errors get recorded in the same way, as there all must return
//xml responses.
LOGGER.warning("encountered error: " + getMessage());
String indent = " ";
StringBuffer returnXml = new StringBuffer("\n");
returnXml.append("\n");
//REVISIT: handle multiple service exceptions? must refactor class.
returnXml.append(indent + "\n" + indent + indent);
returnXml.append(getXmlMessage(printStackTrace));
returnXml.append(indent + " \n");
returnXml.append(" ");
LOGGER.fine("return wfs exception is " + returnXml);
return returnXml.toString();
}
/**
* Returns the mime type that should be exposed to the client
* when sending the exception message.
*
*
* Defaults to geoserver.getMimeType()
*
*
* @return
*/
public String getMimeType(GeoServer geoserver) {
return SE_XML + "; charset=" + geoserver.getCharSet().name();
}
}