api

Jacek Obarymski

API Reference

The following topics offer a detailed reference to the options provided by SOAP/REST Mock Service.

Mock configuration check

You can check what service mocks have been defined under the following URL and follow links available for each service operation.

http://server:port/{APP_CONTEXT}/services

API's concerning both REST and SOAP webservice mocks are similar but for better readability the reference has been split to two independent chapters.

SOAP webservice mocks

Sample mock configuration

SERVICE[0].NAME=dummy-soap-service
SERVICE[0].WSDL=dummy.wsdl
SERVICE[0].TYPE=SOAP

or

SERVICE[0].NAME=dummy-soap-service
SERVICE[0].TYPE=SOAP
SERVICE[0].OPERATION[0].INPUT_MESSAGE=dummySoapRequest
SERVICE[0].OPERATION[0].DEFAULT_RESPONSE=dummy_soap_response.xml

Mocked webservice endpoint

Mocked webservice endpoint is available under the following URL:

http://server:port/{APP_CONTEXT}/services/{SERVICE[i].TYPE}/{SERVICE[i].NAME}/endpoint
Parameter Description
SERVICE[i].TYPE type of service provided in the config file (here: SOAP)
SERVICE[i].NAME name of service provided in the config file

Example:

http://localhost:8080/mock/services/SOAP/dummy-soap-service/endpoint

Mock control resources

Each webservice mock can be controlled with a set of RESTful resources.

Root context

Root url context of each of the control resources is:

http://server:port/{APP_CONTEXT}/services/{SERVICE[i].TYPE}/{SERVICE[i].NAME}/operations/{SERVICE[i].OPERATION[j].INPUT_MESSAGE}
Parameter Description
SERVICE[i].NAME name of service provided in the config file
SERVICE[i].OPERATION[j].INPUT_MESSAGE input message of SOAP request. In practice it's the name of the XML element that goes directly after soap:body element of a SOAP request.

Example:

http://localhost:8080/mock/services/SOAP/dummy-soap-service/operations/dummySoapRequest

The control resources of this root context would affect mock of SOAP operation that accepts dummySoapRequest and is a part of dummy-soap-service.

The Setup Resources

The Setup Resources allow the user to setup mock's behaviour before each test case is performed.

/init
DESCRIPTION This resource allows to initialize mock service endpoint and erase previously recorded requests.
EXAMPLE URLhttp://localhost:8080/mock/services/SOAP/dummy-soap-service/dummySoapRequest/init
HTTP METHODPOST
/responses?code={code}&delay={delaySec}
DESCRIPTIONSets up mock response(s). Posting an xml to this resource will cause the mock to respond with that xml. Multiple consecutive posts to this resource will set a series of consecutive responses
EXAMPLE URLhttp://localhost:8080/mock/services/SOAP/dummy-soap-service/operations/dummySoapRequest/responses?delay=5
HTTP METHODPOST
REQUEST BODYThe response to be returned by mock.
PARAMETERS delaySec - integer, optional - number of seconds mock response is to be delayed for
code - valid http code, optional - HTTP response code to be returned by mock
/responses/{responseNumber}?delay={delaySec}
DESCRIPTIONPUT'ing an xml to this resource will cause the mock to respond with that xml in n-th request to the mock
EXAMPLE URLhttp://localhost:8080/mock/services/SOAP/dummy-soap-service/operations/dummySoapRequest/responses/2?delay=5
HTTP METHODPUT
REQUEST BODYThe response to be returned by mock.
PARAMETERS responseNumber - integer, mandatory - response's serial number
delaySec - integer, optional - number of seconds mock response is to be delayed for

The Verification Resources

The Verification resources allow to verify requests that reached mock.

/recorded/requests
DESCRIPTIONReturns recorded requests.
EXAMPLE URLhttp://localhost:8080/mock/services/SOAP/dummy-soap-service/operations/dummySoapRequest/recorded-requests
HTTP METHODGET
RETURNSRecorded requests (full SOAP envelopes) enclosed in a <requests> xml tag.

Exposing WSDL of a mocked SOAP endpoint

Exposing WSDL of a mocked service might be usefull for using the mock service with SOAP clients that automatically generate requests basing on WSDL.
Note that WSDL is independent of the mock configuration.

../wsdl
DESCRIPTIONReturns contents of the wsdl file.
EXAMPLE URLhttp://localhost:8080/mock/services/SOAP/dummy-soap-service/wsdl
HTTP METHODGET
RETURNSReturns contents of the wsdl file which was defined in ws-mock.properties, SERVICE[i].WSDL property.

RESTful webservice mocks

Sample mock configuration

SERVICE[0].NAME=dummy-rest-service
SERVICE[0].TYPE=REST
SERVICE[0].OPERATION[0].HTTP_METHOD=GET
SERVICE[0].OPERATION[0].DEFAULT_RESPONSE=dummy_default_rest_get_response.xml
SERVICE[0].OPERATION[0].DEFAULT_RESPONSE_CODE=200
SERVICE[0].OPERATION[1].HTTP_METHOD=POST
SERVICE[0].OPERATION[1].DEFAULT_RESPONSE=dummy_default_rest_post_response.xml
SERVICE[0].OPERATION[1].DEFAULT_RESPONSE_CODE=201
SERVICE[0].OPERATION[2].HTTP_METHOD=PUT
SERVICE[0].OPERATION[2].DEFAULT_RESPONSE=dummy_default_rest_put_response.xml
SERVICE[0].OPERATION[2].DEFAULT_RESPONSE_CODE=200
SERVICE[0].OPERATION[3].HTTP_METHOD=DELETE
SERVICE[0].OPERATION[3].DEFAULT_RESPONSE=dummy_default_rest_delete_response.xml
SERVICE[0].OPERATION[3].DEFAULT_RESPONSE_CODE=200

SERVICE[1].NAME=rest-service-json
SERVICE[1].TYPE=REST
SERVICE[1].OPERATION[0].HTTP_METHOD=GET
SERVICE[1].OPERATION[0].DEFAULT_RESPONSE=dummy_default_rest_get_response.json
SERVICE[1].OPERATION[0].DEFAULT_RESPONSE_CODE=200
SERVICE[1].OPERATION[0].DEFAULT_RESPONSE_CONTENT_TYPE=application/json
SERVICE[1].OPERATION[1].HTTP_METHOD=POST
SERVICE[1].OPERATION[1].DEFAULT_RESPONSE=dummy_default_rest_post_response.json
SERVICE[1].OPERATION[1].DEFAULT_RESPONSE_CODE=201
SERVICE[1].OPERATION[1].DEFAULT_RESPONSE_CONTENT_TYPE=application/json    
SERVICE[1].OPERATION[2].HTTP_METHOD=PUT
SERVICE[1].OPERATION[2].DEFAULT_RESPONSE=dummy_default_rest_put_response.json
SERVICE[1].OPERATION[2].DEFAULT_RESPONSE_CODE=200
SERVICE[1].OPERATION[2].DEFAULT_RESPONSE_CONTENT_TYPE=application/json    
SERVICE[1].OPERATION[3].HTTP_METHOD=DELETE
SERVICE[1].OPERATION[3].DEFAULT_RESPONSE=dummy_default_rest_delete_response.json
SERVICE[1].OPERATION[3].DEFAULT_RESPONSE_CODE=200
SERVICE[1].OPERATION[3].DEFAULT_RESPONSE_CONTENT_TYPE=application/json

Mocked webservice endpoint

Mocked webservice endpoint is available under the following URL:

http://server:port/{APP_CONTEXT}/services/{SERVICE[i].TYPE}/{SERVICE[i].NAME}/endpoint/{RESOURCE_ID}
Parameter Description
SERVICE[i].TYPE type of service provided in the config file (here: REST)
SERVICE[i].NAME name of service provided in the config file
RESOURCE_ID resource id - optional, only for PUT,GET and DELETE methods

Example:

http://localhost:8080/mock/services/REST/dummy-rest-service/endpoint/id123

Mock control resources

Each webservice mock can be controlled with a set of RESTful resources.

Root context

Root url context of each of the control resources is:

