Changeset 239


Ignore:
Timestamp:
03/17/10 13:45:10 (14 years ago)
Author:
oschonef
Message:
  • return user error, if submitted internal collection format is invalid
Location:
VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/eu/clarin/cmdi/virtualcollectionregistry
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/eu/clarin/cmdi/virtualcollectionregistry/VirtualCollectionRegistryMarshaller.java

    r215 r239  
    9292
    9393        public VirtualCollection unmarshal(InputStream input, Format format,
    94                         String encoding) throws IOException {
     94                        String encoding) throws VirtualCollectionRegistryException, IOException {
    9595                if (input == null) {
    9696                        throw new NullPointerException("input == null");
     
    104104                        return vc;
    105105                } catch (UnmarshalException e) {
    106                         logger.log(Level.WARNING, "error unmarshalling virtual collection",
    107                                         e.getLinkedException());
    108                         throw new IOException("error unmarshalling virtual collection",
    109                                         e.getLinkedException());
     106                        throw new VirtualCollectionRegistryUsageException("invalid " +
     107                                        "virtual collection format", e.getLinkedException());
    110108                } catch (Exception e) {
    111109                        logger.log(Level.WARNING, "error unmarshalling virtual collection", e);
  • VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/eu/clarin/cmdi/virtualcollectionregistry/rest/VirtualCollectionRegistryExceptionMapper.java

    r236 r239  
    5757                while (t != null) {
    5858                        if (t instanceof SAXParseException) {
    59                                 SAXParseException e = (SAXParseException) t;
    60                                 errors.add(e.getMessage() + ", line = " + e.getLineNumber()
    61                                                 + ", column = " + e.getColumnNumber());
     59                                final SAXParseException e = (SAXParseException) t;
     60                                String message = e.getMessage();
     61                                if (message.startsWith("cvc")) {
     62                                        int pos = message.indexOf(':');
     63                                        if (pos != 0) {
     64                                                message = message.substring(pos + 1);
     65                                        }
     66                                }
     67                                errors.add(message +
     68                           " [line = " + e.getLineNumber() +
     69                                                   ", column = " + e.getColumnNumber() + "]");
     70                        } else if (t instanceof XMLStreamException) {
     71                                final XMLStreamException e = (XMLStreamException) t;
     72                                String message = e.getMessage();
     73                                if (message.startsWith("ParseError")) {
     74                                        int pos = message.indexOf(':');
     75                                        if (pos != -1) {
     76                                                pos = message.indexOf(':', pos + 1);
     77                                                if (pos != -1) {
     78                                                        message = message.substring(pos + 1);
     79                                                }
     80                                        }
     81                                }
     82                                if (e.getLocation() != null) {
     83                                        message = message +
     84                                                " [line = " + e.getLocation().getLineNumber() +
     85                                                ", column = " + e.getLocation().getColumnNumber() +
     86                        "]";
     87                                }
     88                                errors.add(message);
    6289                        } else {
    6390                                errors.add(t.getMessage());
  • VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/eu/clarin/cmdi/virtualcollectionregistry/rest/VirtualCollectionRegistryRestService.java

    r235 r239  
    8585                                        .build();
    8686                        return Response.created(uri).entity(response).build();
    87                 } catch (Exception e) {
     87                } catch (IOException e) {
    8888                        throw new VirtualCollectionRegistryException("create", e);
    8989                }
     
    117117                                MediaType.APPLICATION_JSON })
    118118        public Response updateVirtualCollection(@PathParam("id") long id,
    119                         VirtualCollection vc) throws VirtualCollectionRegistryException {
     119                        InputStream input) throws VirtualCollectionRegistryException {
    120120                Principal principal = security.getUserPrincipal();
    121121                if (principal == null) {
    122122                        throw new NullPointerException("princial == null");
    123123                }
    124                 registry.updateVirtualCollection(principal, id, vc);
    125                 RestResponse response = new RestResponse();
    126                 response.setIsSuccess(true);
    127                 response.setInfo("updated");
    128                 response.setId(id);
    129                 return Response.ok(response).build();
     124                try {
     125                        Format format = getInputFormat();
     126                        String encoding = getInputEncoding();
     127                        VirtualCollection vc = registry.getMarshaller()
     128                                .unmarshal(input, format, encoding);
     129                        registry.updateVirtualCollection(principal, id, vc);
     130                        RestResponse response = new RestResponse();
     131                        response.setIsSuccess(true);
     132                        response.setInfo("updated");
     133                        response.setId(id);
     134                        return Response.ok(response).build();
     135                } catch (IOException e) {
     136                        throw new VirtualCollectionRegistryException("update", e);
     137
     138                }
    130139        }
    131140
Note: See TracChangeset for help on using the changeset viewer.