コード例 #1
0
 public TreatmentRepresentation(TreatmentDto treatmentDTO, UriInfo context) {
   this.diagnosis = treatmentDTO.getDiagnosis();
   this.patient.setRelation(Representation.RELATION_PATIENT);
   this.patient.setMediaType(Representation.MEDTA_TYPE);
   UriBuilder ub1 = context.getBaseUriBuilder();
   this.patient.setUrl(
       ub1.path("patient").path("{id}").build(treatmentDTO.getPatientId()).toString());
   this.provider.setRelation(Representation.RELATION_PROVIDER);
   this.provider.setMediaType(Representation.MEDTA_TYPE);
   UriBuilder ub2 = context.getBaseUriBuilder();
   this.provider.setUrl(
       ub2.path("provider").path("{id}").build(treatmentDTO.getPatientId()).toString());
   if (treatmentDTO.TreatmentType instanceof DrugTreatmentType) {
     DrugTreatmentType dt = (DrugTreatmentType) treatmentDTO.TreatmentType;
     this.drugTreatment.setDosage(dt.getDosage());
     this.drugTreatment.setName(dt.getName());
   } else if (treatmentDTO.TreatmentType instanceof SurgeryType) {
     this.surgery.setDate(((SurgeryType) treatmentDTO.TreatmentType).getDate());
   } else if (treatmentDTO.TreatmentType instanceof RadiologyType) {
     List<Date> dates = ((RadiologyType) treatmentDTO.TreatmentType).getDate();
     List<Date> treatmentDates = this.radiology.getDate();
     for (Date i : dates) {
       treatmentDates.add(i);
     }
   }
 }
コード例 #2
0
 protected static URI getRedirectUri(final UriInfo m_uriInfo, final Object... pathComponents) {
   if (pathComponents != null && pathComponents.length == 0) {
     final URI requestUri = m_uriInfo.getRequestUri();
     try {
       return new URI(
           requestUri.getScheme(),
           requestUri.getUserInfo(),
           requestUri.getHost(),
           requestUri.getPort(),
           requestUri.getPath().replaceAll("/$", ""),
           null,
           null);
     } catch (final URISyntaxException e) {
       return requestUri;
     }
   } else {
     UriBuilder builder = m_uriInfo.getRequestUriBuilder();
     for (final Object component : pathComponents) {
       if (component != null) {
         builder = builder.path(component.toString());
       }
     }
     return builder.build();
   }
 }
コード例 #3
0
  /**
   * Adds a trust bundle to the system.
   *
   * @param uriInfo Injected URI context used for building the location URI.
   * @param bundle The bundle to add to the system.
   * @return Status of 201 if the bundle was added or a status of 409 if a bundle with the same name
   *     already exists.
   */
  @PUT
  @Consumes(MediaType.APPLICATION_JSON)
  public Response addTrustBundle(@Context UriInfo uriInfo, TrustBundle bundle) {
    // make sure it doesn't exist
    try {
      if (bundleDao.getTrustBundleByName(bundle.getBundleName()) != null)
        return Response.status(Status.CONFLICT).cacheControl(noCache).build();
    } catch (Exception e) {
      log.error("Error looking up bundle.", e);
      return Response.serverError().cacheControl(noCache).build();
    }

    try {
      final org.nhindirect.config.store.TrustBundle entityBundle =
          EntityModelConversion.toEntityTrustBundle(bundle);

      bundleDao.addTrustBundle(entityBundle);

      final UriBuilder newLocBuilder = uriInfo.getBaseUriBuilder();
      final URI newLoc = newLocBuilder.path("trustbundle/" + bundle.getBundleName()).build();

      // the trust bundle does not contain any of the anchors
      // they must be fetched from the URL... use the
      // refresh route to force downloading the anchors
      template.sendBody(entityBundle);

      return Response.created(newLoc).cacheControl(noCache).build();
    } catch (Exception e) {
      log.error("Error adding trust bundle.", e);
      return Response.serverError().cacheControl(noCache).build();
    }
  }
