How to get eTag value in Comos v4 sync api container.queryItems() - azure-sql-database

Facing this issue when using comsos v4 java async apis.
I am seeing eTag value, if used container.readItem(), but not in container.queryItems().
when I check response header data in queryItem response, eTag is coming as null.
Can anyone please tell me, if it's cosmos API bug or am I missing something?
responseDocuments
.byPage(1)
.log()
.flatMap(person-> {
person.getResults().stream().forEach(document-> {
if(document.get("optInStatus") != null) {
} else {
list.add(gson.fromJson(gson.toJson(document, LinkedHashMap.class), Person.class));
}
});
System.out.println(person.getResponseHeaders().get("etag")); // coming as null
System.out.println(person.getContinuationToken());
System.out.println(person.getResponseHeaders().toString());
return Flux.empty();
})
.blockLast();

if it's cosmos API bug or am I missing something?
There isn't anything you missed and I don't think this is a bug. I tried the REST API. It also won't give the _eTag property in the response header. If you need that system property when you query items, you can add that property to your POJO.

Related

Ktor Client, how to specify body parameters

I'm trying to send a POST request to the server, this post requires parameters "email" and "password".
but I don't know how to specify parameters, I read the documentation but I didn't understand.
this is my code:
val request=client.post<String> {
url(BASE_URL+"login.php")
body="email=$email,password=$password"
}
fwiw I use something like following here....though I would have thought specifying url like you do should also work. What issue do you see? The body might also be some json for example, or maybe a data class etc if you have serialization setup.
response = client.post(url) {
body = "some params/data etc"
}
It should work if you use serialization, but I solved my problem by using 'Uploading multipart/form-data'
val request=client.post(url) {
body=MultiPartFormDataContent(formData {
append("email","data")
append("password","data")
})
}
see Documentation

Nest 2.0 enable trace

I am on updating to the latest Nest version. Since I am getting not the expected results I am searching for replacement of the EnableTrace() method which was a method of ConnectionSettings on previous versions.
EnableTrace() will be back, but it's not available yet(have a look).
For now you can use this code to print out information about request and response:
var settings = new ConnectionSettings(connectionPool)
.DefaultIndex(indexName)
.DisableDirectStreaming()
.OnRequestCompleted(details =>
{
Debug.WriteLine("### ES REQEUST ###");
if(details.RequestBodyInBytes != null) Debug.WriteLine(Encoding.UTF8.GetString(details.RequestBodyInBytes));
Debug.WriteLine("### ES RESPONSE ###");
if (details.ResponseBodyInBytes != null) Debug.WriteLine(Encoding.UTF8.GetString(details.ResponseBodyInBytes));
})
.PrettyJson();
Make sure you have set .DisableDirectStreaming() on ConnectionSettings.
Hope it helps.

Understanding seam filter url-pattern and possible conflicts

I made a custom editor plugin, in a Seam 2.2.2 project, which makes file upload this way:
1) config the editor to load my specific xhtml upload page;
2) call the following method inside this page, and return a javascript callback;
public String sendImageToServer()
{
HttpServletRequest request = ServletContexts.instance().getRequest();
try
{
List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
processItems(items);//set the file data to specific att
saveOpenAttachment();//save the file to disk
}
//build callback
For this to work I have to put this inside components.xml:
<web:multipart-filter create-temp-files="false"
max-request-size="1024000" url-pattern="*"/>
The attribute create-temp-files do not seems to matter whatever its value.
But url-pattern has to be "" or "/myUploadPage.seam", any other value makes the item list returns empty. Does Anyone know why?
This turns into a problem because when I use a url-pattern that work to this case, every form with enctype="multipart/form-data" in my application stops to submit data. So I end up with other parts of the system crashing.
Could someone help me?
To solve my problem, I changed the solution to be like Seam multipart filter handle requests:
ServletRequest request = (ServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
try
{
if (!(request instanceof MultipartRequest))
{
request = unwrapMultipartRequest(request);
}
if (request instanceof MultipartRequest)
{
MultipartRequest multipartRequest = (MultipartRequest) request;
String clientId = "upload";
setFileData(multipartRequest.getFileBytes(clientId));
setFileContentType(multipartRequest.getFileContentType(clientId));
setFileName(multipartRequest.getFileName(clientId));
saveOpenAttachment();
}
}
Now I handle the request like Seam do, and do not need the web:multipart-filter config that was breaking other types of request.

REST GET api - what to return when resource not found

I am using jersey to create rest api. I have GET api which returns xml or json representation of an object instance using JaXB. Everything is fine as long as I can get this instance based on id and return it. But when I don't find instance what should I return. I know 404 response has to be returned. But my method already returns a given type. So how do I setup 404 status is response?
Here is simplified version of my method
#GET
#Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public GameDAO getGameState(#PathParam("gameId") String gameId)
{
//code to get game instance based on gameId
if(game != null)
{
GameDAO d = new GameDAO(game);
return d; //gets auto converted to xml or json
}
return null; //how to return not found response ?
}
A 404 response is what you want, and I think the best way to get there is by throwing a "not found" WebApplicationException. Here's an example:
throw new WebApplicationException(Response.Status.NOT_FOUND);
There are plenty of ways to customize the error handling; you can find more details in the Jersey docs: https://jersey.java.net/documentation/latest/representations.html

ASP.Net MVC Api won't accept an int parameter

I have the following code:
[HttpPost]
public async Task<ReturnStatus> Delete([FromBody]int id)
{
await new BusinessLogic.Templates().DeleteTemplate(id);
return ReturnStatus.ReturnStatusSuccess();
}
When I run this as an AJAX request, the id is null. I've inspected the data coming in through Fiddler and the body is:
{"id":"11"}
The header has Content-Type: application/json; charset=UTF-8.
If I modify the code slightly to
[HttpPost]
public async Task<ReturnStatus> Delete([FromBody]string id)
{
await new BusinessLogic.Templates().DeleteTemplate(Convert.ToInt64(id));
return ReturnStatus.ReturnStatusSuccess();
}
it works just fine.
What am I doing wrong here?
Please read this part, number 3 in particular:
http://encosia.com/using-jquery-to-post-frombody-parameters-to-web-api/
3. [FromBody] parameters must be encoded as =value
(quoting the section for future reference:)
There are two ways to make jQuery satisfy Web API’s encoding requirement. First, you can hard code the = in front of your value, like this:
$.post('api/values', "=" + value);
Personally, I’m not a fan of that approach. Aside from just plain looking kludgy, playing fast and loose with JavaScript’s type coercsion is a good way to find yourself debugging a “wat” situation.
Instead, you can take advantage of how jQuery encodes object parameters to $.ajax, by using this syntax:
$.post('api/values', { '': value });