cancel
Showing results for 
Search instead for 
Did you mean: 

Using SCP Predictive Service in Java app

Former Member
0 Kudos

I need to call Predictive Services inside Java servlet. When I make GET request for retrieving registered datasets using the link <C4PA URL>/api/analytics/dataset (where <C4PA URL> is https://aac4paservices<SCP account name>.hanatrial.ondemand.com/com.sap.aa.c4pa.services) using class CloaseableHttpClient, I get the following HTML page that says that Javascript is not supported.

<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
    <meta http-equiv="pragma" content="no-cache" />
</head>
<body style="background-color:#FFFFFF" onload="var url=window.location.hash;if(url&&0!==url.length){var anchorCookie='oucrsrzceptfcaokfcvabtltx_anchor="'+encodeURIComponent(url)+'"';document.cookie=anchorCookie}document.forms[0].submit()">
    <p>
        <script language="javascript">
            document.write("Please wait ...");
        </script>
    </p>
    <noscript>
        <p>Note: Your browser does not support JavaScript or it is turned off. Press the button to proceed.</p>
    </noscript>
    <form method="post" action="https://accounts.sap.com/saml2/idp/sso/accounts.sap.com">
        <input type="hidden" name="SAMLRequest" value="PEF1dGhukVoNVRPT08L2RXN0Pg==" />
        <input type="hidden" name="RelayState" value="oucrsrzceptfcaokfcvabtltx" />
        <noscript>
            <input type="submit" value="Continue" />
        </noscript>
    </form>
</body>
</html> 

What are the other ways for using SCP Predictive services inside Java servlet? The only guides that I found on the Internet were about making calls to Predictive Service resources using Javascript (e.g., in SAPUI5 apps).

I would like to note that I'm using SCP trial account. I thought that changing authentication configuration of aac4paservices app to only support basic authentication with username and password, I could log in using basic authentication. However, after I changed authentication configuration and restarted aac4paservices app, I kept getting 401 error. That's when I accidentally found this blog post. Here is what is says in the comment section:

"It seems only SAML authentication is supported in the HCP free developer trial (and not basic auth) and SAML authentication is difficult to configure in Postman"

Is that correct? If yes, has the reason for getting "Javascript not supported" error been that I was redirected to SAML login which required Javascript? If there is no way to use basic authentication in trial account, is there any other way to call Predictive services inside Java app?

Accepted Solutions (1)

Accepted Solutions (1)

abdel_dadouche
Active Contributor
0 Kudos

Hi Jake,


First of all, thanks for providing your feedback.


The SAP Cloud Platform predictive services supports other forms of authentication than SAML even on trial. For example OAuth is available, but you need to know how to get your key.


I wrote a series of tutorials a while back on this topic. You can check the configuration from the following tutorial (step 5): https://www.sap.com/developer/tutorials/hcpps-ps-configure.html


Can I ask you then using Postman to validate that this is actually properly working (without the Postman Interceptor).


If Postman (or any other REST Client works fine), then can you share your Java code as there is many ways to address this?


Thanks

Abdel

Former Member
0 Kudos

Hi Abdel. Thank you very much for your help.

1) Do you know if Basic authentication is supported for Trial?

2) I don't have experience with OAuth authentication. If I can't use Basic authentication and have to stick with OAuth, can you tell me how I would configure Postman request to use OAuth with aac4paservices app? Would I need to use OAuth 2.0 or OAuth 1.0? What would I write in Authorization section of Postman? Would I need to make custom authentication configuration of aac4paservices app?

abdel_dadouche
Active Contributor
0 Kudos

Hi,

You are very welcome!

Here are my answer

1) Basic Authentication is the most commonly used scheme for authentication.

It's the one used by the tutorial series I sent you earlier when using Postman as a REST client.

It requires a header property to be set with your encoded credentials.

Now in Java, you would do something like this:

URL url = new URL ("http://xyz");
String encoding = Base64Encoder.encode ("user:password");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty ("Authorization","Basic "+ encoding); 

2) OAuth is not really complex as well.

You will need to register a new OAuth client with a callback URL etc.

I was able to test that fairly quickly with Postman, so this works pretty well.

Abdel

jacqueso
Explorer
0 Kudos

Hi There,

I have the same issue and basic authentication to the predictive service does not seem to work, we are using an IDP on our cloudplatform. The link you provided no longer works. (https://www.sap.com/developer/tutorials/hcpps-ps-configure.html) can you please advise what the correct link is?

Any help would be appreciated.

Thanks

Answers (0)