I\'m working on a RESTful web service in Java. I need a good way to send error messages to the client if something\'s wrong.
According to the Javadoc, HttpServlet
In Spring powered web application, running on Tomcat I use following bean:
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import org.springframework.beans.factory.InitializingBean;
public class SystemPropertiesInitializingBean implements InitializingBean {
private Map systemProperties;
@Override
public void afterPropertiesSet() throws Exception {
if (null == systemProperties || systemProperties.isEmpty()) {
return;
}
final Set> entrySet = systemProperties.entrySet();
for (final Entry entry : entrySet) {
final String key = entry.getKey();
final String value = entry.getValue();
System.setProperty(key, value);
}
}
public void setSystemProperties(final Map systemProperties) {
this.systemProperties = systemProperties;
}
}
And in applicationContext.xml: