当前位置: 首页>>代码示例>>Java>>正文


Java Entity.form方法代码示例

本文整理汇总了Java中javax.ws.rs.client.Entity.form方法的典型用法代码示例。如果您正苦于以下问题:Java Entity.form方法的具体用法?Java Entity.form怎么用?Java Entity.form使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.ws.rs.client.Entity的用法示例。


在下文中一共展示了Entity.form方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: submit

import javax.ws.rs.client.Entity; //导入方法依赖的package包/类
public AccessToken submit() throws IOException {
  Form form = new Form();
  form.param("assertion", assertion);
  form.param("grant_type", "urn:ietf:params:oauth:grant-type:jwt-bearer");

  Entity<Form> entity = Entity.form(form);

  Response response = client.target(EINSTEIN_VISION_URL + "/v1/oauth2/token")
      .request()
      .post(entity);

  if (!isSuccessful(response)) {
    throw new IOException("Error occurred while fetching Access Token " + response);
  }
  return readResponseAs(response, AccessToken.class);
}
 
开发者ID:MetaMind,项目名称:quickstart,代码行数:17,代码来源:AccessTokenRequest.java

示例2: retrieveValueStationCountList

import javax.ws.rs.client.Entity; //导入方法依赖的package包/类
/** Retrieve a generic list containing a value/stationcount mapping.
 * @param subpath the API sub path to use for the call.
 * @return map of value and stationcount pairs.
 * */
private Map<String, Integer> retrieveValueStationCountList(
        final String subpath) {
    MultivaluedMap<String, String> requestParams =
            new MultivaluedHashMap<>();

    Entity entity = Entity.form(requestParams);

    Response response = null;
    try {
        response = builder(webTarget.path(subpath))
                .post(entity);

        List<Map<String, String>> map = response.readEntity(
                new GenericType<List<Map<String, String>>>() {
        });
        checkResponseStatus(response);
        return map.stream()
                .collect(Collectors.toMap(
                m -> m.get("value"),
                m -> Integer.parseInt(m.get("stationcount"))));
    } finally {
        close(response);
    }
}
 
开发者ID:sfuhrm,项目名称:radiobrowser4j,代码行数:29,代码来源:RadioBrowser.java

示例3: listStationsPath

import javax.ws.rs.client.Entity; //导入方法依赖的package包/类
/** 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> listStationsPath(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 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);
    }
}
 
开发者ID:sfuhrm,项目名称:radiobrowser4j,代码行数:29,代码来源:RadioBrowser.java

示例4: triggerStationState

import javax.ws.rs.client.Entity; //导入方法依赖的package包/类
/**
 * Calls a state alteration method for one station.
 * @param station the station to undelete/delete from the REST service.
 * @param path the URL path of the state alteration endpoint.
 * @see <a href="http://www.radio-browser.info/webservice#station_delete">
 *     The API endpoint</a>
 */
private void triggerStationState(final Station station,
                                 final String path) {
    Objects.requireNonNull(station, "station must be non-null");
    MultivaluedMap<String, String> requestParams =
            new MultivaluedHashMap<>();

    Entity entity = Entity.form(requestParams);

    Response response = null;

    try {
        response = builder(webTarget
                    .path(path)
                    .path(station.getId()))
                .post(entity);
        logResponseStatus(response);
        UrlResponse urlResponse = response.readEntity(
                UrlResponse.class);
        if (!urlResponse.isOk()) {
            throw new RadioBrowserException(urlResponse.getMessage());
        }
    } finally {
        close(response);
    }
}
 
开发者ID:sfuhrm,项目名称:radiobrowser4j,代码行数:33,代码来源:RadioBrowser.java

示例5: listStationsBy

import javax.ws.rs.client.Entity; //导入方法依赖的package包/类
/** 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(final Paging paging,
                                    final SearchMode searchMode,
                                    final String searchTerm,
                                    final ListParameter...listParam) {
    Objects.requireNonNull(searchMode,
            "searchMode must be non-null");
    Objects.requireNonNull(searchTerm,
            "searchTerm must be non-null");

    MultivaluedMap<String, String> requestParams =
            new MultivaluedHashMap<>();
    applyPaging(paging, requestParams);
    Arrays.stream(listParam).forEach(l -> l.applyTo(requestParams));
    Entity entity = Entity.form(requestParams);
    Response response = null;

    try {
        response = builder(webTarget
                   .path("json/stations")
                   .path(searchMode.name())
                   .path(searchTerm))
                .post(entity);
        checkResponseStatus(response);
        return response.readEntity(new GenericType<List<Station>>() {
        });
    } finally {
        close(response);
    }
}
 
开发者ID:sfuhrm,项目名称:radiobrowser4j,代码行数:39,代码来源:RadioBrowser.java

示例6: postNewOrEditStation

import javax.ws.rs.client.Entity; //导入方法依赖的package包/类
/** Posts a new station to the server.
 * Note: This call only transmits certain fields.
 * The fields are:
 * name, url, homepage, favicon, country, state, language and tags.
 * @param station the station to add to the REST service.
 * @param path the path of the new / edit call.
 * @return the {@linkplain Station#id id} of the new station.
 * @throws RadioBrowserException if there was a problem
 * creating the station.
 * @see <a href="http://www.radio-browser.info/webservice#add_station">
 *     The API endpoint</a>
 */
private String postNewOrEditStation(final Station station,
                                    final String path) {
    // http://www.radio-browser.info/webservice/json/add
    Objects.requireNonNull(station, "station must be non-null");
    MultivaluedMap<String, String> requestParams =
            new MultivaluedHashMap<>();
    transferToMultivaluedMap(station, requestParams);
    Entity entity = Entity.form(requestParams);

    Response response = null;
    try {
        response = builder(webTarget
                .path(path))
                .post(entity);

        logResponseStatus(response);
        UrlResponse urlResponse = response.readEntity(
                UrlResponse.class);

        if (log.isDebugEnabled()) {
            log.debug("Result: {}", urlResponse);
        }

        if (!urlResponse.isOk()) {
            throw new RadioBrowserException(urlResponse.getMessage());
        }

        return urlResponse.getId();
    } finally {
        close(response);
    }
}
 
开发者ID:sfuhrm,项目名称:radiobrowser4j,代码行数:45,代码来源:RadioBrowser.java

示例7: testFormParam

import javax.ws.rs.client.Entity; //导入方法依赖的package包/类
@Test
public void testFormParam() {
    final Entity<Form> form = Entity.form(new Form("test", "Hello"));
    assertEquals(
            "Hello",
            target("/formtest").request().post(form, String.class));
}
 
开发者ID:minijax,项目名称:minijax,代码行数:8,代码来源:FormParamTest.java

示例8: testFormParamDefaultValue

import javax.ws.rs.client.Entity; //导入方法依赖的package包/类
@Test
public void testFormParamDefaultValue() {
    final Entity<Form> form = Entity.form(new Form());
    assertEquals(
            "foo",
            target("/defval").request().post(form, String.class));
}
 
开发者ID:minijax,项目名称:minijax,代码行数:8,代码来源:FormParamTest.java

示例9: testWholeForm

import javax.ws.rs.client.Entity; //导入方法依赖的package包/类
@Test
public void testWholeForm() {
    final Entity<Form> form = Entity.form(new Form("test", "Hello"));
    assertEquals(
            "Hello",
            target("/wholeform").request().post(form, String.class));
}
 
开发者ID:minijax,项目名称:minijax,代码行数:8,代码来源:FormParamTest.java


注:本文中的javax.ws.rs.client.Entity.form方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。