Created
March 6, 2014 13:26
consume-json-service
This file contains 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
public class JsonTest { | |
public static void main(String[] args) throws Exception { | |
HttpHost targetHost = new HttpHost("localhost", 8080, "http"); | |
DefaultHttpClient httpclient = new DefaultHttpClient(); | |
httpclient.getCredentialsProvider().setCredentials( | |
new AuthScope(targetHost.getHostName(), targetHost.getPort()), | |
new UsernamePasswordCredentials("username", "password")); | |
AuthCache authCache = new BasicAuthCache(); | |
BasicScheme basicAuth = new BasicScheme(); | |
authCache.put(targetHost, basicAuth); | |
BasicHttpContext ctx = new BasicHttpContext(); | |
ctx.setAttribute(ClientContext.AUTH_CACHE, authCache); | |
HttpPost post = new HttpPost("/<<portlet-context>>/api/secure/jsonws/sample/say-hello"); | |
List<NameValuePair> params = new ArrayList<NameValuePair>(); | |
params.add(new BasicNameValuePair("name", “Harish”)); | |
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF-8"); | |
post.setEntity(entity); | |
HttpResponse resp = httpclient.execute(targetHost, post, ctx); | |
resp.getEntity().writeTo(System.out); | |
httpclient.getConnectionManager().shutdown(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment