Wiremock fake that a service is down - wiremock

In my current setup, if one of my services is down and a request is made to that service, I send a certain HTTP code in the response.
Now to test this I'm using Wiremock to mock my service. Is there a way to mock that the service is unavailable and return a specific response as a result?
I've tried looking through the Wiremock code but there are barely any comments for the methods. I've also tried looking through the docs and I couldn't find anything about bringing down the service.

you could try ResponseDefinitionBuilder.aResponse().withFault(Fault.CONNECTION_RESET_BY_PEER), ResponseDefinitionBuilder.serviceUnavailable() or simply point your client to a port that is guaranteed to have no listeners, depending on what exactly would you like to test with
service is unavailable and return a specific response as a result

Related

Including a body in a GET, PUT, or POST request results in response of "You need to enable JavaScript to run this app"?

The short story: If I hit my endpoint /api/something with a PUT and no body, it goes through to my Lambda (via CF -> API GW -> Lambda). If I add a body to the request, it doesn't work and seems to die before hitting the API Gateway. I'm not sure why it would do this.
The long story:
I've set up a CloudFront distribution that sends requests to /api to our API gateway and all other requests just vend static website resources.
It has been working great so far for our simple use cases. We previously only hit the API Gateway with GET requests, but now we're going to start needing to send PUT or POST requests to the API Gateway. I had to update the CloudFront distribution "behaviors" for the /api path pattern (the one going to the API gateway) to allow all HTTP methods after that, I was able to start getting responses from the API Gateway for PUT and POST responses (previously only worked for GET).
However, I noticed that if I try to send a payload or body with the request (regardless of the request type), I don't think it actually hits the API Gateway or the Lambda that the API Gateway is routing to because I get a response of "You need to enable JavaScript to run this app". I tried looking at the logs but couldn't find anything. The heads shows "Error from cloudfront" but I'm not sure why or where to find what the error was.
Any tips on how to troubleshoot this or what the issue might be?
Update (10/8): I figured out the "enable javascript" thing was coming up because of my custom error pages for 403&404 errors. I deleted them in my development environment and now get a clearer error.
"This distribution is not configured to allow the HTTP request method
that was used for this request. The distribution supports only
cachable requests. We can't connect to the server for this app or
website at this time. There might be too much traffic or a
configuration error. Try again later, or contact the app or website
owner."
However, I still don't know what to do, as the request type (PUT) is enabled and the request works as long as I don't provide a body. Not sure how to get it to be ok with a body at the moment.

XCUITest mock specific endpoints

I'm trying to achieve mocked responses for certain endpoints for UI testing in XCUITests. However all the available mock servers set the url at the start of the test and hence all the requests go through them.
How can I make only specific requests to go through the local mock server and rest of the requests to go through the default prod / stage endpoints?
checkout http://wiremock.org/. There is proxy setting that allow you to redirect URL to actual end points v/s mock end point. Technical name is proxy stub mapping : http://wiremock.org/docs/proxying/
Copy And Paste from documents
Proxy stub mappings
Proxy responses are defined in exactly the same manner as stubs, meaning that the same request matching criteria can be used.
The following code will proxy all GET requests made to http://:/other/service/.* to http://otherservice.com/approot, e.g. when running WireMock locally a request to http://localhost:8080/other/service/doc/123 would be forwarded to http://otherservice.com/approot/other/service/doc/123.

How to handle BizTalk POST while exposing schema as REST service?

I have a BizTalk application where I have exposed schema as a RESTful web service, which calls another REST service. I am able to successfully handle GET, DELETE request.
Is there a way to handle POST request without writing a pipeline component to serialize the POST request to a schema?
Also, the application may have to handle several POST calls, so will it be possible to serve this from one single receive location and then filtering the request on the send port?
Please let me know if any more details are required.
So, here's the thing. You're mixing together some things that technically have nothing to do with each other.
For instance, a Plain Old Xml (POX) service, usually a POST, does not 'expose' a Schema in the way a SOAP service does. It just takes whatever content is POSTed to it.
Following that, serialization/deserialization is also a concept more related to SOAP that POX or REST.
So...
Yes, but what exactly are you doing?
Yes. A plain http endpoint can accept any content type. Once it's over the wire, all the normal BizTalk processing rules apply.

Restful service naming convention for service

I have a service connecting to an enterprise service which I have no control over. The service requires I make a call to it to initiate a ping to a device and then make subsequent calls to it to get the status. After 20 or so seconds I will get the status back.
I have been thinking of a rest pattern and just getting stuck on the fact that it is not truly restful Id like to reach out for feedback and get some opinions. I could just do a normal get /device/status and hit it over and over again? Or i could break up the call into /device/ping and /device/status or something like that. Any ideas are appreciated!
Thanks
For status, REST standards would suggest a format of '/device/{deviceId}/status'. But if the enterprise service you are connecting to does not support multiple devices; you could go for '/device/status' with 'GET' http verb.
You could use '/device/status' with 'HEAD' http verb as an exposure for the ping call
I will suggest to return the a JMS queue URL in location header in API response. Usually, in device management applications, separate JMS server is deployed. Make use of it - if it's there.
Take a hint from here.
.

Can I send a SOAP message to a web service without using tool kits like gsoap and get the same result, or is it necessary to use gsoap?

I mean that if I know the format of message that I want to send, then can I do it manually by sending the message as a string over HTTP without using gsoap and get the same desired result?
There is no problem doing it manually. It will even work using just telnet, as long as you use the correct headers and message body.
SOAP is an application layer protocol. So, it will make no difference if you use a tool
or just create and connect a Tcp/Ip socket to the web service endpoint. As long as you
put the right xml with the soap envelope, headers and body it will work well.