hapifhir / hapi-fhir

🔥 HAPI FHIR - Java API for HL7 FHIR Clients and Servers
http://hapifhir.io
Apache License 2.0
2k stars 1.31k forks source link

CXF Rest Webservice failing to marshal/unmarshal the FHIR Data Model objects #282

Closed gafoorsk closed 8 years ago

gafoorsk commented 8 years ago

Hi , I am implementing CXF Rest service with FHIR Data Model(HAPI) and i am using "org.codehaus.jackson.jaxrs.JacksonJsonProvider" for Marshaling/unmarshalling . when i try to give Patient input json, CXF is not able to unmarshall the patient FHIR Data model object. do i need to specify any json provider in CXF Rest service configuration?

KevinMayfield commented 8 years ago

If your just using HAPI as a data model you could switch to me.fhir. We use it with our Apache Camel rest services, the code is virtually the same (except for the (un)marshaling). Believe HAPI also uses this package

me.fhir fhir-dstu2 ${hl7-fhir-me-version}

On 13 January 2016 at 12:59, gafoorsk notifications@github.com wrote:

Hi , I am implementing CXF Rest service with FHIR Data Model(HAPI) and i am using "orgcodehausjacksonjaxrsJacksonJsonProvider" for Marshaling/unmarshalling when i try to give Patient input json, CXF is not able to unmarshall the patient FHIR Data model object do i need to specify any json provider in CXF Rest service configuration?

— Reply to this email directly or view it on GitHub https://github.com/jamesagnew/hapi-fhir/issues/282.

jamesagnew commented 8 years ago

Hi @gafoorsk , are you using CXF as a JAX-RS provider? If so, we have a JAX-RS Server module that was contributed by Agfa that will be included in the next release of HAPI (1.4, due very soon). You can find this here: https://github.com/jamesagnew/hapi-fhir/tree/master/hapi-fhir-jaxrsserver-base

