Java Code Examples for javax.ws.rs.Path

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project candlepin, under directory /src/main/java/org/candlepin/util/apicrawl/.

Source file: ApiCrawler.java

  18 
vote

private List<RestApiCall> processClass(Class c){
  Path a=(Path)c.getAnnotation(Path.class);
  String parentUrl=a.value();
  List<RestApiCall> classApiCalls=new LinkedList<RestApiCall>();
  for (  Method m : c.getDeclaredMethods()) {
    if (Modifier.isPublic(m.getModifiers())) {
      classApiCalls.add(processMethod(parentUrl,m));
    }
  }
  return classApiCalls;
}
 

Example 2

From project bpm-console, under directory /server/war/src/main/java/org/jboss/bpm/console/server/util/.

Source file: RsDocBuilder.java

  17 
vote

private StringBuffer build(Class root){
  Path rootPath=(Path)root.getAnnotation(Path.class);
  RsComment rootComment=(RsComment)root.getAnnotation(RsComment.class);
  List<Representation> representations=new ArrayList<Representation>();
  for (  Method m : root.getDeclaredMethods()) {
    Path resPath=m.getAnnotation(Path.class);
    if (resPath != null) {
      Representation r=new Representation();
      r.path=resPath.value();
      r.httpMethod=m.getAnnotation(GET.class) != null ? "GET" : "POST";
      r.consume=(m.getAnnotation(Consumes.class) != null) ? arrayToString(m.getAnnotation(Consumes.class).value()) : "*/*";
      r.produce=(m.getAnnotation(Produces.class) != null) ? arrayToString(m.getAnnotation(Produces.class).value()) : "*/*";
      representations.add(r);
    }
  }
  StringBuffer sb=new StringBuffer();
  if (rootComment != null) {
    sb.append("<tr>");
    sb.append("<td colspan=5 style='border-bottom:1px solid black;'>");
    sb.append("<b>").append(rootComment.title()).append("</b>").append("<br>");
    sb.append("<i>").append(rootComment.description()).append("</i>");
    sb.append("</td>");
    sb.append("</tr>");
  }
  for (  Representation r : representations) {
    sb.append("<tr>");
    sb.append("<td>").append(r.httpMethod.toUpperCase()).append("</td>");
    sb.append("<td>").append(buildPath(rootPath.value(),r.path)).append("</td>");
    sb.append("<td>").append("").append("</td>");
    sb.append("<td>").append(r.consume).append("</td>");
    sb.append("<td>").append(r.produce).append("</td>");
    sb.append("</tr>");
  }
  sb.append("<tr><td colspan=5>&nbsp;</td></tr>");
  return sb;
}
 

Example 3

From project action-core, under directory /src/main/java/com/ning/metrics/action/endpoint/.

Source file: HdfsBrowser.java

  15 
vote

/** 
 * Build a Viewable to browse HDFS.
 * @param path      path in HDFS to render (directory listing or file), defaults to /
 * @param raw       optional, whether to try to deserialize
 * @param recursive optional, whether to crawl all files under a directory
 * @return Viewable to render the jsp
 * @throws IOException HDFS crawling error
 */
@GET @Path("/hdfs") @Produces({"text/html","text/plain"}) @Timed public Viewable getListing(@QueryParam("path") String path,@QueryParam("raw") final boolean raw,@QueryParam("recursive") final boolean recursive) throws IOException {
  log.debug(String.format("Got request for path=[%s], raw=[%s] and recursive=[%s]",path,raw,recursive));
  if (path == null) {
    path="/";
  }
  if (hdfsReader.isDir(path) && !recursive) {
    return new Viewable("/rest/listing.jsp",hdfsReader.getListing(path));
  }
 else {
    if (raw) {
      return new Viewable("/rest/contentRaw.jsp",hdfsReader.getListing(path,raw,recursive));
    }
 else {
      return new Viewable("/rest/content.jsp",hdfsReader.getListing(path,raw,recursive));
    }
  }
}
 

Example 4

From project amber, under directory /oauth-2.0/integration-tests/src/test/java/org/apache/amber/oauth2/integration/.

Source file: EndUserAuthorizationTest.java

  15 
