Java Code Examples for javax.ws.rs.PathParam

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

  21 
vote

private void processVerifiedParams(Method m,RestApiCall apiCall){
  for (int i=0; i < m.getParameterAnnotations().length; i++) {
    boolean hasVerify=false;
    String pathName=null;
    for (    Annotation a : m.getParameterAnnotations()[i]) {
      if (a instanceof Verify) {
        hasVerify=true;
      }
 else       if (a instanceof PathParam) {
        PathParam p=(PathParam)a;
        pathName=p.value();
      }
    }
    if (hasVerify && pathName != null) {
      apiCall.verifiedParams.add(pathName);
    }
  }
}
 

Example 2

From project airlift, under directory /sample-server/src/main/java/io/airlift/sample/.

Source file: PersonResource.java

  19 
vote

@GET @Produces(MediaType.APPLICATION_JSON) public Response get(@PathParam("id") String id,@Context UriInfo uriInfo){
  Preconditions.checkNotNull(id,"id must not be null");
  Person person=store.get(id);
  if (person == null) {
    return Response.status(Response.Status.NOT_FOUND).entity("[" + id + "]").build();
  }
  return Response.ok(from(person,uriInfo.getRequestUri())).build();
}
 

Example 3

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

Source file: AnnisWebService.java

  19 
vote

@GET @Path("graphs/{top}/{doc}") @Produces("application/xml") public SaltProject graph(@PathParam("top") String toplevelCorpusName,@PathParam("doc") String documentName){
  try {
    long start=new Date().getTime();
    SaltProject p=annisDao.retrieveAnnotationGraph(toplevelCorpusName,documentName);
    long end=new Date().getTime();
    logQuery("GRAPH",toplevelCorpusName,documentName,end - start);
    return p;
  }
 catch (  Exception ex) {
    log.error("error when accessing graph " + toplevelCorpusName + "/"+ documentName,ex);
    throw new WebApplicationException(ex);
  }
}
 

Example 4

From project Arecibo, under directory /aggregator/src/main/java/com/ning/arecibo/aggregator/rest/.

Source file: EventAggregatorEndPoint.java

  19 
vote

@GET @Produces({MediaType.TEXT_HTML,"text/html+agg"}) public Response get(@PathParam("name") String name){
  AggregatorImpl def=registry.getAggregatorImpl(name);
  if (def != null) {
    return Response.ok(def).type("text/html+agg").build();
  }
 else {
    return Response.ok(registry).type(MediaType.TEXT_HTML).build();
  }
}
 

Example 5

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

Source file: CustomerResource.java

  19 
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 6

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

Source file: CardsResource.java

  19 
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 7

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

Source file: GenericCollectionResource.java

  19 
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 8

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

Source file: ProductWebServiceImpl.java

  19 
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 9

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

Source file: CustomerResource.java

  19 
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 10

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

Source file: AdaptorController.java

  19 
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 11

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

Source file: AdminChainREST.java

  19 
vote

/** 
 * Retrieve a mediation chain.
 * @param id The ID of the chain  to retrieve 
 * @return The required Chain, return <code>null<code> if chain does not exist.
 * @throws ParseException 
 */
@GET @Produces("application/json") public String chain(@PathParam("chainid") String chainid){
  if (chainid == null || chainid.length() < 1 || chainid.compareToIgnoreCase("cilia") == 0) {
    return getChainNames();
  }
  Chain chain=admin.getChain(chainid);
  StringBuilder result=new StringBuilder();
  if (chain == null) {
    result.append("{").append(chainid).append(": Does not exist}");
  }
 else {
    result.append(chain);
  }
  return result.toString();
}
 

Example 12

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

Source file: InstanceResource.java

  19 
vote

@GET @Produces(MediaType.APPLICATION_JSON) public Response getInstance(@PathParam("id") String instanceId,@Context UriInfo uriInfo){
  checkNotNull(instanceId);
  checkNotNull(uriInfo);
  for (  Map.Entry<String,InstanceConnector> instanceConnectorEntry : instanceConnectorMap.entrySet()) {
    Instance instance=instanceConnectorEntry.getValue().getInstance(instanceId);
    if (instance != null) {
      return Response.ok(InstanceRepresentation.fromInstance(instance.toBuilder().setProvider(instanceConnectorEntry.getKey()).setHostname(dnsManager.getFullyQualifiedDomainName(instance)).setTags(tagManager.getTags(instance)).build(),constructSelfUri(uriInfo,instanceId))).build();
    }
  }
  return Response.status(Status.NOT_FOUND).build();
}
 

