Project

General

Profile

« Previous | Next » 

Revision 7095

Modify reserveIdentifier() to use parameters parsed from the mime multipart entity rather than the request params. Need to check that the unit test uses MMP params. This partially addresses https://redmine.dataone.org/issues/2526.

View differences:

src/edu/ucsb/nceas/metacat/restservice/CNResourceHandler.java
22 22
 */
23 23
package edu.ucsb.nceas.metacat.restservice;
24 24

  
25
import java.io.ByteArrayInputStream;
26 25
import java.io.File;
27 26
import java.io.FileInputStream;
28 27
import java.io.IOException;
......
821 820
     * @throws IdentifierNotUnique
822 821
     * @throws NotImplemented
823 822
     * @throws InvalidRequest
824
     * @throws IOException
825
     * @throws JiBXException
826 823
     */
827
    private void reserve() throws InvalidToken, ServiceFailure, NotAuthorized,
828
            IdentifierNotUnique, NotImplemented, InvalidRequest, IOException,
829
            JiBXException {
824
    private void reserve() 
825
        throws InvalidToken, ServiceFailure, NotAuthorized, IdentifierNotUnique, 
826
        NotImplemented, InvalidRequest {
830 827
        Identifier pid = null;
831 828
        String scope = null;
832 829
        String format = null;
830

  
831
        // Parse the params out of the multipart form data
832
        logMetacat.debug("Parsing reserve parameters from the mime multipart entity");
833
        try {
834
            collectMultipartParams();
835
            
836
        } catch (FileUploadException e1) {
837
            String msg = "FileUploadException: Couldn't parse the mime multipart information: " +
838
            e1.getMessage();
839
            logMetacat.debug(msg);
840
            throw new ServiceFailure("4210", msg);
841

  
842
        } catch (IOException e1) {
843
            String msg = "IOException: Couldn't parse the mime multipart information: " +
844
            e1.getMessage();
845
            logMetacat.debug(msg);
846
            throw new ServiceFailure("4210", msg);
847
        
848
        } catch (Exception e1) {
849
            String msg = "Exception: Couldn't parse the mime multipart information: " +
850
            e1.getMessage();
851
            logMetacat.debug(msg);
852
            throw new ServiceFailure("4210", msg);
853

  
854
        }
855
        
833 856
        // gather the params
834 857
        try {
835
            String id = params.get("pid")[0];
858
            String id = multipartparams.get("pid").get(0);
836 859
            pid = new Identifier();
837 860
            pid.setValue(id);
838
        } catch (Exception e) {
839
            logMetacat.warn("pid not specified");
861
            
862
        } catch (NullPointerException e) {
863
            String msg = "The 'pid' must be provided as a parameter and was not.";
864
            logMetacat.error(msg);
865
            throw new InvalidRequest("4200", msg);
866
 
840 867
        }
868
        
869
        // call the implementation
841 870
        try {
842
            scope = params.get("scope")[0];
843
        } catch (Exception e) {
844
            logMetacat.warn("pid not specified");
871
            Identifier resultPid = CNodeService.getInstance(request).reserveIdentifier(session, pid);
872
            OutputStream out = response.getOutputStream();
873
            response.setStatus(200);
874
            response.setContentType("text/xml");
875
            // send back the reserved pid
876
            TypeMarshaller.marshalTypeToOutputStream(resultPid, out);
877
            
878
        } catch (IOException e) {
879
            String msg = "Couldn't write the identifier to the response output stream: " +
880
                e.getMessage();
881
            logMetacat.debug(msg);
882
            throw new ServiceFailure("4210", msg);
883
        
884
        } catch (JiBXException e) {
885
            String msg = "Couldn't marshall the identifier to the response output stream: " +
886
            e.getMessage();
887
            logMetacat.debug(msg);
888
            throw new ServiceFailure("4210", msg);
889
            
845 890
        }
846
        try {
847
            format = params.get("format")[0];
848
        } catch (Exception e) {
849
            logMetacat.warn("pid not specified");
850
        }
851
        // call the implementation
852
        Identifier resultPid = CNodeService.getInstance(request)
853
                .reserveIdentifier(session, pid);
854
        OutputStream out = response.getOutputStream();
855
        response.setStatus(200);
856
        response.setContentType("text/xml");
857
        // send back the reserved pid
858
        TypeMarshaller.marshalTypeToOutputStream(resultPid, out);
859 891
    }
860 892

  
861 893
    /**

Also available in: Unified diff