I am facing a problem on restxq multiple parallel request of post, put. When request from web application as async bulk request (approx. more then 5 ).
declare
%rest:path("/docs/{$doc-id}")
%rest:PUT("{$body}")
%rest:consumes("application/json")
%output:method("json")
function doc-rx:update-docs($doc-id as xs:string, $body) {
try{
let $request:= parse-json(util:binary-to-string( $body))
return
<result>Success</result>
}catch * {
<error>Caught error {$err:description}</error>
}
};
Some request will failed with below message, some request got cancelled
Failed Message:
The underlying InputStream has been closed. Unable to encode string value: The underlying InputStream has been closed Some Request got cancelled.
Please advise how can I resolve this issue.
Related
I am facing a problem on restxq multiple parallel request of post, put. When request from web application as async bulk request (approx. more then 5 ).
I am using exist db 5.1.0 or 5.1.1
I am sending request through angular forkjoin because of i want to submit more then 20 or 50 request in parallel
declare
%rest:path("/docs/{$doc-id}")
%rest:PUT("{$body}")
%rest:consumes("application/json")
%output:method("json")
function doc-rx:update-docs($doc-id as xs:string, $body) {
try{
let $request:= parse-json(util:binary-to-string( $body))
return
<result>Success</result>
}catch * {
<error>Caught error {$err:description}</error>
}
};
Some request will failed with below message, some request got cancelled
Failed Message:
The underlying InputStream has been closed. Unable to encode string value: The underlying InputStream has been closed Some Request got cancelled.
Please advise how can I resolve this issue.
When connecting via a non-secured protocol (http), my MVC 5 web application returns the error message properly. But the moment I connect via https, the error message is blank. Thought? NOTE: I try json return also. Thanks!
Browser debugger output
HTTP
HTTPS
MVC Controller:
string message = string.Join(" ", errors);
Response.StatusCode = (int)HttpStatusCode.RequestedRangeNotSatisfiable;
return new HttpStatusCodeResult(Response.StatusCode, string.Join(" ", message));
Script:
function ajaxOnFailure(response, status, error) {
debugger;
if (response.status == 500) {
error = "An internal error has occurred. Please try again. If the problem persists, please contact IT."
}
toastr.error("", error);
}
I ended up using a workaround. Instead of return a fail response, I return OK response and determine the type of message via jquery. It would have been nice if a fail response return the message via https.
I am hoping for some direction on this error. I have a loop that connects with the google places API. Every few times I test it I get an HTTP request failed error. But when I take the API call from the error it works in a browser or in postman. Any suggestions for what might be causing this? Thanks for all of your help. Here is my API call and the error.
$googleApiPlaceUri = 'https://maps.googleapis.com/maps/api/place/textsearch/json';
foreach ($attractions as $attraction) {
$api_call = "{$googleApiPlaceUri}?query={$attraction}+in+{$city}&key={$api_key}";
$api_return_array[] = json_decode(file_get_contents($api_call));
foreach ($api_return_array as $result) {
$results = $result->results;
array_push($results_array, $results);
}
}
Here is the error I get...
Warning: file_get_contents(https://maps.googleapis.com/maps/api/place/textsearch/json?query=hiking +in+Denver&key=API_KEY): failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request
Currently my client authenticates request only on case of 401 response:
this.client.authenticator(new okhttp3.Authenticator() {
public Request authenticate(Route route, Response response) throws IOException {
String credentials = authenticator.getCredentials();
if (credentials.equals(response.request().header("Authorization"))) {
throw new TraversonException(401, "Unauthorized", response.request().url().toString());
} else {
defaultHeader("Authorization", credentials);
Request.Builder newRequest = response.request().newBuilder()
.headers(Headers.of(defaultHeaders));
return newRequest.build();
}
});
But I'd like to change this behavior and be able to call it either manually or auto per first call? Is it possible somehow?
If the authentication is predictably required and not related to a proxy, then the solution is to implement an Interceptor instead of Authenticator.
OkHttpClient.Builder clientBuilder = ...;
clientBuilder.networkInterceptors().add(0, myInterceptor);
client = clientBuilder.build();
Example Interceptor https://github.com/yschimke/oksocial/blob/48e0ca53b85e608443eab614829cb0361c79aa47/src/main/java/com/baulsupp/oksocial/uber/UberAuthInterceptor.java
n.b. There is discussion around possible support for this usecase in https://github.com/square/okhttp/pull/2458. One issue with current Authenticator API is that it assumes a Response from the failed (401) request.
I have two problems here. So I need your help.
The result of microsoft.com's response code is some time HTTP/1.1 403 Forbidden or HTTP/1.1 200 OK.`
try
{
IdHTTP->Get("http://www.microsoft.com");
ListBox->Items->Add(IdHTTP->Response->ResponseCode);
}
catch (const EIdException &E)
{
ListBox->Items->Add(E.Message);
ListBox->Items->Add(IdHTTP->Response->ResponseText);
}
But when I checked it on http://web-sniffer.net/ or http://tools.seobook.com/server-header-checker then its results is HTTP/1.1 302 Moved Temporarily.
Why the results from IdHTTP is different from the both url above?. How can IdHTTP achieve the same http status code?.
Colorize & replace E.Message error of EIdException / Exception in TListBox.
For example, I want to replace the "Socket Error # 10061Connection refused" with "your connection is refused".
ListBox->Items->Add(StringReplace(E.Message,"Socket Error # 10061Connection refused.","your connection is refused.",TReplaceFlags()<<rfReplaceAll));
But using that way, the result is still same.
Thanks for taking the time to read this. Any help or suggestions with would be greatly appreciated!!
Outside of site maintenance, I doubt http://www.microsoft.com would ever return a 403 Forbidden error under normal conditions. But, like any site, I suppose it could happen at times. It is a fatal error, you cannot access the URL at that time (if at all).
302 Moved Temporarily is an HTTP redirect. The TIdHTTP.OnRedirect event will be triggered to give you the new URL. If the TIdHTTP.HandleRedirects property is true, or the OnRedirect event handler returns true, TIdHTTP will handle the redirect internally and automatically request the new URL for you. TIdHTTP.Get() does not exit until the final URL is reached, or an error occurs.
As for error handling, if you want to customize the message you display based on the type of error that occurred, you need to actually differentiate between the various types of errors that can occur, eg:
try
{
IdHTTP->Get("http://www.microsoft.com");
ListBox->Items->Add(IdHTTP->Response->ResponseCode);
}
catch (const EIdHTTPProtocolException &E)
{
// HTTP error
// E.ErrorCode contains the ResponseCode
// E.Message contains the ResponseText
// E.ErrorMessage contains the content of the error body, if any
ListBox->Items->Add(E.Message);
}
catch (const EIdSocketError &E)
{
// Socket error
// E.LastError contains the socket error code
// E.Message contains the socket error message
if (E.LastError == Id_WSAECONNREFUSED)
ListBox->Items->Add("Your connection is refused");
else
ListBox->Items->Add(E.Message);
}
catch (const EIdException &E)
{
// any other Indy error
ListBox->Items->Add(E.Message);
}
catch (const Exception &E)
{
// any other non-Indy error
ListBox->Items->Add(E.Message);
}