Can't we have multiple @Search() methods ?

67 views
Skip to first unread message

Maruthi chava

unread,
Jun 12, 2019, 5:59:55 PM6/12/19
to HAPI FHIR
Can't we have multiple @Search() methods in a class ?

I have a situation to create two @Search() methods in a class.

here is the illustration.

@Path("/Resource")
@Produces({ MediaType.APPLICATION_JSON, Constants.CT_FHIR_JSON, Constants.CT_FHIR_XML })
public class ReportResourceProvider
{
....

@Search()
public List<Resource> getReportByPatient(@RequiredParam(name = Resource.SP_PATIENT) ReferenceParam patient,
@RequiredParam(name = Resource.SP_VALUE_QUANTITY) String count,
@RequiredParam(name = Resource.SP_IDENTIFIER) String startVal)
{...
}

@Search()
public Resource searchRporteByEncounter(@RequiredParam(name = Resource.SP_ENCOUNTER ) ReferenceParam encounter
 {
...
}

When I try to implement the same, I' getting the following exception

java.lang.IllegalArgumentException: Multiple Search Method Bindings Found

James Agnew

unread,
Jun 12, 2019, 6:02:23 PM6/12/19
to Maruthi chava, HAPI FHIR
FWIW this is definitely possible in the regular (non JAX-RS) server. It's possible that there is a limitation in the JAX-RS module though..

Cheers,
James

--
You received this message because you are subscribed to the Google Groups "HAPI FHIR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hapi-fhir+...@googlegroups.com.
To post to this group, send email to hapi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hapi-fhir/fdf9207a-8686-43b4-b1e8-3955c824bca9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Maruthi chava

unread,
Jun 12, 2019, 6:06:46 PM6/12/19
to HAPI FHIR
I'm trying to do that in regular (non JAX-RS) server but I'm ended up with 

java.lang.IllegalArgumentException: Multiple Search Method Bindings Found : public java.util.List com..........
at ca.uhn.fhir.jaxrs.server.util.JaxRsMethodBindings.addMethodBinding(JaxRsMethodBindings.java:89)
at ca.uhn.fhir.jaxrs.server.util.JaxRsMethodBindings.<init>(JaxRsMethodBindings.java:61)
at ca.uhn.fhir.jaxrs.server.util.JaxRsMethodBindings.getMethodBindings(JaxRsMethodBindings.java:138).....

On Wednesday, 12 June 2019 17:02:23 UTC-5, James Agnew wrote:
FWIW this is definitely possible in the regular (non JAX-RS) server. It's possible that there is a limitation in the JAX-RS module though..

Cheers,
James

On Wed, Jun 12, 2019 at 5:59 PM Maruthi chava <maruth...@gmail.com> wrote:
Can't we have multiple @Search() methods in a class ?

I have a situation to create two @Search() methods in a class.

here is the illustration.

@Path("/Resource")
@Produces({ MediaType.APPLICATION_JSON, Constants.CT_FHIR_JSON, Constants.CT_FHIR_XML })
public class ReportResourceProvider
{
....

@Search()
public List<Resource> getReportByPatient(@RequiredParam(name = Resource.SP_PATIENT) ReferenceParam patient,
@RequiredParam(name = Resource.SP_VALUE_QUANTITY) String count,
@RequiredParam(name = Resource.SP_IDENTIFIER) String startVal)
{...
}

@Search()
public Resource searchRporteByEncounter(@RequiredParam(name = Resource.SP_ENCOUNTER ) ReferenceParam encounter
 {
...
}

When I try to implement the same, I' getting the following exception

java.lang.IllegalArgumentException: Multiple Search Method Bindings Found

--
You received this message because you are subscribed to the Google Groups "HAPI FHIR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hapi...@googlegroups.com.

James Agnew

unread,
Jun 12, 2019, 6:20:21 PM6/12/19
to Maruthi chava, HAPI FHIR
That is definitely the JAX-RS server you're using- you can see "JaxRsMethodBindings" right in the stack trace.

The following sample project might be helpful in terms of getting started with the non-jaxrs server:


Cheers,
James





To unsubscribe from this group and stop receiving emails from it, send an email to hapi-fhir+...@googlegroups.com.

To post to this group, send email to hapi...@googlegroups.com.

GM C

unread,
Jan 23, 2024, 4:36:01 PM1/23/24
to HAPI FHIR
I'm having the same problem and checked the code where the error was thrown.  It seems like it's not possible to have more than one method with @Search annotation, unless it's a compartment? Without compartment, the key is always the default key.  Is the implementation guide wrong?

/**
* Get the key for the baseMethodBinding. This is:
* <ul>
* <li>the compartName for SearchMethodBindings
* <li>the methodName for OperationMethodBindings
* <li> {@link #DEFAULT_METHOD_KEY} for all other MethodBindings
* </ul>
* @param theBinding the methodbinding
* @return the key for the methodbinding.
*/
private String getBindingKey(final BaseMethodBinding theBinding) {
  if (theBinding instanceof OperationMethodBinding) {
    return ((OperationMethodBinding) theBinding).getName();
  } else if (theBinding instanceof SearchMethodBinding) {
    Search search = theBinding.getMethod().getAnnotation(Search.class);
    return search.compartmentName();
  } else {
    return DEFAULT_METHOD_KEY;
  }
}

GM C

unread,
Jan 23, 2024, 4:41:33 PM1/23/24
to HAPI FHIR
Ok, just additional information, this is for the class extending the AbstractJaxRsResourceProvider 
Reply all
Reply to author
Forward
0 new messages