예제 #1
0
파일: IceRestClient.java 프로젝트: JBEI/ice
  public <T> T putWor(
      String url,
      String resourcePath,
      Object object,
      Class<T> responseClass,
      Map<String, Object> queryParams,
      String worToken) {
    WebTarget target = client.target("https://" + url).path(resourcePath);
    if (queryParams != null) {
      for (Map.Entry<String, Object> entry : queryParams.entrySet()) {
        target = target.queryParam(entry.getKey(), entry.getValue());
      }
    }

    Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE);
    setHeaders(invocationBuilder, worToken);
    Response putResponse =
        invocationBuilder.put(Entity.entity(object, MediaType.APPLICATION_JSON_TYPE));
    if (putResponse.getStatus() != Response.Status.OK.getStatusCode()) {
      Logger.error(
          "PUT call to "
              + url
              + "/"
              + resourcePath
              + " returned status of "
              + putResponse.getStatus());
      return null;
    }

    if (responseClass != null
        && putResponse.hasEntity()
        && putResponse.getStatus() == Response.Status.OK.getStatusCode())
      return putResponse.readEntity(responseClass);
    return null;
  }
예제 #2
0
파일: IceRestClient.java 프로젝트: JBEI/ice
 public boolean delete(String token, String url, String resourcePath) {
   WebTarget target = client.target("https://" + url).path(resourcePath);
   Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE);
   setHeaders(invocationBuilder, token);
   Response response = invocationBuilder.delete();
   return response.getStatus() == Response.Status.OK.getStatusCode();
 }
예제 #3
0
파일: IceRestClient.java 프로젝트: JBEI/ice
 @Override
 public <T> T get(String url, String path, Class<T> clazz, Map<String, Object> queryParams) {
   WebTarget target = client.target("https://" + url).path(path);
   if (queryParams != null) {
     for (Map.Entry<String, Object> entry : queryParams.entrySet()) {
       target = target.queryParam(entry.getKey(), entry.getValue());
     }
   }
   return target.request(MediaType.APPLICATION_JSON_TYPE).buildGet().invoke(clazz);
 }
예제 #4
0
파일: IceRestClient.java 프로젝트: JBEI/ice
 public Response postSequenceFile(
     String url, String recordId, EntryType entryType, String sequence) {
   WebTarget target = client.target("https://" + url).path("/rest/file/sequence");
   Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE);
   final FormDataMultiPart multiPart = new FormDataMultiPart();
   multiPart.field("file", IOUtils.toInputStream(sequence), MediaType.TEXT_PLAIN_TYPE);
   multiPart.field("entryRecordId", recordId);
   multiPart.field("entryType", entryType.name());
   return invocationBuilder.post(Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE));
 }
예제 #5
0
파일: IceRestClient.java 프로젝트: JBEI/ice
 // WOR
 public <T> T getWor(
     String url, String path, Class<T> clazz, Map<String, Object> queryParams, String token) {
   WebTarget target = client.target("https://" + url).path(path);
   if (queryParams != null) {
     for (Map.Entry<String, Object> entry : queryParams.entrySet()) {
       target = target.queryParam(entry.getKey(), entry.getValue());
     }
   }
   Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE);
   setHeaders(invocationBuilder, token);
   return invocationBuilder.buildGet().invoke(clazz);
 }
 public static String checkLogin(Userinfo ui) {
   Client client = ClientBuilder.newClient(config);
   WebTarget target = client.target(getBaseUri());
   return target
       .path("users")
       .path("role=" + ui.getUsertype())
       .path("email=" + ui.getUsername())
       .path("password=" + ui.getPassword())
       .request()
       .accept(MediaType.TEXT_HTML)
       .get(String.class);
 }
예제 #7
0
  public Session login(final UserCredential userCredential) {
    WebTarget target =
        client
            .target("http://auth.getprismatic.com")
            .path("auth")
            .path("login")
            .queryParam("api-version", "1.2")
            .queryParam("ignore", "true")
            .queryParam("whitelist_url", "http%3A%2F%2Fgetprismatic.com%2Fnews%2Fhome")
            .queryParam("soon_url", "http%3A%2F%2Fgetprismatic.com%2Fwelcome")
            .queryParam("create_url", "http%3A%2F%2Fgetprismatic.com%2Fcreateaccount")
            .queryParam("resetpassword_url", "http%3A%2F%2Fgetprismatic.com%2Fresetpassword");

    Response response =
        target.request().post(Entity.entity(userCredential, MediaType.APPLICATION_JSON_TYPE));

    checkResponseStatus(response);

    return Session.parseFromHeaders(response.getHeaders().get("Set-Cookie"));
  }
예제 #8
0
파일: IceRestClient.java 프로젝트: JBEI/ice
  @Override
  public <T> T post(
      String url,
      String resourcePath,
      Object object,
      Class<T> responseClass,
      Map<String, Object> queryParams) {
    WebTarget target = client.target("https://" + url).path(resourcePath);
    if (queryParams != null) {
      for (Map.Entry<String, Object> entry : queryParams.entrySet()) {
        target = target.queryParam(entry.getKey(), entry.getValue());
      }
    }

    Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE);
    Response postResponse =
        invocationBuilder.post(Entity.entity(object, MediaType.APPLICATION_JSON_TYPE));
    if (postResponse.hasEntity() && postResponse.getStatus() == Response.Status.OK.getStatusCode())
      return postResponse.readEntity(responseClass);
    return null;
  }
예제 #9
0
파일: IceRestClient.java 프로젝트: JBEI/ice
  public <T> T put(String url, String resourcePath, Object object, Class<T> responseClass) {
    WebTarget target = client.target("https://" + url).path(resourcePath);
    Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE);
    Response putResponse =
        invocationBuilder.put(Entity.entity(object, MediaType.APPLICATION_JSON_TYPE));
    if (putResponse.getStatus() != Response.Status.OK.getStatusCode()) {
      Logger.error(
          "PUT call to "
              + url
              + "/"
              + resourcePath
              + " returned status of "
              + putResponse.getStatus());
      return null;
    }

    if (responseClass != null
        && putResponse.hasEntity()
        && putResponse.getStatus() == Response.Status.OK.getStatusCode())
      return putResponse.readEntity(responseClass);
    return null;
  }
예제 #10
0
파일: IceRestClient.java 프로젝트: JBEI/ice
 public Response put(String url, String resourcePath, Object object) {
   WebTarget target = client.target("https://" + url).path(resourcePath);
   Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE);
   return invocationBuilder.put(Entity.entity(object, MediaType.APPLICATION_JSON_TYPE));
 }
예제 #11
0
 private WebTarget createInitialFetchTarget() {
   return client
       .target("http://api.getprismatic.com/")
       .path("news/personal/personalkey")
       .queryParam("api-version", "1.2");
 }
예제 #12
0
 public MobileApi(String appUrl) {
   this.appUrl = appUrl;
   Client client = ClientBuilder.newClient();
   appTarget = client.target(this.appUrl);
 }