restfull + url重定向

时间:2016-07-17 01:54:36

标签: java rest url-redirection

我真的google了很多,寻找解决方案和示例,但找不到任何。 我的问题是,我正在使用java和RESTfull,我想要的是重定向请求。 例如:POST或GET调用:http:/ test / test 这应该重定向到任何其他URL。 我需要这个用于Dropbox api。但response.sendRedirect(authorizePageUrl)不起作用。我的主要问题是,如何获取HttpServletRequest和HttpServletResponse以便我可以使用它。我真的需要帮助。

这是我的代码的一部分:

@Path("/")
public class Dropbox extends AbstractHandler{

private final String USER_AGENT = "Mozilla/5.0";
static String username = System.getProperty("user.name");
//@Context  static HttpServletRequest request;
//@Context  static HttpServletResponse response;

@GET
@Path("/dropBox")
@Consumes(MediaType.MULTIPART_FORM_DATA)
/*
 * This method calls the DropBox API 
 */

public static Response DropBox( 
        @Context HttpServletRequest request,
        @Context HttpServletResponse response){
    // Get your app key and secret from the Dropbox developers website.
    final String APP_KEY = "xxxxxxxxx";
    final String APP_SECRET = "xxxxxxxxxxxxx";
    DbxAppInfo appInfo = new DbxAppInfo(APP_KEY, APP_SECRET);



    DbxRequestConfig config = new DbxRequestConfig("JavaTutorial/1.0",
        Locale.getDefault().toString());
    DbxWebAuth auth = new DbxWebAuth(config, appInfo);

    //redirect URL 
    String redirectUri = "http://localhost:8080/DropTest1/drop/dropBox";


    // Select a spot in the session for DbxWebAuth to store the CSRF token.
  //System.out.println("REQUEST: "+request);

        // Select a spot in the session for DbxWebAuth to store the CSRF token.
        HttpSession session = request.getSession(true);
        String sessionKey = APP_SECRET;
        DbxSessionStore csrfTokenStore = new DbxStandardSessionStore(session, sessionKey);


        // Build an auth request
          DbxWebAuth.Request authRequest = DbxWebAuth.newRequestBuilder()
               .withRedirectUri(redirectUri, csrfTokenStore)
               .build();

          // Start authorization.
          String authorizePageUrl = auth.authorize(authRequest);

          // Redirect the user to the Dropbox website so they can approve our application.
          // The Dropbox website will send them back to "http://my-server.com/dropbox-auth-finish"
          // when they're done.
          try {
            response.sendRedirect(authorizePageUrl);

        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

我真的很绝望。

不:如果在其他地方解决了这个问题,我很抱歉。

提前非常感谢!!!

0 个答案:

没有答案