vote

@GET @Path("/redirect") public Response callback(@Context HttpServletRequest request) throws Exception {
  OAuthClientResponse resp=null;
  try {
    OAuthAuthzResponse.oauthCodeAuthzResponse(request);
    fail("exception expected");
  }
 catch (  OAuthProblemException e) {
    assertEquals(OAuthError.CodeResponse.INVALID_REQUEST,e.getError());
  }
  return Response.ok().build();
}
 

Example 5

From project ANNIS, under directory /annis-service/src/main/java/annis/service/internal/.

Source file: AnnisWebService.java

  15 
vote

@GET @Path("search/count") @Produces("plain/text") public Response count(@QueryParam("q") String query,@QueryParam("corpora") String rawCorpusNames){
  requiredParameter(query,"q","AnnisQL query");
  requiredParameter(rawCorpusNames,"corpora","comma separated list of corpus names");
  QueryData data=queryDataFromParameters(query,rawCorpusNames);
  long start=new Date().getTime();
  int count=annisDao.count(data);
  long end=new Date().getTime();
  logQuery("COUNT",query,splitCorpusNamesFromRaw(rawCorpusNames),end - start);
  return Response.ok("" + count).type(MediaType.TEXT_PLAIN).build();
}
 

Example 6

From project Arecibo, under directory /agent/src/main/java/com/ning/arecibo/agent/status/.

Source file: StatusPageHandler.java

  15 
vote

@Path("/") @GET @Produces("text/html") public StreamingOutput getSummary(){
  return new StreamingOutput(){
    @Override public void write(    OutputStream output) throws IOException, WebApplicationException {
      PrintWriter pw=new PrintWriter(output,true);
      List<Status> statusList=dataCollector.getStatus();
      if (statusList != null && statusList.size() > 0) {
        pw.println("<h4>[Click on column headers to sort]</h4>");
        pw.println("<table class=\"sortable\">");
        pw.println("<tr>");
        pw.println("<th>Host</th>");
        pw.println("<th>JMX/SNMP</th>");
        pw.println("<th>Attribute</th>");
        pw.println("<th>Status</th>");
        pw.println("<th>Last update</th>");
        pw.println("<th>Message</th>");
        pw.println("<th>Last Collected Value</th>");
        pw.println("</tr>");
        for (        Status status : statusList) {
          long lastUpdateTime=status.getLastUpdateTime();
          String lastUpdateString=(lastUpdateTime != 0) ? formatter.print(lastUpdateTime) : "--";
          pw.println("<tr>");
          pw.printf("<td>%s</td>\n",status.getHost());
          pw.printf("<td>%s</td>\n",status.getEventName());
          pw.printf("<td>%s</td>\n",status.getValueName());
          pw.printf("<td>%s</td>\n",status.getLastStatus());
          pw.printf("<td>%s</td>\n",lastUpdateString);
          pw.printf("<td>%s</td>\n",status.getLastStatusMessage());
          pw.printf("<td>%s</td>\n",status.getLastValue());
          pw.println("</tr>");
        }
        pw.println("</table>");
      }
 else {
        pw.println("[no status available.]");
      }
    }
  }
;
}
 

Example 7

From project arquillian-showcase, under directory /extensions/resteasy/src/test/java/org/jboss/arquillian/extension/rest/.

Source file: RestClientTestCase.java

  15 
vote

@Test @GET @Path("rest/customer") @Consumes(MediaType.APPLICATION_XML) public void shouldBeAbleToListAllCustomers(ClientResponse<List<Customer>> response){
  Assert.assertEquals(Status.OK.getStatusCode(),response.getStatus());
  List<Customer> customers=response.getEntity(new GenericType<List<Customer>>(){
  }
);
  Assert.assertEquals(2,customers.size());
}
 

Example 8

From project ATHENA, under directory /components/payments/src/main/java/org/fracturedatlas/athena/payments/web/resource/.

Source file: CardsResource.java

  15 
vote

@PUT @Path("{id}") public Object update(@PathParam("id") String id,String json){
  CreditCard card=gson.fromJson(json,CreditCard.class);
  card.setId(id);
  card=cardsManager.save(card);
  return gson.toJson(card);
}
 

