Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The  https://{gateway-host}:{gateway-port}/{gateway-path}/admin/api/v1/servicedefinitions endpoint accepts POST requests to create a brand new service definition. In case the service definition you are trying to create exists already an HTTP response with 500 error code will be returned.

Sample:

Code Block
$ cat testServiceDefinitionPayload.xml 
<?xml version="1.0" encoding="UTF-8"?>
<serviceDefinition>
    <service name="mySampleService" role="MYSAMPLEROLE" version="2.0.0">
        <dispatch classname="org.apache.knox.gateway.dispatch.PassAllHeadersNoEncodingDispatch" use-two-way-ssl="false"/>
        <policies>
            <policy role="webappsec"/>
            <policy name="Anonymous" role="authentication"/>
        </policies>
        <routes>
            <route path="/mysamplerole">
                <rewrite apply="mySampleService/mysamplerole/inbound/root" to="request.url"/>
                <rewrite apply="mySampleService/mysamplerole/outbound/mainpage" to="response.body"/>
            </route>
            <route path="/mysamplerole/**">
                <rewrite apply="mySampleService/mysamplerole/inbound/path" to="request.url"/>
            </route>
            <route path="/mysamplerole/views/SMARTSENSE/**/assets/hstapp-*.js">
                <rewrite apply="mySampleService/mysamplerole/outbound/apiendpoint" to="response.body"/>
            </route>
        </routes>
    </service>
    <rules>
        <rule dir="IN" name="mySampleService/mysamplerole/inbound/root" pattern="*://*:*/**/mysamplerole/">
            <rewrite template="{$serviceUrl[mySampleService]}/"/>
        </rule>
        <rule dir="IN" name="mySampleService/mysamplerole/inbound/path" pattern="*://*:*/**/mysamplerole/{**}">
            <rewrite template="{$serviceUrl[mySampleService]}/{**}"/>
        </rule>
        <rule dir="OUT" name="mySampleService/mysamplerole/outbound/sitepath">
            <rewrite template="{$frontend[path]}/mysamplerole"/>
        </rule>
        <rule dir="OUT" name="mySampleService/mysamplerole/outbound/websocket">
            <rewrite template="{$frontend[path]}/mysamplerolews/api/stomp/v1"/>
        </rule>

        <filter name="mySampleService/mysamplerole/outbound/apiendpoint">
            <content type="*/x-javascript">
                <apply path="/api/v1" rule="mySampleService/mysamplerole/outbound/extrapath"/>
            </content>
            <content type="application/javascript">
                <apply path="/api/v1" rule="mySampleService/mysamplerole/outbound/extrapath"/>
            </content>
        </filter>
        <filter name="mySampleService/mysamplerole/outbound/apiendpoint/html">
            <content type="text/html">
                <apply path="/api/v1" rule="mySampleService/mysamplerole/outbound/extrapath"/>
            </content>
        </filter>
        <filter name="mySampleService/mysamplerole/outbound/mainpage">
            <content type="*/html">
                <apply path="stylesheets/vendor.css" rule="mySampleService/mysamplerole/outbound/vendorcss" />
                <apply path="stylesheets/app.css" rule="mySampleService/mysamplerole/outbound/appcss" />
                <apply path="javascripts/vendor.js" rule="mySampleService/mysamplerole/outbound/vendorjs" />
                <apply path="javascripts/app.js" rule="mySampleService/mysamplerole/outbound/appjs" />
                <apply path="/img/logo.png" rule="mySampleService/mysamplerole/outbound/favicon"/>
                <apply path="/licenses/NOTICE.txt" rule="mySampleService/mysamplerole/outbound/notice"/>
            </content>
        </filter>
    </rules>
</serviceDefinition>


$ curl -H "Content-Type: application/xml" -iku admin:*** -d "@testServiceDefinitionPayload.xml" -X POST 'https://localhost:8443/gateway/admin/api/v1/servicedefinitions'

HTTP/1.1 100 Continue

HTTP/1.1 201 Created
Date: Tue, 19 Nov 2019 13:01:29 GMT
Set-Cookie: KNOXSESSIONID=node0cyn7v4caqbpk1wsou1qmdq1qb17.node0; Path=/gateway/admin; Secure; HttpOnly
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Set-Cookie: rememberMe=deleteMe; Path=/gateway/admin; Max-Age=0; Expires=Mon, 18-Nov-2019 13:01:29 GMT
Location: https://localhost:8443/gateway/admin/api/v1/servicedefinitions/mySampleService/MYSAMPLEROLE/2.0.0
Content-Length: 0
Server: Jetty(9.4.22.v20191022)

$ curl -H "Content-Type: application/xml" -iku admin:*** -d "@testServiceDefinitionPayload.xml" -X POST 'https://localhost:8443/gateway/admin/api/v1/servicedefinitions'
HTTP/1.1 100 Continue

HTTP/1.1 500 Internal Server Error
Date: Tue, 19 Nov 2019 13:01:36 GMT
Set-Cookie: KNOXSESSIONID=node0i9vn469u6vjkinkf8wh9hrk418.node0; Path=/gateway/admin; Secure; HttpOnly
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Set-Cookie: rememberMe=deleteMe; Path=/gateway/admin; Max-Age=0; Expires=Mon, 18-Nov-2019 13:01:36 GMT
Content-Type: application/json
Content-Length: 111
Server: Jetty(9.4.22.v20191022)

{ "CREATION_ERROR": "The requested service definition (mySampleService, MYSAMPLEROLE, 2.0.0) already exists!" }

...

Code Block
$ $ curl -H "Content-Type: application/xml" -iku admin:*** -X DELETE 'https://localhost:8443/gateway/admin/api/v1/servicedefinitions/mysampleservice/mysamplerole/2.0.0'
HTTP/1.1 200 OK
Date: Tue, 19 Nov 2019 13:23:15 GMT
Set-Cookie: KNOXSESSIONID=node015yf04uunrpyjocl05uz4or6k22.node0; Path=/gateway/admin; Secure; HttpOnly
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Set-Cookie: rememberMe=deleteMe; Path=/gateway/admin; Max-Age=0; Expires=Mon, 18-Nov-2019 13:23:15 GMT
Location: https://localhost:8443/gateway/admin/api/v1/servicedefinitions/mysampleservice/mysamplerole/2.0.0
Content-Length: 0
Server: Jetty(9.4.22.v20191022)

$ curl -H "Content-Type: application/xml" -iku admin:admin-password*** -X DELETE 'https://localhost:8443/gateway/admin/api/v1/servicedefinitions/mysampleservice/mysamplerole/2.0.0'
HTTP/1.1 500 Internal Server Error
Date: Tue, 19 Nov 2019 13:23:22 GMT
Set-Cookie: KNOXSESSIONID=node017x14a6arppex10ucm0ooygohp23.node0; Path=/gateway/admin; Secure; HttpOnly
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Set-Cookie: rememberMe=deleteMe; Path=/gateway/admin; Max-Age=0; Expires=Mon, 18-Nov-2019 13:23:22 GMT
Content-Type: application/json
Content-Length: 116
Server: Jetty(9.4.22.v20191022)

{ "DELETION_ERROR": "There is no service definition with the given attributes: mysampleservice,mysamplerole,2.0.0" }

...