I'm writing an app with Java play OAuth2. When I was went through on a sample code(code), It has a line,
String url = routes.Twitter.auth().absoluteURL(request());
Twitter is a class and solve the compile error issue on this line. How may I call the routes like this in a controller?
That's reverse routing and syntax is valid, so if you have compile error at this point that means that you probably didn't add valid route declaration for your action within the /conf/routes file
Related
I have quick and relatively easy question I think, but I don't get it so here I am.
So, I've got something like this:
file.upload = Upload.upload({
url: 'sendemail',
data: {file: file}
});
Whatever about rest of the code. I want to know for what is that url: section. It's for my java spring #RequestMapping("/sendemail")? Or it is for folder on my server to store the file?
Please answer me, I just want to know it :<
So when you are using Java Spring. It provides you a lots of cool annotations.
One of them is
#RequestMapping()
This annotation helps for routing your services. So when you write RequestMapping("/sendemail"), it looks for the end point sendemail and does the job accordingly.
Now to your question,
So {url: 'sendemail'} specifies that the url should end with /sendemail so as to do the mentioned job.
I am using the Stash's REST API in my project. My task is to get the tag details for a specific tag. After checking the Stash's REST API documentation, I found the correct endpoint that I should be using. It is
/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/tags/{name:.*}
Please see this link for the Stash's REST API documentation.
There is one more endpoint /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/tags
With this endpoint I am able to retrieve all the tags. The StashTag object looks something like this.
{
"id": "refs/tags/v4.0.0",
"displayId": "v4.0.0",
"latestChangeset": "234dadf41742cfc2a10cadc7c2364438bd8891c5",
"latestCommit": "234dadf41742cfc2a10cadc7c2278658bd8891c5"
"hash" : "null"
}
My first problem is, I don't know which field to use as the parameter for {name:.*}. Should it be the displayId or Id or anything else.
The second problem is, I don't understand what it means to have : (colon) followed by a . (dot) in the endpoint /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/tags/{name:.*}.
Can someone explain me what is the purpose of :. in the path param and how to hit this kind of an endpoint. Also an example of the complete endpoint would be nice.
So far I have tried hitting
https://stashtest.abc.com/rest/api/1.0/projects/KARTIK/repos/kartiks-test-repository/tags/v4.0.0
https://stashtest.abc.com/rest/api/1.0/projects/KARTIK/repos/kartiks-test-repository/tags/refs/tags/v4.0.0
None of these endpoints work.
Any help is appreciated.
The {name:.*} is really just saying that the field name can be anything. Chalk this one up to poor documentation on their part. Think of it like Regex field, because that's exactly what it is. I'm sure at one point they had something like ^[0-9] then went back and changed it when they realized using only tag numbers would omit anyone using their lightweight tag features.
Remove the v from your tag version and see if that helps. If it does not, I would also recommend creating a lightweight tag (something like mytag) and seeing if you can hit it that way (i.e., /kartiks-test-repository/tags/mytag).
But looking at that documentation is telling me that your v in your tag name is throwing off the REST call.
I am using Apache Camel in my Application. I am trying to use Composed Message Processor. I have exchange whose body contains some URLs to hit and by using split(body(), MyAggregationStrategy()), I am trying to get the data from urls and using Aggregation Strategy want to combine each data. But there is a problem where I am stuck. If there is some invalid url on the first line of the body then it happens that aggregation is working fine but it is not moving to the next processor and if invalid url is anywhere else except first line than it is working fine..
please help,
Here is the code for reference
onException(HttpOperationFailedException.class).handled(true)
.retryAttemptedLogLevel(LoggingLevel.DEBUG)
.maximumRedeliveries(5).redeliveryDelay(3000)
.process(new HttpExceptionProcessor(exceptions));
from("jms:queue:supplier")
.process(
new RequestParserProcessor(payloadDetailsMap,
metaDataDetailsPOJO, routesEndpointNamePOJO))
.choice().when(new AggregateStrategy(metaDataDetailsPOJO))
.to("direct:aggregate").otherwise().to("direct:single");
from("direct:aggregate").process(new SplitBodyProcessor())
.split(body(), new AggregatePayload(aggregatePayload))
.to("direct:aggregatepayloadData").end()
.to("direct:payloadDataAggregated").end();
from("direct:aggregatepayloadData").process(basicProcessor)
.recipientList(header(ApplicationConstants.URL));
from("direct:payloadDataAggregated")
.process(
new AggregateJsonGenerator(aggregatePayload,
payloadDetailsMap, metaDataDetailsPOJO)).
In this code AggregateJsonProcessor is never called if there some invalid url on the first hit..
You probably need to set continue(true) in your OnException code. See here:
http://camel.apache.org/exception-clause.html
Good day Everyone,
I am new to Play framework and am trying to get started building an application. Under the app/controllers folders i have created sub packages so i have something like app/controllers/products/ProductController.class.
In my routes.conf file i have added a sample route like this
GET /createproduct controllers.products.ProductController.listAllProducts()
POST /createproduct controllers.products.ProductController.createProductDetail()
and i can goto the url http://localhost:9000/createproduct and see a sample view that i created.
My issue now is that i want to add a form to the view and when i try to use the form helper method to POST data to the POST URL above from my new view like this
#helper.form(action = routes.products.ProductController.createProductDetail()) {
i get the error that
value products is not a member of object controllers.routes
All the samples that i saw online only use the route.Application example which is doesnt fit my issue.
So my question is how do i reverse route to this action or route from a view using the Form helper
The valid syntax is:
[full-package-name].routes.[controller].[method]
So in your case it should be
controllers.products.routes.ProductController.createProductDetail()
controllers.routes is imported implicity, therefore for using with controllers in default package you can short it to:
routes.Controller.action()
I have a request in the form of json,which looks like this.
{"User":{"email":"test#test.com","FName":"fname"}}
When I try to send it via REST assured ,the U in the User is seen to change its case.i.e. changes to a lower case.
To send the request I have created my own serialized classes. The end-point is seen like this:
{"user":{"email":"test#test.com","FName":"fname"}}
but somehow it is not changing the case of the remaining fields.I don't knwo why this is happening.
I've even tried to create a filter for a request specification,but couldn't go any further with that too. I also then thought of first converting the serialized object to a gson,and then check the case of the User, still no luck.
Error I get is:
The class, User,does not match the payload object for payload.
Please note I am trying to use the service of another team,so I really don't have an access to their code-base(Although not needed).Observe the space between the first , and user in the above message, is it worth noting?
I finally got away with it by converting the object(JSON) into a JSON string/payload.
And while passing it as a form parameter,passed the string/payload.
Somehow,still couldn't figure out why the formparameter/formparam option in RESTAssured did not allow the serialized object to go through. But,anyway got around it this time.
Thanks for the suggestions all.