Example 9

From project bam, under directory /modules/activity-management/activity-server-rests/src/main/java/org/overlord/bam/activity/server/rest/.

Source file: RESTActivityServer.java

  15 
vote

/** 
 * This method handles queries for activity events.
 * @param qspec The query spec
 * @return The list of activity events
 * @throws Exception Failed to query activity events
 */
@POST @Path("/query") @Produces("application/json") public String query(String qspec) throws Exception {
  String ret="";
  QuerySpec qs=ActivityUtil.deserializeQuerySpec(qspec.getBytes());
  if (LOG.isLoggable(Level.FINEST)) {
    LOG.finest("Activity Server Query Spec=" + qs);
  }
  if (_activityServer == null) {
    throw new Exception("Activity Server is not available");
  }
  java.util.List<ActivityUnit> list=_activityServer.query(qs);
  if (list != null) {
    byte[] b=ActivityUtil.serializeActivityUnitList(list);
    ret=new String(b);
  }
  if (LOG.isLoggable(Level.FINEST)) {
    LOG.finest("Activity Server Query Result=" + ret);
  }
  return (ret);
}
 

Example 10

From project blog_1, under directory /miniprojects/generic-pojo-mappers/src/main/java/net/jakubholy/blog/genericmappers/rest/.

Source file: GenericCollectionResource.java

  15 
vote

@GET @Path("/{collectionName}") public Response listStoredCollection(@PathParam("collectionName") String collectionName){
  try {
    Iterable<Map<String,Object>> collectionElements=storage.getDocumentsAsMap(collectionName);
    return Response.ok().entity(collectionElements).expires(getDefaultCachePeriod()).build();
  }
 catch (  Exception e) {
    log.log(Level.SEVERE,"Failed to list the collection " + collectionName,e);
    return Response.serverError().entity("Failure: " + e).build();
  }
}
 

Example 11

From project caseconductor-platform, under directory /utest-webservice/utest-webservice-impl/src/main/java/com/utest/webservice/impl/v2/.

Source file: ProductWebServiceImpl.java

  15 
vote

@PUT @Path("/{id}/undo_delete/") @Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON}) @Consumes({MediaType.APPLICATION_FORM_URLENCODED,MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON}) @Override @Secured({Permission.PRODUCT_EDIT,Permission.DELETED_ENTITY_UNDO}) public Boolean undeleteProduct(@Context final UriInfo ui_,@PathParam("id") final Integer productId,@FormParam("originalVersionId") final Integer originalVersionId_) throws Exception {
  UtestSearch search=new UtestSearch();
  search.addFilterEqual("productId",productId);
  productService.undoAllDeletedEntities(ProductComponent.class,search);
  return productService.undoDeletedEntity(Product.class,productId);
}
 

Example 12

From project cdi-arq-workshop, under directory /arquillian-showcase/jaxrs/src/main/java/com/acme/jaxrs/resource/.

Source file: CustomerResource.java

  15 
vote

@GET @Path("/{id:[1-9][0-9]*}") @Produces("text/html") public String getCustomerHtml(@PathParam("id") long id){
  Customer c=findCustomerById(id);
  if (c != null) {
    StringBuilder html=new StringBuilder();
    html.append("<html><head><title>");
    html.append(c.getName());
    html.append("</title></head><body><h1>");
    html.append(c.getName());
    html.append("</h1><dl><dt>Id</dt><dd>");
    html.append(c.getId());
    html.append("</dd><dt>Name</dt><dd>");
    html.append(c.getName());
    html.append("</dd></dl></body>");
    return html.toString();
  }
  return null;
}
 

Example 13

From project chukwa, under directory /src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/.

Source file: AdaptorController.java

  15 
vote

/** 
 * Remove an adaptor from the agent
 * @param context ServletContext
 * @param adaptorId id of adaptor to remove.
 * @return Response object
 */
