コード例 #1
0
  private void deleteObject(final String key) {

    WebClient client =
        getWebClient()
            .accept(MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON)
            .path(CALL_PATH, key);

    try {
      client.delete();
    } catch (NotFoundException e) {
      return;
    } catch (WebApplicationException e) {
      handleWebException(e);
    } catch (Throwable e) {
      if (e instanceof ConnectException || e instanceof ClientException) {
        if (null != client) {
          client.reset();
        }
        switchServerURL(client.getBaseURI().toString());
        deleteObject(key);
      }
    } finally {
      if (null != client) {
        client.reset();
      }
    }
  }
コード例 #2
0
  private String lookupObject(final String contextKey) {

    WebClient client =
        getWebClient()
            .accept(MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON)
            .path(CALL_PATH, contextKey);

    String object = null;
    try {
      object = client.get(String.class);
    } catch (NotFoundException e) {
      return null;
    } catch (WebApplicationException e) {
      handleWebException(e);
    } catch (Throwable e) {
      if (e instanceof ConnectException || e instanceof ClientException) {
        if (null != client) {
          client.reset();
        }
        switchServerURL(client.getBaseURI().toString());
        return lookupObject(contextKey);
      }
    } finally {
      if (null != client) {
        client.reset();
      }
    }

    return object;
  }
コード例 #3
0
  @Override
  public String saveObject(E ctx) {

    String key = findAuxiliaryObjectFactory().createObjectKey(ctx);

    WebClient client =
        getWebClient()
            .accept(MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON)
            .path(CALL_PATH, key);

    try {
      Response resp = client.put(findAuxiliaryObjectFactory().marshalObject(ctx));
      if (resp.getStatus() == 404) {
        if (null != client) {
          client.reset();
        }
        switchServerURL(client.getBaseURI().toString());
        return saveObject(ctx);
      }

      return key;
    } catch (WebApplicationException e) {
      handleWebException(e);
    } catch (Throwable e) {
      if (e instanceof ConnectException || e instanceof ClientException) {
        if (null != client) {
          client.reset();
        }
        switchServerURL(client.getBaseURI().toString());
        return saveObject(ctx);
      }
    } finally {
      if (null != client) {
        client.reset();
      }
    }
    return null;
  }