Unable to consume RESTful api of Hippo

129 views
Skip to first unread message

Pradeepa Kadiyala

unread,
Jun 30, 2016, 7:51:56 AM6/30/16
to Hippo Community
 I have deployed my hippo CMS on a dev environment and enabled the RESTful services for the same using the essentials tool. 
My Dev server is a linux based serer with some IP and we are able to access the same by using the URL : http://aaa.bb.ccc.dd:8080/cms.
Post enabling my REST services i also get my documents list using the URL: http://aaa.bb.ccc.dd:8080/site/api/documents
BUt when i try to use the same url from one of my other intergrated applications using the following code i am getting an error:

restEndPoint=properties.getProperty("cmsRestapiAddress");
logger.info("StringTemplateUtilsCms::getTemplateList::Cms Mount point URL :"+restEndPoint);
URL url = new URL(restEndPoint);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod(serviceType);
Date currentDate = new Date();
Map<String,Object> params = new HashMap<String, Object>();
params.put("interactionDate", currentDate.toString());
String timestamp=generateCode();
//params.put("token", new String(KeyUtils.generateToken(timestamp)));
params.put("timestamp", timestamp);

StringBuilder postData = new StringBuilder();
for (Map.Entry<String,Object> param : params.entrySet()) {
if (postData.length() != 0) postData.append('&');
postData.append(URLEncoder.encode(param.getKey(), "UTF-8"));
postData.append('=');
postData.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8"));
}
byte[] postDataBytes = postData.toString().getBytes("UTF-8");
conn.setRequestProperty("Accept", serviceReturntype);
conn.setDoOutput(true);

conn.getOutputStream().write(postDataBytes);

if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));

here my property file entryu for the end point is :
cmsRestapiAddress=http\://localhost\:8080/site/api

When my above code hits the URL i get the below exception:
[INFO] [talledLocalContainer] 30.06.2016 17:01:07 WARN  http-nio-8080-exec-8 [JAXRSUtils.findTargetMethod:522] No operation matching request path "/site/api/" is found, Relative Path: /, HTTP Method: GET, ContentType: */*, Accept: text/html,application/xhtml+xml,image/webp,application/xml;q=0.9,*/*;q=0.8,. Please enable FINE/TRACE log level for more details.
[INFO] [talledLocalContainer] 30.06.2016 17:01:07 WARN  http-nio-8080-exec-8 [WebApplicationExceptionMapper.toResponse:72] javax.ws.rs.ClientErrorException: HTTP 404 Not Found

AM i missing any configs?
My mountpoint configurations are as follows:



Oscar Scholten

unread,
Jun 30, 2016, 8:24:11 AM6/30/16
to hippo-c...@googlegroups.com
Hi Pradeepa,

I suspect that there is a small problem in your properties file. You wrote it contains:

cmsRestapiAddress=http\://localhost\:8080/site/api

Can you try with:

cmsRestapiAddress=http\://localhost\:8080/site/api/documents

Cheers, Oscar

--
Hippo Community Group: The place for all discussions and announcements about Hippo CMS (and HST, repository etc. etc.)
 
To post to this group, send email to hippo-c...@googlegroups.com
RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
---
You received this message because you are subscribed to the Google Groups "Hippo Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hippo-communi...@googlegroups.com.
Visit this group at https://groups.google.com/group/hippo-community.
For more options, visit https://groups.google.com/d/optout.



--
Amsterdam - Oosteinde 11, 1017 WT Amsterdam
Boston - 71 Summer Street, Boston, MA 02110

Europe +31(0)20 522 4466
US +1 877 414 4776
www.onehippo.com | www.onehippo.org

Pradeepa Kadiyala

unread,
Jul 1, 2016, 1:41:50 AM7/1/16
to Hippo Community
Hi Oscar,

Thanks for the suggestion. I tried with the way you suggested. I am getting a HTTP 405 error now in my logs.

[main] INFO  util.StringTemplateUtilsCms  - StringTemplateUtilsCms::getTemplateList::Cms Mount point URL :http://localhost:8080/site/api/documents
[main] ERROR util.StringTemplateUtilsCms  - Exception in CMSRestAPI because : Failed : HTTP error code : 405
[main] ERROR org.springframework.batch.core.step.AbstractStep  - Encountered an error executing the step

Oscar Scholten

unread,
Jul 1, 2016, 3:57:11 AM7/1/16
to hippo-c...@googlegroups.com
Hi Pradeepa,

I'm assuming you are using the Content REST API [1]?

The Content REST API only supports GET operations. Looking at your code you are sending either a POST or PUT request. The following works for me:

        URL url = new URL("http://localhost:8080/site/api/documents");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");

        if (conn.getResponseCode() != 200) {
            throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
        }

        System.out.println(IOUtils.toString(conn.getInputStream(), StandardCharsets.UTF_8));

Cheers, Oscar


--
Hippo Community Group: The place for all discussions and announcements about Hippo CMS (and HST, repository etc. etc.)
 
To post to this group, send email to hippo-c...@googlegroups.com
RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
---
You received this message because you are subscribed to the Google Groups "Hippo Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hippo-communi...@googlegroups.com.
Visit this group at https://groups.google.com/group/hippo-community.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages