org.iata.ndc.UnmarshallingResponseHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ndc-client Show documentation
Show all versions of ndc-client Show documentation
NDC Client for calling services implmenting IATA NDC standard
package org.iata.ndc;
import java.io.IOException;
import java.io.InputStream;
import javax.xml.bind.*;
import org.apache.http.HttpEntity;
import org.apache.http.client.ResponseHandler;
import org.apache.http.impl.client.AbstractResponseHandler;
class UnmarshallingResponseHandler extends AbstractResponseHandler implements ResponseHandler {
@Override
public T handleEntity(HttpEntity entity) throws IOException {
return unmarshallRequest(entity.getContent());
}
@SuppressWarnings("unchecked")
private T unmarshallRequest(InputStream response) {
try {
JAXBContext context = NdcClient.getJaxbContext();
Unmarshaller unmarshaller = context.createUnmarshaller();
return (T) unmarshaller.unmarshal(response);
} catch (JAXBException e) {
throw new ClientException(e);
}
}
}