Project

General

Profile

« Previous | Next » 

Revision 6272

use logging, not system.out

View differences:

src/edu/ucsb/nceas/metacat/restservice/MNResourceHandler.java
157 157
                resource = resource.trim();
158 158
            }
159 159
                        
160
            System.out.println("handling verb " + httpVerb + " request with resource '" + resource + "'");
161
            System.out.println("resource: '" + resource + "'");
160
            logMetacat.debug("handling verb " + httpVerb + " request with resource '" + resource + "'");
161
            logMetacat.debug("resource: '" + resource + "'");
162 162
            boolean status = false;
163 163
            
164 164
            if (resource != null) {
......
173 173
	                	// set the access rules
174 174
	                    setaccess();
175 175
	                    status = true;
176
	                    System.out.println("done setting access");
176
	                    logMetacat.debug("done setting access");
177 177
                    }
178 178
                } else if (resource.equals(RESOURCE_IS_AUTHORIZED)) {
179 179
                    if (httpVerb == GET) {
......
184 184
                        }
185 185
	                    isAuthorized(objectId);
186 186
	                    status = true;
187
	                    System.out.println("done getting access");
187
	                    logMetacat.debug("done getting access");
188 188
                    }
189 189
                } else if (resource.equals(RESOURCE_META)) {
190
                    System.out.println("Using resource 'meta'");
190
                    logMetacat.debug("Using resource 'meta'");
191 191
                    String objectId = request.getPathInfo();
192 192
                    if (objectId != null && objectId.length() > 1) {
193 193
                        objectId = request.getPathInfo().substring(1);
......
200 200
                    }
201 201
                    
202 202
                } else if (resource.equals(RESOURCE_OBJECTS)) {
203
                    System.out.println("Using resource 'object'");
203
                    logMetacat.debug("Using resource 'object'");
204 204

  
205 205
                    String objectId = request.getPathInfo();
206 206
                    if (objectId != null && objectId.length() > 1) {
......
209 209
                        objectId = null;
210 210
                    }
211 211
                    
212
                    System.out.println("objectId: " + objectId);
212
                    logMetacat.debug("objectId: " + objectId);
213 213
                    logMetacat.debug("verb:" + httpVerb);
214 214

  
215 215
                    if (httpVerb == GET) {
......
230 230
                    }
231 231
                  
232 232
                } else if (resource.equals(RESOURCE_LOG)) {
233
                    System.out.println("Using resource 'log'");
233
                    logMetacat.debug("Using resource 'log'");
234 234
                    // handle log events
235 235
                    if (httpVerb == GET) {
236 236
                        getLog();
237 237
                        status = true;
238 238
                    }
239 239
                } else if (resource.equals(RESOURCE_CHECKSUM)) {
240
                    System.out.println("Using resource 'checksum'");
240
                    logMetacat.debug("Using resource 'checksum'");
241 241
                    // handle checksum requests
242 242
                    if (httpVerb == GET) {
243 243
                        checksum();
......
252 252
                    status = true;
253 253
                } else if (resource.equals(RESOURCE_REPLICATE)) {
254 254
                	if (httpVerb == POST) {
255
	                    System.out.println("processing replicate request");
255
	                    logMetacat.debug("processing replicate request");
256 256
	                    replicate();
257 257
	                    status = true;
258 258
                	}
......
283 283
            serializeException(be, out);
284 284
        } catch (Exception e) {
285 285
            logMetacat.error(e.getClass() + ": " + e.getMessage());
286
            System.out.println("Error handle(): " + e.getClass() + ": " + e.getMessage());
286
            logMetacat.debug("Error handle(): " + e.getClass() + ": " + e.getMessage());
287 287
            e.printStackTrace();
288 288
        }
289 289
    }
......
314 314
    }
315 315
    