コード例 #4
0
  private UriInfo setUpCmdExpectations(
      String[] commands, String[] returns, String collectionType, String newId, boolean build)
      throws Exception {
    mockStatic(PowerShellCmd.class);
    for (int i = 0; i < Math.min(commands.length, returns.length); i++) {
      if (commands[i] != null) {
        expect(PowerShellCmd.runCommand(setUpPoolExpectations(), commands[i]))
            .andReturn(returns[i]);
      }
    }

    UriInfo uriInfo = null;
    if (collectionType != null && newId != null) {
      uriInfo = setUpBasicUriExpectations();
      if (build) {
        UriBuilder uriBuilder = createMock(UriBuilder.class);
        expect(uriInfo.getAbsolutePathBuilder()).andReturn(uriBuilder);
        expect(uriBuilder.path(newId)).andReturn(uriBuilder);
        expect(uriBuilder.build())
            .andReturn(new URI("vms/" + VM_ID + "/" + collectionType + "/" + newId))
            .anyTimes();
      }
    }

    replayAll();

    return uriInfo;
  }
コード例 #5
0
 @Override
 protected URI getBaseUri() {
   final UriBuilder baseUriBuilder =
       UriBuilder.fromUri(super.getBaseUri()).path("sse-item-store-webapp");
   final boolean externalFactoryInUse =
       getTestContainerFactory() instanceof ExternalTestContainerFactory;
   return externalFactoryInUse ? baseUriBuilder.path("resources").build() : baseUriBuilder.build();
 }
コード例 #6
0
 JsonObject createCacheLinks(UriInfo info, String name) {
   JsonObjectBuilder response = Json.createObjectBuilder();
   UriBuilder cacheLink = info.getAbsolutePathBuilder().path(name);
   UriBuilder entries = cacheLink.path("entries");
   response.add("name", name);
   response.add("link", cacheLink.build().toASCIIString());
   response.add("entries", entries.build().toASCIIString());
   return response.build();
 }
  public static LinkType getRadiologyLink(String diag, UriInfo uriInfo) {
    UriBuilder ub = uriInfo.getBaseUriBuilder();
    ub.path("radiologytreatment").path("{diagnosys}");
    String radiologyURI = ub.build(diag).toString();

    LinkType link = new LinkType();
    link.setUrl(radiologyURI);
    link.setRelation(Representation.RELATION_TREATMENT);
    link.setMediaType(Representation.MEDIA_TYPE);
    return link;
  }
コード例 #8
0
ファイル: Util.java プロジェクト: tavisrudd/RSB
 /**
  * Builds a data directory URI.
  *
  * @param applicationName
  * @param jobId
  * @param httpHeaders
  * @param uriInfo
  * @return
  * @throws URISyntaxException
  */
 public static URI buildDataDirectoryUri(
     final HttpHeaders httpHeaders, final UriInfo uriInfo, final String... directoryPathElements)
     throws URISyntaxException {
   UriBuilder uriBuilder = getUriBuilder(uriInfo, httpHeaders).path(Constants.DATA_DIR_PATH);
   for (final String directoryPathElement : directoryPathElements) {
     if (StringUtils.isNotEmpty(directoryPathElement)) {
       uriBuilder = uriBuilder.path(directoryPathElement);
     }
   }
   return uriBuilder.build();
 }
コード例 #9
0
ファイル: WebResource.java プロジェクト: berendt/midonet
 private com.sun.jersey.api.client.WebResource makeResource(String path) {
   com.sun.jersey.api.client.WebResource resource = resource();
   UriBuilder b = resource.getUriBuilder();
   if (path.startsWith("/")) {
     b.replacePath(path);
   } else {
     b.path(path);
   }
   URI uri = b.build();
   return resource.uri(uri);
 }
コード例 #10
0
 @Before
 public void setUp() throws Exception {
   initMocks(this);
   testObj = new FedoraRepositoryNodeTypes();
   setField(testObj, "nodeService", mockNodes);
   setField(testObj, "uriInfo", getUriInfoImpl());
   mockSession = mockSession(testObj);
   setField(testObj, "session", mockSession);
   when(mockUriInfo.getBaseUriBuilder()).thenReturn(mockUriBuilder);
   when(mockUriBuilder.path(any(Class.class))).thenReturn(mockUriBuilder);
   when(mockUriBuilder.build(any(String.class))).thenReturn(URI.create("mock:uri"));
 }
コード例 #11
0
 @SuppressWarnings("unchecked")
 @Override
 public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
   GeneratedHttpRequest<?> r = GeneratedHttpRequest.class.cast(request);
   String payload = r.getJavaMethod().getAnnotation(Payload.class).value();
   if (postParams.size() > 0) {
     UriBuilder builder = uriBuilders.get();
     builder.uri(URI.create("http://test/"));
     builder.path(payload);
     URI fake = builder.buildFromMap(postParams);
     payload = fake.getPath().substring(1);
   }
   return (R) request.toBuilder().payload(Payloads.newStringPayload(payload)).build();
 }
コード例 #12
0
ファイル: JAXBElementProvider.java プロジェクト: jboss/cxf
 protected String resolveXMLResourceURI(String path) {
   MessageContext mc = getContext();
   if (mc != null) {
     String httpBasePath = (String) mc.get("http.base.path");
     UriBuilder builder = null;
     if (httpBasePath != null) {
       builder = UriBuilder.fromPath(httpBasePath);
     } else {
       builder = mc.getUriInfo().getBaseUriBuilder();
     }
     return builder.path(path).path(xmlResourceOffset).build().toString();
   } else {
     return path;
   }
 }
コード例 #13
0
  @Test
  public void shouldCreateTodoItem() throws Exception {
    final TodoItem todoItem = createTodoItem();
    final UriInfo uriInfo = mock(UriInfo.class);
    final UriBuilder uriBuilder = mock(UriBuilder.class);
    final URI todoUri = new URI(baseUri + todoItem.getId());
    given(todoItems.createTodoItem(todoItem.getTitle(), todoItem.getCompleted()))
        .willReturn(todoItem);
    given(uriInfo.getAbsolutePathBuilder()).willReturn(uriBuilder);
    given(uriBuilder.path("/" + todoItem.getId())).willReturn(uriBuilder);
    given(uriBuilder.build()).willReturn(todoUri);

    final Response response = todoItemsResource.createTodoItem(todoItem, uriInfo);

    assertThat(response.getStatus(), is(equalTo(Status.CREATED)));
  }
コード例 #14
0
 private RowResource getResource(Row row) {
   String appId = dm.getAppId();
   String tableId = dm.getTableId();
   String rowId = row.getRowId();
   UriBuilder ub = info.getBaseUriBuilder();
   ub.path(TableService.class);
   URI self =
       ub.clone()
           .path(TableService.class, "getData")
           .path(DataService.class, "getRow")
           .build(appId, tableId, rowId);
   URI table = ub.clone().path(TableService.class, "getTable").build(appId, tableId);
   RowResource resource = new RowResource(row);
   resource.setSelfUri(self.toASCIIString());
   resource.setTableUri(table.toASCIIString());
   return resource;
 }
コード例 #15
0
ファイル: CompositeResource.java プロジェクト: winsx/Payara
 private URI getParentUri(boolean isCollectionChild) throws Exception {
   List<PathSegment> pathSegments = this.uriInfo.getPathSegments();
   int count = pathSegments.size() - 1; // go up a level to get to the parent
   if (isCollectionChild) {
     count--; // collection children have the url pattern .../foos/id/myfoo. need to go up another
     // level
   }
   // [0] = 'javaservice', which is a resource
   if (count <= 0) {
     return null; // top level resource
   }
   UriBuilder bldr = this.uriInfo.getBaseUriBuilder();
   for (int i = 0; i < count; i++) {
     bldr.path(pathSegments.get(i).getPath());
   }
   return bldr.build();
 }
コード例 #16
0
 @VisibleForTesting
 public URI getLocationURI(List<String> guids) {
   URI locationURI = null;
   if (uriInfo != null) {
     UriBuilder ub = uriInfo.getAbsolutePathBuilder();
     locationURI = guids.isEmpty() ? null : ub.path(guids.get(0)).build();
   } else {
     String uriPath = AtlasClient.API.GET_ENTITY.getPath();
     locationURI =
         guids.isEmpty()
             ? null
             : UriBuilder.fromPath(AtlasConstants.DEFAULT_ATLAS_REST_ADDRESS)
                 .path(uriPath)
                 .path(guids.get(0))
                 .build();
   }
   return locationURI;
 }
