与 Lotus Connections 交互

发布于 2024-09-26 07:35:50 字数 525 浏览 4 评论 0原文

我需要从某些 Lotus 连接站点获取数据,例如来自其他站点的用户状态。我尝试通过java与lotus建立连接,例如

> server = "https://" + path + param + "&format=full";
> URL profiles_url = new URL(server);
> // Open the URL: throws exception if not found
> HttpURLConnection profiles_conn = HttpURLConnection)profiles_url.openConnection();
> profiles_conn.connect();
> // Process the Atom feed in the response content
> readResponse(profiles_url.openStream(),args[0]);

但我总是得到响应:HTTP/1.1 401 Unauthorized 请给我任何建议吗?

I need to get the data from some lotus connection site, for example user's status, from the other site. I try to setup a connection with lotus via java, e.g.

> server = "https://" + path + param + "&format=full";
> URL profiles_url = new URL(server);
> // Open the URL: throws exception if not found
> HttpURLConnection profiles_conn = HttpURLConnection)profiles_url.openConnection();
> profiles_conn.connect();
> // Process the Atom feed in the response content
> readResponse(profiles_url.openStream(),args[0]);

But I always get the Response: HTTP/1.1 401 Unauthorized
Please give me any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柠檬色的秋千 2024-10-03 07:35:50

我这样解决了身份验证问题:

protected void doView(RenderRequest rRequest, RenderResponse rResponse) throws PortletException, IOException, UnavailableException {
try { 
rResponse.setContentType("text/html");          
        URL url = new URL(
                "https://xxx/activities/service/atom2/todos");
        URLConnection con = url.openConnection();
        con.setConnectTimeout(150000);
        con.setReadTimeout(150000);
        writeCookies(con, rRequest);                        

        DO_SOMETHING (con.getInputStream());
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}       


private String doesLTPATokenCookieExists(RenderRequest request) {
Cookie[] cookie = request.getCookies();
for (int i = 0; i < cookie.length; i++) {
    System.out.println("Cookie Name " + cookie[i].getName());
    if (cookie[i].getName().equals("LtpaToken"))
        return cookie[i].getValue();
}
return null;
}

public URLConnection writeCookies(URLConnection urlConn,
    RenderRequest request) {
String cookieString = "";
cookieString += "LtpaToken" + "=" + doesLTPATokenCookieExists(request) + "; ";
urlConn.setRequestProperty("Cookie", cookieString);     
return urlConn;
}

I solved the authentication issue this way:

protected void doView(RenderRequest rRequest, RenderResponse rResponse) throws PortletException, IOException, UnavailableException {
try { 
rResponse.setContentType("text/html");          
        URL url = new URL(
                "https://xxx/activities/service/atom2/todos");
        URLConnection con = url.openConnection();
        con.setConnectTimeout(150000);
        con.setReadTimeout(150000);
        writeCookies(con, rRequest);                        

        DO_SOMETHING (con.getInputStream());
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}       


private String doesLTPATokenCookieExists(RenderRequest request) {
Cookie[] cookie = request.getCookies();
for (int i = 0; i < cookie.length; i++) {
    System.out.println("Cookie Name " + cookie[i].getName());
    if (cookie[i].getName().equals("LtpaToken"))
        return cookie[i].getValue();
}
return null;
}

public URLConnection writeCookies(URLConnection urlConn,
    RenderRequest request) {
String cookieString = "";
cookieString += "LtpaToken" + "=" + doesLTPATokenCookieExists(request) + "; ";
urlConn.setRequestProperty("Cookie", cookieString);     
return urlConn;
}
转身以后 2024-10-03 07:35:50

您没有提及如何进行身份验证,这一点至关重要。正如 401 错误所暗示的那样,Connections 不会将您的请求视为已通过身份验证。您需要一个有效的 Authenticator 实例,但您的代码片段表明您还没有实现这一点,对吗?

(顺便说一句,在使用 Lotus Connections API 时,建议使用 Apache Abdera 项目)。

You don't mention how you're authenticating, which is crucial. As the 401 error implies, Connections isn't treating your request as being authenticated. You need a valid Authenticator instance in there, but your code snippet suggests you haven't got that going, correct?

(As an aside, the Apache Abdera project is recommended when working with the Lotus Connections API).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文