Skip to Content

SAPUI5 consuming Java web service

Hello experts,

I'm following this blog to implement s4hana cloud sdk step 9 Implement and Deploy a Frontend Application.

https://blogs.sap.com/2017/09/09/step-9-with-sap-s4hana-cloud-sdk-implement-and-deploy-a-frontend-application/

I've set destination to Java application

In my ui5 application controller, onInit event, i try to make a request to java app.

$.ajax({
				type: "GET",
				url: "/FirstApp/products",
				dataType: "json",
				async: true,
				success: function(oData) {
					console.log(oData);
				},
				error: function(error) {
					console.log(error);
				}
			});

It returns no data but this error

<!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">
    <h1>Unauthorized</h1>
        <HR size="1" noshade="noshade">
            <p>
                <b>type</b> Status report
            </p>
            <p>
                <b>message</b>
                <u>Unauthorized</u>
            </p>
            <p>
                <b>description</b>
                <u>This request requires HTTP authentication.</u>
            </p>
        </body>
    </html>

I later add header to ajax call

$.ajax({
				type: "GET",
				url: "/FirstApp/products",
				dataType: "json",
				async: true,
headers: {
		'Authorization': 'Basic ' + btoa('<username>:<password>')
				},

				success: function(oData) {
					console.log(oData);
				},
				error: function(error) {
					console.log(error);
				}
			});

But it still doesn't work.

What could cause this error?

Thanks in advance.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    avatar image
    Former Member
    Nov 10, 2017 at 11:49 AM

    You have to setup both. The manifest.yml and xs-app.json.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 07, 2017 at 11:44 AM

    You have to set you desired destination in the app-router configuration. You did it in cloud platform cockpit. Those are completely different destinations.

    Add comment
    10|10000 characters needed characters exceeded

  • Nov 07, 2017 at 10:23 PM

    Hi Frank,

    Thanks for your reply.

    I don't get your "app-router configuration". You mean manifest.json or neo-app.json?

    In my neo-app.json, I included destination:

    {
    	"welcomeFile": "/webapp/index.html",
    	"routes": [{
    		"path": "/resources",
    		"target": {
    			"type": "service",
    			"name": "sapui5",
    			"entryPath": "/resources"
    		},
    		"description": "SAPUI5 Resources"
    	}, {
    		"path": "/test-resources",
    		"target": {
    			"type": "service",
    			"name": "sapui5",
    			"entryPath": "/test-resources"
    		},
    		"description": "SAPUI5 Test Resources"
    	}, {
    		"path": "/FirstApp",
    		"target": {
    			"type": "destination",
    			"name": "FirstApp"
    		},
    		"description": "First App Java application"
    	}],
    	"sendWelcomeFileRedirect": true
    }
    

    Please let me know if this is correct.

    Thanks in advance.

    Tri

    Add comment
    10|10000 characters needed characters exceeded