http://server:port/{APP_CONTEXT}/services/{SERVICE[i].TYPE}/{SERVICE[i].NAME}/operations/{SERVICE[i].OPERATION[j].HTTP_METHOD}
Parameter Description
SERVICE[i].NAME name of service provided in the config file
SERVICE[i].OPERATION[j].HTTP_METHOD HTTP method - PUT, POST, GET or DELETE

Example:
http://localhost:8080/mock/services/REST/dummy-rest-service/operations/POST

The control resources of this root context would affect mock of POST method of dummy-rest-service

The Setup Resources

The Setup Resources allow the user to setup mock's behaviour before each test case is performed.

/init
DESCRIPTION This resource allows to initialize mock service endpoint and erase previously recorded requests.
EXAMPLE URLhttp://localhost:8080/mock/services/REST/dummy-rest-service/operations/PUT/init
HTTP METHODPOST
/responses?code={code}&delay={delaySec}
DESCRIPTION Sets up mock response(s). Posting an xml/json string and response code to this resource will cause the mock to respond with that string and response code. If response code is not specified the mock will return the default response code defined in ws-mock.properties for given service and method. Multiple consecutive posts to this resource will set a series of consecutive responses
EXAMPLE URLhttp://localhost:8080/mock/services/REST/dummy-rest-service/operations/POST/responses?code=201
HTTP METHODPOST
HTTP HEADERS Content-Type - (optional, default: text/xml) The MIME type of the body of the custom response
REQUEST BODYThe response to be returned by mock.
PARAMETERS code - valid http code, optional - HTTP response code to be returned by mock
delaySec - integer, optional - number of seconds mock response is to be delayed for
/responses/{n}?code={code}&delay={delaySec}
DESCRIPTIONPUTting an xml/json string, response code and request number to this resource will cause the mock to respond with that string and response code to a consecutive request in n-th request to the mock. E.g. if n=3, then the specified response will be returned to 3rd request. If the response code is not specified the mock will return the default response code defined in ws-mock.properties for given service and method.
EXAMPLE URLhttp://localhost:8080/mock/services/REST/dummy-rest-service/operations/POST/responses/3?code=200&delay=3
HTTP METHODPUT
HTTP HEADERS Content-Type - (optional, default: text/xml) The MIME type of the body of the custom response
REQUEST BODYThe response body to be returned by mock.
PARAMETERS n - integer, mandatory - response's serial number
code - valid http code, optional - HTTP response code to be returned by mock
delaySec - integer, optional - number of seconds mock response is to be delayed for

The Verification Resources

The Verification resources allow to verify requests that reached mock.

/recorded-full-requests
DESCRIPTIONReturns recorded requests.
EXAMPLE URLhttp://localhost:8080/mock/services/REST/dummy-rest-service/operations/PUT/recorded-full-requests
HTTP METHODGET
RETURNSFull data data about recorded requests enclosed in an xml response.
/recorded-requests
DESCRIPTIONReturns recorded request payloads only.
EXAMPLE URLhttp://localhost:8080/mock/services/REST/dummy-rest-service/operations/PUT/recorded-requests
HTTP METHODGET
RETURNSRecorded requests payloads in a <recorded-requests> xml tag.
/recorded-resource-ids
DESCRIPTIONReturns resource ids that were requested in GET, PUT and DELETE requests.
EXAMPLE URLhttp://localhost:8080/mock/services/REST/dummy-rest/operations/PUT/recorded-resource-ids
HTTP METHODGET
RETURNSRecorded resource ids enclosed in a <recorded-resource-ids> xml tag:
 <recorded-resource-ids>
   <recorded-resource-id>id123</recorded-resource-id>
   <recorded-resource-id>id546</recorded-resource-id>
 </recorded-resource-ids>
/recorded-request-params
DESCRIPTIONReturns recorded url query params.
EXAMPLE URLhttp://localhost:8080/mock/services/REST/dummy-rest/operations/PUT/recorded-request-params
HTTP METHODGET
RETURNSRecorded resource ids enclosed in a <recorded-request-params> xml tag:
 <recorded-request-params>
   <recorded-request-param>id123</recorded-request-param>
   <recorded-request-param>id546</recorded-request-param>
 </recorded-request-params>

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks