Pass parameter to REST web service via URL

I am creating a small REST web service using Netbeans. This is my code:

private UriInfo context;
private String name;

public GenericResource() {
}

@GET
@Produces("text/html")
public String getHtml() {
    //TODO return proper representation object
    return "Hello "+ name;
}


@PUT
@Consumes("text/html")
public void putHtml(String name) {
    this.name = name;
}

I call the get ok method, because when I call http: // localhost: 8080 / RestWebApp / resources / greeting , I get "Hello null", but I'm trying to pass the parameter http: // localhost: 8080 / RestWebApp / resources / greeting ? name = Krt_Malta , but the PUT method is not called ... Is this the correct way to pass a parameter or am I missing something

I am new to bdw holidays, so if this is a simple question.

Thank you! :) Krt_Malta p>

+3
source share
4 answers

URL- - GET. PUT, , . , URL GET.

0

HTTP-, POST GET:

GET /RestWebApp/resources/greeting?name=Krt_Malta HTTP/1.0

POST /RestWebApp/resources/greeting?name=Krt_Malta HTTP/1.0

HTML-, - "PUT":

<form action="/RestWebApp/resources/greeting" method="PUT">
0

JAX-RS , @PUT, PUT. , cURL HTTP.

, JAX-RS @QueryParam.

public void putWithQueryParam(@QueryParam("name") String name) {
  // do something
}
0

:

@PUT
@path{/putHtm}
@Consumes("text/html")
public void putHtml(String name) {
    this.name = name;
}

- Google Volley, .

        GsonRequest<String> asdf = new GsonRequest<String>(ConnectionProperties.happyhourURL + "/putHtm", String.class, yourString!!, true,
                new Response.Listener<Chain>() {
                    @Override
                    public void onResponse(Chain response) {

                    }
                }, new CustomErrorListener(this));
        MyApplication.getInstance().addToRequestQueue(asdf);

GsonRequest :

public GsonRequest(String url, Class<T> _clazz, T object, boolean needLogin, Listener<T> successListener, Response.ErrorListener errorlistener) {
    super(Method.PUT, url, errorlistener);
    _headers = new HashMap<String, String>();
    this._clazz = _clazz;
    this.successListener = successListener;
    this.needsLogin = needLogin;
    _object = object;
    setTimeout();
}
0

Source: https://habr.com/ru/post/1773857/


All Articles