@DELETE @Path("/{adaptorId}") @Produces({"text/plain"}) public Response removeAdaptor(@Context ServletContext context,@PathParam("adaptorId") String adaptorId){
  ChukwaAgent agent=(ChukwaAgent)context.getAttribute("ChukwaAgent");
  if (adaptorId == null) {
    return badRequestResponse("Missing adaptorId.");
  }
  if (agent.getAdaptor(adaptorId) == null) {
    return badRequestResponse("Invalid adaptorId: " + adaptorId);
  }
  agent.stopAdaptor(adaptorId,true);
  return Response.ok().build();
}
 

Example 14

From project Cilia_1, under directory /framework/remote/src/main/java/fr/liglab/adele/cilia/remote/impl/.

Source file: AdminChainREST.java

  15 
vote

/** 
 * Retrieve a mediation component.
 * @param chainid The chain where the component is.
 * @param componentId The id of the component
 * @return The required component, null if it does not exist.
 */
@GET @Path("{componentId}") @Produces("application/json") public String getComponent(@PathParam("chainid") String chainid,@PathParam("componentId") String componentId){
  MediatorComponent component=acomponent.getComponent(chainid,componentId);
  StringBuilder result=new StringBuilder();
  if (component != null) {
    result.append(component);
  }
 else {
    result.append("{ chain : ").append(chainid).append(",\n");
    result.append(componentId).append(" : Does not exist}");
  }
  return result.toString();
}
 

Example 15

From project cloud-management, under directory /src/test/java/com/proofpoint/cloudmanagement/service/inventoryclient/.

Source file: MockInventoryServer.java

  15 
vote

@GET @Path("/pcmsystemname/{instanceId}") public Map<String,String> getPcmName(@PathParam("instanceId") String instanceId){
  Map<String,String> system=systemWithInstanceId(instanceId);
  if (system == null) {
    system=Maps.newHashMap();
    system.put(NAME_KEY,UUID.randomUUID().toString());
    system.put(INSTANCE_ID_KEY,instanceId);
    inventory.add(system);
  }
  return ImmutableMap.of(NAME_KEY,system.get(NAME_KEY));
}
 

Example 16

From project collector, under directory /src/main/java/com/ning/metrics/collector/jaxrs/.

Source file: AsyncEventResource.java

  15 
vote

@Path("/event") @GET @Produces({APPLICATION_JSON,APPLICATION_JSONP}) public SuspendResponse subscribe(@PathParam("type") @DefaultValue(EventListenerDispatcher.NO_FILTER_KEY) final Broadcaster feed,@QueryParam("type") @DefaultValue(EventListenerDispatcher.NO_FILTER_KEY) final String eventType){
  Broadcaster broadcaster=feed;
  if (feed == null || feed.getAtmosphereResources().size() == 0) {
    broadcaster=BroadcasterFactory.getDefault().lookup(JerseySimpleBroadcaster.class,eventType);
    if (broadcaster == null) {
      broadcaster=BroadcasterFactory.getDefault().lookup(JerseySimpleBroadcaster.class,eventType,true);
      final NewEventListener listener=new NewEventListener(config,broadcaster);
      dispatcher.addListener(eventType,listener);
    }
  }
  return new SuspendResponse.SuspendResponseBuilder<String>().broadcaster(broadcaster).resumeOnBroadcast(false).outputComments(true).build();
}
 

Example 17

From project Core_2, under directory /javaee-impl/src/test/java/org/jboss/forge/spec/plugin/.

Source file: RestPluginTest.java

  15 
vote

@Test public void testCreateEndpoint() throws Exception {
  Project project=getProject();
  JavaClass entity=generateEntity(project,null,"User");
  assertFalse(entity.hasAnnotation(XmlRootElement.class));
  setupRest();
  queueInputLines("");
  getShell().execute("rest endpoint-from-entity");
  JavaSourceFacet java=project.getFacet(JavaSourceFacet.class);
  JavaResource resource=java.getJavaResource(java.getBasePackage() + ".rest.UserEndpoint");
  JavaClass endpoint=(JavaClass)resource.getJavaSource();
  assertEquals("/users",endpoint.getAnnotation(Path.class).getStringValue());
  assertEquals("java.util.List",endpoint.getMethod("listAll").getQualifiedReturnType());
  Method<JavaClass> method=endpoint.getMethod("findById",Long.class);
  Type<JavaClass> returnTypeInspector=method.getReturnTypeInspector();
  assertEquals("javax.ws.rs.core.Response",returnTypeInspector.getQualifiedName());
  assertTrue(java.getJavaResource(entity).getJavaSource().hasAnnotation(XmlRootElement.class));
  getShell().execute("build");
}
 

