use of org.apache.commons.httpclient.methods.GetMethod in project zeppelin by apache.
the class ZeppelinRestApiTest method getNoteContent.
private String getNoteContent(String id) throws IOException {
GetMethod get = httpGet("/notebook/export/" + id);
assertThat(get, isAllowed());
get.addRequestHeader("Origin", "http://localhost");
Map<String, Object> resp = gson.fromJson(get.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
}.getType());
assertEquals(200, get.getStatusCode());
String body = resp.get("body").toString();
// System.out.println("Body is " + body);
get.releaseConnection();
return body;
}
use of org.apache.commons.httpclient.methods.GetMethod in project Openfire by igniterealtime.
the class CrowdManager method getAllUsers.
/**
* Get all the users from Crowd
* @return a List of User containing all the users stored in Crowd
* @throws RemoteException
*/
public List<User> getAllUsers() throws RemoteException {
if (LOG.isDebugEnabled())
LOG.debug("fetching all crowd users");
int maxResults = 100;
int startIndex = 0;
List<User> results = new ArrayList<>();
StringBuilder request = new StringBuilder("search?entity-type=user&expand=user&restriction=active%3dtrue").append("&max-results=").append(maxResults).append("&start-index=");
try {
while (true) {
GetMethod get = createGetMethodXmlResponse(crowdServer.resolve(request.toString() + startIndex));
Users users = null;
try {
int httpCode = client.executeMethod(get);
if (httpCode != 200) {
handleHTTPError(get);
}
users = JAXB.unmarshal(get.getResponseBodyAsStream(), Users.class);
} finally {
get.releaseConnection();
}
if (users != null && users.user != null) {
for (User user : users.user) {
user.name = JID.escapeNode(user.name);
results.add(user);
}
if (users.user.size() != maxResults) {
break;
} else {
startIndex += maxResults;
}
} else {
break;
}
}
} catch (IOException ioe) {
handleError(ioe);
}
return results;
}
use of org.apache.commons.httpclient.methods.GetMethod in project Openfire by igniterealtime.
the class CrowdManager method getUserGroups.
/**
* Get all the groups of a given username
* @param username
* @return a List of groups name
* @throws RemoteException
*/
public List<String> getUserGroups(String username) throws RemoteException {
username = JID.unescapeNode(username);
if (LOG.isDebugEnabled())
LOG.debug("fetch all crowd groups for user:" + username);
int maxResults = 100;
int startIndex = 0;
List<String> results = new ArrayList<>();
StringBuilder request = new StringBuilder("user/group/nested?username=").append(urlEncode(username)).append("&max-results=").append(maxResults).append("&start-index=");
try {
while (true) {
GetMethod get = createGetMethodXmlResponse(crowdServer.resolve(request.toString() + startIndex));
Groups groups = null;
try {
int httpCode = client.executeMethod(get);
if (httpCode != 200) {
handleHTTPError(get);
}
groups = JAXB.unmarshal(get.getResponseBodyAsStream(), Groups.class);
} finally {
get.releaseConnection();
}
if (groups != null && groups.group != null) {
for (Group group : groups.group) {
results.add(group.name);
}
if (groups.group.size() != maxResults) {
break;
} else {
startIndex += maxResults;
}
} else {
break;
}
}
} catch (IOException ioe) {
handleError(ioe);
}
return results;
}
use of org.apache.commons.httpclient.methods.GetMethod in project Openfire by igniterealtime.
the class CrowdManager method createGetMethodXmlResponse.
private GetMethod createGetMethodXmlResponse(URI uri) {
GetMethod get = new GetMethod(uri.toString());
get.addRequestHeader(HEADER_ACCEPT_APPLICATION_XML);
get.addRequestHeader(HEADER_ACCEPT_CHARSET_UTF8);
return get;
}
use of org.apache.commons.httpclient.methods.GetMethod in project Openfire by igniterealtime.
the class CrowdManager method getGroupMembers.
/**
* Get the members of the given group
* @param groupName
* @return a List of String with the usernames members of the given group
* @throws RemoteException
*/
public List<String> getGroupMembers(String groupName) throws RemoteException {
if (LOG.isDebugEnabled())
LOG.debug("Get all members for group:" + groupName);
int maxResults = 100;
int startIndex = 0;
List<String> results = new ArrayList<>();
StringBuilder request = new StringBuilder("group/user/nested?groupname=").append(urlEncode(groupName)).append("&max-results=").append(maxResults).append("&start-index=");
try {
while (true) {
GetMethod get = createGetMethodXmlResponse(crowdServer.resolve(request.toString() + startIndex));
Users users = null;
try {
int httpCode = client.executeMethod(get);
if (httpCode != 200) {
handleHTTPError(get);
}
users = JAXB.unmarshal(get.getResponseBodyAsStream(), Users.class);
} finally {
get.releaseConnection();
}
if (users != null && users.user != null) {
for (org.jivesoftware.openfire.crowd.jaxb.User user : users.user) {
results.add(JID.escapeNode(user.name));
}
if (users.user.size() != maxResults) {
break;
} else {
startIndex += maxResults;
}
} else {
break;
}
}
} catch (IOException ioe) {
handleError(ioe);
}
return results;
}
Aggregations