316 316
    private boolean monitor() throws NotFound, ParseException, NotImplemented, ServiceFailure, NotAuthorized, InvalidRequest, InsufficientResources, UnsupportedType, IOException, JiBXException {
317
    	System.out.println("processing monitor request");
317
    	logMetacat.debug("processing monitor request");
318 318
        String pathInfo = request.getPathInfo();
319 319
        
320
        System.out.println("verb is GET");
321
        System.out.println("pathInfo is " + pathInfo);
320
        logMetacat.debug("verb is GET");
321
        logMetacat.debug("pathInfo is " + pathInfo);
322 322
        pathInfo = pathInfo.substring(1);
323 323
        
324 324
        if (pathInfo.toLowerCase().equals("ping")) {
325
            System.out.println("processing ping request");
325
            logMetacat.debug("processing ping request");
326 326
            boolean result = MNodeService.getInstance().ping();
327 327
            return result;
328 328
            
329 329
        } else if (pathInfo.toLowerCase().equals("status")) {
330
            System.out.println("processing status request");
330
            logMetacat.debug("processing status request");
331 331
            // TODO: implement in MNCore
332 332
            //MNodeService.getInstance().getStatus();
333 333
            return false;
334 334
            
335 335
        } else if (pathInfo.toLowerCase().equals("object")) {
336
            System.out.println("processing object request");
336
            logMetacat.debug("processing object request");
337 337
            Identifier pid = null;
338 338
            ObjectFormat format = null;
339 339
            if (params.containsKey("format")) {
......
350 350
            //ObjectStatistics objectStats = MNodeService.getInstance().getObjectStatistics(format, pid);
351 351
            
352 352
        } else if (pathInfo.toLowerCase().equals("event")) {
353
            System.out.println("processing event request");
353
            logMetacat.debug("processing event request");
354 354
            ObjectFormat format = null;
355 355
            Integer period = null;
356 356
            String requestor = null;
......
403 403
            //do nothing.  default to MD5
404 404
        	logMetacat.warn("No algorithm specified, using default: " + checksumAlgorithm);
405 405
        }
406
        System.out.println("getting checksum for object " + guid + " with algorithm " + checksumAlgorithm);
406
        logMetacat.debug("getting checksum for object " + guid + " with algorithm " + checksumAlgorithm);
407 407
        try {
408 408
            Checksum c = MNodeService.getInstance().getChecksum(session, guidid, checksumAlgorithm);
409
            System.out.println("got checksum " + c.getValue());
409
            logMetacat.debug("got checksum " + c.getValue());
410 410
            response.setStatus(200);
411
            System.out.println("serializing response");
411
            logMetacat.debug("serializing response");
412 412
            serializeServiceType(Checksum.class, c, response.getOutputStream());
413
            System.out.println("done serializing response.");
413
            logMetacat.debug("done serializing response.");
414 414
        }
415 415
        catch(NotAuthorized na)
416 416
        {
......
445 445
     */
446 446
    private void replicate() throws Exception {
447 447

  
448
        System.out.println("in POST replicate()");
448
        logMetacat.debug("in POST replicate()");
449 449

  
450 450
        File tmpDir = getTempDirectory();
451
        System.out.println("temp dir: " + tmpDir.getAbsolutePath());
451
        logMetacat.debug("temp dir: " + tmpDir.getAbsolutePath());
452 452
        MultipartRequestResolver mrr = new MultipartRequestResolver(
453 453
                tmpDir.getAbsolutePath(), 1000000000, 0);
454 454
        MultipartRequest mr = mrr.resolveMultipart(request);
......
456 456
        Iterator keys = files.keySet().iterator();
457 457
        while(keys.hasNext()) {
458 458
            String key = (String)keys.next();
459
            System.out.println("files key: " + key);
460
            System.out.println("files value: " + files.get(key));
459
            logMetacat.debug("files key: " + key);
460
            logMetacat.debug("files value: " + files.get(key));
461 461
        }
462 462
        
463 463
        Map<String, List<String>> params = mr.getMultipartParameters();
464 464
        keys = params.keySet().iterator();
465 465
        while(keys.hasNext()) {
466 466
            String key = (String)keys.next();
467
            System.out.println("params key: " + key);
468
            System.out.println("params value: " + params.get(key));
467
            logMetacat.debug("params key: " + key);
468
            logMetacat.debug("params value: " + params.get(key));
469 469
        }
470 470
        
471 471
        // File f = files.get("sysmeta");
472 472
        // the files are not being keyed by the part name, but rather the filename
473 473
        File f = files.get(files.keySet().iterator().next());
474 474
        
475
        System.out.println("file: " + f.getAbsolutePath());
475
        logMetacat.debug("file: " + f.getAbsolutePath());
476 476
        FileInputStream fis = new FileInputStream(f);
477 477

  
478 478
        String sn = params.get("sourceNode").get(0);
479
        System.out.println("sourceNode: " + sn);
479
        logMetacat.debug("sourceNode: " + sn);
480 480
        NodeReference sourceNode = (NodeReference) deserializeServiceType(NodeReference.class, new ByteArrayInputStream(sn.getBytes("UTF-8")));
481 481
        
482 482
        //parse the systemMetadata
......
589 589
            
590 590
            try {
591 591
            	String fromDateS = params.get("fromDate")[0];
592
                System.out.println("param fromDateS: " + fromDateS);
592
                logMetacat.debug("param fromDateS: " + fromDateS);
593 593
                fromDate = parseDateAndConvertToGMT(fromDateS);
594 594
            } catch (Exception e) {
595 595
            	logMetacat.warn("Could not parse fromDate: " + e.getMessage());
596 596
            }
597 597
            try {
598 598
            	String toDateS = params.get("toDate")[0];
599
                System.out.println("param toDateS: " + toDateS);
599
                logMetacat.debug("param toDateS: " + toDateS);
600 600
                toDate = parseDateAndConvertToGMT(toDateS);
601 601
            } catch (Exception e) {
602 602
            	logMetacat.warn("Could not parse toDate: " + e.getMessage());
......
607 607
            } catch (Exception e) {
608 608
            	logMetacat.warn("Could not parse event: " + e.getMessage());
609 609
			}
610
            System.out.println("fromDate: " + fromDate + " toDate: " + toDate);
610
            logMetacat.debug("fromDate: " + fromDate + " toDate: " + toDate);
611 611
            
612 612
            try {
613 613
            	start =  Integer.parseInt(params.get("start")[0]);
......
620 620
				logMetacat.warn("Could not parse count: " + e.getMessage());
621 621
			}
622 622
            
623
            System.out.println("calling getLogRecords");
623
            logMetacat.debug("calling getLogRecords");
624 624
            Log log = MNodeService.getInstance().getLogRecords(session, fromDate, toDate, event, start, count);
625 625
            
626 626
            out = response.getOutputStream();
......
713 713
                catch(Exception e)
714 714
                {
715 715
                    response.setStatus(500);
716
                    System.out.println("Error with Crud.get().  " +
716
                    logMetacat.error("Error with Crud.get().  " +
717 717
                            "If this is an 'Exception producing data' error, " +
718 718
                            "go to CrudService.get() for better debugging.  " +
719 719
                            "Here's the error: " + e.getClass() + ": " + e.getMessage());
......
739 739
                    String[] value = (String[])request.getParameterValues(name);
740 740
                    /*for(int i=0; i<value.length; i++)
741 741
                    {
742
                        System.out.println("name: " + name + " value: " + value[i]);
742
                        logMetacat.debug("name: " + name + " value: " + value[i]);
743 743
                    }*/
744 744
                    if(name.equals("startTime") && value != null)
745 745
                    {
......
750 750
                        }
751 751
                        catch(Exception e)
752 752
                        {  //if we can't parse it, just don't use the startTime param
753
                            System.out.println("Could not parse startTime: " + value[0]);
753
                            logMetacat.warn("Could not parse startTime: " + value[0]);
754 754
                            startTime = null;
755 755
                        }
756 756
                    }
......
763 763
                        }
764 764
                        catch(Exception e)
765 765
                        {  //if we can't parse it, just don't use the endTime param
766
                            System.out.println("Could not parse endTime: " + value[0]);
766
                            logMetacat.warn("Could not parse endTime: " + value[0]);
767 767
                            endTime = null;
768 768
                        }
769 769
                    }
......
790 790
                    }
791 791
                }
792 792
                //make the crud call
793
                System.out.println("session: " + session + " startTime: " + startTime +
793
                logMetacat.debug("session: " + session + " startTime: " + startTime +
794 794
                        " endtime: " + endTime + " objectFormat: " + 
795 795
                        objectFormat + " replicaStatus: " + replicaStatus + 
796 796
                        " start: " + start + " count: " + count);
......
886 886
     * @throws NotFound 
887 887
     */
888 888
    protected void putObject(String pid, String action) throws ServiceFailure, InvalidRequest, FileNotFoundException, JiBXException, InvalidToken, NotAuthorized, IdentifierNotUnique, UnsupportedType, InsufficientResources, InvalidSystemMetadata, NotImplemented, NotFound {
889
        System.out.println("putObject with pid " + pid);
889
        logMetacat.debug("putObject with pid " + pid);
890 890
        logMetacat.debug("Entering putObject: " + pid + "/" + action);
891 891
        OutputStream out = null;
892 892
        try {
......
914 914

  
915 915
            Identifier id = new Identifier();
916 916
            id.setValue(pid);
917
            System.out.println("creating object with pid " + pid);
917
            logMetacat.debug("creating object with pid " + pid);
918 918
            Identifier rId = MNodeService.getInstance().create(session, id, object, smd);
919 919
            serializeServiceType(Identifier.class, rId, out);
920 920
            
......
962 962
        Identifier id = new Identifier();
963 963
        id.setValue(guid);
964 964
        try {
965
            System.out.println("Calling delete");
965
            logMetacat.debug("Calling delete");
966 966
            MNodeService.getInstance().delete(session, id);
967 967
            serializeServiceType(Identifier.class, id, out);
968 968
        } 
src/edu/ucsb/nceas/metacat/restservice/CNResourceHandler.java
373 373
        
374 374
        try {
375 375
        	String fromDateS = params.get("fromDate")[0];
376
            System.out.println("param fromDateS: " + fromDateS);
376
            logMetacat.debug("param fromDateS: " + fromDateS);
377 377
            fromDate = parseDateAndConvertToGMT(fromDateS);
378 378
        } catch (Exception e) {
379 379
        	logMetacat.warn("Could not parse fromDate: " + e.getMessage());
380 380
        }
381 381
        try {
382 382
        	String toDateS = params.get("toDate")[0];
383
            System.out.println("param toDateS: " + toDateS);
383
            logMetacat.debug("param toDateS: " + toDateS);
384 384
            toDate = parseDateAndConvertToGMT(toDateS);
385 385
        } catch (Exception e) {
386 386
        	logMetacat.warn("Could not parse toDate: " + e.getMessage());
......
391 391
        } catch (Exception e) {
392 392
        	logMetacat.warn("Could not parse event: " + e.getMessage());
393 393
		}
394
        System.out.println("fromDate: " + fromDate + " toDate: " + toDate);
394
        logMetacat.debug("fromDate: " + fromDate + " toDate: " + toDate);
395 395
        
396 396
        try {
397 397
        	start =  Integer.parseInt(params.get("start")[0]);
......
404 404
			logMetacat.warn("Could not parse count: " + e.getMessage());
405 405
		}
406 406
        
407
        System.out.println("calling getLogRecords");
407
        logMetacat.debug("calling getLogRecords");
408 408
        Log log = CNodeService.getInstance().getLogRecords(session, fromDate, toDate, event, start, count);
409 409
        
410 410
        OutputStream out = response.getOutputStream();
src/edu/ucsb/nceas/metacat/restservice/D1ResourceHandler.java
235 235
        
236 236
        // handle MMP inputs
237 237
        File tmpDir = getTempDirectory();
238
        System.out.println("temp dir: " + tmpDir.getAbsolutePath());
238
        logMetacat.debug("temp dir: " + tmpDir.getAbsolutePath());
239 239
        MultipartRequestResolver mrr = 
240 240
        	new MultipartRequestResolver(tmpDir.getAbsolutePath(), 1000000000, 0);
241 241
        MultipartRequest mr = null;
......
245 245
            throw new ServiceFailure("1202", 
246 246
            		"Could not resolve multipart files: " + e.getMessage());
247 247
		}
248
        System.out.println("resolved multipart request");
248
        logMetacat.debug("resolved multipart request");
249 249
        Map<String, File> files = mr.getMultipartFiles();
250 250
        if (files == null) {
251 251
            throw new ServiceFailure("1202", "create/update must have multipart files with names 'object' and 'sysmeta'");
252 252
        }
253
        System.out.println("got multipart files");
253
        logMetacat.debug("got multipart files");
254 254
        
255 255
        if (files.keySet() == null) {
256
            System.out.println("No file keys in MMP request.");
256
            logMetacat.error("No file keys in MMP request.");
257 257
            throw new ServiceFailure("1202", "No file keys found in MMP.  " +
258 258
                    "create/update must have multipart files with names 'object' and 'sysmeta'");
259 259
        }
......
261 261
		// for logging purposes, dump out the key-value pairs that constitute the request
262 262
		// 3 types exist: request params, multipart params, and multipart files
263 263
        Iterator it = files.keySet().iterator();
264
        System.out.println("iterating through files");
264
        logMetacat.debug("iterating through files");
265 265
        while (it.hasNext()) {
266 266
            String key = (String)it.next();
267
            System.out.println("files key: " + key);
268
            System.out.println("files value: " + files.get(key));
267
            logMetacat.debug("files key: " + key);
268
            logMetacat.debug("files value: " + files.get(key));
269 269
        }
270 270
        
271 271
        multipartparams = mr.getMultipartParameters();
272 272
        it = multipartparams.keySet().iterator();
273
        System.out.println("iterating through multipartparams");
273
        logMetacat.debug("iterating through multipartparams");
274 274
        while (it.hasNext()) {
275 275
            String key = (String)it.next();
276
            System.out.println("multipartparams key: " + key);
277
            System.out.println("multipartparams value: " + multipartparams.get(key));
276
            logMetacat.debug("multipartparams key: " + key);
277
            logMetacat.debug("multipartparams value: " + multipartparams.get(key));
278 278
        }
279 279
        
280 280
        it = params.keySet().iterator();
281
        System.out.println("iterating through params");
281
        logMetacat.debug("iterating through params");
282 282
        while (it.hasNext()) {
283 283
            String key = (String)it.next();
284
            System.out.println("param key: " + key);
285
            System.out.println("param value: " + params.get(key));
284
            logMetacat.debug("param key: " + key);
285
            logMetacat.debug("param value: " + params.get(key));
286 286
        }
287
        System.out.println("done iterating the request...");
287
        logMetacat.debug("done iterating the request...");
288 288

  
289 289
        File smFile = files.get("sysmeta");
290 290
		if (smFile == null) {
291 291
		    throw new InvalidRequest("1102", "Missing the required file-part 'sysmeta' from the multipart request.");
292 292
		}
293
        System.out.println("smFile: " + smFile.getAbsolutePath());
293
        logMetacat.debug("smFile: " + smFile.getAbsolutePath());
294 294
        File objFile = files.get("object");
295 295
		if (objFile == null) {
296 296
		    throw new InvalidRequest("1102", "Missing the required file-part 'object' from the multipart request.");
297 297
		}
298
        System.out.println("objectfile: " + objFile.getAbsolutePath());
298
        logMetacat.debug("objectfile: " + objFile.getAbsolutePath());
299 299
        
300 300
        return files;
301 301
    }
......
403 403
                break;
404 404
            }
405 405
        }
406
        System.out.println("boundary is: '" + boundary + "'");
407 406
        return endResult;
408 407
    }
409 408
    

Also available in: Unified diff