Project

General

Profile

« Previous | Next » 

Revision 6542

add User-Agent logging to support D1 requirements

View differences:

test/edu/ucsb/nceas/metacat/dataone/MockCNode.java
71 71
    public String lookupNodeBaseUrl(String nodeId) throws ServiceFailure, NotImplemented {
72 72

  
73 73
    	try {
74
			return MNodeService.getInstance().getCapabilities().getBaseURL();
74
			return MNodeService.getInstance(null).getCapabilities().getBaseURL();
75 75
		} catch (Exception e) {
76 76
			// TODO Auto-generated catch block
77 77
			e.printStackTrace();
test/edu/ucsb/nceas/metacat/dataone/MNodeServiceTest.java
165 165
      guid.setValue("testGet." + System.currentTimeMillis());
166 166
      InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
167 167
      SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
168
      Identifier pid = MNodeService.getInstance().create(session, guid, object, sysmeta);
169
      InputStream result = MNodeService.getInstance().get(session, guid);
168
      Identifier pid = MNodeService.getInstance(request).create(session, guid, object, sysmeta);
169
      InputStream result = MNodeService.getInstance(request).get(session, guid);
170 170
      // go back to beginning of original stream
171 171
      object.reset();
172 172
      // check
......
238 238
      guid.setValue("testGetSystemMetadata." + System.currentTimeMillis());
239 239
      InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
240 240
      SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
241
      Identifier pid = MNodeService.getInstance().create(session, guid, object, sysmeta);
242
      SystemMetadata newsysmeta = MNodeService.getInstance().getSystemMetadata(session, pid);
241
      Identifier pid = MNodeService.getInstance(request).create(session, guid, object, sysmeta);
242
      SystemMetadata newsysmeta = MNodeService.getInstance(request).getSystemMetadata(session, pid);
243 243
      assertEquals(newsysmeta.getIdentifier().getValue(), sysmeta.getIdentifier().getValue());
244 244
      
245 245
    } catch (UnsupportedEncodingException e) {
......
306 306
      guid.setValue("testCreate." + System.currentTimeMillis());
307 307
      InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
308 308
      SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
309
      Identifier pid = MNodeService.getInstance().create(session, guid, object, sysmeta);
309
      Identifier pid = MNodeService.getInstance(request).create(session, guid, object, sysmeta);
310 310
      assertEquals(guid.getValue(), pid.getValue());
311 311
    } catch (UnsupportedEncodingException e) {
312 312
      e.printStackTrace();
......
368 368
      guid.setValue("testDelete." + System.currentTimeMillis());
369 369
      InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
370 370
      SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
371
      Identifier pid = MNodeService.getInstance().create(session, guid, object, sysmeta);
372
      Identifier deletedPid = MNodeService.getInstance().delete(session, pid);
371
      Identifier pid = MNodeService.getInstance(request).create(session, guid, object, sysmeta);
372
      Identifier deletedPid = MNodeService.getInstance(request).delete(session, pid);
373 373
      assertEquals(pid.getValue(), deletedPid.getValue());
374 374
      
375 375
    } catch (UnsupportedEncodingException e) {
......
398 398
      Identifier newPid = new Identifier();
399 399
      newPid.setValue("testUpdate." + System.currentTimeMillis());
400 400
      Identifier pid = 
401
        MNodeService.getInstance().create(session, guid, object, sysmeta);
401
        MNodeService.getInstance(request).create(session, guid, object, sysmeta);
402 402
      
403 403
      SystemMetadata newSysMeta = createSystemMetadata(newPid, session.getSubject(), object);
404 404
            
405 405
      // do the update
406 406
      Identifier updatedPid = 
407
        MNodeService.getInstance().update(session, pid, object, newPid, newSysMeta);
407
        MNodeService.getInstance(request).update(session, pid, object, newPid, newSysMeta);
408 408
      
409 409
      // get the updated system metadata
410 410
      SystemMetadata updatedSysMeta = 
411
        MNodeService.getInstance().getSystemMetadata(session, updatedPid);
411
        MNodeService.getInstance(request).getSystemMetadata(session, updatedPid);
412 412

  
413 413
      assertEquals(updatedPid.getValue(), newPid.getValue());
414 414
//      assertTrue(updatedSysMeta.getObsolete(0).getValue().equals(pid.getValue()));
......
476 476
        InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
477 477
        SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
478 478
        // save locally
479
        Identifier pid = MNodeService.getInstance().create(session, guid, object, sysmeta);
479
        Identifier pid = MNodeService.getInstance(request).create(session, guid, object, sysmeta);
480 480
        // get our node reference (attempting to replicate with self)
481
        NodeReference sourceNode = MNodeService.getInstance().getCapabilities().getIdentifier();
481
        NodeReference sourceNode = MNodeService.getInstance(request).getCapabilities().getIdentifier();
482 482
        // attempt to replicate with ourselves -- this should fail!
483 483
      boolean result = false;
484 484
      try {
485
        result = MNodeService.getInstance().replicate(session, sysmeta, sourceNode);
485
        result = MNodeService.getInstance(request).replicate(session, sysmeta, sourceNode);
486 486
      } catch (Exception inu) {
487 487
        // we are expecting this to fail since we already have the doc
488 488
        result = true;
......
506 506
      guid.setValue("testGetSystemMetadata." + System.currentTimeMillis());
507 507
      InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
508 508
      SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
509
      Identifier pid = MNodeService.getInstance().create(session, guid, object, sysmeta);
510
      DescribeResponse describeResponse = MNodeService.getInstance().describe(session, pid);
509
      Identifier pid = MNodeService.getInstance(request).create(session, guid, object, sysmeta);
510
      DescribeResponse describeResponse = MNodeService.getInstance(request).describe(session, pid);
511 511
      assertEquals(describeResponse.getDataONE_Checksum().getValue(), sysmeta.getChecksum().getValue());
512 512
      assertEquals(describeResponse.getDataONE_ObjectFormatIdentifier(), sysmeta.getFmtid());
513 513
      
......
574 574
      guid.setValue("testGetChecksum." + System.currentTimeMillis());
575 575
      InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
576 576
      SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
577
      Identifier pid = MNodeService.getInstance().create(session, guid, object, sysmeta);
578
      Checksum checksum = MNodeService.getInstance().getChecksum(session, pid, "MD5");
577
      Identifier pid = MNodeService.getInstance(request).create(session, guid, object, sysmeta);
578
      Checksum checksum = MNodeService.getInstance(request).getChecksum(session, pid, "MD5");
579 579
      assertEquals(checksum.getValue(), sysmeta.getChecksum().getValue());
580 580
    
581 581
    } catch (UnsupportedEncodingException e) {
......
651 651
        testCreate();
652 652
        // now check that we have at least one
653 653
        ObjectList objectList = 
654
          MNodeService.getInstance().listObjects(session, startTime, endTime, 
654
          MNodeService.getInstance(request).listObjects(session, startTime, endTime, 
655 655
              objectFormatId, replicaStatus, start, count);
656 656
        assertNotNull(objectList);
657 657
        assertTrue(objectList.getCount() == count);
......
668 668
  public void testGetCapabilities() {
669 669
      printTestHeader("testGetCapabilities");
670 670
    try {
671
      Node node = MNodeService.getInstance().getCapabilities();
671
      Node node = MNodeService.getInstance(request).getCapabilities();
672 672
      assertNotNull(node);
673 673
      // TODO: should probably test other parts of the node information
674 674
    } catch (Exception e) {
......
686 686
        Date startTime = sdf.parse("2010-01-01");
687 687
        Date endTime = new Date();
688 688
      MonitorList monitorList = 
689
        MNodeService.getInstance().getOperationStatistics(
689
        MNodeService.getInstance(request).getOperationStatistics(
690 690
            session, 
691 691
            startTime, 
692 692
            endTime, 
......
706 706
  public void testPing() {
707 707

  
708 708
    try {
709
      boolean pingable = MNodeService.getInstance().ping();
709
      boolean pingable = MNodeService.getInstance(request).ping();
710 710
      assertTrue(pingable);
711 711
      
712 712
    } catch (NotImplemented e) {
......
747 747
        pid.setValue("testSynchronizationFailed." + System.currentTimeMillis());
748 748
        InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
749 749
        SystemMetadata sysmeta = createSystemMetadata(pid, session.getSubject(), object);
750
        Identifier retPid = MNodeService.getInstance().create(session, pid, object, sysmeta);
750
        Identifier retPid = MNodeService.getInstance(request).create(session, pid, object, sysmeta);
751 751
        assertEquals(retPid.getValue(), pid.getValue());
752 752
        
753 753
        // pretend the sync failed
754 754
      SynchronizationFailed syncFailed = 
755 755
        new SynchronizationFailed("0000", "Testing Synch Failure");
756 756
      syncFailed.setPid(pid.getValue());
757
      MNodeService.getInstance().synchronizationFailed(session, syncFailed );
757
      MNodeService.getInstance(request).synchronizationFailed(session, syncFailed );
758 758
    } catch (Exception e) {
759 759
      e.printStackTrace();
760 760
        fail("Unexpected error: " + e.getMessage());
......
778 778
    int count = 1;
779 779
    
780 780
    try {
781
      log = MNodeService.getInstance().getLogRecords(session, fromDate, toDate, 
781
      log = MNodeService.getInstance(request).getLogRecords(session, fromDate, toDate, 
782 782
        event, start, count);
783 783
      
784 784
      assertNotNull(log);      
......
825 825
      InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
826 826
      SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
827 827
      Identifier pid = 
828
        MNodeService.getInstance().create(session, guid, object, sysmeta);
828
        MNodeService.getInstance(request).create(session, guid, object, sysmeta);
829 829
      // set the access
830 830
      AccessPolicy accessPolicy = new AccessPolicy();
831 831
      AccessRule allow = new AccessRule();
......
836 836
      accessPolicy.addAllow(allow);
837 837
      
838 838
      accessWasSet = 
839
        MNodeService.getInstance().setAccessPolicy(session, pid, accessPolicy);
839
        MNodeService.getInstance(request).setAccessPolicy(session, pid, accessPolicy);
840 840
      assertTrue(accessWasSet);
841 841
      // test that it is enforced
842 842
      session.setSubject(publicSubject);
843
      boolean isAuthorized = MNodeService.getInstance().isAuthorized(session, pid, Permission.WRITE);
843
      boolean isAuthorized = MNodeService.getInstance(request).isAuthorized(session, pid, Permission.WRITE);
844 844
      assertTrue(isAuthorized);
845 845

  
846 846
    } catch (UnsupportedEncodingException e) {
......
907 907
      InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
908 908
      SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
909 909
      Identifier pid = 
910
        MNodeService.getInstance().create(session, guid, object, sysmeta);
910
        MNodeService.getInstance(request).create(session, guid, object, sysmeta);
911 911
      boolean isAuthorized = 
912
        MNodeService.getInstance().isAuthorized(session, pid, Permission.READ);
912
        MNodeService.getInstance(request).isAuthorized(session, pid, Permission.READ);
913 913
      assertEquals(isAuthorized, true);
914 914
      
915 915
    } catch (UnsupportedEncodingException e) {
test/edu/ucsb/nceas/metacat/dataone/CNodeServiceTest.java
30 30
import java.text.SimpleDateFormat;
31 31
import java.util.Date;
32 32

  
33
import javax.servlet.http.HttpServletRequest;
34

  
33 35
import junit.framework.Test;
34 36
import junit.framework.TestSuite;
35 37

  
36 38
import org.apache.commons.io.IOUtils;
39
import org.apache.wicket.protocol.http.MockHttpServletRequest;
37 40
import org.dataone.service.util.Constants;
38 41
import org.dataone.service.exceptions.InsufficientResources;
39 42
import org.dataone.service.exceptions.InvalidRequest;
......
117 120
			guid.setValue("testRegisterSystemMetadata." + System.currentTimeMillis());
118 121
			InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
119 122
			SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
120
			Identifier retGuid = CNodeService.getInstance().registerSystemMetadata(session, guid, sysmeta);
123
			Identifier retGuid = CNodeService.getInstance(request).registerSystemMetadata(session, guid, sysmeta);
121 124
			assertEquals(guid.getValue(), retGuid.getValue());
122 125
			return retGuid;
123 126
        } catch(Exception e) {
......
138 141
			guid.setValue("testGetSystemMetadata." + System.currentTimeMillis());
139 142
			InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
140 143
			SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
141
			Identifier retGuid = CNodeService.getInstance().registerSystemMetadata(session, guid, sysmeta);
144
			Identifier retGuid = CNodeService.getInstance(request).registerSystemMetadata(session, guid, sysmeta);
142 145
			assertEquals(guid.getValue(), retGuid.getValue());
143 146
			// get it
144
			SystemMetadata retSysmeta = CNodeService.getInstance().getSystemMetadata(session, guid);
147
			SystemMetadata retSysmeta = CNodeService.getInstance(request).getSystemMetadata(session, guid);
145 148
			// check it
146 149
			assertEquals(sysmeta.getIdentifier().getValue(), retSysmeta.getIdentifier().getValue());
147 150
        } catch(Exception e) {
......
161 164
		    int start = 0;
162 165
		    int count = 1;
163 166
	    
164
		    Log log = CNodeService.getInstance().getLogRecords(session, fromDate, toDate, 
167
		    Log log = CNodeService.getInstance(request).getLogRecords(session, fromDate, toDate, 
165 168
		    	event, start, count);
166 169
		    assertNotNull(log);
167 170
		    assertTrue(log.getCount() == count);
......
182 185
			guid.setValue("testCreate." + System.currentTimeMillis());
183 186
			InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
184 187
			SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
185
			Identifier pid = CNodeService.getInstance().create(session, guid, object, sysmeta);
188
			Identifier pid = CNodeService.getInstance(request).create(session, guid, object, sysmeta);
186 189
			assertEquals(guid, pid);
187 190
        } catch(Exception e) {
188 191
        	e.printStackTrace();
......
199 202
			guid.setValue("testGet." + System.currentTimeMillis());
200 203
			InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
201 204
			SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
202
			Identifier pid = CNodeService.getInstance().create(session, guid, object, sysmeta);
205
			Identifier pid = CNodeService.getInstance(request).create(session, guid, object, sysmeta);
203 206
			assertEquals(guid.getValue(), pid.getValue());
204 207
			// get it
205
			InputStream retObject = CNodeService.getInstance().get(session, pid);
208
			InputStream retObject = CNodeService.getInstance(request).get(session, pid);
206 209
			// check it
207 210
			object.reset();
208 211
			assertTrue(IOUtils.contentEquals(object, retObject));
......
225 228
			describePid.setValue("describePid." + System.currentTimeMillis());
226 229
			sysmeta.setObsoletes(describePid);
227 230
			// save it
228
			Identifier retGuid = CNodeService.getInstance().registerSystemMetadata(session, guid, sysmeta);
231
			Identifier retGuid = CNodeService.getInstance(request).registerSystemMetadata(session, guid, sysmeta);
229 232
			assertEquals(guid.getValue(), retGuid.getValue());
230 233
			// save the other
231 234
			InputStream object2 = new ByteArrayInputStream("test".getBytes("UTF-8"));
232 235
			SystemMetadata describeSysmeta = createSystemMetadata(describePid, session.getSubject(), object2);
233
			Identifier retDescribePid = CNodeService.getInstance().registerSystemMetadata(session, describePid, describeSysmeta);
236
			Identifier retDescribePid = CNodeService.getInstance(request).registerSystemMetadata(session, describePid, describeSysmeta);
234 237
			assertEquals(describePid.getValue(), retDescribePid.getValue());
235 238
			// check it
236
			boolean result = CNodeService.getInstance().assertRelation(session, guid, "obsoletes", describePid);
239
			boolean result = CNodeService.getInstance(request).assertRelation(session, guid, "obsoletes", describePid);
237 240
			assertTrue(result);
238 241
        } catch(Exception e) {
239 242
        	e.printStackTrace();
......
251 254
			InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
252 255
			SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
253 256
			// save it
254
			Identifier retGuid = CNodeService.getInstance().registerSystemMetadata(session, guid, sysmeta);
257
			Identifier retGuid = CNodeService.getInstance(request).registerSystemMetadata(session, guid, sysmeta);
255 258
			assertEquals(guid.getValue(), retGuid.getValue());
256 259
			// check it
257
			Checksum checksum = CNodeService.getInstance().getChecksum(session, guid);
260
			Checksum checksum = CNodeService.getInstance(request).getChecksum(session, guid);
258 261
			assertEquals(sysmeta.getChecksum().getValue(), checksum.getValue());
259 262
        } catch(Exception e) {
260 263
            fail("Unexpected error: " + e.getMessage());
......
265 268
	    printTestHeader("testListNodes");
266 269

  
267 270
	    try {
268
	    	CNodeService.getInstance().listNodes();
271
	    	CNodeService.getInstance(request).listNodes();
269 272
        } catch(NotImplemented e) {
270 273
        	// expecting not implemented
271 274
            assertTrue(true);
......
282 285
			Identifier guid = new Identifier();
283 286
			guid.setValue("testReserveIdentifier." + System.currentTimeMillis());
284 287
			// reserve it
285
			boolean result = CNodeService.getInstance().reserveIdentifier(session, guid);
288
			boolean result = CNodeService.getInstance(request).reserveIdentifier(session, guid);
286 289
			assertTrue(result);
287 290
	    } catch(NotImplemented ni) {
288 291
        	// this is not implemented in Metacat
......
304 307
			SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
305 308
			
306 309
			// save it
307
			Identifier retGuid = CNodeService.getInstance().registerSystemMetadata(session, guid, sysmeta);
310
			Identifier retGuid = CNodeService.getInstance(request).registerSystemMetadata(session, guid, sysmeta);
308 311
			assertEquals(guid.getValue(), retGuid.getValue());
309 312
			// search for it
310
			ObjectList objectList = CNodeService.getInstance().search(session, null, null);
313
			ObjectList objectList = CNodeService.getInstance(request).search(session, null, null);
311 314
			// check it
312 315
			assertNotNull(objectList);
313 316
			boolean result = false;
......
334 337
			InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
335 338
			SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
336 339
			// save it
337
			Identifier retGuid = CNodeService.getInstance().registerSystemMetadata(session, guid, sysmeta);
340
			Identifier retGuid = CNodeService.getInstance(request).registerSystemMetadata(session, guid, sysmeta);
338 341
			assertEquals(guid.getValue(), retGuid.getValue());
339 342
			Subject rightsHolder = new Subject();
340 343
			rightsHolder.setValue("newUser");
341 344
			// set it
342
			Identifier retPid = CNodeService.getInstance().setOwner(session, guid, rightsHolder);
345
			Identifier retPid = CNodeService.getInstance(request).setOwner(session, guid, rightsHolder);
343 346
			assertEquals(guid, retPid);
344 347
			// get it
345
			sysmeta = CNodeService.getInstance().getSystemMetadata(session, guid);
348
			sysmeta = CNodeService.getInstance(request).getSystemMetadata(session, guid);
346 349
			assertNotNull(sysmeta);
347 350
			// check it
348 351
			assertEquals(rightsHolder.getValue(), sysmeta.getRightsHolder().getValue());
......
362 365
			InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
363 366
			SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
364 367
			// save it
365
			Identifier retGuid = CNodeService.getInstance().registerSystemMetadata(session, guid, sysmeta);
368
			Identifier retGuid = CNodeService.getInstance(request).registerSystemMetadata(session, guid, sysmeta);
366 369
			assertEquals(guid.getValue(), retGuid.getValue());
367 370
			AccessPolicy accessPolicy = new AccessPolicy();
368 371
			AccessRule accessRule = new AccessRule();
......
372 375
			accessRule.addSubject(publicSubject);
373 376
			accessPolicy.addAllow(accessRule);
374 377
			// set it
375
			boolean result = CNodeService.getInstance().setAccessPolicy(session, guid, accessPolicy );
378
			boolean result = CNodeService.getInstance(request).setAccessPolicy(session, guid, accessPolicy );
376 379
			assertTrue(result);
377 380
			// check it
378
			result = CNodeService.getInstance().isAuthorized(session, guid, Permission.WRITE);
381
			result = CNodeService.getInstance(request).isAuthorized(session, guid, Permission.WRITE);
379 382
			assertTrue(result);
380 383
        } catch(Exception e) {
381 384
            fail("Unexpected error: " + e.getMessage());
......
392 395
			InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
393 396
			SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
394 397
			// save it
395
			Identifier retGuid = CNodeService.getInstance().registerSystemMetadata(session, guid, sysmeta);
398
			Identifier retGuid = CNodeService.getInstance(request).registerSystemMetadata(session, guid, sysmeta);
396 399
			assertEquals(guid.getValue(), retGuid.getValue());
397 400
			// check it
398 401
			Subject publicSubject = new Subject();
399 402
			publicSubject.setValue(Constants.SUBJECT_PUBLIC);
400 403
			session.setSubject(publicSubject);
401 404
			// public read
402
			boolean result = CNodeService.getInstance().isAuthorized(session, guid, Permission.READ);
405
			boolean result = CNodeService.getInstance(request).isAuthorized(session, guid, Permission.READ);
403 406
			assertTrue(result);
404 407
			// not public write
405 408
			try {
406 409
				result = false;
407
				result = CNodeService.getInstance().isAuthorized(session, guid, Permission.WRITE);
410
				result = CNodeService.getInstance(request).isAuthorized(session, guid, Permission.WRITE);
408 411
				fail("Public WRITE should be denied");
409 412
			} catch (NotAuthorized nae) {
410 413
				result = true;
......
425 428
			InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
426 429
			SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
427 430
			// save it
428
			Identifier retGuid = CNodeService.getInstance().registerSystemMetadata(session, guid, sysmeta);
431
			Identifier retGuid = CNodeService.getInstance(request).registerSystemMetadata(session, guid, sysmeta);
429 432
			assertEquals(guid.getValue(), retGuid.getValue());
430 433
			
431 434
			ReplicationPolicy policy = new ReplicationPolicy();
......
433 436
			node.setValue("testNode");
434 437
			policy.addPreferredMemberNode(node );
435 438
			// set it
436
			boolean result = CNodeService.getInstance().setReplicationPolicy(session, guid, policy);
439
			boolean result = CNodeService.getInstance(request).setReplicationPolicy(session, guid, policy);
437 440
			assertTrue(result);
438 441
			// get it
439
			sysmeta = CNodeService.getInstance().getSystemMetadata(session, guid);
442
			sysmeta = CNodeService.getInstance(request).getSystemMetadata(session, guid);
440 443
			assertNotNull(sysmeta);
441 444
			// check it
442 445
			assertEquals(policy.getPreferredMemberNode(0).getValue(), sysmeta.getReplicationPolicy().getPreferredMemberNode(0).getValue());
......
463 466
			replica.setReplicaVerified(new Date());
464 467
			sysmeta.addReplica(replica );
465 468
			// save it
466
			Identifier retGuid = CNodeService.getInstance().registerSystemMetadata(session, guid, sysmeta);
469
			Identifier retGuid = CNodeService.getInstance(request).registerSystemMetadata(session, guid, sysmeta);
467 470
			assertEquals(guid.getValue(), retGuid.getValue());
468 471
			// set it
469 472
			ReplicationStatus status = ReplicationStatus.COMPLETED;
470
			boolean result = CNodeService.getInstance().setReplicationStatus(session, guid, replicaMemberNode, status);
473
			boolean result = CNodeService.getInstance(request).setReplicationStatus(session, guid, replicaMemberNode, status);
471 474
			assertTrue(result);
472 475
			// get it
473
			sysmeta = CNodeService.getInstance().getSystemMetadata(session, guid);
476
			sysmeta = CNodeService.getInstance(request).getSystemMetadata(session, guid);
474 477
			assertNotNull(sysmeta);
475 478
			// check it
476 479
			assertEquals(status, sysmeta.getReplica(0).getReplicationStatus());
......
506 509
  	ObjectFormatList objectFormatList;
507 510
  	
508 511
  	try {
509
	    objectFormatList = CNodeService.getInstance().listFormats();
512
	    objectFormatList = CNodeService.getInstance(request).listFormats();
510 513
	  	assertTrue(objectFormatList.getTotal() >= formatsCount);
511 514
  	
512 515
  	} catch (InvalidRequest e) {
......
545 548
    try {
546 549
	    
547 550
			String result = 
548
				CNodeService.getInstance().getFormat(fmtid).getFmtid().getValue();
551
				CNodeService.getInstance(request).getFormat(fmtid).getFmtid().getValue();
549 552
	  	System.out.println("Expected result: " + knownFormat);
550 553
	  	System.out.println("Found    result: " + result);
551 554
	  	assertTrue(result.equals(knownFormat));
......
586 589
  	try {
587 590
  		
588 591
	    ObjectFormat objectFormat = 
589
	    	CNodeService.getInstance().getFormat(fmtid);
592
	    	CNodeService.getInstance(request).getFormat(fmtid);
590 593
      
591 594
  	} catch (Exception e) {
592 595
	    
test/edu/ucsb/nceas/metacat/dataone/D1NodeServiceTest.java
36 36
import java.security.NoSuchAlgorithmException;
37 37
import java.util.Date;
38 38

  
39
import org.apache.wicket.protocol.http.MockHttpServletRequest;
39 40
import org.dataone.client.ObjectFormatCache;
40 41
import org.dataone.service.util.Constants;
41 42
import org.dataone.service.util.TypeMarshaller;
......
60 61
 */
61 62
public class D1NodeServiceTest extends MCTestCase {   
62 63
    
63
    /**
64
    protected MockHttpServletRequest request;
65

  
66
	/**
64 67
    * constructor for the test
65 68
    */
66 69
    public D1NodeServiceTest(String name) {
67 70
        super(name);
71
        // set up the fake request (for logging)
72
        request = new MockHttpServletRequest(null, null, null);
68 73
    }
69 74
  
70 75
    /**
test/edu/ucsb/nceas/metacat/dataone/hazelcast/HazelcastServiceTest.java
28 28
import java.io.ByteArrayInputStream;
29 29
import java.io.InputStream;
30 30

  
31
import javax.servlet.http.HttpServletRequest;
32

  
31 33
import junit.framework.Test;
32 34
import junit.framework.TestSuite;
33 35

  
36
import org.apache.wicket.protocol.http.MockHttpServletRequest;
34 37
import org.dataone.service.types.v1.Identifier;
35 38
import org.dataone.service.types.v1.Session;
36 39
import org.dataone.service.types.v1.SystemMetadata;
......
60 63
		}
61 64
			
62 65
	}
63
		
66

  
67
	private HttpServletRequest request;
68

  
64 69
    /**
65 70
    * constructor for the test
66 71
    */
67 72
    public HazelcastServiceTest(String name) {
68 73
        super(name);
69 74

  
75
        // set up the fake request (for logging)
76
        request = new MockHttpServletRequest(null, null, null);
70 77
    }
71 78
    
72 79
    /**
......
116 123
			systemMetadataMap.put(guid, sysmeta);
117 124
			
118 125
			// get it from the store
119
			SystemMetadata sysmetaFromStore = CNodeService.getInstance().getSystemMetadata(session, guid);
126
			SystemMetadata sysmetaFromStore = CNodeService.getInstance(request).getSystemMetadata(session, guid);
120 127
			assertNotNull(sysmetaFromStore);
121 128

  
122 129
		} catch (Exception e) {
test/edu/ucsb/nceas/metacattest/EventLogTest.java
60 60
     */
61 61
    public void testLog()
62 62
    {
63
        EventLog.getInstance().log("192.168.1.103", "public", "test.2.1", "read");
63
        EventLog.getInstance().log("192.168.1.103", "Mozilla", "public", "test.2.1", "read");
64 64
        assertTrue(1 == 1);
65 65
    }
66 66

  
src/xmltables-oracle.sql
527 527
CREATE TABLE access_log (
528 528
  entryid       NUMBER(20),     -- the identifier for the log event
529 529
  ip_address    VARCHAR2(512),  -- the ip address inititiating the event
530
  user_agent    VARCHAR2(512),  -- the user agent for the request
530 531
  principal     VARCHAR2(512),  -- the user initiiating the event
531 532
  docid         VARCHAR2(250),	-- the document id #
532 533
  event         VARCHAR2(512),  -- the code symbolizing the event type
src/upgrade-db-to-1.10.0-postgres.sql
58 58
*/
59 59
ALTER TABLE xml_access ADD COLUMN guid text;
60 60

  
61
/**
62
 * track the user-agent for the request
63
 */
64
ALTER TABLE acces_log ADD COLUMN user_agent VARCHAR(512);
65

  
61 66
/*
62 67
 * Register the DataONE schemas
63 68
 */
src/xmltables-postgres.sql
390 390
CREATE TABLE access_log (
391 391
  entryid       INT8 default nextval ('access_log_id_seq'), -- the identifier for the log event
392 392
  ip_address    VARCHAR(512),   -- the ip address inititiating the event
393
  principal     VARCHAR(512),   -- the user initiiating the event
393
  user_agent    VARCHAR(512),   -- the user agent for the request
394
  principal     VARCHAR(512),   -- the user initiating the event
394 395
  docid         VARCHAR(250),	-- the document id #
395 396
  event         VARCHAR(512),   -- the code symbolizing the event type
396 397
  date_logged   TIMESTAMP,      -- the datetime on which the event occurred
src/upgrade-db-to-1.10.0-oracle.sql
50 50
*/
51 51
ALTER TABLE xml_access ADD COLUMN guid VARCHAR2(2000);
52 52

  
53
/**
54
 * track the user-agent for the request
55
 */
56
ALTER TABLE acces_log ADD COLUMN user_agent VARCHAR2(512);
57

  
53 58
/*
54 59
 * add the nodedatadate column to xml_nodes 
55 60
 * TODO: load the data into it (java?)
......
59 64
ALTER TABLE xml_path_index ADD COLUMN nodedatadate TIMESTAMP;
60 65
CREATE INDEX xml_path_index_idx4 ON xml_path_index (nodedatadate);
61 66

  
62

  
63 67
/*
64 68
 * Register the DataONE schemas
65 69
 */
src/edu/ucsb/nceas/metacat/EventLogData.java
32 32
 */
33 33
public class EventLogData {
34 34
	private String ipAddress;
35
	private String userAgent;
35 36
	private String principal;
36 37
	private String docid;
37 38
	private String event;
......
46 47
	 * @param revision the revision of the document to which the event applies
47 48
	 * @param event the string code for the event
48 49
	 */
49
	public EventLogData(String ipAddress, String principal, String docid,
50
			String event) {
50
	public EventLogData(String ipAddress, String principal, String docid, String event) {
51 51
		this.ipAddress = ipAddress;
52 52
		this.principal = principal;
53 53
		this.docid = docid;
......
126 126
	public void setPrincipal(String principal) {
127 127
		this.principal = principal;
128 128
	}
129

  
130
	public String getUserAgent() {
131
		return userAgent;
132
	}
133

  
134
	public void setUserAgent(String userAgent) {
135
		this.userAgent = userAgent;
136
	}
129 137
}
src/edu/ucsb/nceas/metacat/restservice/MNResourceHandler.java
308 308
		} catch (Exception e) {
309 309
			logMetacat.warn("No permission specified");
310 310
		}
311
		boolean result = MNodeService.getInstance().isAuthorized(session, pid, permission);
311
		boolean result = MNodeService.getInstance(request).isAuthorized(session, pid, permission);
312 312
		response.setStatus(200);
313 313
		response.setContentType("text/xml");
314 314
		return result;
......
335 335
			throw new ServiceFailure("2161", e.getMessage());
336 336
		}
337 337
		
338
		MNodeService.getInstance().synchronizationFailed(session, syncFailed);
338
		MNodeService.getInstance(request).synchronizationFailed(session, syncFailed);
339 339
    }
340 340
    
341 341

  
......
364 364
        
365 365
        if (pathInfo.toLowerCase().equals("ping")) {
366 366
            logMetacat.debug("processing ping request");
367
            boolean result = MNodeService.getInstance().ping();
367
            boolean result = MNodeService.getInstance(request).ping();
368 368
            return result;
369 369
            
370 370
        } else if (pathInfo.toLowerCase().equals("status")) {
......
429 429
                event = Event.convert(eventName);
430 430
            }
431 431
            
432
            MonitorList monitorList = MNodeService.getInstance().getOperationStatistics(session, fromDate, toDate, subject, event, fmtid);
432
            MonitorList monitorList = MNodeService.getInstance(request).getOperationStatistics(session, fromDate, toDate, subject, event, fmtid);
433 433
            
434 434
            OutputStream out = response.getOutputStream();
435 435
            response.setStatus(200);
......
500 500
        }
501 501
        logMetacat.debug("getting checksum for object " + pid + " with algorithm " + checksumAlgorithm);
502 502
        
503
        Checksum c = MNodeService.getInstance().getChecksum(session, pidid, checksumAlgorithm);
503
        Checksum c = MNodeService.getInstance(request).getChecksum(session, pidid, checksumAlgorithm);
504 504
        logMetacat.debug("got checksum " + c.getValue());
505 505
        response.setStatus(200);
506 506
        logMetacat.debug("serializing response");
......
534 534
        logMetacat.debug("sourceNode: " + sn);
535 535
        NodeReference sourceNode = TypeMarshaller.unmarshalTypeFromStream(NodeReference.class, new ByteArrayInputStream(sn.getBytes("UTF-8")));
536 536
        
537
        MNodeService.getInstance().replicate(session, sysmeta, sourceNode);
537
        MNodeService.getInstance(request).replicate(session, sysmeta, sourceNode);
538 538

  
539 539
        response.setStatus(200);
540 540

  
......
553 553
    private void node() 
554 554
        throws JiBXException, IOException, NotImplemented, NotAuthorized, ServiceFailure, InvalidRequest {
555 555
        
556
        Node n = MNodeService.getInstance().getCapabilities();
556
        Node n = MNodeService.getInstance(request).getCapabilities();
557 557
        
558 558
        response.setContentType("text/xml");
559 559
        response.setStatus(200);
......
580 580
        Identifier id = new Identifier();
581 581
        id.setValue(pid);
582 582

  
583
        DescribeResponse dr = MNodeService.getInstance().describe(session, id);
583
        DescribeResponse dr = MNodeService.getInstance(request).describe(session, id);
584 584
        //response.addHeader("pid", pid);
585 585
        response.addHeader("DataONE-Checksum", dr.getDataONE_Checksum().getAlgorithm() + "," + dr.getDataONE_Checksum().getValue());
586 586
        response.addHeader("Content-Length", dr.getContent_Length() + "");
......
644 644
		}
645 645
        
646 646
        logMetacat.debug("calling getLogRecords");
647
        Log log = MNodeService.getInstance().getLogRecords(session, fromDate, toDate, event, start, count);
647
        Log log = MNodeService.getInstance(request).getLogRecords(session, fromDate, toDate, event, start, count);
648 648
        
649 649
        OutputStream out = response.getOutputStream();
650 650
        response.setStatus(200);
......
673 673
            Identifier id = new Identifier();
674 674
            id.setValue(pid);
675 675
                
676
            SystemMetadata sm = MNodeService.getInstance().getSystemMetadata(session, id);
676
            SystemMetadata sm = MNodeService.getInstance(request).getSystemMetadata(session, id);
677 677
            
678 678
            //set the content type
679 679
            if (sm.getFmtid().getValue().trim().equals(
......
699 699
                response.setHeader("Content-Disposition", "inline; filename=" + id.getValue() + ".xml");
700 700
            }
701 701
            
702
            InputStream data = MNodeService.getInstance().get(session, id);
702
            InputStream data = MNodeService.getInstance(request).get(session, id);
703 703

  
704 704
            out = response.getOutputStream();  
705 705
            IOUtils.copyLarge(data, out);
......
783 783
          	 
784 784
            }
785 785
            ObjectList ol = 
786
           	 MNodeService.getInstance().listObjects(session, startTime, endTime, 
786
           	 MNodeService.getInstance(request).listObjects(session, startTime, endTime, 
787 787
               fmtid, replicaStatus, start, count);
788 788
           
789 789
            out = response.getOutputStream();  
......
813 813

  
814 814
        Identifier id = new Identifier();
815 815
        id.setValue(pid);
816
        SystemMetadata sysmeta = MNodeService.getInstance().getSystemMetadata(session, id);
816
        SystemMetadata sysmeta = MNodeService.getInstance(request).getSystemMetadata(session, id);
817 817
        
818 818
        response.setContentType("text/xml");
819 819
        response.setStatus(200);
......
870 870
            Identifier id = new Identifier();
871 871
            id.setValue(pid);
872 872
            logMetacat.debug("creating object with pid " + pid);
873
            Identifier rId = MNodeService.getInstance().create(session, id, object, smd);
873
            Identifier rId = MNodeService.getInstance(request).create(session, id, object, smd);
874 874
            TypeMarshaller.marshalTypeToOutputStream(rId, out);
875 875
            
876 876
        } else if (action.equals(FUNCTION_NAME_UPDATE)) {
......
893 893
            // get the systemmetadata object
894 894
            SystemMetadata smd = TypeMarshaller.unmarshalTypeFromStream(SystemMetadata.class, sysmeta);
895 895

  
896
            Identifier rId = MNodeService.getInstance().update(session, obsoletedPid, object, newPid, smd);
896
            Identifier rId = MNodeService.getInstance(request).update(session, obsoletedPid, object, newPid, smd);
897 897
            TypeMarshaller.marshalTypeToOutputStream(rId, out);
898 898
        } else {
899 899
            throw new InvalidRequest("1000", "Operation must be create or update.");
......
925 925
        id.setValue(pid);
926 926

  
927 927
        logMetacat.debug("Calling delete");
928
        MNodeService.getInstance().delete(session, id);
928
        MNodeService.getInstance(request).delete(session, id);
929 929
        TypeMarshaller.marshalTypeToOutputStream(id, out);
930 930
        
931 931
    }    
......
953 953
        id.setValue(pid);
954 954
        
955 955
        AccessPolicy accessPolicy = collectAccessPolicy();
956
        MNodeService.getInstance().setAccessPolicy(session, id, accessPolicy);
956
        MNodeService.getInstance(request).setAccessPolicy(session, id, accessPolicy);
957 957
        
958 958
        
959 959
    }
src/edu/ucsb/nceas/metacat/restservice/CNResourceHandler.java
330 330
    	Identifier guidid = new Identifier();
331 331
        guidid.setValue(guid);
332 332
        logMetacat.debug("getting checksum for object " + guid);
333
        Checksum c = CNodeService.getInstance().getChecksum(session, guidid);
333
        Checksum c = CNodeService.getInstance(request).getChecksum(session, guidid);
334 334
        logMetacat.debug("got checksum " + c.getValue());
335 335
        response.setStatus(200);
336 336
        logMetacat.debug("serializing response");
......
395 395
		}
396 396
        
397 397
        logMetacat.debug("calling getLogRecords");
398
        Log log = CNodeService.getInstance().getLogRecords(session, fromDate, toDate, event, start, count);
398
        Log log = CNodeService.getInstance(request).getLogRecords(session, fromDate, toDate, event, start, count);
399 399
        
400 400
        OutputStream out = response.getOutputStream();
401 401
        response.setStatus(200);
......
421 421
        Identifier id = new Identifier();
422 422
        id.setValue(guid);
423 423
            
424
        SystemMetadata sm = CNodeService.getInstance().getSystemMetadata(session, id);
424
        SystemMetadata sm = CNodeService.getInstance(request).getSystemMetadata(session, id);
425 425
        
426 426
        //set the content type
427 427
        if(sm.getFmtid().getValue().trim().equals(
......
447 447
            response.setHeader("Content-Disposition", "inline; filename=" + id.getValue() + ".xml");
448 448
        }
449 449
        
450
        InputStream data = CNodeService.getInstance().get(session, id);
450
        InputStream data = CNodeService.getInstance(request).get(session, id);
451 451
        
452 452
        OutputStream out = response.getOutputStream();
453 453
        response.setStatus(200);
......
472 472

  
473 473
        Identifier id = new Identifier();
474 474
        id.setValue(guid);
475
        SystemMetadata sysmeta = CNodeService.getInstance().getSystemMetadata(session, id);
475
        SystemMetadata sysmeta = CNodeService.getInstance(request).getSystemMetadata(session, id);
476 476
        
477 477
        response.setContentType("text/xml");
478 478
        response.setStatus(200);
......
522 522
            Identifier id = new Identifier();
523 523
            id.setValue(pid);
524 524
            logMetacat.debug("creating object with pid " + id.getValue());
525
            Identifier rId = CNodeService.getInstance().create(session, id, object, smd);
525
            Identifier rId = CNodeService.getInstance(request).create(session, id, object, smd);
526 526
            
527 527
            OutputStream out = response.getOutputStream();
528 528
            response.setStatus(200);
......
548 548
	private void listFormats() throws InvalidRequest, ServiceFailure, NotFound, InsufficientResources, NotImplemented, IOException, JiBXException {
549 549
      logMetacat.debug("Entering listFormats()");
550 550

  
551
      ObjectFormatList objectFormatList = CNodeService.getInstance().listFormats();
551
      ObjectFormatList objectFormatList = CNodeService.getInstance(request).listFormats();
552 552
      // get the response output stream
553 553
      OutputStream out = response.getOutputStream();
554 554
      response.setStatus(200);
......
577 577
      fmtid.setValue(fmtidStr);
578 578
      
579 579
	  // get the specified object format
580
      ObjectFormat objectFormat = CNodeService.getInstance().getFormat(fmtid);
580
      ObjectFormat objectFormat = CNodeService.getInstance(request).getFormat(fmtid);
581 581
      
582 582
      OutputStream out = response.getOutputStream();
583 583
      response.setStatus(200);
......
621 621
			logMetacat.warn("pid not specified");
622 622
		} 
623 623
		// call the implementation
624
		boolean result = CNodeService.getInstance().reserveIdentifier(session, pid);
624
		boolean result = CNodeService.getInstance(request).reserveIdentifier(session, pid);
625 625
		OutputStream out = response.getOutputStream();
626 626
		response.setStatus(200);
627 627
		response.setContentType("text/xml");
......
643 643
    private void resolve(String id) throws InvalidRequest, InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented, IOException, JiBXException {
644 644
		Identifier pid = new Identifier();
645 645
		pid.setValue(id);
646
		ObjectLocationList locationList = CNodeService.getInstance().resolve(session, pid);
646
		ObjectLocationList locationList = CNodeService.getInstance(request).resolve(session, pid);
647 647
	    OutputStream out = response.getOutputStream();
648 648
		response.setStatus(200);
649 649
		response.setContentType("text/xml");
......
678 678
		} catch (Exception e) {
679 679
			logMetacat.warn("pidOfObject not specified");
680 680
		}
681
		boolean result = CNodeService.getInstance().assertRelation(session, pidOfSubject, relationship, pidOfObject);
681
		boolean result = CNodeService.getInstance(request).assertRelation(session, pidOfSubject, relationship, pidOfObject);
682 682
		response.setStatus(200);
683 683
		response.setContentType("text/xml");
684 684
		return result;
......
703 703
		pid.setValue(id);
704 704
		String subjectStr = params.get("subject")[0];
705 705
		Subject subject = TypeMarshaller.unmarshalTypeFromStream(Subject.class, new ByteArrayInputStream(subjectStr.getBytes("UTF-8")));
706
		Identifier retPid = CNodeService.getInstance().setOwner(session, pid, subject);
706
		Identifier retPid = CNodeService.getInstance(request).setOwner(session, pid, subject);
707 707
		OutputStream out = response.getOutputStream();
708 708
		response.setStatus(200);
709 709
		response.setContentType("text/xml");
......
725 725
		Identifier pid = new Identifier();
726 726
		pid.setValue(id);
727 727
		String permission = params.get("action")[0];
728
		boolean result = CNodeService.getInstance().isAuthorized(session, pid, Permission.convert(permission));
728
		boolean result = CNodeService.getInstance(request).isAuthorized(session, pid, Permission.convert(permission));
729 729
		response.setStatus(200);
730 730
		response.setContentType("text/xml");
731 731
		return result;
......
754 754
		Identifier guid = new Identifier();
755 755
		guid.setValue(pid);
756 756
		logMetacat.debug("registering system metadata with pid " + guid.getValue());
757
		Identifier retGuid = CNodeService.getInstance().registerSystemMetadata(session, guid, systemMetadata);
757
		Identifier retGuid = CNodeService.getInstance(request).registerSystemMetadata(session, guid, systemMetadata);
758 758
		
759 759
		response.setStatus(200);
760 760
		response.setContentType("text/xml");
......
783 783
        id.setValue(pid);
784 784
        
785 785
        AccessPolicy accessPolicy = collectAccessPolicy();
786
        CNodeService.getInstance().setAccessPolicy(session, id, accessPolicy);
786
        CNodeService.getInstance(request).setAccessPolicy(session, id, accessPolicy);
787 787

  
788 788
    }
789 789
    
......
814 814
		}
815 815
		
816 816
    	// expecting to throw NotImplemented
817
		CNodeService.getInstance().search(session, queryType, query);
817
		CNodeService.getInstance(request).search(session, queryType, query);
818 818
    }
819 819

  
820 820
}
src/edu/ucsb/nceas/metacat/MetaCatServlet.java
890 890
			} else if (action.equals("insert") || action.equals("update")) {
891 891
				PrintWriter out = response.getWriter();
892 892
				if ((userName != null) && !userName.equals("public")) {
893
					handler.handleInsertOrUpdateAction(request.getRemoteAddr(), response, out, params, userName,
893
					handler.handleInsertOrUpdateAction(request.getRemoteAddr(), request.getHeader("User-Agent"), response, out, params, userName,
894 894
							groupNames);
895 895
				} else {
896 896
					response.setContentType("text/xml");
src/edu/ucsb/nceas/metacat/EventLog.java
92 92
     * that initiated the event.
93 93
     * 
94 94
     * @param ipAddress the internet protocol address for the event
95
     * @param userAgent the agent making the request
95 96
	 * @param principal the principal for the event (a username, etc)
96 97
	 * @param docid the identifier of the document to which the event applies
97 98
	 * @param event the string code for the event
98 99
     */
99
    public void log(String ipAddress, String principal, String docid,
100
			String event)
101
    {
102
        EventLogData logData = new EventLogData(ipAddress, principal, docid,
103
                event);
100
    public void log(String ipAddress, String userAgent, String principal, String docid, String event) {
101
        EventLogData logData = new EventLogData(ipAddress, principal, docid, event);
104 102
        insertLogEntry(logData);
105 103
    }
106 104
    
......
112 110
    private void insertLogEntry(EventLogData logData)
113 111
    {
114 112
        String insertString = "insert into access_log"
115
                + "(ip_address, principal, docid, "
113
                + "(ip_address, user_agent, principal, docid, "
116 114
                + "event, date_logged) "
117 115
                + "values ("
118 116
                + "'" + logData.getIpAddress() + "', " 
117
                + "'" + logData.getUserAgent() + "', " 
119 118
                + "'" + logData.getPrincipal() + "', "
120 119
                + "'" + logData.getDocid() + "', "
121 120
                + "'" + logData.getEvent() + "', "
......
160 159
    {
161 160
        StringBuffer resultDoc = new StringBuffer();
162 161
        StringBuffer query = new StringBuffer();
163
        query.append("select entryid, ip_address, principal, docid, "
162
        query.append("select entryid, ip_address, user_agent, principal, docid, "
164 163
            + "event, date_logged from access_log");
165 164
//                        + ""
166 165
//                        + "event, date_logged) " + "values (" + "'"
......
233 232
                		generateXmlRecord(
234 233
                				rs.getString(1), //id
235 234
                				anonymous ? "" : rs.getString(2), //ip
236
                				anonymous ? "" : rs.getString(3), //principal
237
                                rs.getString(4), 
235
                				rs.getString(3), //userAgent	
236
                				anonymous ? "" : rs.getString(4), //principal
238 237
                                rs.getString(5), 
239
                                rs.getTimestamp(6)));
238
                                rs.getString(6), 
239
                                rs.getTimestamp(7)));
240 240
            }
241 241
            resultDoc.append("</log>");
242 242
            stmt.close();
......
286 286
     * 
287 287
     * @param entryId the identifier of the log entry
288 288
     * @param ipAddress the internet protocol address for the event
289
     * @param the agent making the request
289 290
	 * @param principal the principal for the event (a username, etc)
290 291
	 * @param docid the identifier of the document to which the event applies
291 292
	 * @param event the string code for the event
292 293
     * @param dateLogged the date on which the event occurred
293 294
     * @return String containing the formatted XML
294 295
     */
295
    private String generateXmlRecord(String entryId, String ipAddress, 
296
    private String generateXmlRecord(String entryId, String ipAddress, String userAgent,
296 297
            String principal, String docid, String event, Timestamp dateLogged)
297 298
    {
298 299
        StringBuffer rec = new StringBuffer();
299 300
        rec.append("<logEntry>");
300 301
        rec.append(generateXmlElement("entryid", entryId));
301 302
        rec.append(generateXmlElement("ipAddress", ipAddress));
303
        rec.append(generateXmlElement("userAgent", userAgent));
302 304
        rec.append(generateXmlElement("principal", principal));
303 305
        rec.append(generateXmlElement("docid", docid));
304 306
        rec.append(generateXmlElement("event", event));
src/edu/ucsb/nceas/metacat/MetacatHandler.java
719 719
            }
720 720
            out.close();
721 721
            
722
            EventLog.getInstance().log(request.getRemoteAddr(), user,
722
            EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"), user,
723 723
                    inlineDataId, "readinlinedata");
724 724
        } catch (Exception e) {
725 725
            try {
......
818 818
                        if (zip) {
819 819
                            addDocToZip(request, docid, providedFileName, zout, user, groups);
820 820
                        } else {
821
                            readFromMetacat(request.getRemoteAddr(), response, response.getOutputStream(), docid, qformat,
821
                            readFromMetacat(request.getRemoteAddr(), request.getHeader("User-Agent"), response, response.getOutputStream(), docid, qformat,
822 822
                                    user, groups, withInlineData, params);
823 823
                        }
824 824
                        
......
840 840
                    	if (out == null) {
841 841
                    		out = response.getOutputStream();
842 842
                    	}
843
                        readFromMetacat(request.getRemoteAddr(), response, out, docid, qformat,
843
                        readFromMetacat(request.getRemoteAddr(), request.getHeader("User-Agent"), response, out, docid, qformat,
844 844
                                user, groups, withInlineData, params);
845 845
                    }
846 846
                }
......
1171 1171
      try {
1172 1172
          
1173 1173
        DocumentImpl.delete(docid, user, groups, null); // null: don't notify server
1174
        EventLog.getInstance().log(request.getRemoteAddr(),
1174
        EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"),
1175 1175
                user, docid, "delete");
1176 1176
        response.setContentType("text/xml");
1177 1177
        out.println(this.PROLOG);
......
1251 1251
    }
1252 1252
    
1253 1253
    /** read metadata or data from Metacat
1254
     * @param userAgent 
1254 1255
     * @throws PropertyNotFoundException 
1255 1256
     * @throws ParseLSIDException 
1256 1257
     * @throws InsufficientKarmaException 
1257 1258
     */
1258
    public void readFromMetacat(String ipAddress,
1259
    public void readFromMetacat(String ipAddress, String userAgent,
1259 1260
            HttpServletResponse response, OutputStream out, String docid, String qformat,
1260 1261
            String user, String[] groups, boolean withInlineData, 
1261 1262
            Hashtable<String, String[]> params) throws ClassNotFoundException, 
......
1400 1401
                }
1401 1402
                
1402 1403
            }
1403
            EventLog.getInstance().log(ipAddress, user, docid, "read");
1404
            EventLog.getInstance().log(ipAddress, userAgent, user, docid, "read");
1404 1405
        } catch (PropertyNotFoundException except) {
1405 1406
            throw except;
1406 1407
        }
......
1607 1608
                    zout.write(bytestring, 0, bytestring.length);
1608 1609
                    zout.closeEntry();
1609 1610
                }
1610
                EventLog.getInstance().log(request.getRemoteAddr(), user,
1611
                EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"), user,
1611 1612
                        docid, "read");
1612 1613
            } catch (Exception except) {
1613 1614
                throw except;
......
1648 1649
    /**
1649 1650
     * Handle the database putdocument request and write an XML document to the
1650 1651
     * database connection
1652
     * @param userAgent 
1651 1653
     */
1652
    public String handleInsertOrUpdateAction(String ipAddress,
1654
    public String handleInsertOrUpdateAction(String ipAddress, String userAgent,
1653 1655
            HttpServletResponse response, PrintWriter out, Hashtable<String, String[]> params,
1654 1656
            String user, String[] groups) {
1655 1657
        Logger logMetacat = Logger.getLogger(MetacatHandler.class);
......
1817 1819
                		          "writing with null acnumber");
1818 1820
                  newdocid = documentWrapper.write(dbConn, doctext[0], pub, dtd,
1819 1821
                          doAction, null, user, groups);
1820
                  EventLog.getInstance().log(ipAddress, user, "", action[0]);
1822
                  EventLog.getInstance().log(ipAddress, userAgent, user, "", action[0]);
1821 1823
              
1822 1824
              } else {
1823 1825
                  newdocid = documentWrapper.write(dbConn, doctext[0], pub, dtd,
1824 1826
                          doAction, accNumber, user, groups);
1825 1827
            
1826
                  EventLog.getInstance().log(ipAddress, user, accNumber, action[0]);
1828
                  EventLog.getInstance().log(ipAddress, userAgent, user, accNumber, action[0]);
1827 1829
              
1828 1830
              }
1829 1831
              
......
2890 2892
                doctextArr[0] = doctext;
2891 2893
                params.put("doctext", doctextArr);
2892 2894
                //call the insert routine
2893
                handleInsertOrUpdateAction(request.getRemoteAddr(), response, out, 
2895
                handleInsertOrUpdateAction(request.getRemoteAddr(), request.getHeader("User-Agent"), response, out, 
2894 2896
                          params, username, groupnames);
2895 2897
              }
2896 2898
              catch(Exception e)
......
3027 3029
                            throw ee;
3028 3030
                        }
3029 3031

  
3030
                        EventLog.getInstance().log(request.getRemoteAddr(),
3032
                        EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"),
3031 3033
                                username, docid, "upload");
3032 3034
                        // Force replication this data file
3033 3035
                        // To data file, "insert" and update is same
src/edu/ucsb/nceas/metacat/dataone/MNodeService.java
32 32
import java.util.List;
33 33
import java.util.Timer;
34 34

  
35
import javax.servlet.http.HttpServletRequest;
36

  
35 37
import org.apache.commons.io.IOUtils;
36 38
import org.apache.log4j.Logger;
37 39
import org.dataone.client.CNode;
......
90 92
import edu.ucsb.nceas.metacat.database.DBConnection;
91 93
import edu.ucsb.nceas.metacat.database.DBConnectionPool;
92 94
import edu.ucsb.nceas.metacat.properties.PropertyService;
95
import edu.ucsb.nceas.metacat.util.SystemUtil;
93 96
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
94 97

  
95 98
/**
......
121 124
 */
122 125
public class MNodeService extends D1NodeService implements MNAuthorization, MNCore, MNRead, MNReplication, MNStorage {
123 126

  
124
    /* the instance of the MNodeService object */
125
    private static MNodeService instance = null;
126

  
127 127
    /* the logger instance */
128 128
    private Logger logMetacat = null;
129 129

  
......
132 132
     * 
133 133
     * @return instance - the instance of MNodeService
134 134
     */
135
    public static MNodeService getInstance() {
136
        if (instance == null) {
137
            instance = new MNodeService();
138
        }
139
        return instance;
135
    public static MNodeService getInstance(HttpServletRequest request) {
136
        return new MNodeService(request);
140 137
    }
141 138

  
142 139
    /**
143 140
     * Constructor, private for singleton access
144 141
     */
145
    private MNodeService() {
146
        super();
142
    private MNodeService(HttpServletRequest request) {
143
        super(request);
147 144
        logMetacat = Logger.getLogger(MNodeService.class);
148 145
    }
149 146

  
......
203 200
            try {
204 201
                // delete the document
205 202
                DocumentImpl.delete(localId, username, groupnames, null);
206
                EventLog.getInstance().log(metacatUrl, username, localId, Event.DELETE.xmlValue());
203
                EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"), username, localId, Event.DELETE.xmlValue());
207 204

  
208 205
            } catch (McdbDocNotFoundException e) {
209 206
                throw new InvalidRequest("1322", "The provided identifier was invalid.");
......
336 333
            insertSystemMetadata(sysmeta);
337 334

  
338 335
            // log the update event
339
            EventLog.getInstance().log(metacatUrl, subject.getValue(), localId, "update");
336
            EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"), subject.getValue(), localId, Event.UPDATE.toString());
340 337

  
341 338
        } else {
342 339
            throw new NotAuthorized("1200", "The provided identity does not have " + "permission to UPDATE the object identified by " + pid.getValue()
......
668 665

  
669 666
            // Set the properties of the node based on configuration information and
670 667
            // calls to current status methods
668
            String serviceName = SystemUtil.getContextURL() + "/" + PropertyService.getProperty("dataone.serviceName");
671 669
            Node node = new Node();
672
            node.setBaseURL(metacatUrl + "/" + nodeTypeString);
670
            node.setBaseURL(serviceName + "/" + nodeTypeString);
673 671
            node.setDescription(nodeDesc);
674 672

  
675 673
            // set the node's health information
......
884 882
        	principal = session.getSubject().getValue();
885 883
        }
886 884
        try {
887
        	EventLog.getInstance().log(syncFailed.getNodeId(), principal, localId, "synchronization_failed");
885
        	EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"), principal, localId, "synchronization_failed");
888 886
        } catch (Exception e) {
889 887
            throw new ServiceFailure("2161", "Could not log the error for: " + syncFailed.getPid());
890 888
		}
......
943 941
        if (session.getSubject() != null) {
944 942
            principal = session.getSubject().getValue();
945 943
        }
946
        EventLog.getInstance().log(null, principal, localId, "getreplica");
944
        EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"), principal, localId, "getreplica");
947 945

  
948 946
        return inputStream;
949 947
    }
src/edu/ucsb/nceas/metacat/dataone/CNodeService.java
27 27
import java.util.List;
28 28
import java.util.Set;
29 29

  
30
import javax.servlet.http.HttpServletRequest;
31

  
30 32
import org.apache.log4j.Logger;
31 33
import org.dataone.client.CNode;
32 34
import org.dataone.client.D1Client;
......
78 80
public class CNodeService extends D1NodeService implements CNAuthorization,
79 81
    CNCore, CNRead, CNReplication {
80 82

  
81
  /* the instance of the CNodeService object */
82
  private static CNodeService instance = null;
83

  
84 83
  /* the logger instance */
85 84
  private Logger logMetacat = null;
86 85

  
87 86
  /**
88 87
   * singleton accessor
89 88
   */
90
  public static CNodeService getInstance() { 
91
    if (instance == null) {
92
    
93
      instance = new CNodeService();
94
      
95
    }
96
  
97
    return instance;
89
  public static CNodeService getInstance(HttpServletRequest request) { 
90
    return new CNodeService(request);
98 91
  }
99 92
  
100 93
  /**
101 94
   * Constructor, private for singleton access
102 95
   */
103
  private CNodeService() {
104
    super();
96
  private CNodeService(HttpServletRequest request) {
97
    super(request);
105 98
    logMetacat = Logger.getLogger(CNodeService.class);
106 99
        
107 100
  }
......
559 552
        }
560 553
        
561 554
        logMetacat.debug("Returning from registerSystemMetadata");
562
        EventLog.getInstance().log(null, session.getSubject().getValue(), guid.getValue(), "registerSystemMetadata");
555
        EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"), session.getSubject().getValue(), guid.getValue(), "registerSystemMetadata");
563 556
        return guid;
564 557
  }
565 558

  
......
625 618
    	}
626 619
        
627 620
        logMetacat.debug("Returning from updateSystemMetadata");
628
        EventLog.getInstance().log(null, session.getSubject().getValue(), guid.getValue(), "updateSystemMetadata");
621
        EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"), session.getSubject().getValue(), guid.getValue(), "updateSystemMetadata");
629 622
        return true;
630 623
  }
631 624
  
src/edu/ucsb/nceas/metacat/dataone/D1NodeService.java
38 38
import java.util.Timer;
39 39
import java.util.Vector;
40 40

  
41
import javax.servlet.http.HttpServletRequest;
41 42

  
43

  
42 44
import org.apache.commons.io.IOUtils;
43 45
import org.apache.log4j.Logger;
44 46
import org.dataone.client.ObjectFormatCache;
......
87 89
  
88 90
  private static Logger logMetacat = Logger.getLogger(D1NodeService.class);
89 91

  
90
  /* the metacat URL as a string (including ending /d1 service)*/
91
  protected String metacatUrl;
92
  /** For logging the operations */
93
  protected HttpServletRequest request;
92 94
  
93 95
  /* reference to the metacat handler */
94 96
  protected MetacatHandler handler;
......
101 103
   * 
102 104
   * @param metacatUrl - the URL of the metacat service, including the ending /d1
103 105
   */
104
  public D1NodeService() {
105
  	this.metacatUrl = "";
106
  	
107
    try {
108
	    this.metacatUrl = SystemUtil.getContextURL() + "/" +
109
	    PropertyService.getProperty("dataone.serviceName");
110
    } catch (PropertyNotFoundException e) {
111
      throw new RuntimeException("Error getting the servlet url in D1NodeService: " + 
112
        	e.getMessage());
113

  
114
    }
115
    
116
  }
106
  public D1NodeService(HttpServletRequest request) {
107
		this.request = request;
108
	}
117 109
  
118 110
  /**
119 111
   * Adds a new object to the Node, where the object is either a data 
......
351 343
      String entryId = getLogEntryField("entryid", entry);
352 344
      String ipAddress = getLogEntryField("ipAddress", entry);
353 345
      String principal = getLogEntryField("principal", entry);
346
      String userAgent = getLogEntryField("userAgent", entry);
354 347
      String docid = getLogEntryField("docid", entry);
355 348
      String eventS = getLogEntryField("event", entry);
356 349
      String dateLogged = getLogEntryField("dateLogged", entry);
......
401 394
      Subject princ = new Subject();
402 395
      princ.setValue(principal);
403 396
      le.setSubject(princ);
404
      le.setUserAgent("metacat/RESTService");
397
      le.setUserAgent(userAgent);
405 398

  
406 399
      // event filtering?
407 400
      if (event == null) {
......
492 485
    if (session != null && session.getSubject() != null) {
493 486
    	principal = session.getSubject().getValue();
494 487
    }
495
    EventLog.getInstance().log(null, principal, localId, "read");
488
    EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"), principal, localId, "read");
496 489
    
497 490
    return inputStream;
498 491
  }
......
836 829
    
837 830
    // do the insert or update action
838 831
    handler = new MetacatHandler(new Timer());
839
    String result = handler.handleInsertOrUpdateAction(metacatUrl, null, 
832
    String result = handler.handleInsertOrUpdateAction(request.getRemoteAddr(), request.getHeader("User-Agent"), null, 
840 833
                        null, params, username, groupnames);
841 834
    
842 835
    if(result.indexOf("<error>") != -1) {
......
938 931
          }
   
           logMetacat.debug("Logging the creation event.");
-          EventLog.getInstance().log(metacatUrl, username, localId, "create");
+          EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"), username, localId, "create");
   
           // Schedule replication for this data file
           logMetacat.debug("Scheduling replication.");
Index: src/edu/ucsb/nceas/metacat/admin/PropertiesAdmin.java
src/edu/ucsb/nceas/metacat/admin/PropertiesAdmin.java
357 357
        CNode cn;
358 358
        try {
359 359
            logMetacat.debug("Get the Node description.");
360
            Node node = MNodeService.getInstance().getCapabilities();
360
            Node node = MNodeService.getInstance(null).getCapabilities();
361 361
            logMetacat.debug("Setting client certificate location.");
362 362
            String certificatePath = PropertyService.getProperty("dataone.certpath");
363 363
            if (!certificatePath.endsWith(File.separator)) {
src/edu/ucsb/nceas/metacat/replication/ReplicationHandler.java
475 475
          REVINSERTNUMBER++;
476 476
      }
477 477
      String ip = getIpFromURL(u);
478
      EventLog.getInstance().log(ip, ReplicationService.REPLICATIONUSER, accNumber, actions);
478
      EventLog.getInstance().log(ip, null, ReplicationService.REPLICATIONUSER, accNumber, actions);
479 479
      
480 480

  
481 481
    }//try
......
627 627
            REVINSERTNUMBER++;
628 628
        }
629 629
        String ip = getIpFromURL(u);
630
        EventLog.getInstance().log(ip, ReplicationService.REPLICATIONUSER, accNumber, actions);
630
        EventLog.getInstance().log(ip, null, ReplicationService.REPLICATIONUSER, accNumber, actions);
631 631
        
632 632
      }//if
633 633
      else
......
697 697
         logReplication.info("ReplicationHandler.handleDeleteSingleDocument - Doc " + docId + " deleted");
698 698
         URL u = new URL("https://"+notifyServer);
699 699
         String ip = getIpFromURL(u);
700
         EventLog.getInstance().log(ip, ReplicationService.REPLICATIONUSER, docId, "delete");
700
         EventLog.getInstance().log(ip, null, ReplicationService.REPLICATIONUSER, docId, "delete");
701 701
      }
702 702

  
703 703
    }//try
......
840 840
							+ guid);
841 841

  
842 842
			String ip = getIpFromURL(sysMetaUrl);
843
			EventLog.getInstance().log(ip, ReplicationService.REPLICATIONUSER, guid, "systemMetadata");
843
			EventLog.getInstance().log(ip, null, ReplicationService.REPLICATIONUSER, guid, "systemMetadata");
844 844

  
845 845
		} catch (Exception e) {
846 846
			logMetacat.error("ReplicationHandler.handleSystemMetadata - "
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff