insert a new document json using http post apache solr - json

What I have: Apache Solr 5.2.1
What I want: add a new document in a specific core defined by me
example: address of the solr core -->
http://IP_ADDRESS:8984/solr/myCustom_core/
I want to add a document json formed by {"id":"00001","title":"my title"} to the core above directly from the browser's url bar.
Problem:
I'm trying to address this problem in such a way:
http://IP_ADDRESS:8984/solr/myCustom_core/update?wt=json&{add:{"id":"00001","title":"my title"}}&commit=true
The response of the browser is:
{"responseHeader":{"status":0,"QTime":88}}
However, when I check on the server side the new entry is not added.
Conversely,it is works if I try to add such a document using the submit command provided in the UI of Solr.
Can someone provide me the correct way to build the correct url address?
Thanks
EDIT: thanks to MatsLindh I solved my problem using this:
http://IP_ADDRESS:PORT/solr/myCustom_core/update?stream.body=<add><doc><field name="exampleField">example value</field></doc></add>&commit=true

You can use stream.body to send an arbitrary content stream through GET variables instead of using POST (or a regular body).
Be sure to perform appropriate escaping of the content you use in your URL.
You'll also have to perform a commit before the submitted content becomes searchable, either through commit=true in the request or by issuing a separate commit request.

Related

TYPO3 remove cache comment for json view

I want to have a json output of my page, so I have a typoscript setup with
diableAllHeaderCode and additionalHeaders Content-Type: application/json
Everything is good for the first call after clearing caches, but after that the json format is invalid because typo3 adds a comment to the bottom of the page like <!-- Cached page generated _-_-_ _:_. Expires _-_-_ _:_ -->
Can I somehow remove that tag or prevent it from being rendered without blocking the whole caching mechanism ?
And I would like to not change the TypoScriptFrontendController.php directly but rather find a solution to manage this from my extension
That information is displayed only for development/debug environment.
Dependend on your TYPO3 version you could try to disable this kind of debugging with some typoscript:
either global with config.debug = 0
or specific for your pagetype you use to generate JSON: json.config.debug = 0 (assumed this page object is named json)
Otherwise you test your JSON on the production system.
or you save your output, remove the comment and feed the file to your further process.

Get last segment of URL path with MVC Razor

I have this URL: http://localhost:.../home/blogpost/#'I want to get this string'
I get it when pressing:
#item.Title
#item.Title is from my database and that string will change. Now I need to get the 'I want to get this string' string on that page so that I can do a if statement with it, like this:
#if(#item.Title == 'I want to get this string')
Any suggestions?
The target attribute (the part of an URI after the #) is not sent to the server when the browser retrieves the page. So, you cannot get it out of a normal GET or POST request on the server at all.
That data is available in the browser, so you could access it using javascript of even CSS.
Using ajax techniques, you could load a skeleton page and send the target string yourself to the server and have it react to it, and only then load the rest of the page. A bit overkill for most uses I'm afraid and there are drawbacks as well (e.g. search engine might have more trouble to see your content).
It's easier to send the string to the server as a GET parameter if you have the level of control you seem to have. [simply replace the # with a ?], that will be sent to the server by the browser.
Do note that you should URLencode any data you add on to a URL ...

Pentaho HTTP Post using JSON

I'm brand new to Pentaho and I'm trying to do the following workflow:
read a bunch of lines out of a DB
do some transformations
POST them to a REST web service in JSON
I've got the first two figured out using an input step and the Json Output step.
However I have two problems doing the final step:
1) I can't get the JSON formatted how I want. It insists on doing {""=[{...}]} when I just want {...}. This isn't a big deal - I can work around this since I have control over the web service and I could relax the input requirements a bit. (Note: this page http://wiki.pentaho.com/display/EAI/JSON+output gives an example for the output I want by setting no. rows in a block=1 and an empty JSON block name, but it doesn't work as advertised.)
2) This is the critical one. I can't get the data to POST as JSON. It posts as key=value, where the key is the name I specify in the HTTP Post field name (on the 'Fields' tab) and the value is the encoded JSON. I just want to post the JSON as the request body. I've tried googling on this but can't find anyone else doing it, leading me to believe that I'm just approaching this wrong. Any pointers in the right direction?
Edit: I'm comfortable scripting (in Javascript or another language) but when I tried to use XmlHttpRequest in a custom javascript snippet I got an error that XmlHttpRequest is not defined.
Thanks!
This was trivial...just needed to use the REST Client (http://wiki.pentaho.com/display/EAI/Rest+Client) instead of the HTTP Post task. Somehow all my googling didn't discover that, so I'll leave this answer here in case someone else has the same problem as me.
You need to parse the JSON using a Modified JavaScript step. e.g. if the Output Value from the JSON Output is called result and its contents are {"data"=[{...}]}, you should call var plainJSON = JSON.stringify(JSON.parse(result).data[0]) to get the JSON.
In the HTTP Post step, the Request entity field should be plainJSON. Also, don't forget to add a header for Content-Type as application/json (you might have to add that as a constant)

How can I post JSON data in a way that results in a full page load?

I can already use jQuery.post to send JSON data to the server, but I can't find a way to have the response replace my current page just as a regular old POST would when using plain HTML.
The only way I know right now to come close is to create a dummy form, add the JSON data as a value, then trigger submit. This seems like a big hack and also requires the server side to know where to look for this value (whereas it automatically detects JSON when jQuery sends it).
Please tell me there's a better way!
Example desired usage (note that I don't want the data encoded in the URL):
magic_load_page('/page', {'foo':'bar', 'list':[1,4,9,16]}); // uses POST request

Testing PUT methods on a RESTful web service

I have a simple RESTful web service and I wish to test the PUT method on a certain resource. I would like to do it in the most simple way using as few additional tools as possible.
For instance, testing the GET method of a resource is the peak of simplicity - just going to the resource URL in the browser. I understand that it is impossible to reach the same level of simplicity when testing a PUT method.
The following two assumptions should ease the task:
The request body is a json string prepared beforehand. Meaning, whatever is the solution to my problem it does not have to compose a json string from the user input - the user input is the final json string.
The REST engine I use (OpenRasta) understands certain URL decorators, which tell it what is the desired HTTP method. Hence I can issue a POST request, which would be treated as a PUT request inside the REST engine. This means, regular html form can be used to test the PUT action.
However, I wish the user to be able to enter the URL of the resource to be PUT to, which makes the task more complicated, but eases the testing.
Thanks to all the good samaritans out there in advance.
P.S.
I have neither PHP nor PERL installed, but I do have python. However, staying within the realm of javascript seems to be the simplest approach, if possible. My OS is Windows, if that matters.
I'd suggest using the Poster add-on for Firefox. You can find it over here.
As well as providing a means to inspect HTTP requests coming from desktop and web applications, Fiddler allows you to create arbitrary HTTP requests (as well as resend ones that were previously sent by an application).
It is browser-agnostic.
I use the RESTClient firefox plugin (you can not use an URL for the message body but at least you can save your request) but also would recommend curl on the command line.
Maybe you should also have a look at this SO question.