Created
September 12, 2013 19:59
-
-
Save jpotts/6542996 to your computer and use it in GitHub Desktop.
Hitting the Public API of a local Alfresco 4.2.d server using the Google HTTP Client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.someco; | |
import java.io.IOException; | |
import com.google.api.client.http.GenericUrl; | |
import com.google.api.client.http.HttpRequest; | |
import com.google.api.client.http.HttpRequestFactory; | |
import com.google.api.client.http.HttpRequestInitializer; | |
import com.google.api.client.http.HttpTransport; | |
import com.google.api.client.http.javanet.NetHttpTransport; | |
import com.google.api.client.json.JsonObjectParser; | |
import com.google.api.client.json.jackson.JacksonFactory; | |
public class GoogleHttpClientExample { | |
public static final String SITES_URL = "http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/sites?maxItems=10"; | |
public static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport(); | |
public static void main(String[] args) { | |
try { | |
HttpRequestFactory requestFactory = HTTP_TRANSPORT | |
.createRequestFactory(new HttpRequestInitializer() { | |
@Override | |
public void initialize(HttpRequest request) | |
throws IOException { | |
request.setParser(new JsonObjectParser( | |
new JacksonFactory())); | |
request.getHeaders().setBasicAuthentication( | |
"admin", "admin"); | |
} | |
}); | |
HttpRequest request = requestFactory | |
.buildGetRequest(new GenericUrl( | |
GoogleHttpClientExample.SITES_URL)); | |
SiteList siteList = request.execute().parseAs(SiteList.class); | |
System.out.println("Up to 10 sites you can see are:"); | |
for (SiteEntry siteEntry : siteList.list.entries) { | |
System.out.println(siteEntry.entry.id); | |
} | |
System.out.println("Done"); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment