Project

General

Profile

« Previous | Next » 

Revision 5301

Modified ResourceHandler to return error codes in XML format for the get() method.

View differences:

src/edu/ucsb/nceas/metacat/restservice/ResourceHandler.java
37 37
import org.apache.commons.io.IOUtils;
38 38
import org.apache.log4j.Logger;
39 39
import org.dataone.service.exceptions.BaseException;
40
import org.dataone.service.exceptions.InvalidToken;
41
import org.dataone.service.exceptions.NotAuthorized;
42
import org.dataone.service.exceptions.NotFound;
43
import org.dataone.service.exceptions.NotImplemented;
44 40
import org.dataone.service.exceptions.ServiceFailure;
45 41
import org.dataone.service.types.AuthToken;
46 42
import org.dataone.service.types.IdentifierType;
......
458 454
            InputStream data = cs.get(token, new IdentifierType(guid));
459 455
            IOUtils.copyLarge(data, response.getOutputStream());
460 456
        } catch (BaseException e) {
461
            try {
457
                response.setContentType("text/xml");
458
                response.setStatus(e.getCode());
462 459
                // TODO: Use content negotiation to determine which return format to use
463
                IOUtils.write(e.serialize(BaseException.FMT_XML), 
464
                        response.getOutputStream());
465
            } catch (IOException e1) {
466
                logMetacat.error("Error writing service exception to stream. " 
467
                        + e1.getMessage());
468
            }
460
                try {
461
                    IOUtils.write(e.serialize(BaseException.FMT_XML), 
462
                            response.getOutputStream());
463
                } catch (IOException e1) {
464
                    logMetacat.error("Error writing exception to stream. " 
465
                            + e1.getMessage());
466
                }
469 467
        } catch (IOException e) {
470 468
            ServiceFailure sf = new ServiceFailure(1030, e.getMessage());
469
            response.setContentType("text/xml");
470
            response.setStatus(sf.getCode());
471 471
            try {
472 472
                IOUtils.write(sf.serialize(BaseException.FMT_XML), 
473 473
                        response.getOutputStream());

Also available in: Unified diff