Revision 5320
Added by Matt Jones about 14 years ago
ResourceHandler.java | ||
---|---|---|
22 | 22 |
*/ |
23 | 23 |
package edu.ucsb.nceas.metacat.restservice; |
24 | 24 |
|
25 |
import java.io.BufferedReader; |
|
26 |
import java.io.File; |
|
27 |
import java.io.FileNotFoundException; |
|
28 |
import java.io.FileOutputStream; |
|
29 | 25 |
import java.io.IOException; |
30 | 26 |
import java.io.InputStream; |
31 | 27 |
import java.io.OutputStream; |
... | ... | |
54 | 50 |
import org.dataone.service.exceptions.ServiceFailure; |
55 | 51 |
import org.dataone.service.exceptions.UnsupportedType; |
56 | 52 |
import org.dataone.service.types.AuthToken; |
57 |
import org.dataone.service.types.IdentifierType;
|
|
53 |
import org.dataone.service.types.Identifier; |
|
58 | 54 |
import org.dataone.service.types.SystemMetadata; |
59 |
import org.exolab.castor.jdo.conf.DataSource; |
|
55 |
import org.jibx.runtime.BindingDirectory; |
|
56 |
import org.jibx.runtime.IBindingFactory; |
|
57 |
import org.jibx.runtime.IUnmarshallingContext; |
|
58 |
import org.jibx.runtime.JiBXException; |
|
60 | 59 |
|
61 | 60 |
import edu.ucsb.nceas.metacat.DBUtil; |
62 | 61 |
import edu.ucsb.nceas.metacat.IdentifierManager; |
... | ... | |
470 | 469 |
OutputStream out = null; |
471 | 470 |
try { |
472 | 471 |
out = response.getOutputStream(); |
473 |
InputStream data = cs.get(token, new IdentifierType(guid)); |
|
472 |
Identifier id = new Identifier(); |
|
473 |
id.setValue(guid); |
|
474 |
InputStream data = cs.get(token, id); |
|
474 | 475 |
IOUtils.copyLarge(data, response.getOutputStream()); |
475 | 476 |
} catch (BaseException e) { |
476 | 477 |
serializeException(e, out); |
... | ... | |
604 | 605 |
} |
605 | 606 |
} |
606 | 607 |
|
608 |
// TODO: access control! |
|
607 | 609 |
//if (username != null && !username.equals("public")) { |
608 | 610 |
if (username != null) { |
609 | 611 |
|
610 | 612 |
logMetacat.debug("Commence creation..."); |
611 | 613 |
AuthToken token = null; |
612 |
SystemMetadata m = new SystemMetadata(sysmeta); |
|
613 |
logMetacat.debug(m.serialize(SystemMetadata.FMT_XML)); |
|
614 |
//IOUtils.copy(object, System.out); |
|
615 |
// byte[] b = new byte[2048]; |
|
616 |
// int len = object.read(b); |
|
617 |
// logMetacat.debug("Read " + len + " bytes from object: " + new String(b)); |
|
614 |
IBindingFactory bfact = |
|
615 |
BindingDirectory.getFactory(SystemMetadata.class); |
|
616 |
IUnmarshallingContext uctx = bfact.createUnmarshallingContext(); |
|
617 |
SystemMetadata m = (SystemMetadata) uctx.unmarshalDocument(sysmeta, null); |
|
618 |
|
|
618 | 619 |
CrudService cs = new CrudService(servletContext, request, response); |
619 |
cs.create(token, new IdentifierType(guid), object, m); |
|
620 |
Identifier id = new Identifier(); |
|
621 |
id.setValue(guid); |
|
622 |
cs.create(token, id, object, m); |
|
620 | 623 |
|
621 | 624 |
} else { |
622 | 625 |
logMetacat.debug("Unauthorized to create."); |
... | ... | |
649 | 652 |
} catch (IOException e) { |
650 | 653 |
ServiceFailure sf = new ServiceFailure(1000, e.getMessage()); |
651 | 654 |
serializeException(sf, out); |
655 |
} catch (JiBXException e) { |
|
656 |
e.printStackTrace(System.out); |
|
657 |
InvalidSystemMetadata ism = new InvalidSystemMetadata(1080, e.getMessage()); |
|
658 |
serializeException(ism, out); |
|
652 | 659 |
} |
653 | 660 |
} |
654 | 661 |
|
Also available in: Unified diff
Refactored metacat to use dataone-service-api-0.3.0 jar file, with the new JIBX generated types and serialization. Included JIBX runtime jar in metacat to handle serialization and deserialization of SystemMetadata objects. Removed the old API jar file.