In spring-data-mongodb version 2.0.0 i can call a findOne method on gridFsOperation and i get a com.mongodb.client.gridfs.model.GridFSFile back:
com.mongodb.client.gridfs.model.GridFSFile gridFsFile = gridFsOperations.findOne(query(whereMetaData("firstName").is("Hardy")));
Now how can i get the content of this GridFSFile?
I understand that i can query for a filename and get a back GridFsResource. From this i can get the content as inputStream:
GridFsResource gridRes1 = gridFsOperations.getResource("myFile1.txt");
InputStream is = gridRes.getInputStream();
But this does not work for GridFSFile. And i also cannot get a resource by meta-data, but only by filename.
Related
I'm using REST in Java for android and want to send query {"query": "*"} to get list of all documents.
I use this url: https://api-eu.clusterpoint.com/my_accoundID/my_db_name
Here are my connection classes to URL:
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");
But I get database status, not list of all documents.
If you want to send Search query to get list of all documents, you should secify Search command in url and use POST method instead of GET. GET is used for Status. Method, that needs to be used, depends on what you are trying to do.
Just add search command to url: https://api-eu.clusterpoint.com/my_accoundID/my_db_name/_search and change method to "POST".
In elastic search java api, suppose I am building the indexed data using this client
Node node = nodeBuilder().clusterName("es").node();
Client client = node.client();
IndexResponse response = client.prepareIndex("twitter", "tweet", "1")
.setSource(jsonBuilder()
.startObject()
.field("user", "kimchy")
.field("postDate", new Date())
.field("message", "trying out Elasticsearch")
.endObject()
)
.execute()
.actionGet();
This indexed data is stored in folder XYZ/elasticsearch/data.
My question is how to retrieve this indexed data in java from some other client or some other code. Is there any way in which I can give the path and the already indexed data can be imported, then I can perform queries on it?
Edit :
The code for client on other computer
Node node = nodeBuilder().clusterName("es").node();
Client client = node.client();
MatchQueryBuilder qb = QueryBuilders.matchQuery("user", "kimchy");
SearchRequestBuilder srb = client.prepareSearch("twitter").setTypes("tweet");
SearchResponse big = srb.setQuery(qb).execute().actionGet();
SearchHit[] results = big.getHits().getHits();
This shows
search.SearchPhaseExecutionException: Failed to execute phase [query], all shards failed
Thanks
Arya
I'm not sure I understand the question, but if it's just querying in java here's an example :
MatchQueryBuilder qb = QueryBuilders.matchQuery("user", "kimchy);
SearchRequestBuilder srb = client.prepareSearch("twitter").setTypes("tweet");
srb.setQuery(qb);
SearchResponse response = srb.execute().actionGet();
//Here goes your code where you use response.getHits() that contains your items
The message you get by using my snippet usually indicates that your client doesn't manage to connect to your server. Check your server status (i.e. that you launched your server properly) and try using this.
Node node = NodeBuilder.nodeBuilder().client(true).node();
client = node.client();
I don't think you need to specify the clustername unless you have some custom configuration i'm not aware of. Also check your index name.
I am trying to do following:
get element(div in this case) containing a URL for eg.
`ele = "www.xyz.com".
Use getAttribute('value') or getText() to
grep URL
Use this URL to fork new instance of browser and GET the
URL
newBrowser = browser.forkNewDriverInstance();
ele.getAttribute('value').then(function(val){
newBrowser.get(val);
});
and I am getting following error:
RangeError: Maximum call stack size exceeded
Second method I tried was without promise and got the error saying that url should be string and not object.
As in:
var url = ele.getText();
newBrowser.get(url);
Is there a way to convert the object returned by getText() into a string and store into variable so that it can be used in some other place.
In your second appraoch, ele.getText() will give you a promise that needs to be resolved. You can resolve the promise on the second approach by using something like this-
ele.getText().then(function(url){
newBrowser.get(url);
})
If this does not work, try printing url with console.log(url). I think it is an object array and you need to get the item you need by referring to the index like url[0] or url[1]. try using console log to print all these values.
I'm building an application that inserts documents into MarkLogic server using the MLPHP library. The problem is when I insert a binary document, for example a PDF. The mime type will not be set properly, therefore the file cannot be opened as it should.
This is the code I use to insert a document:
// initialize REST client
$client = new MLPHP\RESTClient('127.0.0.1', 8010, 'v1', '', 'rest-writer-user', 'writer-pw');
// create new document and load content
$doc = new MLPHP\Document($client);
$doc->setContentType("application/pdf");
$doc->setContentFile("demo.pdf");
$doc->write('pdf_demo');
This is a dump of the $doc object after submitting to the server:
And here we have the inserted document in the search results:
But as expected, the browser cannot handle the file due to the wrong mimetype:
Anyone has got a clue what's going wrong here?
Check to see what the Response Header for content type is.
You Might have to set the format URL Parameter to binary. You can read the full documentation at http://docs.marklogic.com/REST/GET/v1/documents
here is what the request would look like
http://localhost:8010/v1/documents?uri=/pdf_demo.pdf&format=binary
I am using AXIS2 as client for handling SOAP response. The client stubs are generated using WSDL2JAVA command. To solve an issue, I am trying to read an xml response stored in .xml file in the generated stub, and assign to SOAPEnvelope. Below is the code written to load .xml content :
InputStream is = new ByteArrayInputStream((sb.toString()).getBytes());
javax.xml.parsers.DocumentBuilderFactory factory = avax.xml.parsers.DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
javax.xml.parsers.DocumentBuilder builder = null;
builder = factory.newDocumentBuilder();
org.w3c.dom.Document doc = builder.parse(is);
System.out.println("Got Document ..............");
is.close();
org.apache.axis2.saaj.util.SAAJUtil su = new org.apache.axis2.saaj.util.SAAJUtil();
org.apache.axiom.soap.SOAPEnvelope _returnEnv1 = su.getSOAPEnvelopeFromDOOMDocument(doc);
Am getting ClassCastException at the last line in the code (assigning to SOAPEnvelope).
Can someone please help me with this.
Axis2clients are used to send requests and receive response. Why are you trying to load response from a file? You should receive the response from the backend service. Check this guide to get to know about the clientapi. You can find detail guide in axis2 documentation also.