i am trying to learn restful services and as part of that i am designing a sample request and response page...see i am getting everything right except the following resource called:
<i>
package com.tutorialspoint;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@Path("/RestService")
public class CrunchifyRESTService {
@POST
@Path("/crunchifyService")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response crunchifyREST(InputStream incomingData) {
StringBuilder crunchifyBuilder = new StringBuilder();
try {
BufferedReader in = new BufferedReader(new InputStreamReader(incomingData));
String line = null;
while ((line = in.readLine()) != null) {
crunchifyBuilder.append(line);
}
} catch (Exception e) {
System.out.println("Error Parsing: - ");
}
System.out.println("Data Received: " + crunchifyBuilder.toString());
// return HTTP response 200 in case of success
return Response.status(200).entity(crunchifyBuilder.toString()).build();
}
@GET
@Path("/verify")
@Produces(MediaType.APPLICATION_JSON)
public Response verifyRESTService(InputStream incomingData) {
String result = "CrunchifyRESTService Successfully started..";
// return HTTP response 200 in case of success
return Response.status(200).entity(result).build();
}
@POST
@Path("/login")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response loginserv(newUser user){
String data="";
data=user.uname+" and auth "+user.pwd;
return Response.status(200).entity(data).build();
}
}
and the request i am using is POST and the url is http://localhost:8080/com/rest/RestService/login/sudheer/123
and the response i am getting is
<!DOCTYPE html>
<html>
<head>
<title>Apache Tomcat/8.5.4 - Error report</title>
<style type="text/css">H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}.line {height: 1px; background-color: #525D76; border: none;}</style>
</head>
<body>
<h1>HTTP Status 415 - Unsupported Media Type</h1>
<div class="line"></div>
<p>
<b>type</b> Status report
</p>
<p>
<b>message</b>
<u>Unsupported Media Type</u>
</p>
<p>
<b>description</b>
<u>The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.</u>
</p>
<hr class="line">
<h3>Apache Tomcat/8.5.4</h3>
</body>
</html>
Response headers
Content-Language →en
Content-Length →1133
Content-Type →text/html;charset=utf-8
Date →Mon, 24 Oct 2016 06:35:48 GM
T
and know what is the exact problem with the code pls clarify me