Skip to content

Commit

Permalink
First try to resolve #101
Browse files Browse the repository at this point in the history
  • Loading branch information
ralscha committed Aug 15, 2013
1 parent a28f718 commit b983640
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public class ConfigurationService implements InitializingBean, DisposableBean {
@Autowired(required = false)
private JsonHandler jsonHandler;

@Autowired(required = false)
private RouterExceptionHandler routerExceptionHandler;

private ParametersResolver parametersResolver;

@Override
Expand All @@ -60,6 +63,10 @@ public void afterPropertiesSet() {
if (jsonHandler == null) {
jsonHandler = new JsonHandler();
}

if (routerExceptionHandler == null) {
routerExceptionHandler = new DefaultRouterExceptionHandler(this);
}

if (configuration.getBatchedMethodsExecutionPolicy() == BatchedMethodsExecutionPolicy.CONCURRENT
&& configuration.getBatchedMethodsExecutorService() == null) {
Expand Down Expand Up @@ -116,4 +123,8 @@ public ParametersResolver getParametersResolver() {
return parametersResolver;
}

public RouterExceptionHandler getRouterExceptionHandler() {
return routerExceptionHandler;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Copyright 2010-2013 Ralph Schaer <ralphschaer@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.ralscha.extdirectspring.controller;

import ch.ralscha.extdirectspring.bean.BaseResponse;
import ch.ralscha.extdirectspring.util.ExtDirectSpringUtil;

public class DefaultRouterExceptionHandler implements RouterExceptionHandler {

private final ConfigurationService configurationService;

public DefaultRouterExceptionHandler(ConfigurationService configurationService) {
this.configurationService = configurationService;
}

@Override
public void handleException(BaseResponse response, Exception e) {
Throwable cause;
if (e.getCause() != null) {
cause = e.getCause();
} else {
cause = e;
}

response.setType("exception");
response.setMessage(configurationService.getConfiguration().getMessage(cause));

if (configurationService.getConfiguration().isSendStacktrace()) {
response.setWhere(ExtDirectSpringUtil.getStackTrace(cause));
} else {
response.setWhere(null);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -477,21 +477,7 @@ private Object processRemotingRequest(HttpServletRequest request, HttpServletRes
}

private void handleException(BaseResponse response, Exception e) {
Throwable cause;
if (e.getCause() != null) {
cause = e.getCause();
} else {
cause = e;
}

response.setType("exception");
response.setMessage(configurationService.getConfiguration().getMessage(cause));

if (configurationService.getConfiguration().isSendStacktrace()) {
response.setWhere(ExtDirectSpringUtil.getStackTrace(cause));
} else {
response.setWhere(null);
}
configurationService.getRouterExceptionHandler().handleException(response, e);
}

private void handleMethodNotFoundError(BaseResponse response, String beanName, String methodName) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright 2010-2013 Ralph Schaer <ralphschaer@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.ralscha.extdirectspring.controller;

import ch.ralscha.extdirectspring.bean.BaseResponse;

public interface RouterExceptionHandler {
void handleException(BaseResponse response, Exception e);
}

0 comments on commit b983640

Please sign in to comment.