RestTemplate exchange fail on GET call but works on CURL - spring

I have the follow GET call works in CURL
curl -X GET 'https://us.api.blizzard.com/profile/wow/character/kiljaeden/n%C3%B8m?access_token=123&namespace=profile-us&locale=en_US'
But the following Java code gives 404 error
String testurl = "https://us.api.blizzard.com/profile/wow/character/kiljaeden/n%C3%B8m?access_token=123&namespace=profile-us&locale=en_US";
RestTemplate restTemplate = new RestTemplate();
String out = restTemplate.getForObject(testurl, String.class);
Exact error
org.springframework.web.client.HttpClientErrorException$NotFound: 404 Not Found
at org.springframework.web.client.HttpClientErrorException.create(HttpClientErrorException.java:85)
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:122)
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:102)
at org.springframework.web.client.ResponseErrorHandler.handleError(ResponseErrorHandler.java:63)

The "n%C3%B8m" part is URL-encoded, and RestTemplate is URL-encoding it again, escaping the % symbols, generating a different URL that causes the 404 error.
If you put the URL right in the code you should use the Java encoding (unicode), in this case use "n\u00F8m" instead of "n%C3%B8m".
If you need to support the "n%C3%B8m" format in the Java code you can use URLDecoder to URL-decode the String before using with RestTemplate.

Related

Spring Cloud Config Server ResourceController does not map request with useDefaultLabel when path contains slashes

I have a simple Spring Cloud Config Server project (using spring-cloud-config-server-4.0.0)
With a default branch property set
spring.cloud.config.server.git.default-label
This works without a label:
GET http://localhost:8888/myAppName/myProfiles/test.txt?useDefaultLabel
This does not (path includes slash):
GET http://localhost:8888/myAppName/myProfiles/path/test.txt?useDefaultLabel
Throws the following Exception:
RefNotFoundException: Ref path cannot be resolved
...
at org.springframework.cloud.config.server.resource.ResourceController.retrieve(ResourceController.java:107)
It resolves to the wrong controller endpoint:
#GetMapping("/{name}/{profile}/{label}/**")
instead of
#GetMapping(value = "/{name}/{profile}/{path:.*}", params = "useDefaultLabel")
To my understanding this should work because of this change: https://github.com/spring-cloud/spring-cloud-config/issues/824
I've tried without success:
Encoding the slash
Assigning something ("true") to the useDefaultLabel request parameter

How to properly connect to my VM to get json?

I'm new in Spring and I have a problem when I run Spring WEB in VM.
Test on local computer works:
I run app mvn spring-boot:run -Dspring-boot.run.profiles=test and check request:
curl -X POST ``http://localhost:8080/api/v1/dictionary/yandex-alice-skill`` -H "Content-Type: application/json" -d "{}"
and get {"response":{"text":"Hi! I can help you to learn words.","end_session":false},"version":"1.0"}
When I run app in VM and try to get json in my VM everything works fine too:
BUT when I try to get json in my local computer I get 404
Page have 404, but why I can't get json? How to properly connect to my virtual machine?
Controller:
#RestController
#Slf4j
#RequestMapping("/api/v1/dictionary/yandex-alice-skill")
#RequiredArgsConstructor
public class DictionaryController {
#Autowired
private DictionaryService dictionaryService;
#PostMapping
public #ResponseBody talkYandexAlice(
#RequestBody YandexAliceRequest request) {
return dictionaryService.talkYandexAlice(request);
}
}
I want to get json, but I get HTML from server.

Why is this handler method(/trying) returning the error 404 instead of sending the request to another handler method /addpage

#RequestMapping("/trying")
public String trying(){
return "/addpage";
}
"/addpage" is a request handler method used for handling a request....... But when I try returning "/addpage" from the handler method "/trying" I get the error 404.
How can I solve this...
Make sure that you project is compiling correctly : mvn clean install
The server is starting without errors
remove the "/" to "/addpage" ==> you do not need it if you dont have a path to put other wise ==> "path/to/folder/addpage"

Html-parsing with Oga and httpclient in ruby

I'm trying to download a page with httpclient and parse it useing oga (https://github.com/YorickPeterse/oga)
My program looks like this:
require 'httpclient'
require 'oga'
url = 'http://stackoverflow.com/questions/1496096/is-there-a-limit-to-the-length-of-html-attributes'
c = HTTPClient.new
content = c.get_content(url)
document = Oga.parse_html(content)
I get this error:
LL::ParserError: Unexpected end of input, expected element closing tag instead on line 431
parser_error at /home/binaryplease/.rvm/gems/jruby-1.7.19/gems/oga-0.3.1-java/lib/oga/xml/parser.rb:255
each_token at /home/binaryplease/.rvm/gems/jruby-1.7.19/gems/oga-0.3.1-java/lib/oga/xml/parser.rb:231
parse at org/libll/Driver.java:303
parse at /home/binaryplease/.rvm/gems/jruby-1.7.19/gems/oga-0.3.1-java/lib/oga/xml/parser.rb:262
parse_html at /home/binaryplease/.rvm/gems/jruby-1.7.19/gems/oga-0.3.1-java/lib/oga/oga.rb:25
(root) at test.rb:12
I verified that httpclient is downloading correctly and the file doesnt end there. I also tryed other links, some work but most of them give me this error.
In general smaller pages seem to work just fine
Is there a problem with the library or am I making an error?

CodeIgniter Curl Library Capturing Error

I am trying to retrieve an error when my CI curl request fails. However, I cant seem to get $this->curl->error_code or $this->curl->error_string to output any data. I am trying to make a request to an API and I am breaking the URL to force an error.
$api_url = "http://breamkebreakmedfd.com";
$this->curl->create($api_url);
$this->curl->execute();
echo($this->curl->error_string);
I get no error when I echo the error.

Resources