org.restlet.Response.redirectSeeOther()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(165)

本文整理了Java中org.restlet.Response.redirectSeeOther方法的一些代码示例,展示了Response.redirectSeeOther的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.redirectSeeOther方法的具体详情如下:
包路径:org.restlet.Response
类名称:Response
方法名:redirectSeeOther

Response.redirectSeeOther介绍

[英]Redirects the client to a different URI that SHOULD be retrieved using a GET method on that resource. This method exists primarily to allow the output of a POST-activated script to redirect the user agent to a selected resource. The new URI is not a substitute reference for the originally requested resource.

If you pass a relative target URI, it will be resolved with the current base reference of the request's resource reference (see Request#getResourceRef() and Reference#getBaseRef().
[中]将客户端重定向到另一个URI,应该使用该资源上的GET方法检索该URI。此方法主要用于允许后激活脚本的输出将用户代理重定向到选定的资源。新URI不是最初请求的资源的替代引用。
如果传递相对目标URI,它将使用请求的资源引用的当前基引用进行解析(请参见请求#getResourceRef()和引用#getBaseRef()。

代码示例

代码示例来源:origin: org.restlet.osgi/org.restlet

/**
 * Redirects the client to a different URI that SHOULD be retrieved using a
 * GET method on that resource. This method exists primarily to allow the
 * output of a POST-activated script to redirect the user agent to a
 * selected resource. The new URI is not a substitute reference for the
 * originally requested resource.
 * 
 * @param targetRef
 *            The target reference.
 */
@Override
public void redirectSeeOther(Reference targetRef) {
  getWrappedResponse().redirectSeeOther(targetRef);
}

代码示例来源:origin: org.restlet.osgi/org.restlet

/**
 * Redirects the client to a different URI that SHOULD be retrieved using a
 * GET method on that resource. This method exists primarily to allow the
 * output of a POST-activated script to redirect the user agent to a
 * selected resource. The new URI is not a substitute reference for the
 * originally requested resource.
 * 
 * @param targetUri
 *            The target URI.
 */
@Override
public void redirectSeeOther(String targetUri) {
  getWrappedResponse().redirectSeeOther(targetUri);
}

代码示例来源:origin: com.whizzosoftware.hobson.hub/hobson-hub-auth

private void sendErrorRedirect(String redirectUri, String code, String msg) {
    try {
      getResponse().redirectSeeOther(
          redirectUri + "?error=" + URLEncoder.encode(code, "UTF-8") +
              "&error_description=" + URLEncoder.encode(msg, "UTF-8")
      );
    } catch (UnsupportedEncodingException e) {
      throw new HobsonRuntimeException("Error creating redirect URL", e);
    }
  }
}

代码示例来源:origin: joshsh/sesametools

private Representation representNonInformationResource(final MediaType type) {
  RDFFormat format = RDFMediaTypes.findRdfFormat(type);
  if (null == format) {
    throw new IllegalStateException("no RDF format for media type " + type);
  }
  String suffix = format.getDefaultFileExtension();
  if (null == suffix) {
    throw new IllegalStateException("no suffix for RDF format " + type);
  }
  getResponse().redirectSeeOther(selfURI + "." + suffix);
  return null;
}

代码示例来源:origin: net.fortytwo.sesametools/linked-data-server

private Representation representNonInformationResource(final MediaType type) {
  RDFFormat format = RDFMediaTypes.findRdfFormat(type);
  if (null == format) {
    throw new IllegalStateException("no RDF format for media type " + type);
  }
  String suffix = format.getDefaultFileExtension();
  if (null == suffix) {
    throw new IllegalStateException("no suffix for RDF format " + type);
  }
  getResponse().redirectSeeOther(selfURI + "." + suffix);
  return null;
}

代码示例来源:origin: org.codeartisans.qipki/qipki-ca-http

/**
 * Shortcut to apply POST/302/GET redirect pattern.
 *
 * @param getURI URI of the updated resource
 * @return An EmptyRepresentation with proper HTTP headers to apply the redirection
 */
protected final Representation redirectToUpdatedResource( String getURI )
{
  getResponse().redirectSeeOther( getURI );
  return new EmptyRepresentation();
}

