11-26-2009 06:36 PM
11-26-2009 07:47 PM
11-26-2009 09:43 PM
// Webscript URL
String url = "http://localhost:8080/alfresco/wcservice/controlled-metadata/subjects?format=json";
// Build http request
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
// Prepare callback methods for error and success
RequestCallback callback = new RequestCallback() {
public void onError(Request request, Throwable exception) {
Window.alert("Error: " + exception.getMessage());
}
public void onResponseReceived(Request request, Response response) {
if (200 == response.getStatusCode()) {
// ANY CUSTOM method to parse JSON response
parseResponse(response.getText());
} else {
Window.alert("Error: Couldn't retrieve JSON (" + response.getStatusText() + ")");
}
}
};
// SEND Request to server and catch any errors.
try {
builder.sendRequest(null, callback);
} catch (RequestException e) {
Window.alert("Error: Couldn't retrieve JSON (" + e.getMessage() + ")");
}
11-26-2009 09:52 PM
private static final String GET = "GET";
private String webscriptUrl = "http://localhost:8080/alfresco/service/controlled-metadata/subjects?format=xml";
private String username;
private String password;
public void getStuffFromXML() throws Exception {
// Build request url
URL url = new URL(webscriptUrl);
// Get response
InputStream inputStream = submitGetRequest(url, username, password);
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse(inputStream);
// Normalize text representation
doc.getDocumentElement().normalize();
// Parse XML response
doSomethingUseful();
}
/**
* Submit an HTTP GET request to the specified url
*/
private InputStream submitGetRequest(URL url, String username, String password) throws IOException {
// openConnection() doesn't actually open the connection,
// just gives you a URLConnection. connect() will open the connection.
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod(GET);
// Write auth header
BASE64Encoder encoder = new BASE64Encoder();
String encodedCredential = encoder.encode( (username + ":" + password).getBytes() );
connection.setRequestProperty("Authorization", "BASIC " + encodedCredential);
// Do request
connection.connect();
return connection.getInputStream();
}
02-12-2010 10:31 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.