コード例 #1
0
 /** Test scheme getting/setting. */
 public void testScheme() throws Exception {
   final Reference ref = getDefaultReference();
   assertEquals(DEFAULT_SCHEME, ref.getScheme());
   final String scheme = "https";
   ref.setScheme(scheme);
   assertEquals(scheme, ref.getScheme());
   ref.setScheme(DEFAULT_SCHEME);
   assertEquals(DEFAULT_SCHEME, ref.getScheme());
 }
コード例 #2
0
  /**
   * Redirects a given call to a target reference. In the default implementation, the request HTTP
   * headers, stored in the request's attributes, are removed before dispatching. After dispatching,
   * the response HTTP headers are also removed to prevent conflicts with the main call.
   *
   * @param targetRef The target reference with URI variables resolved.
   * @param request The request to handle.
   * @param response The response to update.
   */
  protected void outboundServerRedirect(Reference targetRef, Request request, Response response) {
    Restlet next = (getApplication() == null) ? null : getApplication().getOutboundRoot();

    if (next == null) {
      next = getContext().getClientDispatcher();
    }

    serverRedirect(next, targetRef, request, response);
    if (response.getEntity() != null
        && !request.getResourceRef().getScheme().equalsIgnoreCase(targetRef.getScheme())) {
      // Distinct protocol, this data cannot be exposed.
      response.getEntity().setLocationRef((Reference) null);
    }
  }
コード例 #3
0
 /**
  * Tests the parsing of a reference into its components
  *
  * @param reference
  * @param scheme
  * @param authority
  * @param path
  * @param query
  * @param fragment
  */
 private void testRef0(
     String reference,
     String scheme,
     String authority,
     String path,
     String query,
     String fragment) {
   final Reference ref = new Reference(reference);
   assertEquals(scheme, ref.getScheme());
   assertEquals(authority, ref.getAuthority());
   assertEquals(path, ref.getPath());
   assertEquals(query, ref.getQuery());
   assertEquals(fragment, ref.getFragment());
 }
コード例 #4
0
 /**
  * Test the behaviour of several getters upon a Reference object.
  *
  * @param reference
  * @param query
  * @param fragment
  * @param toString
  */
 private void testRef4(
     Reference reference,
     String scheme,
     String authority,
     String path,
     String remainingPart,
     String toString,
     String targetRef,
     String query,
     String relativePart) {
   assertEquals(reference.getScheme(), scheme);
   assertEquals(reference.getAuthority(), authority);
   assertEquals(reference.getPath(), path);
   assertEquals(reference.getRemainingPart(), remainingPart);
   assertEquals(reference.toString(), toString);
   assertEquals(reference.getTargetRef().toString(), targetRef);
   assertEquals(reference.getQuery(), query);
   assertEquals(reference.getRelativePart(), relativePart);
 }