代码示例来源:origin: org.codeartisans.qipki/qipki-ca-http

/**
 * Shortcut to apply POST/302/GET redirect pattern.
 *
 * @param getURI URI of the created resource
 * @return An EmptyRepresentation with proper HTTP headers to apply the redirection
 */
protected final Representation redirectToCreatedResource( String getURI )
{
  getResponse().redirectSeeOther( getURI );
  return new EmptyRepresentation();
}

代码示例来源:origin: org.restlet.osgi/org.restlet

/**
 * Redirects the client to a different URI that SHOULD be retrieved using a
 * GET method on that resource. This method exists primarily to allow the
 * output of a POST-activated script to redirect the user agent to a
 * selected resource. The new URI is not a substitute reference for the
 * originally requested resource.
 * 
 * @param targetRef
 *            The target reference.
 */
public void redirectSeeOther(Reference targetRef) {
  if (getResponse() != null) {
    getResponse().redirectSeeOther(targetRef);
  }
}

代码示例来源:origin: com.github.ansell.oas/oas-webservice-impl

/**
   * Redirects to the given path, using an absolute URI based on this.getRequest().getRootRef().
   * 
   * @param path
   *            The path to redirect to.
   */
  protected void redirectToPath(final String path)
  {
    final String rootRef = this.getRequest().getRootRef().toString(false, false);
    
    final boolean rootHasSlash = rootRef.endsWith("/");
    final boolean pathHasSlash = path.startsWith("/");
    
    if(rootHasSlash && pathHasSlash && path.length() > 1)
    {
      this.getResponse().redirectSeeOther(rootRef + path.substring(1));
    }
    else
    // if((rootHasSlash && !pathHasSlash) || (!rootHasSlash && pathHasSlash))
    {
      this.getResponse().redirectSeeOther(rootRef + path);
    }
  }
}

代码示例来源:origin: org.restlet.osgi/org.restlet

/**
 * Redirects the client to a different URI that SHOULD be retrieved using a
 * GET method on that resource. This method exists primarily to allow the
 * output of a POST-activated script to redirect the user agent to a
 * selected resource. The new URI is not a substitute reference for the
 * originally requested resource.<br>
 * <br>
 * If you pass a relative target URI, it will be resolved with the current
 * base reference of the request's resource reference (see {@link Request#getResourceRef()} and
 * {@link Reference#getBaseRef()}.
 * 
 * @param targetUri
 *            The target URI.
 */
public void redirectSeeOther(String targetUri) {
  if (getResponse() != null) {
    getResponse().redirectSeeOther(targetUri);
  }
}

代码示例来源:origin: com.github.ansell.restlet-utils/restlet-utils

response.redirectSeeOther(Reference.decode(targetUri));
return;
response.redirectSeeOther(this.getFixedRedirectUri());
return;
response.redirectSeeOther(FixedRedirectCookieAuthenticator.DEFAULT_FIXED_REDIRECT_URI);
return;

代码示例来源:origin: org.restlet.jse/org.restlet.example

/**
 * Remove this resource.
 */
@Delete
public void removeContact() throws ResourceException {
  getObjectsFacade().deleteContact(this.user, this.contact);
  getResponse().redirectSeeOther(
      getRequest().getResourceRef().getParentRef());
}

代码示例来源:origin: org.restlet.jse/org.restlet.example

/**
 * Remove this resource.
 */
@Delete
public void removeUser() throws ResourceException {
  getObjectsFacade().deleteUser(this.user);
  getResponse().redirectSeeOther(
      getRequest().getResourceRef().getParentRef());
}

代码示例来源:origin: org.restlet.jse/org.restlet.example

/**
 * Accept the representation of a new user, and create it.
 */