Example 18

From project crest, under directory /integration/server/src/main/java/org/codegist/crest/server/stubs/handler/.

Source file: RetryHandlersStub.java

  15 
vote

@GET @Path("retry") public Response retry(@QueryParam("value") String value){
  if (++count != failFor) {
    return Response.status(418).build();
  }
 else {
    return Response.ok(value).build();
  }
}
 

Example 19

From project curator, under directory /curator-x-discovery-server/src/main/java/com/netflix/curator/x/discovery/server/rest/.

Source file: DiscoveryResource.java

  15 
vote

@PUT @Path("v1/service/{name}/{id}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response putService(ServiceInstance<T> instance,@PathParam("name") String name,@PathParam("id") String id){
  if (!instance.getId().equals(id) || !instance.getName().equals(name)) {
    log.info("Request where path id and/or name doesn't match entity");
    return Response.status(Response.Status.BAD_REQUEST).build();
  }
  if (instance.getServiceType() == ServiceType.DYNAMIC) {
    log.info("Service type cannot be dynamic");
    return Response.status(Response.Status.BAD_REQUEST).build();
  }
  try {
    context.getServiceDiscovery().registerService(instance);
  }
 catch (  Exception e) {
    log.error("Trying to register service",e);
    return Response.serverError().build();
  }
  return Response.status(Response.Status.CREATED).build();
}
 

Example 20

From project data-access, under directory /src/org/pentaho/platform/dataaccess/datasource/wizard/service/impl/.

Source file: AnalysisDatasourceService.java

  15 
vote

/** 
 * This is used by PUC to use a Jersey put to import a Mondrian Schema XML into PUR
 * @author : tband  date: 7/10/12
 * @param dataInputStream
 * @param schemaFileInfo
 * @param catalogName
 * @param datasourceName
 * @param overwrite
 * @param xmlaEnabledFlag
 * @param parameters
 * @return this method returns a response of "3" for success, 8 if exists, etc.
 * @throws PentahoAccessControlException
 */
@PUT @Path("/putSchema") @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces("text/plain") public Response putMondrianSchema(@FormDataParam(UPLOAD_ANALYSIS) InputStream dataInputStream,@FormDataParam(UPLOAD_ANALYSIS) FormDataContentDisposition schemaFileInfo,@FormDataParam(CATALOG_NAME) String catalogName,@FormDataParam(DATASOURCE_NAME) String datasourceName,@FormDataParam(OVERWRITE_IN_REPOS) String overwrite,@FormDataParam(XMLA_ENABLED_FLAG) String xmlaEnabledFlag,@FormDataParam(PARAMETERS) String parameters) throws PentahoAccessControlException {
  Response response=null;
  String statusCode=String.valueOf(PlatformImportException.PUBLISH_GENERAL_ERROR);
  try {
    validateAccess();
    String fileName=schemaFileInfo.getFileName();
    processMondrianImport(dataInputStream,catalogName,overwrite,xmlaEnabledFlag,parameters,fileName);
    statusCode=SUCCESS;
  }
 catch (  PentahoAccessControlException pac) {
    logger.error(pac.getMessage());
    statusCode=String.valueOf(PlatformImportException.PUBLISH_USERNAME_PASSWORD_FAIL);
  }
catch (  PlatformImportException pe) {
    logger.error("Error putMondrianSchema " + pe.getMessage() + " status = "+ pe.getErrorStatus());
    statusCode=String.valueOf(pe.getErrorStatus());
  }
catch (  Exception e) {
    logger.error("Error putMondrianSchema " + e.getMessage());
    statusCode=String.valueOf(PlatformImportException.PUBLISH_GENERAL_ERROR);
  }
  response=Response.ok().status(new Integer(statusCode)).type(MediaType.TEXT_PLAIN).build();
  logger.debug("putMondrianSchema Response " + response);
  return response;
}