我在SpringBootApplication中编写了非常基本的REST服务.当我试图打到api时,我得到了响应Unexpected 'S'
这是我的api,
@RestController
@RequestMapping(value="/rally")
public class CreateProjectApi {
@RequestMapping(value = "/createProject",
produces = { "application/json" },
consumes = { "application/json" },
method = RequestMethod.GET)
public ResponseEntity<String> createProj() {
String s = "Success...";
return new ResponseEntity<String>(s, HttpStatus.OK);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的POM.XML,
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.altimetrik.rally</groupId>
<artifactId>RallyRestApi</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>RallyRestApi</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency> …Run Code Online (Sandbox Code Playgroud) 我正在尝试进行 oAuth2 DB 身份验证,下面是我使用 tokenUrl 作为的代码片段
http://localhost:8025/oauth2db/oauth/token?grant_type=password&username=nithi5@gmail.com&password=nithi%
HttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(tokenUrl);
try {
String auth = authConfiguration.getDatabaseClientId() + ":" + authConfiguration.getDatabaseClientSecret();
byte[] authEncrypted = Base64.encodeBase64(auth.getBytes(Charset.forName("ISO-8859-1")));
httpPost.setHeader("Authorization", "Basic " + new String(authEncrypted));
}
HttpResponse httpResponse = httpClient.execute(httpPost);
Run Code Online (Sandbox Code Playgroud)
在这样做时,我收到错误
"Malformed escape pair at index 103: http://localhost:8025/oauth2db/oauth/token?grant_type=password&username=nithi5@gmail.com&password=nithi%"
Run Code Online (Sandbox Code Playgroud)
下面我附上完整的日志
2018-02-14 11:28:08.991 INFO 18028 --- [nio-8027-exec-1] c.a.s.c.oauth2.OAuth2Controller : *********Login WithDataBase*****************
2018-02-14 11:28:08.991 INFO 18028 --- [nio-8027-exec-1] com.altimetrik.security.util.OAuth2Util : token URLhttp://localhost:8025/oauth2db/oauth/token?grant_type=password&username=nithi5@gmail.com&password=nithi%
2018-02-14 11:28:09.004 ERROR 18028 --- [nio-8027-exec-1] c.a.s.exception.RESTExceptionHandler : Error occured …Run Code Online (Sandbox Code Playgroud)