コード例 #1
0
  @Path("/Client/{cid}")
  @GET
  @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
  public Response getAssociatedPersons(
      @HeaderParam("Authorization") String authorization, @PathParam("cid") String cid)
      throws Exception {
    clientService = ClientService.instance();

    Response authorizationResponse = processAuthorization(authorization);
    if (authorizationResponse != null) {
      return authorizationResponse;
    }

    try {

      log.info("getting the client");
      OxAuthClient client = clientService.getClientByInum(cid);

      if (client == null) {
        // sets HTTP status code 404 Not Found
        return getErrorResponse(
            "Resource " + cid + " not found", Response.Status.NOT_FOUND.getStatusCode());
      }

      log.info("mapping client attributes");
      ClientAssociation clientAssociation = MapperUtil.map(client, null);
      log.info("getting URL");
      URI location = new URI("/ClientAssociation/Client/" + cid);
      log.info("returning response");
      return Response.ok(clientAssociation).location(location).build();

    } catch (EntryPersistenceException ex) {
      log.error("Exception: ", ex);
      return getErrorResponse(
          "Resource " + cid + " not found", Response.Status.NOT_FOUND.getStatusCode());
    } catch (Exception ex) {
      log.error("Exception: ", ex);
      return getErrorResponse(
          "Unexpected processing error, please check the input parameters",
          Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
  }
コード例 #2
0
  @Path("/User/{uid}")
  @GET
  @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
  public Response getAssociatedClients(
      @HeaderParam("Authorization") String authorization, @PathParam("uid") String uid)
      throws Exception {

    personService = PersonService.instance();

    Response authorizationResponse = processAuthorization(authorization);
    if (authorizationResponse != null) {
      return authorizationResponse;
    }

    try {

      GluuCustomPerson gluuPerson = personService.getPersonByInum(uid);
      if (gluuPerson == null) {
        // sets HTTP status code 404 Not Found
        return getErrorResponse(
            "Resource " + uid + " not found", Response.Status.NOT_FOUND.getStatusCode());
      }

      PersonAssociation personAssociation = MapperUtil.map(gluuPerson, null);

      URI location = new URI("/ClientAssociation/User/" + uid);

      return Response.ok(personAssociation).location(location).build();
    } catch (EntryPersistenceException ex) {
      log.error("Exception: ", ex);
      return getErrorResponse(
          "Resource " + uid + " not found", Response.Status.NOT_FOUND.getStatusCode());
    } catch (Exception ex) {
      log.error("Exception: ", ex);
      return getErrorResponse(
          "Unexpected processing error, please check the input parameters",
          Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
  }