首页 > 解决方案 > 客户端休息 Api 不使用服务器中声明的方法

问题描述

我正在使用 rest jersey 开发签名应用程序,但客户端出现错误,它没有使用服务器应用程序中定义的功能。我找不到问题。

我的控制器:

@RequestMapping(value = { "/signpdf50" }, method = RequestMethod.POST)
@Consumes({"text/plain,text/html"})
@Produces("application/pdf")
public ResponseEntity<String>  signPDF5(@RequestBody String pdf) throws Exception {...}

测试方法:

public static Response signPDF50(String pdf1) throws ClientProtocolException, IOException {
    ClientConfig clientConfig = new ClientConfig();

    HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic("sam", "sam");
    clientConfig.register(feature);
    Client client = ClientBuilder.newClient(clientConfig);

    Entity<String> pdf= Entity.json(pdf1);

    Response response = client.target("http://localhost:8094/rubi/rest/signpdf50")
            .request("application/pdf")
            .accept(MediaType.APPLICATION_JSON).post(pdf);
    System.out.println(response.getLocation());
    return response;
}

当我调用此方法时,它总是给我null结果,并且没有任何反应,这意味着它没有使用该方法。
字符串pdf是一个字节数组,在调用方法之前编码为字符串,然后在控制器中解码。

控制器中

@RestController
@ComponentScan
@RequestMapping("/rest")
public class SigningControllerREst {
...
}

我试过 System.out.println(response.readEntity(String.class));

<html><head><title>Login Page</title></head><body onload='document.f.username.focus();'>
<h3>Login with Username and Password</h3><form name='f' action='/rubi/login' method='POST'>
<table>
    <tr><td>User:</td><td><input type='text' name='username' value=''></td></tr>
    <tr><td>Password:</td><td><input type='password' name='password'/></td></tr>
    <tr><td colspan='2'><input name="submit" type="submit" value="Login"/></td></tr>
    <input name="_csrf" type="hidden" value="bbff729a-34e6-465c-a86b-0f521a927ccd" />
</table>
</form></body></html>

application.properties我添加了这两行进行身份验证

spring.security.user.name=sam
spring.security.user.password=sam

谢谢你的帮助。

标签: javaspringrestspring-bootjersey-client

解决方案


推荐阅读