Coming Up for Air

Debugging GlassFish REST Requests

Friday, March 04, 2011 |

If you’ve been following my series on using the GlassFish REST interface, you’ve probably noticed that your JSON and XML output isn’t pretty-printed like mine. While there are several online tools that can fix that for you, there’s no need for the extra step. GlassFish will do that for you. Let’s look at how to make that happen.

To configure the REST interface, we can use the REST interface, in particular http://localhost:4848/management/domain/configs/config/server-config/_set-rest-admin-config

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
$ curl -X OPTIONS http://localhost:4848/management/domain/configs/config/server-config/_set-rest-admin-config
{
    "command": "_set-rest-admin-config",
    "exit_code": "SUCCESS",
    "extraProperties": {"methods": [
        {"name": "GET"},
        {
            "name": "POST",
            "messageParameters": {
                "debug": {
                    "acceptableValues": "",
                    "optional": "true",
                    "type": "string",
                    "defaultValue": ""
                },
                "indentLevel": {
                    "acceptableValues": "",
                    "optional": "true",
                    "type": "int",
                    "defaultValue": "-100"
                },
                "logInput": {
                    "acceptableValues": "",
                    "optional": "true",
                    "type": "string",
                    "defaultValue": ""
                },
                "logOutput": {
                    "acceptableValues": "",
                    "optional": "true",
                    "type": "string",
                    "defaultValue": ""
                },
                "showDeprecatedItems": {
                    "acceptableValues": "",
                    "optional": "true",
                    "type": "string",
                    "defaultValue": ""
                },
                "showHiddenCommands": {
                    "acceptableValues": "",
                    "optional": "true",
                    "type": "string",
                    "defaultValue": ""
                },
                "wadlGeneration": {
                    "acceptableValues": "",
                    "optional": "true",
                    "type": "string",
                    "defaultValue": ""
                }
            }
        }
    ]}
}

Here’s what each of those options mean:

  • debug - To the best of my knowledge, this option is not used.

  • indentLevel - If this option is 0 or greater, the output is pretty-printed, using this value as the indentation level.

  • logInput - Echo to the server log all REST requests.

  • logOutput - Echo to the server log all REST responses.

  • showDeprecatedItems - By default, deprecated items are not shown. If you need to see them, set this to true.

  • showHiddenCommands - By default, hidden commands are not shown. If you need to see them, set this to true. Be warned, though, that hidden commands are hidden for a reason. They are internal, undocumented commands and can be changed or removed without notice.

  • wadlGeneration - Since WADL generation is an expensive process, it is turned off by default. If you need WADL, set this to true. You can then retrieve the WADL document from http://localhost:4848/management/application.wadl. Be careful with that, the resulting file is HUGE.

For technical, implementation-specific reasons (which I won’t go into here), the first attempt to manipulate the REST configuration must be done via http://localhost:4848/management/domain/configs/config/server-config/_set-rest-admin-config. Once that’s done, the rest-config element will show up under server-config as expected. For example, to enable pretty-printing, for example, we can issue these requests:

1
2
3
4
5
6
$ curl -s -S -H "Accept: application/json" -X POST http://localhost:4848/management/domain/configs/config/server-config/_set-rest-admin-config
$ curl -s -S -H "Accept: application/json" -X POST -d indentLevel=4 http://localhost:4848/management/domain/configs/config/server-config/rest-config
{
    "message": "\"http:\/\/localhost:4848\/management\/domain\/configs\/config\/server-config\/rest-config\" updated successfully.",
    "exit_code": "SUCCESS"
}

And that’s all there is to it. Debugging your REST client issues should now be much simpler.

Search

    Quotes

    Sample quote

    Quote source

    About

    My name is Jason Lee. I am a software developer living in the middle of Oklahoma. I’ve been a professional developer since 1997, using a variety of languages, including Java, Javascript, PHP, Python, Delphi, and even a bit of C#. I currently work for Red Hat on the WildFly/EAP team, where, among other things, I maintain integrations for some MicroProfile specs, OpenTelemetry, Micrometer, Jakarta Faces, and Bean Validation. (Full resume here. LinkedIn profile)

    I am the president of the Oklahoma City JUG, and an occasional speaker at the JUG and a variety of technical conferences.

    On the personal side, I’m active in my church, and enjoy bass guitar, running, fishing, and a variety of martial arts. I’m also married to a beautiful woman, and have two boys, who, thankfully, look like their mother.

    My Links

    Publications