I want to write Java API code using playframework! (I'm using the Eclipse IDE.)
What would a sample API look like for insertion and selection?
How do I assign URLs in a routes file?
This answer applies to version 3 of the Play framework.
Here is a sample route file configuration to show a page. In this example, you can visit http://yoursite.com/1 , which will call controllers.Application.show("1").
# Extract the page parameter from the path.
# i.e. http://myserver.com/index
GET /:page controllers.Application.show(page)
SELECTION
Here is the corresponding show method definition in the controllers.Application controller:
public Result show(String page) {
String content = Page.getContentOf(page);
response().setContentType("text/html");
return ok(content);
}
INSERTION
For insertion, check out the "Form submission and validation" and "Working with JSON" sections of the documentation. There are examples there; sorry for not adding them here, but these are more complicated for this short format.
Source, and more information: https://www.playframework.com/documentation/3.0.x/JavaRouting
Related
I need to read some properties of a DOM object via the selenium Java API. I'll explain my requirement via an example.
Let's say first I would like to find the <g> element highlighted in the Chrome Developer Tools (as shown below). I can easily do so via the Selenium Java API with the following code.
WebElement gElement = driver.findElement(By.xpath("//*[#data-id='node_grp_0_id52UVV33EHE7']"));
Then I would like to read several properties of this <g> object via the Selenium Java API. So, I click on this <g> element in the Chrome Developer Tools and open the Properties view on the right hand side of the Chrome Developer Tools (as shown below) in order to find the path to various properties. After finding the paths, I now would like to read several of these properties (e.g. ariaChecked and __data__.label) via the Selenium Java API as shown below:
gElement.getAttribute("ariaChecked");
gElement.getAttribute("__data__.label");
Both the above mentioned lines of code returns null.
The following code also does not return the desired property values:
element.getCssValue("ariaChecked");
element.getCssValue("__data__.label");
Does anyone know how to read various properties of a DOM object (listed in the Properties view of the Chrome Developer Tools as shown below) via the selenium Java API?
Thanks in advance!
I've found a workaround to read a property of a web element via Java Script as shown below. Nested properties are also supported by this workaround:
public String getProperty(final String name) {
return getJavascriptExecutor().executeScript("return arguments[0]." + name + ";", webElement).toString();
}
The above method can be invoked as shown below:
String name = getProperty("name");
or
String label = getProperty("__data__.label"); // This is a nested property.
I'm attempting to do a reverse lookup on a route I've created.
The route is defined as such in my routes file:
POST /login controllers.Web.Application.authenticate
However, when I try to do a reverse on it in a form I made, I can't seem to find it. I'm attempting to do a reverse like this:
#helper.form(action = routes.login())) {
rest of the form here...
}
However, the login appears in red in intellij and when attempting to run the program, I get the following error:
play.sbt.PlayExceptions$CompilationException: Compilation error[value login is not a member of object controllers.routes]
I've attempted recompiling the project multiple times and looking around the docs, but it's just not working... Any ideas?
So, an interesting thing happened recently and I found a way to point to the original structure properly. To do so, rather than writing:
routes.Web.Application.authenticate()
As Tyler suggested, I was supposed to write:
Web.routes.Application.authenticate()
Which is totally counter-intuitive and all, but that allows me to use the original package structure.
Edit:
As we discovered in the comments, the reverse router doesn't seem to like sub packages. You should remove the Web part of your package, and move everything up a level, then change the code to be this:
#helper.form(action = routes.Application.authenticate())) {
rest of the form here...
}
Original answer:
You need to refer to the controller function, and not the name of the route, so it should look something like this:
#helper.form(action = routes.Web.Application.authenticate())) {
rest of the form here...
}
Can anyone give me at least one idea to how can I connect java with protoge?
how can I access OWL using jena API in java?!
The Jena website has plenty of tutorials available. If you have difficulties getting started, please post the code that does not work and we'll help you along.
First tutorial here
// some definitions
static String personURI = "http://somewhere/JohnSmith";
static String fullName = "John Smith";
// create an empty Model
Model model = ModelFactory.createDefaultModel();
// create the resource
Resource johnSmith = model.createResource(personURI);
// add the property
johnSmith.addProperty(VCARD.FN, fullName);
In order to make this work, you'll need the right imports. Assuming that the Java technicalities are not a problem, this example shows how to create a statement and add it to a model, i.e., an rdf file.
From the same page you can get to more complex material, including OWL tutorials.
You have not mentioned which task you're trying to carry out. Can you describe it?
I am new to apache olingo web service. I struck for the past two weeks to implement filter and pagination to my service.I am using latest olingo version 4. I google it and looked many blogs but there is no clear explanation. Kindly help me with sample code.It will be more use full for me.
Following are my scenario,
I am gettting the data from existing web service as XML and then i parse the XML using JAXB make it as list of entity in olingo web services.
Here how can i apply filter. If i having $filter in my URL means it throws page not found exception. If i remove that means it will work and give full result.
My question is How to apply olingo filter in XML string or
How to apply it in List of entity which i having it in a method.
Kindly give me the explenation with some sample code.
I need to give pagination to my response JSON.I need to limit the JSON value as 25 per page and need to next page URL also(For 25 to 50) like that.
How to implement this also.
I overcome lots of blogs but didn't work for me.
Here
https://templth.wordpress.com/2015/04/03/handling-odata-queries-with-elasticsearch/
In this blog,They didn't explain with full code.My problem is,I am getting data from existing web service as XML string and parse it and having in list of entity.
And I also refer this blog,
https://olingo.apache.org/doc/odata2/tutorials/Olingo_Tutorial_AdvancedRead_FilterVisitor.html
In this blog also they tell how to construct the query,My problem is how to implement $filter,$select etc from ODATA in my web service and how to filter from xml string or list of entity
Kindly suggest me with sample code.Thanks.
The Olingo team provides a huge amount of well organized help resources. The sample projects can be found by these instructions:
http://olingo.staging.apache.org/doc/odata4/tutorials/prerequisites/prerequisites.html#tutorial-sources
Complete tutorial about hte pagination can be found here:
https://olingo.apache.org/doc/odata4/tutorials/sqo_tcs/tutorial_sqo_tcs.html
I can also provide you the sample code. For example, if talking about the pagination, in your EntityCollectionProcessor implementation you just have to read the top and skip parameters and use them when generating a query to your existing web service using XML, JSON or whatever:
int skipNumber = 0;
SkipOption skipOption = uriInfo.getSkipOption();
if (skipOption != null) {
skipNumber = skipOption.getValue();
}
int topNumber = -1;
TopOption topOption = uriInfo.getTopOption();
if (topOption != null) {
topNumber = topOption.getValue();
}
EntityCollection responseEntityCollection = getDataFromService(edmEntitySet, skipNumber, topNumber);
Here the getDataFromService method generates a request to your services passing the top/skip parameters and retrieves the response. It is not advisable to filter the result set on the OData service side. Some additional steps you can find in the above mentioned tutorial.
Filtering is more complex but the main idea you can find from here:
https://olingo.apache.org/doc/odata4/tutorials/sqo_f/tutorial_sqo_f.html
I am making a call from a server that is located in US to FindItemsAdvanced of ebay finding api.
I define ListedIn as "EBAY-ENCA", however, when I make the call - I see that it doesn't return results. I believe that this is because that items are not available to US.
I see that there is a parameter called: AvailableTo - but how can I say "to all countries" ? Writing each iso code in the world could be exhausting..
My code:
ItemFilter marketFilter = new ItemFilter();
marketFilter.setName(ItemFilterType.LISTED_IN);
marketFilter.getValue().add("EBAY-ENCA");
request.getItemFilter().add(marketFilter);
ItemFilter conditionFilter = new ItemFilter();
conditionFilter.setName(ItemFilterType.AVAILABLE_TO);
conditionFilter.getValue().add("UK");
request.getItemFilter().add(conditionFilter);
In general this call should work - regardless from where you call the API. So I assume that you get an error message from the API that prevent items from being returned. Be aware that the FindItemsAdvanced call of the eBay Finding API requires either a given "categoryId" or a "keyword". Do you set any of these?
Here is the XML payload of a working call:
<findItemsAdvancedRequest xmlns="http://www.ebay.com/marketplace/search/v1/services">
<keywords>iPhone6</keywords>
<itemFilter>
<name>ListedIn</name>
<value>EBAY-ENCA</value>
</itemFilter>
</findItemsAdvancedRequest>
I've created an example in our API playground. It uses the XML version of the Finding API. Just execute the call to see the valid response with items included. You can adapt and customize the request parameters to your needs and see how the API responses.
The "AvailableTo" filter can only be used once per request with exactly one value. So it won't be possible to add it multiple times or to add it once with multiple values. But I'm not sure if I get your use case right. Do you really want to get only those items that are available world wide? If yes, then I'm afraid this most probably isn't possible without filtering them locally (eg. by filtering for "Worldwide" in the "shipToLocations").