Search in sources :

Example 16 with Form

use of jakarta.ws.rs.core.Form in project radiobrowser4j by sfuhrm.

the class RadioBrowser method listStationsPathWithLimit.

/**
 * Get a list of all stations on a certain API path.
 * @param limit the limit of the page to retrieve.
 * @param path the path to retrieve, for example "json/stations".
 * @param listParam the optional listing parameters.
 * @return the partial list of the stations. Can be empty for exceeding the
 * possible stations.
 */
private List<Station> listStationsPathWithLimit(final Optional<Limit> limit, final String path, final ListParameter... listParam) {
    MultivaluedMap<String, String> requestParams = new MultivaluedHashMap<>();
    Arrays.stream(listParam).forEach(lp -> lp.applyTo(requestParams));
    Entity<Form> entity = Entity.form(requestParams);
    Response response = null;
    try {
        WebTarget target = webTarget.path(path);
        if (limit.isPresent()) {
            target = target.path(Integer.toString(limit.get().getSize()));
        }
        response = builder(target).post(entity);
        checkResponseStatus(response);
        return response.readEntity(new GenericType<List<Station>>() {
        });
    } finally {
        close(response);
    }
}
Also used : MultivaluedHashMap(jakarta.ws.rs.core.MultivaluedHashMap) Response(jakarta.ws.rs.core.Response) Form(jakarta.ws.rs.core.Form) List(java.util.List) WebTarget(jakarta.ws.rs.client.WebTarget)

Example 17 with Form

use of jakarta.ws.rs.core.Form in project radiobrowser4j by sfuhrm.

the class RadioBrowser method listStationsBy.

/**
 * Get a list of stations matching a certain search criteria.
 * Will return a single batch.
 * @param paging the offset and limit of the page to retrieve.
 * @param searchMode the field to match.
 * @param searchTerm the term to search for.
 * @param listParam the optional listing parameters.
 * @return the partial list of the stations. Can be empty for exceeding the
 * number of matching stations.
 */
public List<Station> listStationsBy(@NonNull final Paging paging, @NonNull final SearchMode searchMode, @NonNull final String searchTerm, final ListParameter... listParam) {
    MultivaluedMap<String, String> requestParams = new MultivaluedHashMap<>();
    applyPaging(paging, requestParams);
    Arrays.stream(listParam).forEach(l -> l.applyTo(requestParams));
    Entity<Form> entity = Entity.form(requestParams);
    Response response = null;
    try {
        response = builder(webTarget.path("json/stations").path(searchMode.name().toLowerCase()).path(searchTerm)).post(entity);
        checkResponseStatus(response);
        return response.readEntity(new GenericType<List<Station>>() {
        });
    } finally {
        close(response);
    }
}
Also used : MultivaluedHashMap(jakarta.ws.rs.core.MultivaluedHashMap) Response(jakarta.ws.rs.core.Response) Form(jakarta.ws.rs.core.Form) List(java.util.List)

Example 18 with Form

use of jakarta.ws.rs.core.Form in project radiobrowser4j by sfuhrm.

the class RadioBrowser method listStationsPathWithPaging.

/**
 * Get a list of all stations on a certain API path.
 * @param paging the offset and limit of the page to retrieve.
 * @param path the path to retrieve, for example "json/stations".
 * @param listParam the optional listing parameters.
 * @return the partial list of the stations. Can be empty for exceeding the
 * possible stations.
 */
private List<Station> listStationsPathWithPaging(final Optional<Paging> paging, final String path, final ListParameter... listParam) {
    MultivaluedMap<String, String> requestParams = new MultivaluedHashMap<>();
    paging.ifPresent(p -> applyPaging(p, requestParams));
    Arrays.stream(listParam).forEach(lp -> lp.applyTo(requestParams));
    Entity<Form> entity = Entity.form(requestParams);
    Response response = null;
    try {
        response = builder(webTarget.path(path)).post(entity);
        checkResponseStatus(response);
        return response.readEntity(new GenericType<List<Station>>() {
        });
    } finally {
        close(response);
    }
}
Also used : MultivaluedHashMap(jakarta.ws.rs.core.MultivaluedHashMap) Response(jakarta.ws.rs.core.Response) Form(jakarta.ws.rs.core.Form) List(java.util.List)

Example 19 with Form

use of jakarta.ws.rs.core.Form in project minijax by minijax.

the class FormParamTest method testWholeForm.

@Test
void testWholeForm() {
    final Entity<Form> form = Entity.form(new Form("test", "Hello"));
    assertEquals("Hello", server.target("/wholeform").request().post(form, String.class));
}
Also used : Form(jakarta.ws.rs.core.Form) Test(org.junit.jupiter.api.Test)

Example 20 with Form

use of jakarta.ws.rs.core.Form in project minijax by minijax.

the class FormParamTest method testFormParamDefaultValue.

@Test
void testFormParamDefaultValue() {
    final Entity<Form> form = Entity.form(new Form());
    assertEquals("foo", server.target("/defval").request().post(form, String.class));
}
Also used : Form(jakarta.ws.rs.core.Form) Test(org.junit.jupiter.api.Test)

Aggregations

Form (jakarta.ws.rs.core.Form)80 Response (jakarta.ws.rs.core.Response)60 Test (org.junit.Test)33 Test (org.junit.jupiter.api.Test)24 MinijaxTest (org.minijax.rs.test.MinijaxTest)14 Builder (jakarta.ws.rs.client.Invocation.Builder)11 WebTarget (jakarta.ws.rs.client.WebTarget)10 MinijaxRequestContext (org.minijax.rs.MinijaxRequestContext)8 Cookie (jakarta.ws.rs.core.Cookie)7 MultivaluedHashMap (jakarta.ws.rs.core.MultivaluedHashMap)7 Client (jakarta.ws.rs.client.Client)6 ClientBuilder (jakarta.ws.rs.client.ClientBuilder)6 List (java.util.List)5 JsonBindingTest (org.jboss.resteasy.test.providers.jsonb.basic.JsonBindingTest)5 IOException (java.io.IOException)4 ResteasyWebTarget (org.jboss.resteasy.client.jaxrs.ResteasyWebTarget)4 PetClinicTest (com.example.PetClinicTest)3 Invocation (jakarta.ws.rs.client.Invocation)3 Owner (com.example.model.Owner)2 Holder (io.jans.as.model.common.Holder)2