How to add for format=json in oracle weblogic server - oracle

I have installed oracle weblogic server 11g.Implemented RESTFul but as per document when I place there format=json. It should works but it is not working.
Can you please let me know, how to resolve response as json.

you can get a working example of how to do this here: https://www.samplecode.oracle.com/sf/projects/oracle-parcel-svc/ and we have a webcast series that covers JAX-RS on WLS in Session 4 at this link:http://www.oracle.com/technetwork/middleware/weblogic/learnmore/weblogic-javaee6-webcasts-358613.html
When you configure your method that you want to return JSON from you have to specify that it produces JSON. Here's one way to do it:
#GET
#Path("{id}.json")
#Consumes({MediaType.APPLICATION_JSON})
#Produces({MediaType.APPLICATION_JSON})
public Parcel getParcelById_json(#PathParam("id") int id)
{
return getParcelById(id);
}
You also need to put the right HTTP headers in the client in order to specify that it expects a JSON response. Some test clients like SOAP-UI auto-convert JSON to XML such that you can do an XPATH on it, even though the actual transmission of data is JSON.

Related

Spring Content 1.2.5 JPA(Postgres) .docx file mutates to zip archive

Saved ".docx" file with mimeType "application/vnd.openxmlformats-officedocument.wordprocessingml.document". But when I access it's endpoint in Spring Content and download it's not exactly Word document, but Zip archive(application/zip). Spring Content 1.2.5 supports ".docx" files, how can we fix it?
Demo project to reproduce issue(.docx file attached):
https://github.com/leonaugust/docx-problem
EDIT
Although I understand that resulting file is docx after all and we can choose to open it as Word document, but is there a way to make it less confusing for customers and return back as ".docx" format? In my case a huge amount of documents will most likely be sent in that format
As you have spring-content-rest on the classpath and use the #StoreRestResource annotation I am assuming that you are using that to fetch your content? Please let me know if that is not the case and I will edit.
There are a couple of annotations that, if present on the entity, the spring content rest post/put endpoints would set for you and that are then used later on by the GET endpoint; #MimeType and #OriginalFileName.
If you add these annotations to your entity and set them appropriately in your post endpoint then:-
#PostMapping
public UUID create(#RequestParam("file") MultipartFile multipartFile) {
File file = new File();
file.setMimeType(multipartFile.getContentType());
store.setContent(file, multipartFile.getResource());
file.setMimeType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
file.setOriginalFileName(multipartFile.getOriginalFilename());
UUID id = repository.save(file).getId();
log.info("id {}", id);
return id;
}
When your client fetches content (again, I assume) via the Spring Content REST endpoint it will set the following headers:
Content-type header
content-dispostion form-data attachment header
on the response.
Both of which will direct the browser app as to handle the content appropriately.
This should allow you to make the following get request from your browser.
curl -H 'Accept: application/vnd.openxmlformats-officedocument.wordprocessingml.document' http://localhost:8080/storage/b9ca6fbe-dede-4a51-b444-9e22b798e922
And it should download the attachments as test.docx
Seperately, I'd be curious to know why you added your own "create" endpoint, rather than using the Spring Data REST/Spring Content REST endpoint. It will do this for you automatically. I assume it is because you do not want to use Spring Data REST?

HTTP GET request with a separate entity body in JMeter?

I want to send a JSON payload with HTTP GET request but I want to prevent it to be viewable in URL.
GET http://<domain>/school/search.json
{
schoolId: ["S1","S2","S3"],
location: "Pune"
}
How can I achieve this in JMeter Apache?
Get implies visible in Url, what exactly do you want to do ?
Sending Body data along with HTTP GET request is available for default (HttpClient4) implementation since ver.3.1 (as Bugzilla #60358), as well as request retrying behavior both for PUT and GET with body fixed since ver.3.2 (as Bugzilla #60837).
Just as additional note: you will likely encounter problems if you have cache/proxies in your setup and if you plan to take advantage from their usage.

Retrieving JSON from an external API with backbone

I'm new to backbone.js and I've read other solutions to similar problems but still can't get my example to work. I have a basic rails api that is returning some JSON from the url below and I am trying to access in through a backbone.js front end. Since they are one different servers I think I need to use a 'jsonp' request. I'm currently doing this by overriding the sync function in my backbone collection.
Api url:
http://guarded-wave-4073.herokuapp.com/api/v1/plans.json
sync: function(method, model, options) {
options.timeout = 10000;
options.dataType = 'jsonp';
options.url = 'http://guarded-wave-4073.herokuapp.com/api/v1/plans.json'
return Backbone.sync(method, model, options);
}
To test this I create a new 'plans' collection in my chrome console using "plans = new Plans()" and then "plans.fetch()" to try and get the JSON.
When I call plans.models afterwards I still have an empty array and the object that returns from plans.fetch() doesn't seem to have any json data included.
Any ideas where I'm going wrong?
I have had the same problem before. You should not have to override your sync method.
Taken from Stackoverflow Answer
"The JSONP technique uses a completely different mechanism for issuing HTTP requests to a server and acting on the response. It requires cooperating code in the client page and on the server. The server must have a URL that responds to HTTP "GET" requests with a block of JSON wrapped in a function call. Thus, you can't just do JSONP transactions to any old server; it must be a server that explicitly provides the functionality."
Are you sure your server abides to the above? Test with another compatible jsonp service (Twitter) to see if you receive results?
Have you tried overriding the fetch method as well?
You should add ?callback=? to your api url in order to enable jsonp

POST request in Windows phone

I am trying to get some data from the user and send it to my server for logging purposes. I was able to do it easily with jquery for my website. When I try to write a windows app for the same I am clueless as to how to post the data to my server.
So far I have fetched the data from the user and I am trying to use OpenWriteAsync function of webclient to send it to my server. I understand how OpenWriteAsync function works but I am not able to figure out how to send my own data.
My php script in my server will get values with name "FILENAME" and "FTIME" like,
$fname = $_POST['FILENAME'];
$time = $_POST['FTIME'];
So I have got this information from the user in two different string variables in c# inside my app. Now how do I send this to my server so that my php script gets this value and logs it inside my server.
I hope I am clear.
Take a look at UploadData method.
The way you use it something like this:
UploadData("http://abc.com","POST", "data in byte array");
Note: you need to convert data to byte array
Reference: http://msdn.microsoft.com/en-us/library/ktfa4fek(v=VS.90).aspx
You can do this by using the ContentType property in the HTTPWebRequest object.

WebDAV query for Exchange

I am trying to read a public calendar (in public folders) in my Exchange server.
I am sending the following query to my Exchange server, and the server replies with 400 - Bad Request.
<?xml version=""1.0""?>
<g:searchrequest xmlns:g=""DAV:"">
<g:sql>
SELECT
""urn:schemas:httpmail:subject"",
""urn:schemas:calendar:location"",
""urn:schemas:calendar:dtstart"",
""urn:schemas:calendar:dtend""
FROM
Scope('SHALLOW TRAVERSAL OF ""https://server/public/SomeFolder/SomeCalendar/""')
</g:sql>
</g:searchrequest>
Now that same query works with this store URL:
https://server/exchange/username/calendar/
So I know that's the URL that is wrong in the query.
If I paste the problematic URL in my web browser, it will come up with the calendar, so the URL does seem fine though.
Any help appreciated.
Thanks
Xavier
Try
https://server/public/SomeFolder/SomeCalendar/?cmd=contents
Thanks SillyMonkey for your input.
Your URL returned the same error but I have found out the problem was with the endpoint I was connecting to to submit the query.
I was posting the query to this URI:
string uri = string.Format("{0}/exchange/{1}", server, credentials.UserName);
and now changed it to:
string uri = string.Format("{0}/public", server);
I am a bit surprised that I have to use different endpoints depending whether I am querying the user's mailbox or the public folders, but it seems to be the way it is.

Resources