1 | /* |
2 | * Copyright 2006-2008 the original author or authors. |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | */ |
16 | package org.springframework.batch.core.step.item; |
17 | |
18 | import org.apache.commons.logging.Log; |
19 | import org.apache.commons.logging.LogFactory; |
20 | import org.springframework.batch.core.listener.ItemListenerSupport; |
21 | |
22 | /** |
23 | * Default implementation of the {@link ItemListenerSupport} class that |
24 | * writes all exceptions via commons logging. Since generics can't be used to |
25 | * ensure the list contains exceptions, any non exceptions will be logged out by |
26 | * calling toString on the object. |
27 | * |
28 | * @author Lucas Ward |
29 | * |
30 | */ |
31 | public class DefaultItemFailureHandler extends ItemListenerSupport { |
32 | |
33 | protected static final Log logger = LogFactory |
34 | .getLog(DefaultItemFailureHandler.class); |
35 | |
36 | /* |
37 | * (non-Javadoc) |
38 | * |
39 | * @see org.springframework.batch.core.domain.ItemFailureLog#log(java.util.List) |
40 | */ |
41 | public void onReadError(Exception ex) { |
42 | try { |
43 | logger.error("Error encountered while reading", ex); |
44 | } catch (Exception exception) { |
45 | logger.error("Invalid type for logging: [" + exception.toString() |
46 | + "]"); |
47 | } |
48 | } |
49 | |
50 | public void onWriteError(Exception ex, Object item) { |
51 | try { |
52 | logger.error("Error encountered while writing item: [ " + item + "]", ex); |
53 | } catch (Exception exception) { |
54 | logger.error("Invalid type for logging: [" + exception.toString() |
55 | + "]"); |
56 | } |
57 | } |
58 | |
59 | } |