If you're not doing JAX-RS, you probably need to implement a custom marshaller/unmarshaller for CXF. The FHIR model objects aren't designed to be natively marshalled by JAXB (you need to use HAPI's Parser) so that needs to be woven in.

The only other thing I'd mention is that it you have an existing stack using CXF it makes sense to try and build on it, but you might find it more pleasant to just use HAPI's server framework. It it much more tailored to the many specific rules in FHIR, so there will be a lot less boilerplate required than there would be trying to recreate the FHIR rules natively in CXF.

gafoorsk commented 8 years ago

Hi ,

Thanks for reply. I tried using me.FHIR jars, it's gives the following exception. "Unrecognized field "resourceType" (Class org.hl7.fhir.instance.model.Patient), not marked as ignorable"

do you have any sample program available related to me FHIR on git hub?

Thanks, Gafoor

On Wed, Jan 13, 2016 at 8:07 PM, KevinMayfield notifications@github.com wrote:

If your just using HAPI as a data model you could switch to me.fhir. We use it with our Apache Camel rest services, the code is virtually the same (except for the (un)marshaling). Believe HAPI also uses this package

me.fhir fhir-dstu2 ${hl7-fhir-me-version}

On 13 January 2016 at 12:59, gafoorsk notifications@github.com wrote:

Hi , I am implementing CXF Rest service with FHIR Data Model(HAPI) and i am using "orgcodehausjacksonjaxrsJacksonJsonProvider" for Marshaling/unmarshalling when i try to give Patient input json, CXF is not able to unmarshall the patient FHIR Data model object do i need to specify any json provider in CXF Rest service configuration?

— Reply to this email directly or view it on GitHub https://github.com/jamesagnew/hapi-fhir/issues/282.

— Reply to this email directly or view it on GitHub https://github.com/jamesagnew/hapi-fhir/issues/282#issuecomment-171310205 .

gafoorsk commented 8 years ago

Thanks James for replay, As you suggested, i willtry with custom provider and use HAPI parser to marshall/unmarshall.

Thanks, Gafoor

On Wed, Jan 13, 2016 at 8:29 PM, James Agnew notifications@github.com wrote:

Hi @gafoorsk https://github.com/gafoorsk , are you using CXF as a JAX-RS provider? If so, we have a JAX-RS Server module that was contributed by Agfa that will be included in the next release of HAPI (1.4, due very soon). You can find this here: https://github.com/jamesagnew/hapi-fhir/tree/master/hapi-fhir-jaxrsserver-base

If you're not doing JAX-RS, you probably need to implement a custom marshaller/unmarshaller for CXF. The FHIR model objects aren't designed to be natively marshalled by JAXB (you need to use HAPI's Parser) so that needs to be woven in.

The only other thing I'd mention is that it you have an existing stack using CXF it makes sense to try and build on it, but you might find it more pleasant to just use HAPI's server framework. It it much more tailored to the many specific rules in FHIR, so there will be a lot less boilerplate required than there would be trying to recreate the FHIR rules natively in CXF.

— Reply to this email directly or view it on GitHub https://github.com/jamesagnew/hapi-fhir/issues/282#issuecomment-171321110 .

jamesagnew commented 8 years ago

Cool, best of luck!

Incidentally, if you do get a custom provider working for CXF and happen to want to contribute back any info on how to make this working, we're always happy to find a spot for it on our website. Others would undoubtedly find it useful. :)

KevinMayfield commented 8 years ago

Gafoor,

Have left out building the Patient resource:

// Patient is import org.hl7.fhir.instance.model.Patient; Patient patient = this.toFHIR(patientrs);

String Response = null; if (!xmlformat) {

ResourceSerialiser class is below:

import java.io.ByteArrayOutputStream; import java.io.OutputStream;

import org.hl7.fhir.instance.formats.IParser.OutputStyle; import org.hl7.fhir.instance.formats.JsonParser; import org.hl7.fhir.instance.formats.ParserType; import org.hl7.fhir.instance.formats.XmlParser; import org.hl7.fhir.instance.model.Bundle; import org.hl7.fhir.instance.model.Resource; import org.slf4j.Logger; import org.slf4j.LoggerFactory;

public class ResourceSerialiser {

On 14 January 2016 at 16:21, gafoorsk notifications@github.com wrote:

Hi ,

Thanks for reply. I tried using me.FHIR jars, it's gives the following exception. "Unrecognized field "resourceType" (Class org.hl7.fhir.instance.model.Patient), not marked as ignorable"

do you have any sample program available related to me FHIR on git hub?

Thanks, Gafoor

On Wed, Jan 13, 2016 at 8:07 PM, KevinMayfield notifications@github.com wrote:

If your just using HAPI as a data model you could switch to me.fhir. We use it with our Apache Camel rest services, the code is virtually the same (except for the (un)marshaling). Believe HAPI also uses this package

me.fhir fhir-dstu2 ${hl7-fhir-me-version}

On 13 January 2016 at 12:59, gafoorsk notifications@github.com wrote:

Hi , I am implementing CXF Rest service with FHIR Data Model(HAPI) and i am using "orgcodehausjacksonjaxrsJacksonJsonProvider" for Marshaling/unmarshalling when i try to give Patient input json, CXF is not able to unmarshall the patient FHIR Data model object do i need to specify any json provider in CXF Rest service configuration?

— Reply to this email directly or view it on GitHub https://github.com/jamesagnew/hapi-fhir/issues/282.

— Reply to this email directly or view it on GitHub < https://github.com/jamesagnew/hapi-fhir/issues/282#issuecomment-171310205> .

— Reply to this email directly or view it on GitHub https://github.com/jamesagnew/hapi-fhir/issues/282#issuecomment-171688753 .

gafoorsk commented 8 years ago

Thanks for the help .

On Wed, Jan 13, 2016 at 8:07 PM, KevinMayfield notifications@github.com wrote:

If your just using HAPI as a data model you could switch to me.fhir. We use it with our Apache Camel rest services, the code is virtually the same (except for the (un)marshaling). Believe HAPI also uses this package

me.fhir fhir-dstu2 ${hl7-fhir-me-version}

On 13 January 2016 at 12:59, gafoorsk notifications@github.com wrote:

Hi , I am implementing CXF Rest service with FHIR Data Model(HAPI) and i am using "orgcodehausjacksonjaxrsJacksonJsonProvider" for Marshaling/unmarshalling when i try to give Patient input json, CXF is not able to unmarshall the patient FHIR Data model object do i need to specify any json provider in CXF Rest service configuration?

— Reply to this email directly or view it on GitHub https://github.com/jamesagnew/hapi-fhir/issues/282.

— Reply to this email directly or view it on GitHub https://github.com/jamesagnew/hapi-fhir/issues/282#issuecomment-171310205 .