コード例 #17
0
  @GET
  @Path("/")
  @ApiOperation(
      value = "List the available reports",
      responseClass = "String",
      multiValueResponse = true)
  @Produces({
    MediaType.TEXT_HTML,
    MediaType.APPLICATION_JSON,
    MediaType.APPLICATION_XML,
    "text/csv"
  })
  public Response listReports(@Context HttpHeaders headers, @Context UriInfo uriInfo) {

    List<Link> links = new ArrayList<Link>(reports.length);
    for (String report : reports) {
      UriBuilder uriBuilder = uriInfo.getBaseUriBuilder();
      uriBuilder.path("/reports/{report}");
      URI uri = uriBuilder.build(report);
      Link link = new Link(report, uri.toString());
      links.add(link);
    }

    MediaType mediaType = headers.getAcceptableMediaTypes().get(0);
    Response.ResponseBuilder builder = Response.ok();
    if (mediaType.getType().equals("text") && mediaType.getSubtype().equals("csv")) {
      StringBuilder stringBuilder = new StringBuilder();
      stringBuilder.append("Report,URL\n");
      for (Link link : links) {
        stringBuilder.append(link.getRel()).append(",").append(link.getHref());
        stringBuilder.append('\n');
      }
      builder.entity(stringBuilder.toString());
    } else if (mediaType.equals(MediaType.TEXT_HTML_TYPE)) {
      builder.entity(renderTemplate("reportIndex", links));
    } else {
      GenericEntity<List<Link>> list = new GenericEntity<List<Link>>(links) {};
      builder.entity(list);
    }
    CacheControl cacheControl = new CacheControl();
    cacheControl.setMaxAge(86400); // TODO 1 day or longer? What unit is this anyway?
    builder.cacheControl(cacheControl);
    return builder.build();
  }
コード例 #18
0
ファイル: AbstractClient.java プロジェクト: Lxzw/cxf
  private URI calculateNewRequestURI(URI newBaseURI, URI requestURI, boolean proxy) {
    String baseURIPath = newBaseURI.getRawPath();
    String reqURIPath = requestURI.getRawPath();

    UriBuilder builder = new UriBuilderImpl().uri(newBaseURI);
    String basePath = reqURIPath.startsWith(baseURIPath) ? baseURIPath : getBaseURI().getRawPath();
    builder.path(reqURIPath.equals(basePath) ? "" : reqURIPath.substring(basePath.length()));

    String newQuery = newBaseURI.getRawQuery();
    if (newQuery == null) {
      builder.replaceQuery(requestURI.getRawQuery());
    } else {
      builder.replaceQuery(newQuery);
    }

    URI newRequestURI = builder.build();

    resetBaseAddress(newBaseURI);
    URI current = proxy ? newBaseURI : newRequestURI;
    resetCurrentBuilder(current);

    return newRequestURI;
  }
コード例 #19
0
ファイル: AccountService.java プロジェクト: rishiHPE/keycloak
 public static UriBuilder accountServiceBaseUrl(UriBuilder base) {
   return base.path(RealmsResource.class).path(RealmsResource.class, "getAccountService");
 }
コード例 #20
0
ファイル: AdminRoot.java プロジェクト: appcube/keycloak
 public static UriBuilder adminBaseUrl(UriBuilder base) {
   return base.path(AdminRoot.class);
 }
コード例 #21
0
ファイル: ClientProxyImpl.java プロジェクト: eonezhang/cxf
 private void addNonEmptyPath(UriBuilder builder, String pathValue) {
   if (!SLASH.equals(pathValue)) {
     builder.path(pathValue);
   }
 }
コード例 #22
0
 public static UriBuilder loginActionsBaseUrl(UriBuilder baseUriBuilder) {
   return baseUriBuilder
       .path(RealmsResource.class)
       .path(RealmsResource.class, "getLoginActionsService");
 }
