Package ca.uhn.fhir.rest.method

Examples of ca.uhn.fhir.rest.method.BaseMethodBinding


      }
      resourceName = tok.nextToken();

      Object provider=null;
      ResourceBinding resourceBinding=null;
      BaseMethodBinding resourceMethod=null;
      if ("metadata".equals(resourceName)) {
        provider = myServerConformanceProvider;
        if (provider==null) {
          throw new ResourceNotFoundException("This server does not support 'metadata' query");
        }
        resourceMethod = myServerConformanceMethod;
      } else {
        resourceBinding = myResourceNameToProvider.get(resourceName);
        if (resourceBinding == null) {
          throw new MethodNotFoundException("Unknown resource type '" + resourceName+"' - Server knows how to handle: "+myResourceNameToProvider.keySet());
        }
        provider = resourceBinding.getResourceProvider();
      }


      if (tok.hasMoreTokens()) {
        String nextString = tok.nextToken();
        if (nextString.startsWith("_")) {
          operation = nextString;
        } else {
          id = new IdDt(nextString);
        }
      }

      if (tok.hasMoreTokens()) {
        String nextString = tok.nextToken();
        if (nextString.startsWith("_")) {
          if (operation !=null) {
            throw new InvalidRequestException("URL Path contains two operations (part beginning with _): " + requestPath);
          }
          operation = nextString;
        }
      }

      if (tok.hasMoreTokens()) {
        String nextString = tok.nextToken();
        versionId = new IdDt(nextString);
      }

      // TODO: look for more tokens for version, compartments, etc...

      Request r = new Request();
      r.setResourceName(resourceName);
      r.setId(id);
      r.setVersion(versionId);
      r.setOperation(operation);
      r.setParameters(params);
      r.setRequestType(requestType);
      r.setResourceProvider(provider);
      r.setInputReader(request.getReader());
      r.setFhirServerBase(fhirServerBase);
      r.setCompleteUrl(completeUrl);
      r.setServletRequest(request);

      if (resourceMethod == null && resourceBinding != null) {
        resourceMethod = resourceBinding.getMethod(r);
      }
      if (null == resourceMethod) {
        throw new MethodNotFoundException("No resource method available for the supplied parameters " + params);
      }

      resourceMethod.invokeServer(this, r, response);

    } catch (AuthenticationException e) {
      response.setStatus(e.getStatusCode());
      addHapiHeader(response);
      response.setContentType("text/plain");
View Full Code Here


    Object directRetVal = myMethodToReturnValue.get(theMethod);
    if (directRetVal != null) {
      return directRetVal;
    }

    BaseMethodBinding binding = myBindings.get(theMethod);
    BaseClientInvocation clientInvocation = binding.invokeClient(theArgs);

    HttpRequestBase httpRequest = clientInvocation.asHttpRequest(myUrlBase);
    HttpResponse response = myClient.execute(httpRequest);
    try {

      Reader reader = createReaderFromResponse(response);

      if (ourLog.isTraceEnabled()) {
        String responseString = IOUtils.toString(reader);
        ourLog.trace("FHIR response:\n{}\n{}", response, responseString);
        reader = new StringReader(responseString);
      }

      ContentType ct = ContentType.get(response.getEntity());

      String mimeType = ct.getMimeType();

      Map<String, List<String>> headers = new HashMap<String, List<String>>();
      if (response.getAllHeaders() != null) {
        for (Header next : response.getAllHeaders()) {
          String name = next.getName().toLowerCase();
          List<String> list = headers.get(name);
          if (list == null) {
            list = new ArrayList<String>();
            headers.put(name, list);
          }
          list.add(next.getValue());
        }
      }

      return binding.invokeClient(mimeType, reader, response.getStatusLine().getStatusCode(), headers);

    } finally {
      if (response instanceof CloseableHttpResponse) {
        ((CloseableHttpResponse) response).close();
      }
View Full Code Here

          if (!IResource.class.isAssignableFrom(returnTypeColl)) {
            throw new ConfigurationException("Generic type of collection for method '" + nextMethod + "' is not a subclass of IResource");
          }
          resReturnType = (Class<? extends IResource>) returnTypeColl;
        }
        BaseMethodBinding binding = BaseMethodBinding.bindMethod(resReturnType, nextMethod, myContext,null);
        invocationHandler.addBinding(nextMethod, binding);
      }
      myInvocationHandlers.put(theClientType, invocationHandler);
    }
   
View Full Code Here

TOP

Related Classes of ca.uhn.fhir.rest.method.BaseMethodBinding

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.