Example 13

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

Source file: AsyncEventResource.java

  19 
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 14

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

Source file: DiscoveryResource.java

  19 
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 15

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

Source file: DatasourceResource.java

  19 
vote

@GET @Path("/metadata/{metadataId : .+}/download") @Produces(WILDCARD) public Response doGetMetadataFilesAsDownload(@PathParam("metadataId") String metadataId){
  if (!(metadataDomainRepository instanceof IPentahoMetadataDomainRepositoryExporter)) {
    return Response.serverError().build();
  }
  Map<String,InputStream> fileData=((IPentahoMetadataDomainRepositoryExporter)metadataDomainRepository).getDomainFilesData(metadataId);
  return createAttachment(fileData,metadataId);
}
 

Example 16

From project EasySOA, under directory /easysoa-registry/easysoa-registry-rest/src/main/java/org/easysoa/rest/.

Source file: DashboardRest.java

  19 
vote

@GET @Path("/service/{serviceid}") @Produces(MediaType.APPLICATION_JSON) public Object getServiceById(@Context HttpServletRequest request,@PathParam("serviceid") String serviceid) throws Exception {
  CoreSession session=SessionFactory.getSession(request);
  DocumentModel worskspaceServiceModel=session.getDocument(new IdRef(serviceid));
  String referencePath=(String)worskspaceServiceModel.getProperty(Service.SCHEMA,Service.PROP_REFERENCESERVICE);
  DocumentModel referencedServiceModel=(referencePath != null) ? session.getDocument(new PathRef(referencePath)) : null;
  return getServiceEntry(session.getDocument(new IdRef(serviceid)),referencedServiceModel).toString();
}
 

Example 17

From project entando-core-engine, under directory /src/main/java/org/entando/entando/aps/system/services/api/server/.

Source file: ApiRestStatusServer.java

  19 
vote

@GET @Produces({"application/json","application/xml"}) @Path("/{namespace}/{resourceName}/{httpMethod}") public Object getApiStatus(@PathParam("httpMethod") String httpMethodString,@PathParam("namespace") String namespace,@PathParam("resourceName") String resourceName,@Context HttpServletRequest request){
  StringApiResponse response=new StringApiResponse();
  ApiMethod.HttpMethod httpMethod=Enum.valueOf(ApiMethod.HttpMethod.class,httpMethodString.toUpperCase());
  try {
    IResponseBuilder responseBuilder=(IResponseBuilder)ApsWebApplicationUtils.getBean(SystemConstants.API_RESPONSE_BUILDER,request);
    ApiMethod apiMethod=responseBuilder.extractApiMethod(httpMethod,namespace,resourceName);
    if (null != apiMethod.getRequiredPermission()) {
      response.setResult(ApiStatus.AUTHORIZATION_REQUIRED.toString(),null);
    }
 else     if (apiMethod.getRequiredAuth()) {
      response.setResult(ApiStatus.AUTHENTICATION_REQUIRED.toString(),null);
    }
 else {
      response.setResult(ApiStatus.FREE.toString(),null);
    }
  }
 catch (  ApiException ae) {
    response.addErrors(((ApiException)ae).getErrors());
    response.setResult(ApiStatus.INACTIVE.toString(),null);
  }
catch (  Throwable t) {
    return this.buildErrorResponse(httpMethod,namespace,resourceName,t);
  }
  return response;
}
 

Example 18

From project examples_1, under directory /datanucleus/com.paremus.example.datanucleus.service/src/com/paremus/example/datanucleus/service/rest/.

Source file: BlogCommentsResource.java

  19 
vote

@GET @Path("{id}") @Produces(MediaType.APPLICATION_JSON) public Response get(@PathParam("id") String id) throws Exception {
  Comment comment=blog.find(id);
  if (comment == null)   return Response.status(Status.NOT_FOUND).build();
  StringWriter output=new StringWriter();
  JsonGenerator generator=jsonFactory.createJsonGenerator(output);
  generateCommentJson(generator,comment,false);
  generator.close();
  return Response.ok().entity(output.toString()).type(MediaType.APPLICATION_JSON).header(RFC2616.HEADER_ALLOW,HttpMethod.GET + "," + HttpMethod.PUT).build();
}
 

Example 19

From project flume_1, under directory /flume-config-web/src/main/java/com/cloudera/flume/master/.

Source file: CommandManagerResource.java

  19 
vote

