use of org.springframework.web.util.NestedServletException in project spring-framework by spring-projects.
the class HttpInvokerServiceExporter method handleRequest.
/**
* Reads a remote invocation from the request, executes it,
* and writes the remote invocation result to the response.
* @see #readRemoteInvocation(HttpServletRequest)
* @see #invokeAndCreateResult(org.springframework.remoting.support.RemoteInvocation, Object)
* @see #writeRemoteInvocationResult(HttpServletRequest, HttpServletResponse, RemoteInvocationResult)
*/
@Override
public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
RemoteInvocation invocation = readRemoteInvocation(request);
RemoteInvocationResult result = invokeAndCreateResult(invocation, getProxy());
writeRemoteInvocationResult(request, response, result);
} catch (ClassNotFoundException ex) {
throw new NestedServletException("Class not found during deserialization", ex);
}
}
use of org.springframework.web.util.NestedServletException in project spring-framework by spring-projects.
the class FrameworkServlet method processRequest.
/**
* Process this request, publishing an event regardless of the outcome.
* <p>The actual event handling is performed by the abstract
* {@link #doService} template method.
*/
protected final void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
long startTime = System.currentTimeMillis();
Throwable failureCause = null;
LocaleContext previousLocaleContext = LocaleContextHolder.getLocaleContext();
LocaleContext localeContext = buildLocaleContext(request);
RequestAttributes previousAttributes = RequestContextHolder.getRequestAttributes();
ServletRequestAttributes requestAttributes = buildRequestAttributes(request, response, previousAttributes);
WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
asyncManager.registerCallableInterceptor(FrameworkServlet.class.getName(), new RequestBindingInterceptor());
initContextHolders(request, localeContext, requestAttributes);
try {
doService(request, response);
} catch (ServletException ex) {
failureCause = ex;
throw ex;
} catch (IOException ex) {
failureCause = ex;
throw ex;
} catch (Throwable ex) {
failureCause = ex;
throw new NestedServletException("Request processing failed", ex);
} finally {
resetContextHolders(request, previousLocaleContext, previousAttributes);
if (requestAttributes != null) {
requestAttributes.requestCompleted();
}
if (logger.isDebugEnabled()) {
if (failureCause != null) {
this.logger.debug("Could not complete request", failureCause);
} else {
if (asyncManager.isConcurrentHandlingStarted()) {
logger.debug("Leaving response open for concurrent processing");
} else {
this.logger.debug("Successfully completed request");
}
}
}
publishRequestHandledEvent(request, response, startTime, failureCause);
}
}
use of org.springframework.web.util.NestedServletException in project spring-boot by spring-projects.
the class MetricFilterAutoConfigurationTests method controllerMethodThatThrowsUnhandledException.
@Test
public void controllerMethodThatThrowsUnhandledException() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class, MetricFilterAutoConfiguration.class);
Filter filter = context.getBean(Filter.class);
MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController()).addFilter(filter).build();
try {
mvc.perform(get("/unhandledException")).andExpect(status().isInternalServerError());
} catch (NestedServletException ex) {
// Expected
}
verify(context.getBean(CounterService.class)).increment("status.500.unhandledException");
verify(context.getBean(GaugeService.class)).submit(eq("response.unhandledException"), anyDouble());
context.close();
}
use of org.springframework.web.util.NestedServletException in project opennms by OpenNMS.
the class ServiceRegistryHttpInvokerServiceExporter method handleRequest.
public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
RemoteInvocation invocation = readRemoteInvocation(request);
Serializable interfaceNameObject = invocation.getAttribute(ServiceRegistryHttpInvokerProxyFactoryBean.ATTRIBUTE_INTERFACE_NAME);
if (interfaceNameObject == null) {
throw new NestedServletException("Interface name attribute not found. This class can only service requests to a " + ServiceRegistryHttpInvokerProxyFactoryBean.class.getSimpleName() + " client.");
} else {
String interfaceName = (String) interfaceNameObject;
try {
// RemoteInvocationResult result = invokeAndCreateResult(invocation, getProxy());
// TODO: Use a method similar to {@link RemoteExporter#getProxyForService()} to create an
// interface proxy that masks any other methods on the remotely invoked object.
RemoteInvocationResult result = invokeAndCreateResult(invocation, serviceRegistry.findProvider(Class.forName(interfaceName)));
writeRemoteInvocationResult(request, response, result);
} catch (IllegalArgumentException e) {
throw new NestedServletException("No provider registered for interface " + interfaceName, e);
}
}
} catch (ClassNotFoundException e) {
throw new NestedServletException("Class not found during deserialization", e);
}
}
use of org.springframework.web.util.NestedServletException in project spring-cloud-sleuth by spring-cloud.
the class MyFilter method should_log_tracing_information_when_500_exception_was_thrown.
@Test
public void should_log_tracing_information_when_500_exception_was_thrown() throws Exception {
Long expectedTraceId = new Random().nextLong();
try {
whenSentToExceptionThrowingEndpoint(expectedTraceId);
fail("Should fail");
} catch (NestedServletException e) {
then(e).hasRootCauseInstanceOf(RuntimeException.class);
}
// we need to dump the span cause it's not in TraceFilter since TF
// has also error dispatch and the ErrorController would report the span
then(this.reporter.getSpans()).hasSize(1);
then(this.reporter.getSpans().get(0).tags()).containsEntry("error", "Request processing failed; nested exception is java.lang.RuntimeException");
}
Aggregations