@Post
public void acceptUser(Representation entity) throws ResourceException {
  Form form = new Form(entity);
  User user = new User();
  user.setFirstName(form.getFirstValue("firstName"));
  user.setLastName(form.getFirstValue("lastName"));
  user.setImage(form.getFirstValue("image"));
  try {
    user = getObjectsFacade().createUser(user);
    getResponse().redirectSeeOther(
        getChildReference(getRequest().getResourceRef(),
            user.getId()));
  } catch (ObjectsException e) {
    final Map<String, Object> dataModel = new TreeMap<String, Object>();
    dataModel.put("users", this.users);
    dataModel.put("resourceRef", getRequest().getResourceRef());
    dataModel.put("rootRef", getRequest().getRootRef());
    dataModel.put("firstName", form.getFirstValue("firstName"));
    dataModel.put("lastName", form.getFirstValue("lastName"));
    dataModel.put("image", form.getFirstValue("image"));
    dataModel.put("errorMessage", e.getMessage());
    getResponse().setEntity(
        getTemplateRepresentation("users.html", dataModel,
            MediaType.TEXT_HTML));
  }
}

代码示例来源:origin: org.restlet.osgi/org.restlet

response.redirectSeeOther(targetRef);
break;

代码示例来源:origin: com.github.ansell.oas/oas-webservice-impl

this.getResponse().redirectSeeOther(referrerRef);
this.getResponse().redirectSeeOther(this.getDefaultRedirect());

代码示例来源:origin: com.whizzosoftware.hobson.hub/hobson-hub-auth

@Override
protected Representation post(Representation entity) throws ResourceException {
  Form form = new Form(entity);
  String responseType = form.getFirstValue("response_type");
  String username = form.getFirstValue("username");
  String password = form.getFirstValue("password");
  String redirectUri = form.getFirstValue("redirect_uri");
  if (redirectUri == null) {
    redirectUri = "/console/";
  }
  if ("token".equals(responseType)) {
    if (username != null && password != null) {
      try {
        HobsonUser user = accessManager.authenticate(username, password);
        String token = accessManager.createToken(user);
        getResponse().redirectSeeOther(redirectUri + "#access_token=" + token + "&token_type=bearer&id_token=" + token);
      } catch (HobsonAuthenticationException e) {
        sendErrorRedirect(redirectUri, "invalid_request", e.getLocalizedMessage());
      }
    } else {
      sendErrorRedirect(redirectUri, "invalid_request", "Missing username and/or password");
    }
  } else {
    sendErrorRedirect(redirectUri, "invalid_request", "Invalid response type");
  }
  return new EmptyRepresentation();
}

代码示例来源:origin: org.restlet.jse/org.restlet.example

/**
 * Update the underlying user according to the given representation.
 */
@Put
public void storeUser(Representation entity) throws ResourceException {
  Form form = new Form(entity);
  this.user.setFirstName(form.getFirstValue("firstName"));
  this.user.setLastName(form.getFirstValue("lastName"));
  this.user.setImage(form.getFirstValue("image"));
  getObjectsFacade().updateUser(this.user);
  getResponse().redirectSeeOther(getRequest().getResourceRef());
}

代码示例来源:origin: org.restlet.jse/org.restlet.example

/**
 * Update the underlying contact according to the given representation.
 */
@Put
public void storeContact(Representation entity) throws ResourceException {
  final Form form = new Form(entity);
  this.contact.setFirstName(form.getFirstValue("firstName"));
  this.contact.setLastName(form.getFirstValue("lastName"));
  this.contact.setImage(form.getFirstValue("image"));
  this.contact.setNickname(form.getFirstValue("nickname"));
  this.contact.setFoafUri(form.getFirstValue("foafUri"));
  getObjectsFacade().updateContact(this.user, this.contact);
  getResponse().redirectSeeOther(getRequest().getResourceRef());
}

代码示例来源:origin: org.restlet.jse/org.restlet.example

/**
 * Accept the representation of a new contact, and create it.
 */
@Post
public void acceptContact(Representation entity) throws ResourceException {
  Form form = new Form(entity);
  Contact contact = new Contact();
  contact.setFirstName(form.getFirstValue("firstName"));
  contact.setLastName(form.getFirstValue("lastName"));
  contact.setImage(form.getFirstValue("image"));
  contact.setNickname(form.getFirstValue("nickname"));
  contact.setFoafUri(form.getFirstValue("foafUri"));
  contact = getObjectsFacade().createContact(this.user, contact);
  getResponse().redirectSeeOther(
      getChildReference(getRequest().getResourceRef(),
          contact.getId()));
}

相关文章