开发者

Interaction with Lotus Connections

开发者 https://www.devze.com 2023-01-19 09:46 出处:网络
I need to get the data from some lotus connectionsite, for example user\'s status,fromthe other site. I try to setup a connection with lotus via java, e.g.

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 U开发者_JAVA百科RL(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?


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;
}


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号