public class JCurl extends Object
//Get a session token
JCurl jcurl = JCurl.builder()
.method(JCurl.HttpMethod.POST)
.keystore("bot.user1.p12") //Set user certificate for authentication
.storepass("changeit")
.storetype("pkcs12")
.extract("skey", "token") //Extract the value of the JSON tag "token" to a map entry under "skey"
.build();
HttpURLConnection connection = jcurl.connect("https://localhost.symphony.com:8444/sessionauth/v1/authenticate");
JCurl.Response response = jcurl.processResponse(connection);
String sessionToken = response.getTag("skey"); //Retrieve the extracted tag saved as "skey"
//Get session info (returns the requesting user ID)
jcurl = JCurl.builder()
.method(JCurl.HttpMethod.GET) //HTTP GET is the default; this line can be skipped
.header("sessionToken", sessionToken) //Set the session token in the request header
.extract("uid", "userId") //Extract the user ID from the response as "uid"
.build();
connection = jcurl.connect("https://localhost.symphony.com:8443/pod/v1/sessioninfo");
response = jcurl.processResponse(connection);
String userId = response.getTag("uid");
System.out.println("User ID: " + userId);
//Create an IM with user 123456
jcurl = JCurl.builder()
.method(JCurl.HttpMethod.POST) //Set implicitly by specifying ".data()"; this line can be skipped
.header("sessionToken", sessionToken) //Set the session token in the request header
.data("[123456]") //Set the JSON payload of the request
.extract("sid", "id") //Extract the stream ID of the conversation as "sid"
.build();
connection = jcurl.connect("https://localhost.symphony.com:8443/pod/v1/im/create");
response = jcurl.processResponse(connection);
String streamId = response.getTag("sid");
System.out.println("Stream ID: " + streamId);
//Print the output of the call
System.out.println(response.getOutput()); //Prints '{"id": "wFwupr-KY3QW1oEkjE61x3___qsvcXdFdA"}'
| Modifier and Type | Class and Description |
|---|---|
static class |
JCurl.Builder |
static class |
JCurl.HttpMethod |
class |
JCurl.Response |
| Constructor and Description |
|---|
JCurl() |
public static void main(String[] argv) throws IOException, CertificateParsingException, KeyManagementException, NoSuchAlgorithmException
Entry point for command-line usage. Call java -jar jcurl.jar for usage info.
argv - an array of String objects.IOException - if any.CertificateParsingException - if any.KeyManagementException - if any.NoSuchAlgorithmException - if any.public static JCurl.Builder builder()
Create a builder.
JCurl.Builder object.public HttpURLConnection connect() throws IOException
JCurl.Builder.url().HttpURLConnection object.IOException - if any.public HttpURLConnection connect(URL url) throws IOException
url - a URL object.HttpURLConnection object.IOException - if any.public HttpURLConnection connect(String urlString) throws IOException
Connect to the provided URL.
urlString - a String object.HttpURLConnection object.IOException - if any.public JCurl.Response processResponse(HttpURLConnection con) throws IOException, CertificateParsingException
JCurl.Response object returned can be printed
out with response.print().con - a HttpURLConnection object.JCurl.Response object.IOException - if any.CertificateParsingException - if any.public String getUrl()
public String getData()
public String getKeyStore()
public String getStoreType()
public String getStorePass()
public String getTrustStore()
public String getTrustType()
public String getTrustPass()
public String getProxyHost()
public String getProxyPort()
public String getNonProxyHosts()
public int getVerbosity()
public int getConnectTimeout()
public int getReadTimeout()
public boolean isTrustAllHostnames()
public boolean isTrustAllCerts()
public boolean isExtractCookies()
public JCurl.HttpMethod getMethod()
public String getContentType()
Copyright © 2019 The Symphony Software Foundation. All rights reserved.