comparison flys-client/src/main/java/de/intevation/flys/client/server/DistanceInfoServiceImpl.java @ 1367:ab8eb2f544f2

Replaced stdout and stderr logging with log4j loggers in server classes. flys-client/trunk@3069 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 25 Oct 2011 12:31:15 +0000
parents 78907f0fb939
children bc06a671ef60
comparison
equal deleted inserted replaced
1366:d0eb2202ffbe 1367:ab8eb2f544f2
4 import java.util.List; 4 import java.util.List;
5 5
6 import org.w3c.dom.Document; 6 import org.w3c.dom.Document;
7 import org.w3c.dom.Element; 7 import org.w3c.dom.Element;
8 import org.w3c.dom.NodeList; 8 import org.w3c.dom.NodeList;
9
10 import org.apache.log4j.Logger;
9 11
10 import com.google.gwt.user.server.rpc.RemoteServiceServlet; 12 import com.google.gwt.user.server.rpc.RemoteServiceServlet;
11 13
12 import de.intevation.artifacts.common.ArtifactNamespaceContext; 14 import de.intevation.artifacts.common.ArtifactNamespaceContext;
13 import de.intevation.artifacts.common.utils.XMLUtils; 15 import de.intevation.artifacts.common.utils.XMLUtils;
27 */ 29 */
28 public class DistanceInfoServiceImpl 30 public class DistanceInfoServiceImpl
29 extends RemoteServiceServlet 31 extends RemoteServiceServlet
30 implements DistanceInfoService 32 implements DistanceInfoService
31 { 33 {
34 private static final Logger logger =
35 Logger.getLogger(DistanceInfoServiceImpl.class);
36
37
32 public static final String ERROR_NO_DISTANCEINFO_FOUND = 38 public static final String ERROR_NO_DISTANCEINFO_FOUND =
33 "error_no_distanceinfo_found"; 39 "error_no_distanceinfo_found";
34 40
35 public static final String XPATH_DISTANCES = "art:distances/art:distance"; 41 public static final String XPATH_DISTANCES = "art:distances/art:distance";
36 42
39 String url, 45 String url,
40 String locale, 46 String locale,
41 String river) 47 String river)
42 throws ServerException 48 throws ServerException
43 { 49 {
44 System.out.println("DistanceInfoServiceImpl.getDistanceInfo"); 50 logger.info("DistanceInfoServiceImpl.getDistanceInfo");
45 51
46 Document doc = XMLUtils.newDocument(); 52 Document doc = XMLUtils.newDocument();
47 53
48 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( 54 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
49 doc, 55 doc,
59 HttpClient client = new HttpClientImpl(url, locale); 65 HttpClient client = new HttpClientImpl(url, locale);
60 66
61 try { 67 try {
62 Document result = client.callService(url, "distanceinfo", doc); 68 Document result = client.callService(url, "distanceinfo", doc);
63 69
64 System.out.println("Extract distance info objects now."); 70 logger.debug("Extract distance info objects now.");
65 DistanceInfoObject[] objects = extractDistanceInfoObjects(result); 71 DistanceInfoObject[] objects = extractDistanceInfoObjects(result);
66 72
67 if (objects != null && objects.length > 0) { 73 if (objects != null && objects.length > 0) {
68 return objects; 74 return objects;
69 } 75 }
70 } 76 }
71 catch (ConnectionException ce) { 77 catch (ConnectionException ce) {
72 System.err.println(ce.getLocalizedMessage()); 78 logger.error(ce, ce);
73 } 79 }
74 80
75 throw new ServerException(ERROR_NO_DISTANCEINFO_FOUND); 81 throw new ServerException(ERROR_NO_DISTANCEINFO_FOUND);
76 } 82 }
77 83
87 throws ServerException 93 throws ServerException
88 { 94 {
89 NodeList list = result.getElementsByTagName("distance"); 95 NodeList list = result.getElementsByTagName("distance");
90 96
91 if (list == null || list.getLength() == 0) { 97 if (list == null || list.getLength() == 0) {
92 System.err.println("No distance info found."); 98 logger.warn("No distance info found.");
93 throw new ServerException(ERROR_NO_DISTANCEINFO_FOUND); 99 throw new ServerException(ERROR_NO_DISTANCEINFO_FOUND);
94 } 100 }
95 101
96 int num = list.getLength(); 102 int num = list.getLength();
97 System.out.println("Response contains " + num + " objects."); 103 logger.debug("Response contains " + num + " objects.");
98 104
99 List<DistanceInfoObject> objects = 105 List<DistanceInfoObject> objects =
100 new ArrayList<DistanceInfoObject>(num); 106 new ArrayList<DistanceInfoObject>(num);
101 107
102 for (int i = 0; i < num; i++) { 108 for (int i = 0; i < num; i++) {
106 if (obj != null) { 112 if (obj != null) {
107 objects.add(obj); 113 objects.add(obj);
108 } 114 }
109 } 115 }
110 116
111 System.out.println("Retrieved " + objects.size() + " distances."); 117 logger.debug("Retrieved " + objects.size() + " distances.");
112 118
113 return (DistanceInfoObject[]) 119 return (DistanceInfoObject[])
114 objects.toArray(new DistanceInfoObject[num]); 120 objects.toArray(new DistanceInfoObject[num]);
115 } 121 }
116 122
140 Double tp = top .length() > 0 ? new Double(top) : null; 146 Double tp = top .length() > 0 ? new Double(top) : null;
141 147
142 return new DistanceInfoObjectImpl(desc, f, t, riverside, b, tp); 148 return new DistanceInfoObjectImpl(desc, f, t, riverside, b, tp);
143 } 149 }
144 catch (NumberFormatException nfe) { 150 catch (NumberFormatException nfe) {
145 System.err.println(nfe.getLocalizedMessage()); 151 logger.warn(nfe.getLocalizedMessage());
146 } 152 }
147 } 153 }
148 154
149 System.err.println("Invalid distance info object found."); 155 logger.warn("Invalid distance info object found.");
150 156
151 return null; 157 return null;
152 } 158 }
153 } 159 }
154 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 160 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org