Vert.x HttpClientRequest setTimeout - timeout

I'm using Vert.x 1.3.1-final and I'm trying to use the method setTimeout when sending a POST request from an HttpClient object, but I get an error: NosuchMethod.
The strange thing is that the method is defined and is public.
This is my code:
HttpClient client = vertx.createHttpClient()
.setHost(config.getString(HOST))
.setPort(config.getInteger(PORT))
.setKeepAlive(true)
.setConnectTimeout(config.getInteger(TIMEOUT));
HttpClientRequest clientRequest = client.post(endpoint, new ResponseHandler());
clientRequest.setTimeout(5*1000L); // Exception: NoSuchMethod !!
What am I doing wrong??
Thanks for your help.

Related

Keep HttpRequest stream open while I issue a Client.post

My dart server has a function which receives a POST request from a client. I want to use information from that request to issue a POST to another server, then use the response from this other server to send a response back to the original client request. When I issue my POST to the other server, it closes the stream on the inbound client request and I can no longer respond. Is there a way to keep the request stream 'alive' while I do a POST? Or, is there another way to do this? I did try to issue the POST on a different Isolate, but that didn't help, the http request stream is still getting closed.
void postRequest(HttpRequest request) async {
final endPoint = 'https://www.anotherserver.com/information';
final client = Client();
final data = request.headers.value('data'); // Get data from client
final response = client.post(endPoint, body: data); // Send data to other server
// Do stuff with the response from endPoint server
// For simplicity of this example, just send back the response body back to the client
// This write call to the request causes an "Stream Sink Closed" exception
// It appears the POST call to the endPoint server, caused the client request stream
// to get closed.
request.response.write(response.body);
await request.response.flush();
await request.response.close();
}
I was not awaiting the client.post.... I need to do a better job of watching out for that.

Different response for same API method

New to the RestAssured and just checking different ways of working with REST APIs. For testing I am using http://dummy.restapiexample.com/api/v1. In this I am trying the GET employee method using RequestSpecification and groovy way but I am getting different response.
My short code is:
RestAssured.baseURI = "http://dummy.restapiexample.com/api/v1";
RequestSpecification request = RestAssured.given();
Response response = request.get("/employee/72100");
System.out.println(response.getBody().asString());
given().baseUri("http://dummy.restapiexample.com/api/v1").get("/employee/72100").then().log().body();
And output I am getting is:
{"id":"72100","employee_name":"mpr51_0280","employee_salary":"123","employee_age":"23","profile_image":""}
<html>
<body>{"id":"72100","employee_name":"mpr51_0280","employee_salary":"123","employee_age":"23","profile_image":""}</body>
</html>
I am not getting why it is returning response with HTML tags. Can anyone explain or give hint to get same response as first call to get method.
NOTE: You may or may not get details for employeeID 72100
You can use any employee ID from response of:
http://dummy.restapiexample.com/api/v1/employees
Because the Body contains it .
You can use below statement if you need only the response
given().baseUri("http://dummy.restapiexample.com/api/v1").get("/employee/72100").then().log();
OR
Response resp = given().baseUri("http://dummy.restapiexample.com/api/v1").get("/employee/72100");
System.out.println(resp.asString());

FSharp.Data HTTP request - unable to set request timeout

We have a simple F# console app that sends a HTTP POST request to a WebAPI endpoint via FSharp.Data Http.Request. We are using the customizeHttpRequest parameter in order to try to set the request timeout property. Our usage is as follows:
let response = Http.Request(
serviceEndpoint,
headers = requestHeaders,
body = requestBody,
silentHttpErrors = true,
customizeHttpRequest = (fun request -> request.Timeout <- 1000; request))
We are observing that our custom timeout is ignored (i.e. the request does not timeout after 1 second as in this example). We have also observed that the request will not timeout after the default System.Net.HttpWebRequest timeout of 100,000ms.
Is there an issue here, or are we not using the customizeHttpRequest parameter correctly?
FSharp.Data uses the asynchronous GetResponse method. According to MSDN, in that case the timeout set on the HttpWebRequest object isn't considered and handling the timeout is left for the client code to implement.
Unfortunately FSharp.Data doesn't do it. There's an open issue for implementing it here.

