0

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?

halfer
  • 19,824
  • 17
  • 99
  • 186
Watt
  • 3,118
  • 14
  • 54
  • 85
  • Are you using the AJAX console in your browser? Chrome and Safari have it built in, Firefox uses Firebug. Checking that would show whether the response from the web service is broken or not. Given the error message, of course, I would concentrate on the Java side of things. – halfer Apr 09 '13 at 20:55

2 Answers2

1

Acording to Pavel Bucek:

It is just minor issue and it has been already fixed - log level for this message was changed to FINE instead of SEVERE..; 1.10 won't be producing these annoying messages anymore.

It does not affect wadl generation at all. It is related to XML Schema generation and is kind of expected in these cases.

Source: http://java.net/projects/jersey/lists/users/archive/2011-10/message/117

0

I guess you cannot return a String array. See here https://stackoverflow.com/a/5393792/461499

Community
  • 1
  • 1
Rob Audenaerde
  • 19,195
  • 10
  • 76
  • 121
  • ok, is there an alternate way to populate the dropdown? The service is doing some complex task, I tried to show a simplified version here. I need to populate dropdown from data returned from the service. – Watt Apr 09 '13 at 20:27
  • Did you check the answer and question in the link? – Rob Audenaerde Apr 09 '13 at 20:28
  • Just read it, please see comments on answer of question you referred, people are complaining that it doesn't work, though somehow OP accepted it. I will try if it works for me in populating drop-down and report here. – Watt Apr 09 '13 at 20:51