1 /*******************************************************************************
2 * Copyright (c) 2017 Politecnico di Torino and others.
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Apache License, Version 2.0
6 * which accompanies this distribution, and is available at
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *******************************************************************************/
9 package it.polito.verigraph.deserializer;
11 import java.io.IOException;
12 import java.io.InputStream;
13 import java.lang.annotation.Annotation;
14 import java.lang.reflect.Type;
15 import javax.ws.rs.Consumes;
16 import javax.ws.rs.ProcessingException;
17 import javax.ws.rs.WebApplicationException;
18 import javax.ws.rs.core.MediaType;
19 import javax.ws.rs.core.MultivaluedMap;
20 import javax.ws.rs.ext.MessageBodyReader;
21 import javax.ws.rs.ext.Provider;
22 import javax.xml.bind.JAXBContext;
23 import javax.xml.bind.JAXBException;
25 import it.polito.neo4j.jaxb.Paths;
28 @Consumes(MediaType.APPLICATION_XML)
29 public class PathsMessageBodyReader implements MessageBodyReader<Paths>{
32 public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
33 return type == Paths.class;
37 public Paths readFrom(Class<Paths> type, Type genericType, Annotation[] annotations, MediaType mediaType,
38 MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
39 throws IOException, WebApplicationException {
41 JAXBContext jaxbContext = JAXBContext.newInstance(Paths.class);
42 Paths paths = (Paths) jaxbContext.createUnmarshaller()
43 .unmarshal(entityStream);
45 } catch (JAXBException jaxbException) {
46 throw new ProcessingException("Error deserializing a Paths object.",