-2

I am not a programmer but have to build some demos using different programming languages as part of my job. I am trying to use a REST API webservice that provides an oauth token first and using this token I need to invoke another webservice. I don't know where to start - I have googled to look for samples in jsp but found nothing. Can I get some samples or high level guidance on how to get an access-token and use this in subsequent POST calls?

1
  • maybe duplicate URL or URL Commented May 1, 2016 at 8:59

1 Answer 1

0

I figured it out by just starting a new JSP project from scratch. I am able to get the OAUTH refresh token from the webservice.

<%@page import="java.io.*"%>
<%@page import="java.util.*"%>
<%@page import="org.apache.commons.*" %>
<%@page import="net.sf.json.JSONObject"%>
<%@page import="net.sf.json.JSONSerializer"%>

<%@page import="org.apache.commons.httpclient.HttpClient"%>
<%@page import="org.apache.commons.httpclient.methods.PostMethod;"%> 

<%

String sp_clientid="64557e87-806e-41bb-9760-acc42de3f281";
String sp_clientsecret="4c115ba5-58d8-44d0-9378-0abe9d1bb9f8";
String sp_refreshtoken="40b19430-5d83-42f6-8b27-14c9cf70b8c1";

String GRANT_TYPE = "refresh_token";
String PARAM_GRANT_TYPE = "refresh_token";

String url="https://api0.silverpop.com/oauth/token";
HttpClient httpclient = new HttpClient();
String responseText="";

PostMethod post = new PostMethod(url);
post.setParameter("client_id",sp_clientid);
post.setParameter("client_secret", sp_clientsecret);
post.setParameter("refresh_token", sp_refreshtoken);
post.setParameter("grant_type",PARAM_GRANT_TYPE);

httpclient.executeMethod(post);
//responseText=getResponseText(post);
InputStream is = post.getResponseBodyAsStream();
Scanner scanner = new Scanner(is).useDelimiter("\\A");
responseText=scanner.hasNext() ? scanner.next() : "";

System.out.println(responseText);

%>



<html>
<head>

<link rel="stylesheet" type="text/css" href="default.css" media="screen" />     
</head>

<body>
        HELLO WORLD
        <TABLE BORDER="0" cellpadding="0" CELLSPACING="0" class=boldtable>
        <TR>
        <FONT size="15">
        <TD WIDTH="450" HEIGHT="600">

        </TD>


        </TR>
        </TABLE>
        </FONT>



</body>

</html>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.