Invoke WCF Data Services Service Operation from iOS

How do I invoke a Service Operation in WCF from iOS?
I have a Service Operation defined in my WCF Data Service (tied to a stored procedure in my DB schema) that I need to invoke from iOS. Say I've got the following declaration in my .svc.cs file:
[WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
public IQueryable<Foo> GetFoos(int param1, DateTime param2, string param3)
{
return CurrentDataSource.GetFoos(param1, param2, param3).AsQueryable();
}
And I've got it set up with the proper rights in InitializeService:
config.SetServiceOperationAccessRule("GetFoos", ServiceOperationRights.AllRead);
When I try to invoke this via HTTP POST from iOS, I get back an error wrapped in JSON:
Bad Request - Error in query syntax.
It seems like it doesn't like how I'm passing my parameters. I'm passing them JSON-encoded (using NSJSONSerialization to turn an NSDictionary into a JSON string) in the request body of a POST request. The same method works on another web service (.svc) not connected to WCF that has operations annotated the same way.
An answer to another question of mine in a similar vein suggests that data formats can be negotiated between client and server, and I've read that dates are a pain to format, so maybe it's my DateTime parameter that's a problem. But I've tried both the JSON format (\/Date(836438400000)\/ and /Date(836438400000)/) and the JSON Light format (1996-07-16T00:00:00) to no avail.
So my question is this: what is the proper way to invoke this operation? If I need to have my app tell the server what format to expect, how do I do that?
Update: I tried using the format datetime'1996-07-16T00:00:00' as mentioned in this question. Same error.
Update 2: The MSDN page for Service Operations seems to suggest that nothing besides Method = "POST" is supported when annotating the WebInvoke for a Service Operation. I tried removing everything from what is quoted in the above code and setting the method to POST. Same error.
Update 3: On Pawel's suggestion, I made a new Service Operation on my Data Service just like this:
[WebInvoke(Method = "POST")]
public IQueryable<string> GetFoos()
{
List<string> foos = new List<string>();
foos.Add("bar");
return foos.AsQueryable();
}
I was able to make it work in Fiddler's Composer pane by setting the method to POST, adding accept:application/json;charset=utf-8 and Content-Length:0 to the headers. Then I added a single int parameter to the operation (called param1). I set the body of my request in Fiddler to {"param1":"1"} and ran it (and Fiddler automatically updated my content-length header), and got the same error. I changed the type of my parameter to string and ran my request again and it worked. So my problem seems to be non-string types.
You need to send parameters in the Url and not in the request body.

RestResponse is null on POST request using RestSharp

I am making a POST request with RestSharp (on windows phone 7.1 client). I sent string to a service in a request body. Looks like the service is successfully called and it returns proper value (integer), however response object is null:
client.ExecuteAsync<T>(request, (response) => {
data = response.Data; // response is null in debugger
});
I cant understand why is that so.
<T> isn't a valid value for that call. I'm not sure that would even build there unless you've wrapped it in a generic method.
Also, is the response coming back as plain text? What's the Content-Type returned? Most likely, you should just use ExecuteAsync(request, callback) without the generic parameter and grab the data out of response.Content which is a string of the response body. response.Data is for the automatically deserialized XML or JSON (or custom) response if you use the generic method overload that specifies a type to deserialize to.
This seems to be an ongoing issue with RestSharp asynchronous calls - for HTTP transport errors ErrorException object is useless (returns null). Check the StatusCode property if it returns with anything but HttpStatusCode.OK. StatusDescription is not extremely useful either as it doesn't match complete status message from server response payload.

Resources