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 *******************************************************************************/
10 package it.polito.escape.verify.deserializer;
12 import java.io.IOException;
13 import java.io.InputStream;
14 import java.lang.annotation.Annotation;
15 import java.lang.reflect.Type;
16 import javax.ws.rs.Consumes;
17 import javax.ws.rs.ProcessingException;
18 import javax.ws.rs.WebApplicationException;
19 import javax.ws.rs.core.MediaType;
20 import javax.ws.rs.core.MultivaluedMap;
21 import javax.ws.rs.ext.MessageBodyReader;
22 import javax.ws.rs.ext.Provider;
23 import javax.xml.bind.JAXBContext;
24 import javax.xml.bind.JAXBException;
26 import it.polito.nffg.neo4j.jaxb.Paths;
29 @Consumes(MediaType.APPLICATION_XML)
30 public class PathsMessageBodyReader implements MessageBodyReader<Paths>{
33 public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
34 return type == Paths.class;
38 public Paths readFrom(Class<Paths> type, Type genericType, Annotation[] annotations, MediaType mediaType,
39 MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
40 throws IOException, WebApplicationException {
42 JAXBContext jaxbContext = JAXBContext.newInstance(Paths.class);
43 Paths paths = (Paths) jaxbContext.createUnmarshaller()
44 .unmarshal(entityStream);
46 } catch (JAXBException jaxbException) {
47 throw new ProcessingException("Error deserializing a Paths object.",