I have written a resteasy-spring service :
@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";
}
}
When i try calling this service from Browser, the response is proper :
http://localhost:8080/ControlAppWeb/rest/ab/ac/abc/name
Success
But when i try calling it from a Rest Client API, it returns a web page which is actually the welcome page for the web application where i have incoroporated the rest service :
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();
}
Kindly help, as to where am i going wrong in invoking from Java API
Further: i tries removing the controller and request mapping annotation from the Service, still the browser call worked and java rest client didn’t. Weird thing is that even if my modify the url to anything random (in the java client) excluding the intial part (http://localhost:8080/ControlAppWeb), the output remains the same and never is an error thrown…
The problem in this case seemed to be arising due to a ‘filter‘ configured in the web.xml of the control application. Due to which all the requests to /* were getting redirected to the welcome page. Removing the filter configuration from the web.xml file resolved the problem and the response for the Java Rest API was ‘Success’ same as for the call from the Browser. Though i am still unclear on why the filter did not affect the request from browser but did so for the request from Java Client.
Anyways hope this helps others who might be struggling with a similar problem.