When I try to form the link like below.
Link userLink = linkTo((controllerClass).slash("?location="+location+"&scheduledDepartur="+scheduleDepatur).withRel(USER_REL));
and it shows error as
The method slash(String) is undefined for the type Class<TrainController>
When try to use below link method I got
Link selfLink = linkTo(methodOn(controllerClass).getOffTrains(trainStatus, valid, locale).slash("?depatureLocation="+depatureLocation+"&scheduledDepartureDate="+scheduleDepatureDate).withSelfRel());
got below error
The method slash(String) is undefined for the type HttpEntity<TrainStatus>.
Help me to resolve this issue.
all your parenthesis are off.
Link selfLink = linkTo(methodOn(controllerClass).getOffTrains(trainStatus, valid, locale).slash("?depatureLocation="+depatureLocation+"&scheduledDepartureDate="+scheduleDepatureDate).withSelfRel());
should be
Link selfLink = linkTo(methodOn(controllerClass).getOffTrains(trainStatus, valid, locale)).slash("?depatureLocation="+depatureLocation+"&scheduledDepartureDate="+scheduleDepatureDate).withSelfRel());
I'm surprised those query string parameters you have aren't methods on the getOffTrains controller method..then it would just work for you.
Related
i have a request with empty path variable that get me a 404 response.how can i get my GET request to go into my webservice and throw exception showing that the pathvariable is empty. for now i'm having a 404 not found exception. exemple : GET
request url : hello/123/me ==> works fine
request url hello//me ===> 404 not found
#GetMapping(value = "/hello/{uuid}/me")
public ResponseEntity<Void> hello(
#PathVariable(name = "uuid", required = false) String uuid){
You can achieve it with the following code.
#GetMapping(value = {"/hello/{uuid}/me", "/hello//me"})
public ResponseEntity<Void> hello(#PathVariable(name = "uuid", required = false) String uuid) {
What I have done is, just added /hello//me also to the request mapping of the same function. You can add multiple URLs just like this.
I suggest making the URL without parameters as /hello/me just to make it a standard, obviously if you have a scenario where you want to achieve it with /hello//me, you can do that.
Maybe this the answer you looking for...., basically you want to pass the value of that uuid to be checked if its valid or not. If its not you can pass the exception into the web service using IllegalStateException. If you using getter and setter with JPA in your spring this can be done :
Optional<ClassName> validUuid = NameObjectofYourJPARepo.findByUuid(YourClassName.getUuid());
if(!validUuid.isPresent()) {
throw new IllegalStateException("404 not found");
}
I hope this can answer your problem
I'm trying to get the value of a field from a single type collection in the home page of a strapi plugin.
const test = strapi.query('global-settings').find({},{'externalUrl':1})
It's returning me an Uncaught TypeError: strapi.query is not a function
Any idea why?
I am not sure about the last part of your request.
But remember that those requests are asynchronous, so try adding await to the call.
This is an example of a query I am using.
const user_settings = await strapi.query('user-settings').find({Send_Monthly_Email: true})
So, that's why I don't understand why you have an empty parameter on that query. >> find({},{'externalUrl':1})
I am assuming you are inside a controller or inside a service.
I am building a plugin in NativeScript.
When I try to access "presentViewController" method on rootViewController, I get the error "property presentViewContrller does not exist".
const rvc = UIApplication.sharedApplication.keyWindow.rootViewContrller;
rvc.presentViewContrller(myViewController, true, completion() {});
It suggests to use presentViewContrllerAnimatedCompletion which does not accept my view controller.
Could you please assist what part of my code (or maybe setup!) is wrong?
The right method name is presentViewControllerAnimatedCompletion only.
You should combine the parameter names with method name while marshalling Objective C to JS/TS.
presentViewController:animated:completion
I have been beating my head against this for a while now and still no joy. I am new to Spring and could really use some help.
I am trying to use Spring Boot to return a list of codes from a DB table. When I call my REST controller from a URL in a browser...
Example URL: localhost:8081/cis/utl/lookupchoice/O.s/
It returns this:
[
{"lookupId":10,"choiceGroup":"O.s","choiceCode":null,"displayLabel":"Pending","hidden":false,"displayOrder":1},
{"lookupId":11,"choiceGroup":"O.s","choiceCode":null,"displayLabel":"Active","hidden":false,"displayOrder":2},
{"lookupId":12,"choiceGroup":"O.s","choiceCode":null,"displayLabel":"Archived","hidden":false,"displayOrder":3},
{"lookupId":13,"choiceGroup":"O.s","choiceCode":null,"displayLabel":"Placeholder","hidden":false,"displayOrder":4}
]
But, I get an error message when trying to run this from a client controller. The call looks like this:
//
//Compiles but does not work
LookupChoice lookupChoice = restTemplate.getForObject(REST_URI+"/utl/lookupchoice/O.s/",
LookupChoice.class);
The error: nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of com.MyPakage.repository.LookupChoice out of START_ARRAY token
Assuming the error occurs because an array is returned instead of a single object, I changed the code to this:
//
//Does not compile
Iterable<LookupChoice> lookupChoice = restTemplate.getForObject(REST_URI+"/utl/lookupchoice/U.r/",
Iterable<LookupChoice.class>);
But, now I get an error in Intellij. It's indicating that an "Expression expected" for the Iterable<LookupChoice.class> param, and I can't get past this.
Thank you for your time and assistance,
Ed
Thanks for your reply. I opted for this and it all seems to work now. Thanks for your help!
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<Object[]> responseEntity;
Object[] lookupChoice;
responseEntity = restTemplate.getForEntity(REST_SERVICE_URI+"/utl/lookupchoice/O.s/" , Object[].class);
lookupChoice = responseEntity.getBody();
model.addAttribute("Status", lookupChoice);
The reason it doesn't compile is because it's impossible in Java to pass a class of generic type parameters because they don't exist at runtime.
You have two options here, either use an array (LookupChoice[]) and convert it to a List<LookupChoice> if necessary:
restTemplate.getForObject(url, LookupChoice[]);
Or you can use the ParameterizedTypeReference:
restTemplate.exchange(url, HttpMethod.GET, null, new ParameterizedTypeReference<List<LookupChoice>>() {}).getBody()
It is an interface though, so either subclass it or use an anonymous class like I did in the code example above.
Also, ParameterizedTypeReference only works on the exchange() method if I'm not mistaken, so you'll get a ResponseEntity in stead of your raw object, so you'll have to use the getBody() method.
#RequestMapping(value = "/{Id}", method = RequestMethod.GET)
public String searchCity( #PathVariable ("Id") Long Id) {
mymethod.something(id);
return "successpage";
}
When I'm trying to write some number it print me Eror 404 resource is not available, but when I write {Id} ("7DId7D" smthing like this) it redirects me to succespage, What is the problem? Help me please...
The information you provided conflicts with known behavior of Spring MVC
http://localhost:8080/MyCountryProject/7 should maps to searchCity fine
http://localhost:8080/MyCountryProject/%7Bld%7D should not even map to searchCity
I would check following to further isolate the problem:
Are you sure you're testing against the right controller? If your controller has #RequestMapping("myController") then your URL would be http://localhost:8080/MyCountryProject/MyController/7
Are you sure you're posting with the correct HTTP method? If you're HTTP form is POST, it wouldn't map to searchCity method
The conversion from string into Long is done by Spring MVC builtin property editor, did you install your own property editor? If so debug this