Statistics
| Revision:

root / hci / trunk / eneraptor-web-app / grails-app / controllers / com / eneraptor / hci / LogicRequestController.groovy @ 66

History | View | Annotate | Download (1.82 KB)

1 3 alexbesir
package com.eneraptor.hci
2
3 58 alexbesir
import grails.converters.*
4
5 3 alexbesir
class LogicRequestController {
6
7
        def reportService
8 6 alexbesir
        def hciLogicCommService
9 3 alexbesir
10
    def testConnection = {
11
12
                def output = "";
13
                output += reportService.println("Conection test using")
14 66 alexbesir
                output += reportService.println("Logic IP address: " + session.hwSet.IPaddress)
15
                output += reportService.println("Logic port number: " + session.hwSet.portNumber)
16 3 alexbesir
17
                output += reportService.println("Test started")
18 6 alexbesir
19 52 alexbesir
                String reqStr = "<?xml version=\"1.0\"?><hci-request type=\"checkConnection\"><data>12345</data></hci-request>"
20 66 alexbesir
                Map testReply = hciLogicCommService.getReplyToRequest(reqStr,session.hwSet.IPaddress,session.hwSet.portNumber)
21 6 alexbesir
22
                if(testReply['status'] == "error") {
23
                        output += reportService.println("<span style='color:red;'>Error: " + testReply['content'] + "</span>")
24
                } else {
25
                        output += reportService.println("Connection established succesfully")
26 58 alexbesir
                        def rootNode = XML.parse(testReply['content'])
27
                        if(rootNode.data == "12345") {
28
                                output += reportService.println("<span style='color:green;'>Logic unit replied! The eneraptor system is set up properly.</span>")
29 6 alexbesir
                        } else {
30
                                output += reportService.println("<span style='color:red;'>The connection was established, but there was no reply from the logic unit.</span>")
31 58 alexbesir
                                output += reportService.println("<span style='color:red;'>You should check the logic's port number and IP address.</span>")
32
                                output += reportService.println("<span style='color:red;'> Returned: " + testReply['content'].encodeAsHTML() + "</span>")
33
                                output += reportService.println("<span style='color:red;'>Should be: " + "<logic-response type=\"checkConnection\"><data>12345</data></logic-response>".encodeAsHTML() + "</span>")
34 6 alexbesir
                        }
35
                }
36
37 3 alexbesir
                output += reportService.println("Test ended")
38
39
                [output:output]
40
41
        }
42
43
}