rddill-IBM / ZeroToBlockchain

Tutorial for Zero to Blockchain series
342 stars 924 forks source link

[{"code":400,"message":"Authorization failure"}]] #11

Closed jstela closed 6 years ago

jstela commented 6 years ago

Hi Bob,

At Chapter06, when I'm trying to Display Order status, Im getting this error : image

And when I'm trying to Add a Order, getting the same authorization problem: image

Could you help me to understand how to fix it ?

rddill-IBM commented 6 years ago

This error will be created if you have docker running and suspend your system or your VM. In that situation, when your system restarts, the docker images are restarted. Because docker images are stateless, the keystore created when you installed your .bna file (buildAndDeploy script) is not restored. Try executing the following sequence of commands:

./buildAndDeploy
npm start

and in your browser,

Admin --> Preload Network
Roles --> Load Buyer User Experience

and then try to add a record.

jstela commented 6 years ago

I did it. I got some errors after click Preload Network:

image

rddill-IBM commented 6 years ago

The app activates the web socket when the browser completes loading the index.html page. Hold down the shift key and click the page reload button to go back to the server code and reload Chapter6. This will automatically activate the web sockets and is required whenever you restart your server side (npm start, node index). That should resolve the web socket error. The error code 500 messages are something composer does not trap correctly. The code in the hlcAdmin and autoLoad files includes code to prevent this error from displaying, however recent releases of hyperledger composer now display this error message on the console. It does not affect how the application responds.

jstela commented 6 years ago

Hi Bob, I tried and I'm getting the same error.

Thank you so much for all your support!

rddill-IBM commented 6 years ago

I am unable to duplicate your error on my OSX machine. I can see that you're running Ubuntu, so will test in a clean Ubuntu image. If I cannot recreate your error, then may need a zipped copy of your Chapter06 folder.

jstela commented 6 years ago

HI Bob,

I can send you the credentials to connect on my envionment. Its a test env hosted at Google Cloud. Please, let me know if that works for you and a way to send it to you (e-mail, skype ,etc)

Ty again

rddill-IBM commented 6 years ago

On a clean installation of Ubuntu, with a clean installation of the repository, taking the default options as documented in the Chapter03 readme.MD file, no errors encountered on installation. Chapter06: copy contents of each file in the Documentation/answers folder to the appropriate file in composer, HTML and js, run ./buildAndDeploy, npm install, npm start. Chapter06 runs as expected with status 500 error messages displayed and the app running correctly in the browser. The error is either in the code (not updated correctly) or in your environment.

node --version 
***==> should return v8.9.4***

composer --version
***==> should return v0.16.0***

in the browser, 
 -->Admin --> load Admin User Experience
  click on "touch a network, check compatibility"
  ***==> should return version 0.16.0***
jstela commented 6 years ago

slightly different: node -- version =>v8.9.3 composer --version =>v0.16.2 "touch a network, check compatibility" version | 0.16.2

rddill-IBM commented 6 years ago

looking at one of your earlier comments, which I had previously missed. You're running on google cloud. I expect that google has restrictions on how you open web sockets, which this app is using. I haven't done that with google yet, so don't know the exact process, but I am sure that the mechanism you use to create and connect to a web socket will be different on google cloud than it is in a native environment, where this was tested. The place where you'll want to look at changing code is in the Z2B_Services.js file in the following two routines:

/**
 * the user experience is enhanced if the browser can be notified of aysnchronous events. 
 * the createMessageSockett function creates a web socket service to which the browser can
 * attach. 
 * @param {integer} _port - port number to use for this socket connection
 * @returns {websocket} - web socket connection to be used on the server side.
 */
    m_connection: null,
    m_socketAddr: null,
    m_socket: null,
    createMessageSocket: function (_port)
    {
        var port = (typeof(_port) == 'undefined' || _port == null) ? app.get('port')+1 : _port
        if (this.m_socket == null)
        {
            this.m_socketAddr = port;
            this.m_socket= new ws.server({httpServer: http.createServer().listen(this.m_socketAddr)});
            var _this = this;            
            this.m_socket.on('request', function(request) 
            {
                _this.m_connection = request.accept(null, request.origin);
                _this.m_connection.on('message', function(message)
                {
                    console.log(message.utf8Data);
                    _this.m_connection.sendUTF('connected');
                    _this.m_connection.on('close', function(m_connection) {console.log('m_connection closed'); });
                });
            });
        }
        return {conn: this.m_connection, socket: this.m_socketAddr};
    },
/**
 * the cs_connection is used to display blockchain information to the web browser over
 * a sepaarate port from the user experience socket. 
 * @returns {websocket} - web socket connection to be used on the server side.
 */

    cs_connection: null,
    cs_socketAddr: null,
    cs_socket: null,
    createChainSocket: function ()
    {
        var port =  app.get('port')+2;
        if (this.cs_socket == null)
        {
            this.cs_socketAddr = port;
            this.cs_socket= new ws.server({httpServer: http.createServer().listen(this.cs_socketAddr)});
            var _this = this;            
            this.cs_socket.on('request', function(request) 
            {
                _this.cs_connection = request.accept(null, request.origin);
                _this.cs_connection.on('message', function(message)
                {
                    console.log(message.utf8Data);
                    _this.cs_connection.sendUTF('connected');
                    _this.cs_connection.on('close', function(cs_connection) {console.log('cs_connection closed'); });
                });
            });
        }
        return {conn: this.cs_connection, socket: this.cs_socketAddr};
    }

}