It's about a parametrized Request. The users of my application should be able to choose the parameters for the request. I will then read xml from the response and parse it with JAXB. I have done it successfully like this:
String uri = "https://cmi.zb.uzh.ch/primo/api/oaipmh?verb=ListRecords&metadataPrefix=oai_primo&set=PRIMO&from=2020-01-22T12:39:59Z&until=2020-02-28T11:40:00Z";
URL url = new URL(uri);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Accept", "application/xml");
JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
InputStream xml = connection.getInputStream();
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
oai = (OAIPMHtype) jaxbUnmarshaller.unmarshal(xml);
But I want to create the request dynamically. There is a JSF-Page where the user can enter the parameters. I thought of a Jersey-Client, because I can easily replace the Strings in the queryParam with fields. But I cannot link the Jersey-Client to my Unmarshaller.
My idea is to cast the response into a inputstream and feed it to Unmarshaller.
Here is what I tried.
Main Method
public static void main(String[] args) {
ClientConfig config = new ClientConfig();
Client client = ClientBuilder.newClient(config);
WebTarget target = client.target("https://cmi.zb.uzh.ch/primo/api/oaipmh");
target.queryParam("verb", "ListRecords")
.queryParam("metadataPrefix", "oai-primo")
.queryParam("set", "PRIMO")
.queryParam("from", "2020-01-22T12:39:59Z")
.queryParam("until", "2020-02-28T11:40:00Z" );
InputStream stream = target.request()
.accept(MediaType.TEXT_XML)
.get(InputStream.class);
}
}
Errormessage
Exception in thread "main" javax.ws.rs.client.ResponseProcessingException: javax.ws.rs.ProcessingException: RESTEASY003145: Unable to find a MessageBodyReader of content-type text/xml;charset=utf-8 and type class java.io.InputStream
at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.extractResult(ClientInvocation.java:163)
at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:467)
at org.jboss.resteasy.client.jaxrs.internal.ClientInvocationBuilder.get(ClientInvocationBuilder.java:197)
at ch.hbu.sacker.oaipmh.VogellaExample.main(VogellaExample.java:45)
Caused by: javax.ws.rs.ProcessingException: RESTEASY003145: Unable to find a MessageBodyReader of content-type text/xml;charset=utf-8 and type class java.io.InputStream
at org.jboss.resteasy.core.interception.ClientReaderInterceptorContext.throwReaderNotFound(ClientReaderInterceptorContext.java:37)
at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.getReader(AbstractReaderInterceptorContext.java:80)
at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:53)
at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readFrom(ClientResponse.java:211)
at org.jboss.resteasy.specimpl.BuiltResponse.readEntity(BuiltResponse.java:88)
at org.jboss.resteasy.specimpl.AbstractBuiltResponse.readEntity(AbstractBuiltResponse.java:256)
at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.extractResult(ClientInvocation.java:127)
... 3 more
Does anyone know why this happens?