Revision 5337
Added by berkley over 14 years ago
test/edu/ucsb/nceas/metacat/dataone/CrudServiceTest.java | ||
---|---|---|
28 | 28 |
import java.util.*; |
29 | 29 |
import java.io.*; |
30 | 30 |
|
31 |
import java.security.MessageDigest; |
|
32 |
|
|
31 | 33 |
import edu.ucsb.nceas.MCTestCase; |
32 | 34 |
import edu.ucsb.nceas.metacat.client.MetacatAuthException; |
33 | 35 |
import edu.ucsb.nceas.metacat.client.MetacatException; |
... | ... | |
36 | 38 |
import junit.framework.Test; |
37 | 39 |
import junit.framework.TestSuite; |
38 | 40 |
|
41 |
import org.dataone.service.types.*; |
|
42 |
|
|
43 |
import edu.ucsb.nceas.metacat.properties.PropertyService; |
|
44 |
import edu.ucsb.nceas.metacat.client.rest.MetacatRestClient; |
|
45 |
|
|
46 |
import edu.ucsb.nceas.metacat.service.SessionService; |
|
47 |
import edu.ucsb.nceas.metacat.util.SessionData; |
|
48 |
|
|
39 | 49 |
/** |
40 | 50 |
* A JUnit test for testing the dataone CrudService class |
41 | 51 |
*/ |
... | ... | |
71 | 81 |
{ |
72 | 82 |
TestSuite suite = new TestSuite(); |
73 | 83 |
suite.addTest(new CrudServiceTest("initialize")); |
74 |
|
|
84 |
suite.addTest(new CrudServiceTest("testSingletonAccessor")); |
|
85 |
suite.addTest(new CrudServiceTest("testCreate")); |
|
86 |
//suite.addTest(new CrudServiceTest("")); |
|
87 |
//suite.addTest(new CrudServiceTest("")); |
|
88 |
//suite.addTest(new CrudServiceTest("")); |
|
89 |
//suite.addTest(new CrudServiceTest("")); |
|
90 |
//suite.addTest(new CrudServiceTest("")); |
|
75 | 91 |
return suite; |
76 | 92 |
} |
93 |
|
|
94 |
/** |
|
95 |
* create(AuthToken token, Identifier guid, InputStream object, SystemMetadata sysmeta) |
|
96 |
* throws InvalidToken, ServiceFailure, NotAuthorized, IdentifierNotUnique, UnsupportedType, |
|
97 |
* InsufficientResources, InvalidSystemMetadata, NotImplemented |
|
98 |
*/ |
|
99 |
public void testCreate() |
|
100 |
{ |
|
101 |
try |
|
102 |
{ |
|
103 |
CrudService cs = CrudService.getInstance(); |
|
104 |
|
|
105 |
//login and get a sessionid |
|
106 |
System.out.println("creating MetacatRestClient with url " + cs.getContextUrl()); |
|
107 |
MetacatRestClient restClient = new MetacatRestClient(cs.getContextUrl()); |
|
108 |
String username = PropertyService.getProperty("test.mcUser"); |
|
109 |
String password = PropertyService.getProperty("test.mcPassword"); |
|
110 |
System.out.println("logging in with username: " + username + " and password " + password + " to context " + cs.getContextUrl()); |
|
111 |
String response = restClient.login(username, password); |
|
112 |
//System.out.println("response to login: " + response); |
|
113 |
String sessionid = restClient.getSessionId(); |
|
114 |
SessionService sessionService = SessionService.getInstance(); |
|
115 |
sessionService.registerSession(new SessionData(sessionid, username, new String[0], password, "CrudServiceLogin")); |
|
116 |
System.out.println("sessionid: " + sessionid); |
|
117 |
AuthToken token = new AuthToken(sessionid); |
|
118 |
|
|
119 |
String s = "<?xml version=\"1.0\"?><test></test>\n"; |
|
120 |
|
|
121 |
//create the system metadata then run the create method |
|
122 |
StringBufferInputStream sbis = new StringBufferInputStream(s); |
|
123 |
String docid = generateDocumentId(); |
|
124 |
String smdocid = generateDocumentId(); |
|
125 |
Identifier id = new Identifier(); |
|
126 |
id.setValue(docid); |
|
127 |
SystemMetadata sm = new SystemMetadata(); |
|
128 |
//set the id |
|
129 |
sm.setIdentifier(id); |
|
130 |
System.out.println("sm id is " + id); |
|
131 |
sm.setObjectFormat(ObjectFormat.convert("eml://ecoinformatics.org/eml-2.1.0")); |
|
132 |
System.out.println("sm objectformat: " + sm.getObjectFormat()); |
|
133 |
//create the checksum |
|
134 |
String checksumS = checksum(s); |
|
135 |
ChecksumAlgorithm ca = ChecksumAlgorithm.convert("MD5"); |
|
136 |
Checksum checksum = new Checksum(); |
|
137 |
checksum.setValue(checksumS); |
|
138 |
checksum.setAlgorithm(ca); |
|
139 |
sm.setChecksum(checksum); |
|
140 |
System.out.println("sm checksum is " + checksumS); |
|
141 |
//set the size |
|
142 |
sm.setSize(s.getBytes().length); |
|
143 |
System.out.println("sm size: " + s.getBytes().length); |
|
144 |
//submitter |
|
145 |
Principal p = new Principal(); |
|
146 |
p.setValue("joe"); |
|
147 |
sm.setSubmitter(p); |
|
148 |
sm.setRightsHolder(p); |
|
149 |
sm.setDateUploaded(new Date()); |
|
150 |
sm.setDateSysMetadataModified(new Date()); |
|
151 |
NodeReference nr = new NodeReference(); |
|
152 |
nr.setValue("metacat"); |
|
153 |
sm.setOriginMemberNode(nr); |
|
154 |
sm.setAuthoritativeMemberNode(nr); |
|
155 |
|
|
156 |
|
|
157 |
cs.create(token, id, sbis, sm); |
|
158 |
} |
|
159 |
catch(Exception e) |
|
160 |
{ |
|
161 |
e.printStackTrace(); |
|
162 |
fail("Error in testCreate: " + e.getMessage()); |
|
163 |
} |
|
164 |
} |
|
77 | 165 |
|
78 | 166 |
/** |
167 |
* getInstance() |
|
168 |
*/ |
|
169 |
public void testSingletonAccessor() |
|
170 |
{ |
|
171 |
CrudService cs = CrudService.getInstance(); |
|
172 |
assertNotNull(cs); |
|
173 |
} |
|
174 |
|
|
175 |
/** |
|
79 | 176 |
* Run an initial test that always passes to check that the test harness is |
80 | 177 |
* working. |
81 | 178 |
*/ |
... | ... | |
84 | 181 |
assertTrue(1 == 1); |
85 | 182 |
} |
86 | 183 |
|
184 |
/** |
|
185 |
* produce an md5 checksum for item |
|
186 |
*/ |
|
187 |
private String checksum(String item) |
|
188 |
throws Exception |
|
189 |
{ |
|
190 |
StringBufferInputStream fis = new StringBufferInputStream(item); |
|
191 |
|
|
192 |
byte[] buffer = new byte[1024]; |
|
193 |
MessageDigest complete = MessageDigest.getInstance("MD5"); |
|
194 |
int numRead; |
|
195 |
|
|
196 |
do |
|
197 |
{ |
|
198 |
numRead = fis.read(buffer); |
|
199 |
if (numRead > 0) |
|
200 |
{ |
|
201 |
complete.update(buffer, 0, numRead); |
|
202 |
} |
|
203 |
} while (numRead != -1); |
|
204 |
|
|
205 |
|
|
206 |
return getHex(complete.digest()); |
|
207 |
} |
|
208 |
|
|
209 |
/** |
|
210 |
* convert a byte array to a hex string |
|
211 |
*/ |
|
212 |
private static String getHex( byte [] raw ) |
|
213 |
{ |
|
214 |
final String HEXES = "0123456789ABCDEF"; |
|
215 |
if ( raw == null ) { |
|
216 |
return null; |
|
217 |
} |
|
218 |
final StringBuilder hex = new StringBuilder( 2 * raw.length ); |
|
219 |
for ( final byte b : raw ) { |
|
220 |
hex.append(HEXES.charAt((b & 0xF0) >> 4)) |
|
221 |
.append(HEXES.charAt((b & 0x0F))); |
|
222 |
} |
|
223 |
return hex.toString(); |
|
224 |
} |
|
87 | 225 |
} |
test/edu/ucsb/nceas/metacattest/restservice/MetacatRestClientTest.java | ||
---|---|---|
84 | 84 |
*/ |
85 | 85 |
public void setUp() |
86 | 86 |
{ |
87 |
System.out.println("contextUrl: " + contextUrl); |
|
87 | 88 |
m = new MetacatRestClient(contextUrl); |
88 | 89 |
} |
89 | 90 |
|
src/edu/ucsb/nceas/metacat/restservice/ResourceHandler.java | ||
---|---|---|
285 | 285 |
initParams(); |
286 | 286 |
|
287 | 287 |
Timer timer = new Timer(); |
288 |
handler = new MetacatHandler(servletContext, timer);
|
|
288 |
handler = new MetacatHandler(timer); |
|
289 | 289 |
|
290 | 290 |
if (resource.equals(RESOURCE_SESSION) && httpVerb == POST |
291 | 291 |
&& params.get(FUNCTION_KEYWORD) != null) { |
... | ... | |
484 | 484 |
*/ |
485 | 485 |
private void getObject(String guid) { |
486 | 486 |
//hack...fix this |
487 |
CrudService cs = new CrudService(servletContext, request, response); |
|
487 |
//CrudService cs = new CrudService(servletContext, request, response); |
|
488 |
CrudService cs = CrudService.getInstance(); |
|
489 |
cs.setParamsFromRequest(request); |
|
488 | 490 |
AuthToken token = null; |
489 | 491 |
OutputStream out = null; |
490 | 492 |
try { |
... | ... | |
506 | 508 |
* @param guid ID of data object to be read |
507 | 509 |
*/ |
508 | 510 |
private void getSystemMetadataObject(String guid) { |
509 |
CrudService cs = new CrudService(servletContext, request, response); |
|
511 |
//CrudService cs = new CrudService(servletContext, request, response); |
|
512 |
CrudService cs = CrudService.getInstance(); |
|
513 |
cs.setParamsFromRequest(request); |
|
510 | 514 |
AuthToken token = null; |
511 | 515 |
OutputStream out = null; |
512 | 516 |
try { |
... | ... | |
669 | 673 |
IUnmarshallingContext uctx = bfact.createUnmarshallingContext(); |
670 | 674 |
SystemMetadata m = (SystemMetadata) uctx.unmarshalDocument(sysmeta, null); |
671 | 675 |
|
672 |
CrudService cs = new CrudService(servletContext, request, response); |
|
676 |
//CrudService cs = new CrudService(servletContext, request, response); |
|
677 |
CrudService cs = CrudService.getInstance(); |
|
678 |
cs.setParamsFromRequest(request); |
|
673 | 679 |
Identifier id = new Identifier(); |
674 | 680 |
id.setValue(guid); |
675 | 681 |
cs.create(token, id, object, m); |
src/edu/ucsb/nceas/metacat/MetaCatServlet.java | ||
---|---|---|
419 | 419 |
SessionService.unRegisterAllSessions(); |
420 | 420 |
|
421 | 421 |
//Initialize Metacat Handler |
422 |
handler = new MetacatHandler(getServletContext(), timer);
|
|
422 |
handler = new MetacatHandler(timer); |
|
423 | 423 |
|
424 | 424 |
handler.set_sitemapScheduled(false); |
425 | 425 |
|
src/edu/ucsb/nceas/metacat/DocumentImpl.java | ||
---|---|---|
2632 | 2632 |
// write to xml_node complete. start the indexing thread. |
2633 | 2633 |
addDocidToIndexingQueue(docid, rev); |
2634 | 2634 |
} catch (Exception e) { |
2635 |
e.printStackTrace(); |
|
2635 | 2636 |
logMetacat.error("DocumentImpl.write - Problem with parsing: " + e.getMessage()); |
2636 | 2637 |
conn.rollback(); |
2637 | 2638 |
conn.setAutoCommit(true); |
... | ... | |
3466 | 3467 |
Vector<XMLSchema> schemaList = XMLSchemaService.findSchemasInXML((StringReader)xml); |
3467 | 3468 |
boolean allSchemasRegistered = |
3468 | 3469 |
XMLSchemaService.areAllSchemasRegistered(schemaList); |
3470 |
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!are all schemas registered: " + allSchemasRegistered); |
|
3469 | 3471 |
if (XMLSchemaService.useFullSchemaValidation() && !allSchemasRegistered) { |
3472 |
System.out.println("setting full schema validation"); |
|
3470 | 3473 |
parser.setFeature(FULLSCHEMAVALIDATIONFEATURE, true); |
3471 | 3474 |
} |
3472 | 3475 |
// From DB to find the register external schema location |
3473 | 3476 |
String externalSchemaLocation = null; |
3474 | 3477 |
externalSchemaLocation = XMLSchemaService.getNameSpaceAndLocationString(); |
3478 |
System.out.println("external schema location: " + externalSchemaLocation); |
|
3475 | 3479 |
logMetacat.debug("DocumentImpl.initalizeParser - Generic external schema location: " + externalSchemaLocation); |
3476 | 3480 |
// Set external schemalocation. |
3477 | 3481 |
if (externalSchemaLocation != null |
3478 | 3482 |
&& !(externalSchemaLocation.trim()).equals("")) { |
3483 |
System.out.println("setting external schema location to " + externalSchemaLocation); |
|
3479 | 3484 |
parser.setProperty(EXTERNALSCHEMALOCATIONPROPERTY, |
3480 | 3485 |
externalSchemaLocation); |
3481 | 3486 |
} |
src/edu/ucsb/nceas/metacat/MetacatHandler.java | ||
---|---|---|
57 | 57 |
import javax.servlet.http.HttpServletRequest; |
58 | 58 |
import javax.servlet.http.HttpServletResponse; |
59 | 59 |
import javax.servlet.http.HttpSession; |
60 |
import javax.activation.MimetypesFileTypeMap; |
|
60 | 61 |
|
61 | 62 |
import org.apache.log4j.Logger; |
62 | 63 |
import org.ecoinformatics.eml.EMLParser; |
... | ... | |
114 | 115 |
private static final String ERROR = "<error>"; |
115 | 116 |
private static final String ERRORCLOSE = "</error>"; |
116 | 117 |
|
117 |
private ServletContext servletContext; |
|
118 | 118 |
private Timer timer; |
119 | 119 |
|
120 |
public MetacatHandler(ServletContext servletContext, Timer timer) { |
|
121 |
this.servletContext = servletContext; |
|
120 |
public MetacatHandler(Timer timer) { |
|
122 | 121 |
this.timer = timer; |
123 | 122 |
} |
124 | 123 |
|
... | ... | |
955 | 954 |
|
956 | 955 |
if (response != null) { |
957 | 956 |
// MIME type |
958 |
String contentType = servletContext.getMimeType(filename); |
|
957 |
//String contentType = servletContext.getMimeType(filename); |
|
958 |
String contentType = (new MimetypesFileTypeMap()).getContentType(filename); |
|
959 | 959 |
if (contentType == null) { |
960 | 960 |
ContentTypeProvider provider = new ContentTypeProvider( |
961 | 961 |
docid); |
... | ... | |
1097 | 1097 |
private void readFromURLConnection(HttpServletResponse response, |
1098 | 1098 |
String docid) throws IOException, MalformedURLException { |
1099 | 1099 |
ServletOutputStream out = response.getOutputStream(); |
1100 |
String contentType = servletContext.getMimeType(docid); //MIME type |
|
1100 |
//String contentType = servletContext.getMimeType(docid); //MIME type |
|
1101 |
String contentType = (new MimetypesFileTypeMap()).getContentType(docid); |
|
1101 | 1102 |
if (contentType == null) { |
1102 | 1103 |
if (docid.endsWith(".xml")) { |
1103 | 1104 |
contentType = "text/xml"; |
... | ... | |
1286 | 1287 |
* Handle the database putdocument request and write an XML document to the |
1287 | 1288 |
* database connection |
1288 | 1289 |
*/ |
1289 |
public void handleInsertOrUpdateAction(String ipAddress,
|
|
1290 |
public String handleInsertOrUpdateAction(String ipAddress,
|
|
1290 | 1291 |
HttpServletResponse response, PrintWriter out, Hashtable<String, String[]> params, |
1291 | 1292 |
String user, String[] groups) { |
1292 | 1293 |
Logger logMetacat = Logger.getLogger(MetaCatServlet.class); |
... | ... | |
1300 | 1301 |
} |
1301 | 1302 |
|
1302 | 1303 |
if(params.get("docid") == null){ |
1303 |
out.println("<?xml version=\"1.0\"?>"); |
|
1304 |
out.println("<error>"); |
|
1305 |
out.println("Docid not specified"); |
|
1306 |
out.println("</error>"); |
|
1307 |
logMetacat.error("MetaCatServlet.handleInsertOrUpdateAction - Docid not specified"); |
|
1308 |
return; |
|
1304 |
String msg = "<?xml version=\"1.0\"?>" + |
|
1305 |
"<error>" + |
|
1306 |
"Docid not specified" + |
|
1307 |
"</error>"; |
|
1308 |
if(out != null) |
|
1309 |
{ |
|
1310 |
out.println(msg); |
|
1311 |
logMetacat.error("MetaCatServlet.handleInsertOrUpdateAction - Docid not specified"); |
|
1312 |
} |
|
1313 |
return msg; |
|
1309 | 1314 |
} |
1310 | 1315 |
|
1311 | 1316 |
try { |
1312 | 1317 |
if (!AuthUtil.canInsertOrUpdate(user, groups)) { |
1313 |
out.println("<?xml version=\"1.0\"?>"); |
|
1314 |
out.println("<error>"); |
|
1315 |
out.println("User '" + user + "' not allowed to insert and update"); |
|
1316 |
out.println("</error>"); |
|
1318 |
String msg = "<?xml version=\"1.0\"?>" + |
|
1319 |
"<error>" + |
|
1320 |
"User '" + user + "' not allowed to insert and update" + |
|
1321 |
"</error>"; |
|
1322 |
if(out != null) |
|
1323 |
{ |
|
1324 |
out.println(msg); |
|
1325 |
} |
|
1326 |
|
|
1317 | 1327 |
logMetacat.error("MetaCatServlet.handleInsertOrUpdateAction - User '" + user + "' not allowed to insert and update"); |
1318 |
return; |
|
1328 |
return msg;
|
|
1319 | 1329 |
} |
1320 | 1330 |
} catch (MetacatUtilException ue) { |
1321 | 1331 |
logMetacat.error("MetaCatServlet.handleInsertOrUpdateAction - Could not determine if user could insert or update: " |
... | ... | |
1346 | 1356 |
} |
1347 | 1357 |
|
1348 | 1358 |
if(doctext == null){ |
1349 |
out.println("<?xml version=\"1.0\"?>"); |
|
1350 |
out.println("<error>"); |
|
1351 |
out.println("Document text not submitted"); |
|
1352 |
out.println("</error>"); |
|
1359 |
String msg = "<?xml version=\"1.0\"?>" + |
|
1360 |
"<error>" + |
|
1361 |
"Document text not submitted." + |
|
1362 |
"</error>"; |
|
1363 |
if(out != null) |
|
1364 |
{ |
|
1365 |
out.println(msg); |
|
1366 |
} |
|
1367 |
|
|
1353 | 1368 |
// TODO: this should really throw an exception |
1354 |
return; |
|
1369 |
return msg;
|
|
1355 | 1370 |
} |
1356 | 1371 |
|
1357 | 1372 |
logMetacat.debug("MetaCatServlet.handleInsertOrUpdateAction - the xml document in metacat servlet (before parsing):\n" + doctext[0]); |
... | ... | |
1463 | 1478 |
} |
1464 | 1479 |
|
1465 | 1480 |
if (qformat == null || qformat.equals("xml")) { |
1466 |
response.setContentType("text/xml"); |
|
1467 |
out.println(output); |
|
1481 |
if(response != null) |
|
1482 |
{ |
|
1483 |
response.setContentType("text/xml"); |
|
1484 |
out.println(output); |
|
1485 |
} |
|
1486 |
return output; |
|
1468 | 1487 |
} else { |
1469 | 1488 |
try { |
1470 | 1489 |
DBTransform trans = new DBTransform(); |
... | ... | |
1479 | 1498 |
e.printStackTrace(System.out); |
1480 | 1499 |
} |
1481 | 1500 |
} |
1501 |
return null; |
|
1482 | 1502 |
} |
1483 | 1503 |
|
1484 | 1504 |
/** |
src/edu/ucsb/nceas/metacat/client/rest/MetacatRestClient.java | ||
---|---|---|
78 | 78 |
*/ |
79 | 79 |
public String login(String username, String password) |
80 | 80 |
throws MetacatAuthException, MetacatInaccessibleException { |
81 |
String urlParams = FUNCTION_KEYWORD+"="+FUNCTION_NAME_LOGIN; |
|
81 |
System.out.println("in login"); |
|
82 |
String urlParams = FUNCTION_KEYWORD+"="+FUNCTION_NAME_LOGIN; |
|
82 | 83 |
String postData = "username="+username+"&password="+password; |
83 | 84 |
String response = null; |
85 |
|
|
84 | 86 |
|
85 | 87 |
try { |
86 | 88 |
response = sendData(RESOURCE_SESSION, POST, urlParams, postData, "application/x-www-form-urlencoded", null, null); |
... | ... | |
561 | 563 |
HttpURLConnection connection = null ; |
562 | 564 |
|
563 | 565 |
String restURL = contextRootUrl+resource; |
566 |
System.out.println("restURL: " + restURL); |
|
564 | 567 |
|
565 | 568 |
if (urlParamaters != null) { |
566 | 569 |
if (restURL.indexOf("?") == -1) |
src/edu/ucsb/nceas/metacat/dataone/CrudService.java | ||
---|---|---|
91 | 91 |
*/ |
92 | 92 |
public class CrudService implements MemberNodeCrud { |
93 | 93 |
|
94 |
private ServletContext servletContext; |
|
94 |
/*private ServletContext servletContext;
|
|
95 | 95 |
private HttpServletRequest request; |
96 |
private HttpServletResponse response; |
|
96 |
private HttpServletResponse response;*/ |
|
97 |
|
|
98 |
private static CrudService crudService = null; |
|
97 | 99 |
|
98 | 100 |
private MetacatHandler handler; |
99 | 101 |
private Hashtable<String, String[]> params; |
100 | 102 |
Logger logMetacat = null; |
103 |
|
|
104 |
private String metacatUrl; |
|
101 | 105 |
|
102 | 106 |
/** |
107 |
* singleton accessor |
|
108 |
*/ |
|
109 |
public static CrudService getInstance() |
|
110 |
{ |
|
111 |
if(crudService == null) |
|
112 |
{ |
|
113 |
crudService = new CrudService(); |
|
114 |
} |
|
115 |
|
|
116 |
return crudService; |
|
117 |
} |
|
118 |
|
|
119 |
/** |
|
103 | 120 |
* Initializes new instance by setting servlet context,request and response. |
104 | 121 |
* TODO: remove dependency on Servlet infrastructure |
105 | 122 |
* TODO: Make this a real service, and make it a Singleton |
106 | 123 |
*/ |
107 |
public CrudService(ServletContext servletContext, |
|
108 |
HttpServletRequest request, HttpServletResponse response) { |
|
124 |
public CrudService() { |
|
109 | 125 |
//change crud service into a singleton. dont pass servlet data structures here |
110 |
|
|
111 |
this.servletContext = servletContext; |
|
126 |
logMetacat = Logger.getLogger(CrudService.class); |
|
127 |
try |
|
128 |
{ |
|
129 |
String server = PropertyService.getProperty("server.name"); |
|
130 |
String port = PropertyService.getProperty("server.httpPort"); |
|
131 |
String context = PropertyService.getProperty("application.context"); |
|
132 |
metacatUrl = "http://" + server + ":" + port + "/" + context; |
|
133 |
logMetacat.debug("Initializing CrudService with url " + metacatUrl); |
|
134 |
} |
|
135 |
catch(Exception e) |
|
136 |
{ |
|
137 |
logMetacat.error("Could not find servlet url in CrudService: " + e.getMessage()); |
|
138 |
e.printStackTrace(); |
|
139 |
throw new RuntimeException("Error getting servlet url in CrudService: " + e.getMessage()); |
|
140 |
} |
|
141 |
|
|
142 |
/*this.servletContext = servletContext; |
|
112 | 143 |
this.request = request; |
113 |
this.response = response; |
|
114 |
logMetacat = Logger.getLogger(CrudService.class); |
|
144 |
this.response = response;*/ |
|
145 |
|
|
146 |
params = new Hashtable<String, String[]>(); |
|
115 | 147 |
|
116 |
handler = new MetacatHandler(this.servletContext, new Timer()); |
|
117 |
initParams(); |
|
118 |
// loadSessionData(); |
|
148 |
handler = new MetacatHandler(new Timer()); |
|
149 |
|
|
119 | 150 |
} |
120 |
|
|
151 |
|
|
121 | 152 |
/** |
122 |
* copies request parameters to a Hashtable which is given as argument to |
|
123 |
* native MetacatHandler functions |
|
153 |
* return the context url CrudService is using. |
|
124 | 154 |
*/ |
125 |
private void initParams() { |
|
126 |
|
|
127 |
String name = null; |
|
128 |
String[] value = null; |
|
129 |
params = new Hashtable<String, String[]>(); |
|
155 |
public String getContextUrl() |
|
156 |
{ |
|
157 |
return metacatUrl; |
|
158 |
} |
|
159 |
|
|
160 |
/** |
|
161 |
* set the params for this service from an HttpServletRequest param list |
|
162 |
*/ |
|
163 |
public void setParamsFromRequest(HttpServletRequest request) |
|
164 |
{ |
|
130 | 165 |
Enumeration paramlist = request.getParameterNames(); |
131 | 166 |
while (paramlist.hasMoreElements()) { |
132 |
name = (String) paramlist.nextElement(); |
|
133 |
value = request.getParameterValues(name);
|
|
167 |
String name = (String) paramlist.nextElement();
|
|
168 |
String[] value = (String[])request.getParameterValues(name);
|
|
134 | 169 |
params.put(name, value); |
135 | 170 |
} |
136 | 171 |
} |
137 | 172 |
|
173 |
/** |
|
174 |
* set the parameter values needed for this request |
|
175 |
*/ |
|
176 |
public void setParameter(String name, String[] value) |
|
177 |
{ |
|
178 |
params.put(name, value); |
|
179 |
} |
|
180 |
|
|
138 | 181 |
public Identifier create(AuthToken token, Identifier guid, |
139 | 182 |
InputStream object, SystemMetadata sysmeta) throws InvalidToken, |
140 | 183 |
ServiceFailure, NotAuthorized, IdentifierNotUnique, UnsupportedType, |
141 | 184 |
InsufficientResources, InvalidSystemMetadata, NotImplemented { |
142 | 185 |
|
143 | 186 |
logMetacat.debug("Starting CrudService.create()..."); |
187 |
System.out.println("sysmeta object format: " + sysmeta.getObjectFormat()); |
|
144 | 188 |
|
145 | 189 |
// authenticate & get user info |
146 | 190 |
SessionData sessionData = getSessionData(token); |
... | ... | |
222 | 266 |
public String produce(final OutputStream dataSink) throws Exception { |
223 | 267 |
|
224 | 268 |
try { |
225 |
handler.readFromMetacat(request.getRemoteAddr(), null,
|
|
269 |
handler.readFromMetacat(/*request.getRemoteAddr()*/metacatUrl, null,
|
|
226 | 270 |
dataSink, localId, "xml", |
227 | 271 |
sessionData.getUserName(), |
228 | 272 |
sessionData.getGroupNames(), true, params); |
... | ... | |
298 | 342 |
@Override |
299 | 343 |
public String produce(final OutputStream dataSink) throws Exception { |
300 | 344 |
try { |
301 |
handler.readFromMetacat(request.getRemoteAddr(), null,
|
|
345 |
handler.readFromMetacat(/*request.getRemoteAddr()*/metacatUrl, null,
|
|
302 | 346 |
dataSink, localId, "xml", |
303 | 347 |
sessionData.getUserName(), |
304 | 348 |
sessionData.getGroupNames(), true, params); |
... | ... | |
374 | 418 |
*/ |
375 | 419 |
private boolean isScienceMetadata(SystemMetadata sysmeta) { |
376 | 420 |
boolean scimeta = false; |
421 |
System.out.println("sysmeta: " + sysmeta.toString()); |
|
422 |
System.out.println("sysmeta format: " + sysmeta.getObjectFormat()); |
|
377 | 423 |
switch (sysmeta.getObjectFormat()) { |
378 | 424 |
case EML_2_1_0: scimeta = true; break; |
379 | 425 |
case EML_2_0_1: scimeta = true; break; |
... | ... | |
441 | 487 |
} |
442 | 488 |
|
443 | 489 |
logMetacat.debug("Logging the creation event."); |
444 |
EventLog.getInstance().log(request.getRemoteAddr(),
|
|
490 |
EventLog.getInstance().log(/*request.getRemoteAddr()*/metacatUrl,
|
|
445 | 491 |
username, localId, "create"); |
446 | 492 |
|
447 | 493 |
// Schedule replication for this data file |
... | ... | |
533 | 579 |
// TODO: refactor handleInsertOrUpdateAction() to not output XML directly |
534 | 580 |
// onto output stream, or alternatively, capture that and parse it to |
535 | 581 |
// generate the right exceptions |
536 |
ByteArrayOutputStream output = new ByteArrayOutputStream(); |
|
537 |
PrintWriter pw = new PrintWriter(output); |
|
538 |
handler.handleInsertOrUpdateAction(request.getRemoteAddr(), response, |
|
539 |
pw, params, sessionData.getUserName(), |
|
540 |
sessionData.getGroupNames()); |
|
541 |
String outputS = new String(output.toByteArray()); |
|
542 |
logMetacat.debug("CrudService.insertDocument - Metacat returned: " + outputS); |
|
582 |
//ByteArrayOutputStream output = new ByteArrayOutputStream(); |
|
583 |
//PrintWriter pw = new PrintWriter(output); |
|
584 |
String result = handler.handleInsertOrUpdateAction(/*request.getRemoteAddr()*/metacatUrl, null, |
|
585 |
null, params, sessionData.getUserName(), sessionData.getGroupNames()); |
|
586 |
//String outputS = new String(output.toByteArray()); |
|
587 |
logMetacat.debug("CrudService.insertDocument - Metacat returned: " + result); |
|
543 | 588 |
// if (!(outputS.indexOf("<success>") > 0 && outputS.indexOf(localId) > 0)) { |
544 | 589 |
// throw new ServiceFailure(1190, outputS); |
545 | 590 |
// } |
Also available in: Unified diff
removed CrudService dependency on servlet params. CrudService is now a singleton. I'm getting an error from metacat saying it can't find teh systemmetadata schema, even though it is, in fact, registered with metacat. need to identify why this is happening.