我写了一个 resteasy-spring 服务:
@Controller
@RequestMapping("/abr/asd")
@Path("/ab/ac")
public class JobSchedulerService {
private static final Logger LOGGER = Logger.getLogger(JobSchedulerService.class);
@GET
@Path("/abc/{param}")
public String scheduleJobs(@PathParam("param") String name) {
return "Success";
}
}
当我尝试从浏览器调用此服务时,响应是正确的:
http://localhost:8080/ControlAppWeb/rest/ab/ac/abc/name
Success
但是当我尝试从 Rest Client API 调用它时,它会返回一个网页,该网页实际上是 Web 应用程序的欢迎页面,我在其中包含了 rest 服务:
try {
URL url = new URL("http://localhost:8080/WebApp/rest/ab/ac/abc/name");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");
if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
throw new RuntimeException("Failed! " + conn.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String output;
System.out.println("Output from Server is: ");
while ((output = br.readLine()) != null) {
System.out.println(output);
}
conn.disconnect();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
请帮忙,关于我从 Java API 调用时哪里出错了
此外:我尝试从服务中删除控制器和请求映射注释,浏览器调用仍然有效,而 java rest 客户端没有。奇怪的是,即使我将 url 修改为任何随机的(在 java 客户端中),不包括初始部分(http://localhost:8080/ControlAppWeb),输出保持不变并且永远不会抛出错误......