@GET @Path("{idx: [0-9]*}") @Produces("application/json") public JSONObject getLog(@PathParam("idx") String sidx){
  long idx=Long.parseLong(sidx);
  CommandStatus cmd=commands.getStatus(idx);
  if (cmd == null) {
    return new JSONObject();
  }
  try {
    return toJSONObject(cmd);
  }
 catch (  JSONException e) {
    LOG.warn("Problem encoding JSON",e);
    return new JSONObject();
  }
}
 

Example 20

From project gatein-sso, under directory /auth-callback/src/main/java/org/gatein/sso/authentication/callback/.

Source file: AuthenticationHandler.java

  19 
vote

@GET @Path("/auth/{1}/{2}") @Produces({MediaType.TEXT_PLAIN}) public String authenticate(@PathParam("1") String username,@PathParam("2") String password){
  try {
    log.debug("---------------------------------------");
    log.debug("Username: " + username);
    log.debug("Password: XXXXXXXXXXXXXXXX");
    Authenticator authenticator=(Authenticator)getContainer().getComponentInstanceOfType(Authenticator.class);
    Credential[] credentials=new Credential[]{new UsernameCredential(username),new PasswordCredential(password)};
    try {
      authenticator.validateUser(credentials);
      return "" + Boolean.TRUE;
    }
 catch (    LoginException le) {
      return "" + Boolean.FALSE;
    }
  }
 catch (  Exception e) {
    log.error(this,e);
    throw new RuntimeException(e);
  }
}
 

Example 21

From project gatein-toolbox, under directory /CoreOrganizationInitializer/src/main/java/org/exoplatform/core/component/organization/initializer/.

Source file: RestOrganizationInitializer.java

  19 
vote

@GET @Path("launchUserListeners/{userName}/{checkFolders}") public String launchUserListeners(@PathParam("userName") String userName,@PathParam("checkFolders") Boolean checkFolders){
  UserHandler userHandler=orgService_.getUserHandler();
  User user;
  try {
    user=userHandler.findUserByName(userName);
    boolean ok=initializerService.treatUser(user,checkFolders);
    String responseString=ok ? "User listeners executed successfuly." : "Error occured during execution of user listeners.";
    return responseString;
  }
 catch (  Exception e) {
    log.warn("Error with user " + userName,e);
    return "Error occured during execution of user listeners: " + e.getMessage();
  }
}
 

Example 22

From project gmc, under directory /src/org.gluster.storage.management.gateway/src/org/gluster/storage/management/gateway/resources/v1_0/.

Source file: ClustersResource.java

  19 
vote

@Path("{" + PATH_PARAM_CLUSTER_NAME + "}") @DELETE public Response unregisterCluster(@PathParam(PATH_PARAM_CLUSTER_NAME) String clusterName){
  if (clusterName == null || clusterName.isEmpty()) {
    throw new GlusterValidationException("Parameter [" + FORM_PARAM_CLUSTER_NAME + "] is missing in request!");
  }
  ClusterInfo cluster=clusterService.getCluster(clusterName);
  if (cluster == null) {
    throw new GlusterValidationException("Cluster [" + clusterName + "] does not exist!");
  }
  clusterService.unregisterCluster(cluster);
  return noContentResponse();
}
 

Example 23

From project grouperfish, under directory /service/src/main/java/com/mozilla/grouperfish/rest/jaxrs/.

Source file: RunResource.java

  19 
vote

@POST public Response runTransformsForQuery(@PathParam("namespace") final String namespace,@Context final HttpServletRequest request){
  final Scope ns=scope(namespace);
  if (!ns.allows(RunResource.class,new HttpAccess(Operation.RUN,request))) {
    return FORBIDDEN;
  }
  try {
    batchService().schedule(ns);
  }
 catch (  final Exception e) {
    log.error(String.format("Error initiating run request '%s'",request.getPathInfo()),e);
    return FAIL;
  }
  return ACCEPTED;
}
 

Example 24

From project hcatalog, under directory /webhcat/svr/src/main/java/org/apache/hcatalog/templeton/.

Source file: Server.java

  19 
vote

/** 
 * List all the tables in an hcat database.
 */
@GET @Path("ddl/database/{db}/table") @Produces(MediaType.APPLICATION_JSON) public Response listTables(@PathParam("db") String db,@QueryParam("like") String tablePattern) throws HcatException, NotAuthorizedException, BusyException, BadParam, ExecuteException, IOException {
  verifyUser();
  verifyDdlParam(db,":db");
  HcatDelegator d=new HcatDelegator(appConf,execService);
  if (!TempletonUtils.isset(tablePattern))   tablePattern="*";
  return d.listTables(getUser(),db,tablePattern);
}