コード例 #23
0
  @POST
  public Response createSubscription(
      @FormParam("durable") @DefaultValue("false") boolean durable,
      @FormParam("autoAck") @DefaultValue("true") boolean autoAck,
      @FormParam("name") String subscriptionName,
      @FormParam("selector") String selector,
      @FormParam("delete-when-idle") Boolean destroyWhenIdle,
      @FormParam("idle-timeout") Long timeout,
      @Context UriInfo uriInfo) {
    ActiveMQRestLogger.LOGGER.debug("Handling POST request for \"" + uriInfo.getPath() + "\"");

    if (timeout == null) timeout = Long.valueOf(consumerTimeoutSeconds * 1000);
    boolean deleteWhenIdle = !durable; // default is true if non-durable
    if (destroyWhenIdle != null) deleteWhenIdle = destroyWhenIdle.booleanValue();

    if (subscriptionName != null) {
      // see if this is a reconnect
      QueueConsumer consumer = queueConsumers.get(subscriptionName);
      if (consumer != null) {
        boolean acked = consumer instanceof AcknowledgedSubscriptionResource;
        acked = !acked;
        if (acked != autoAck) {
          throw new WebApplicationException(
              Response.status(412)
                  .entity("Consumer already exists and ack-modes don't match.")
                  .type("text/plain")
                  .build());
        }
        Subscription sub = (Subscription) consumer;
        if (sub.isDurable() != durable) {
          throw new WebApplicationException(
              Response.status(412)
                  .entity("Consumer already exists and durability doesn't match.")
                  .type("text/plain")
                  .build());
        }
        Response.ResponseBuilder builder = Response.noContent();
        String pathToPullSubscriptions = uriInfo.getMatchedURIs().get(0);
        if (autoAck) {
          headAutoAckSubscriptionResponse(uriInfo, consumer, builder, pathToPullSubscriptions);
          consumer.setSessionLink(
              builder, uriInfo, pathToPullSubscriptions + "/auto-ack/" + consumer.getId());
        } else {
          headAcknowledgedConsumerResponse(uriInfo, (AcknowledgedQueueConsumer) consumer, builder);
          consumer.setSessionLink(
              builder, uriInfo, pathToPullSubscriptions + "/acknowledged/" + consumer.getId());
        }
        return builder.build();
      }
    } else {
      subscriptionName = generateSubscriptionName();
    }
    ClientSession session = null;
    try {
      // if this is not a reconnect, create the subscription queue
      if (!subscriptionExists(subscriptionName)) {
        session = sessionFactory.createSession();

        if (durable) {
          session.createQueue(destination, subscriptionName, true);
        } else {
          session.createTemporaryQueue(destination, subscriptionName);
        }
      }
      QueueConsumer consumer =
          createConsumer(durable, autoAck, subscriptionName, selector, timeout, deleteWhenIdle);
      queueConsumers.put(consumer.getId(), consumer);
      serviceManager.getTimeoutTask().add(this, consumer.getId());

      UriBuilder location = uriInfo.getAbsolutePathBuilder();
      if (autoAck) location.path("auto-ack");
      else location.path("acknowledged");
      location.path(consumer.getId());
      Response.ResponseBuilder builder = Response.created(location.build());
      if (autoAck) {
        QueueConsumer.setConsumeNextLink(
            serviceManager.getLinkStrategy(),
            builder,
            uriInfo,
            uriInfo.getMatchedURIs().get(0) + "/auto-ack/" + consumer.getId(),
            "-1");
      } else {
        AcknowledgedQueueConsumer.setAcknowledgeNextLink(
            serviceManager.getLinkStrategy(),
            builder,
            uriInfo,
            uriInfo.getMatchedURIs().get(0) + "/acknowledged/" + consumer.getId(),
            "-1");
      }
      return builder.build();

    } catch (ActiveMQException e) {
      throw new RuntimeException(e);
    } finally {
      if (session != null) {
        try {
          session.close();
        } catch (ActiveMQException e) {
        }
      }
    }
  }
コード例 #24
0
 private URI buildLink(String isbn) {
   UriBuilder uriBuilder = uriInfo.getBaseUriBuilder();
   return uriBuilder.path(BooksResource.class).path(isbn).build();
 }