I started learning about Jersey web services from this article, and created one. Next thing I want to do is populate a drop-down menu on my webpage from data returned from this service.
But, I get this error message on console where webservice is running every-time I click on more button:
java.lang.IllegalAccessException: Class com.sun.jersey.server.wadl.generators.WadlGeneratorJAXBGrammarGenerator$8 can not access a member of class javax.ws.rs.core.Response with modifiers "protected"
Here is how simplified version of Service java code looks:
@Path("/abcResource")
public class AbcResource{
@GET
@Path("showAllStr")
@Produces(MediaType.TEXT_PLAIN)
public String[] getAllStr() {
String[] result={"option1", "option2","option3"};
return result
}
//This works!! give me results on http://localhost:8080/rest/abcResource/showAll in browser that shows that service is running fine
@GET
@Path("showAll")
@Produces(MediaType.TEXT_PLAIN)
public String showAllStr() {
String result="blah lblah";
return result
}
}
JavaScript code:
<script type="text/javascript">
var offset = 0;
var howMany = 5;
$(document).ready(function() {
$("#btnMore").click(function() {
// fetch some more records from the server side
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "http://localhost:8080/rest/abcResource/showAllStr",
success: onSuccess,
error: onError
});
});
});
function onSuccess(result) {
// process web service return data
// populate ul with data
$("#datalist").empty();
var strings = result.d;
for (var i = 0; i < strings.length; i++)
$("#datalist").append("<li>" + strings[i] + "</li>");
// move offset
offset += howMany;
}
function onError(result) {
// ajax call failed
alert(result.status + ': ' + result.statusText);
}
</script>
HTML code which should open a drop down:
<form id="form1" runat="server">
<div>
<ul id="datalist"></ul>
<br />
<input type="button" id="btnMore" value="more" />
</div>
</form>
I don't get anything in my dropdown either in Chrome or Firefox, but when I open http://localhost:8080/rest/abcResource/showAll
in browser I see the service returning a string.
I am not sure what's wrong I am doing. Can you figure it out from above code?