コード例 #1
0
ファイル: MailClient.java プロジェクト: paulnguyen/cloud
  public static void main(String[] args) throws Exception {
    // Create and configure HTTPS client
    Client client = new Client(new Context(), Protocol.HTTPS);
    Series<Parameter> parameters = client.getContext().getParameters();
    parameters.add("truststorePath", "certs/client-truststore.jks");
    parameters.add("truststorePassword", "password");
    parameters.add("truststoreType", "JKS");

    // Create and configure client resource
    ClientResource clientResource =
        new ClientResource("https://localhost:8183/accounts/chunkylover53/mails/123");
    clientResource.setNext(client);

    // Preemptively configure the authentication credentials
    ChallengeResponse authentication =
        new ChallengeResponse(ChallengeScheme.HTTP_BASIC, "chunkylover53", "pwd");
    clientResource.setChallengeResponse(authentication);

    // Communicate with remote resource
    MailResource mailClient = clientResource.wrap(MailResource.class);
    Mail m = mailClient.retrieve();
    System.out.println("Subject: " + m.getSubject());
    System.out.println("Content: " + m.getContent());

    // Store HTTPS client
    client.stop();
  }
コード例 #2
0
  /**
   * Releases the resource by stopping any connector automatically created and associated to the
   * "next" property (see {@link #getNext()} method.
   */
  @Override
  protected void doRelease() throws ResourceException {
    if ((getNext() != null) && this.nextCreated) {
      if (getNext() instanceof Restlet) {
        try {
          ((Restlet) getNext()).stop();
        } catch (Exception e) {
          throw new ResourceException(e);
        }
      }

      setNext(null);
    }
  }
コード例 #3
0
  /**
   * The constructor is {@code private} to have strict control what instances exist at any time.
   * Instead of the constructor the {@code public} <i>static factory method</i> {@link
   * #getInstance(JavaClient)} returns the instances of the class.
   *
   * @param javaClient The corresponding {@code JavaClient}
   */
  private CoreServiceImpl(JavaClient javaClient) {
    super(CoreServiceID.INSTANCE, javaClient.getAPIBaseURL(), javaClient);

    this.javaClient = javaClient;

    restletClient = ((JavaClientImpl) javaClient).getRestletClient();

    ClientResource clientResource = new ClientResource(serviceURL.toExternalForm());
    clientResource.setNext(restletClient);
    CoreServiceInstanceDataResource coreServiceInstanceDataResource =
        clientResource.get(CoreServiceInstanceDataResource.class);

    System.out.println("[CoreService CoreServiceImpl] " + serviceURL.toExternalForm());

    maxEntityRequestSize = coreServiceInstanceDataResource.getParameters().getBatchLimit();
    paginationSize = coreServiceInstanceDataResource.getParameters().getPaginationSize();
  }
コード例 #4
0
  /**
   * Returns the next Restlet. By default, it is the client dispatcher if a context is available.
   *
   * @return The next Restlet or null.
   */
  public Uniform getNext() {
    Uniform result = this.next;

    if (result == null) {
      synchronized (this) {
        if (result == null) {
          result = createNext();

          if (result != null) {
            setNext(result);
            this.nextCreated = true;
          }
        }
      }
    }

    return result;
  }