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


Java Request类代码示例

本文整理汇总了Java中com.jcabi.http.Request的典型用法代码示例。如果您正苦于以下问题:Java Request类的具体用法?Java Request怎么用?Java Request使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: perform

import com.jcabi.http.Request; //导入依赖的package包/类
@Override
public void perform(
    final Command command, final Log log) throws IOException {
    final String author = command.author();
    final Request follow = command.issue().repo().github().entry()
        .uri().path("/user/following/").path(author).back()
        .method("PUT");
    log.logger().info("Following Github user " + author + " ...");
    try {
        final int status = follow.fetch().status();
        if(status != HttpURLConnection.HTTP_NO_CONTENT) {
            log.logger().error(
                "User follow status response is " + status
                + " . Should have been 204 (NO CONTENT)"
            );
        } else {
            log.logger().info("Followed user " + author + " .");
        }
    } catch (final IOException ex) {
        log.logger().warn("IOException while trying to follow the user.");
    }
    this.next().perform(command, log);
}
 
开发者ID:amihaiemil,项目名称:comdor,代码行数:24,代码来源:FollowUser.java

示例2: AuthByPass

import com.jcabi.http.Request; //导入依赖的package包/类
/**
 * Public ctor, with a custom req.
 *
 * @param uri Hub URI
 * @param req Request to start from
 */
public AuthByPass(
    final URI uri,
    final Request req) {
    this.uri = uri;
    this.req = req.header(HttpHeaders.USER_AGENT, AuthByPass.USER_AGENT)
        .through(AutoRedirectingWire.class)
        .uri()
        .path("/hub/api/rest/oauth2/token")
        .back()
        .method(Request.POST)
        .header(
            HttpHeaders.CONTENT_TYPE,
            "application/x-www-form-urlencoded"
        );
}
 
开发者ID:smallcreep,项目名称:jb-hub-client,代码行数:22,代码来源:Auth.java

示例3: fetch

import com.jcabi.http.Request; //导入依赖的package包/类
/**
 * Get json Array projects.
 * @return Array projects
 * @throws Exception If fails
 */
private JsonArray fetch() throws Exception {
    if (this.response.get() != null) {
        final Optional<Request> next = this.response
            .get()
            .as(PaginationResponse.class)
            .next();
        if (next.has()) {
            this.response.set(
                next.value().fetch()
            );
        } else {
            throw new NoSuchElementException();
        }
    } else {
        this.response.set(this.req.fetch());
    }
    return this.response.get()
        .as(RestResponse.class)
        .assertStatus(HttpURLConnection.HTTP_OK)
        .as(JsonResponse.class)
        .json()
        .readObject()
        .getJsonArray(name);
}
 
开发者ID:smallcreep,项目名称:jb-hub-client,代码行数:30,代码来源:RtPaginationIterator.java

示例4: follow

import com.jcabi.http.Request; //导入依赖的package包/类
/**
 * Follow link.
 * @param pointer Page's pointer
 * @return The same object
 * @throws IOException If fails
 */
private Optional<Request> follow(final String pointer) throws IOException {
    final String link = this.response
        .as(JsonResponse.class)
        .json()
        .readObject()
        .getString(pointer, "");
    final Optional<Request> request;
    if (link.isEmpty()) {
        request = new Optional.Empty<>();
    } else {
        request = new Optional.Single<>(
            new RestResponse(this).jump(URI.create(link))
        );
    }
    return request;
}
 
开发者ID:smallcreep,项目名称:jb-hub-client,代码行数:23,代码来源:PaginationResponse.java

示例5: sameUser

import com.jcabi.http.Request; //导入依赖的package包/类
/**
 * Return the same user.
 * @throws Exception If fails
 */
@Test
public void sameUser() throws Exception {
    final Request req = new JdkRequest("");
    final RtUsers users = new RtUsers(
        req,
        new RtHub(
            req
        )
    );
    MatcherAssert.assertThat(
        new RtUser(
            req,
            users,
            "me"
        ).users(),
        CoreMatchers.equalTo(
            users
        )
    );
}
 
开发者ID:smallcreep,项目名称:jb-hub-client,代码行数:25,代码来源:RtUserTest.java

示例6: selfGet

import com.jcabi.http.Request; //导入依赖的package包/类
/**
 * Self get return correct user.
 * @throws Exception If fails
 */
@Test
public void selfGet() throws Exception {
    final Request req = new JdkRequest("");
    final RtUsers users = new RtUsers(
        req,
        new RtHub(
            req
        )
    );
    MatcherAssert.assertThat(
        users.self(),
        CoreMatchers.equalTo(
            new RtUser(
                req.uri().path("/users").back(),
                users,
                "me"
            )
        )
    );
}
 
开发者ID:smallcreep,项目名称:jb-hub-client,代码行数:25,代码来源:RtUsersTest.java

示例7: guestGet

import com.jcabi.http.Request; //导入依赖的package包/类
/**
 * Guest get return correct user.
 * @throws Exception If fails
 */
@Test
public void guestGet() throws Exception {
    final Request req = new JdkRequest("");
    final RtUsers users = new RtUsers(
        req,
        new RtHub(
            req
        )
    );
    MatcherAssert.assertThat(
        users.guest(),
        CoreMatchers.equalTo(
            new RtUser(
                req.uri().path("/users").back(),
                users,
                "guest"
            )
        )
    );
}
 
开发者ID:smallcreep,项目名称:jb-hub-client,代码行数:25,代码来源:RtUsersTest.java

示例8: markAsReadOk

import com.jcabi.http.Request; //导入依赖的package包/类
/**
 * RtNotifications can mark notifications as read with OK status response
 * @throws Exception If something goes wrong.
 */
@Test
public void markAsReadOk() throws Exception {
    int port = this.port();
    MkContainer server = new MkGrizzlyContainer()
        .next(new MkAnswer.Simple(HttpURLConnection.HTTP_OK)).start(port);
    try {
        Notifications notifications = new RtNotifications(
            new Reason.Fake(),
            "fake_token",
            "http://localhost:"+port+"/"
        );
        notifications.markAsRead();
        MkQuery req = server.take();
        assertTrue(req.method().equals(Request.PUT));
        assertTrue(req.body().equals("{}"));
        assertTrue(req.uri().getQuery().contains("last_read_at="));
    } finally {
        server.stop();
    }
}
 
开发者ID:opencharles,项目名称:mention-notifications-ejb,代码行数:25,代码来源:RtNotificationsTestCase.java

示例9: markAsReadReset

import com.jcabi.http.Request; //导入依赖的package包/类
/**
 * RtNotifications can mark notifications as read with RESET status response.
 * @throws Exception If something goes wrong.
 */
@Test
public void markAsReadReset() throws Exception {
    int port = this.port();
    MkContainer server = new MkGrizzlyContainer()
        .next(new MkAnswer.Simple(HttpURLConnection.HTTP_RESET)).start(port);
    try {
        Notifications notifications = new RtNotifications(
            new Reason.Fake(),
            "fake_token",
            "http://localhost:"+port+"/"
        );
        notifications.markAsRead();
        MkQuery req = server.take();
        assertTrue(req.method().equals(Request.PUT));
        assertTrue(req.body().equals("{}"));
        assertTrue(req.uri().getQuery().contains("last_read_at="));
    } finally {
        server.stop();
    }
}
 
开发者ID:opencharles,项目名称:mention-notifications-ejb,代码行数:25,代码来源:RtNotificationsTestCase.java

示例10: perform

import com.jcabi.http.Request; //导入依赖的package包/类
@Override
public void perform(Command command, Logger logger) throws IOException {
    final String author = command.authorLogin();
    final Github github = command.issue().repo().github();
    final Request follow = github.entry()
        .uri().path("/user/following/").path(author).back()
        .method("PUT");
    logger.info("Following Github user " + author + " ...");
    try {
        final int status = follow.fetch().status();
        if(status != HttpURLConnection.HTTP_NO_CONTENT) {
            logger.error("User follow status response is " + status + " . Should have been 204 (NO CONTENT)");
        } else {
            logger.info("Followed user " + author + " .");
        }
    } catch (final IOException ex) {//don't rethrow, this is just a cosmetic step, not critical.
        logger.error("IOException while trying to follow the user.");
    }
    this.next().perform(command, logger);
}
 
开发者ID:opencharles,项目名称:charles-rest,代码行数:21,代码来源:Follow.java

示例11: hasGhPagesBranch

import com.jcabi.http.Request; //导入依赖的package包/类
/**
 * Returns true if the repository has a gh-pages branch, false otherwise.
 * The result is <b>cached</b> and so the http call to Github API is performed only at the first call.
 * @return true if there is a gh-pages branch, false otherwise.
 * @throws IOException If an error occurs
 *  while communicating with the Github API.
 */
public boolean hasGhPagesBranch() throws IOException {
    try {
        if(this.ghPagesBranch == null) {
            String branchesUrlPattern = this.json().getString("branches_url");
            String ghPagesUrl = branchesUrlPattern.substring(0, branchesUrlPattern.indexOf("{")) + "/gh-pages";
            Request req = new ApacheRequest(ghPagesUrl);
            this.ghPagesBranch = req.fetch().as(RestResponse.class)
                .assertStatus(
                    Matchers.isOneOf(
                        HttpURLConnection.HTTP_OK,
                        HttpURLConnection.HTTP_NOT_FOUND
                    )
                ).status() == HttpURLConnection.HTTP_OK;
            return this.ghPagesBranch;
        }
        return this.ghPagesBranch;
    } catch (AssertionError aerr) {
        throw new IOException ("Unexpected HTTP status response.", aerr);
    }
}
 
开发者ID:opencharles,项目名称:charles-rest,代码行数:28,代码来源:CachedRepo.java

示例12: removeGistComment

import com.jcabi.http.Request; //导入依赖的package包/类
/**
 * RtGistComment can remove comment.
 * @throws IOException if has some problems with json parsing.
 */
@Test
public final void removeGistComment() throws IOException {
    final int identifier = 1;
    final MkContainer container = new MkGrizzlyContainer().next(
        new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")
    ).start();
    final RtGist gist = new RtGist(
        new MkGithub(),
        new FakeRequest().withStatus(HttpURLConnection.HTTP_NO_CONTENT),
        "gistName"
    );
    final RtGistComment comment = new RtGistComment(
        new ApacheRequest(container.home()), gist, identifier
    );
    comment.remove();
    MatcherAssert.assertThat(
        container.take().method(),
        Matchers.equalTo(Request.DELETE)
    );
    container.stop();
}
 
开发者ID:cvrebert,项目名称:typed-github,代码行数:26,代码来源:RtGistCommentTest.java

示例13: create

import com.jcabi.http.Request; //导入依赖的package包/类
@Override
@NotNull(message = "Hook is never NULL")
public Hook create(
    @NotNull(message = "name can't be NULL") final String name,
    @NotNull(message = "config can't be NULL")
    final Map<String, String> config,
    final boolean active
) throws IOException {
    final JsonObjectBuilder builder = Json.createObjectBuilder();
    for (final Map.Entry<String, String> entr : config.entrySet()) {
        builder.add(entr.getKey(), entr.getValue());
    }
    final JsonStructure json = Json.createObjectBuilder()
        .add("name", name)
        .add("config", builder)
        .add("active", active)
        .build();
    return this.get(
        this.request.method(Request.POST)
            .body().set(json).back()
            .fetch().as(RestResponse.class)
            .assertStatus(HttpURLConnection.HTTP_CREATED)
            .as(JsonResponse.class)
            .json().readObject().getInt("id")
    );
}
 
开发者ID:cvrebert,项目名称:typed-github,代码行数:27,代码来源:RtHooks.java

示例14: raw

import com.jcabi.http.Request; //导入依赖的package包/类
/**
 * Get raw release asset content.
 *
 * @see <a href="http://developer.github.com/v3/repos/releases/">Releases API</a>
 * @return Stream with content
 * @throws IOException If some problem inside.
 */
@Override
@NotNull(message = "InputStream is never NULL")
public InputStream raw() throws IOException {
    return new ByteArrayInputStream(
        this.request.method(Request.GET)
            .reset(HttpHeaders.ACCEPT).header(
                HttpHeaders.ACCEPT,
                "application/vnd.github.v3.raw"
            )
            .fetch()
            .as(RestResponse.class)
            .assertStatus(HttpURLConnection.HTTP_OK)
            .binary()
    );
}
 
开发者ID:cvrebert,项目名称:typed-github,代码行数:23,代码来源:RtReleaseAsset.java

示例15: create

import com.jcabi.http.Request; //导入依赖的package包/类
@Override
@NotNull(message = "release is never NULL")
public Release create(
    @NotNull(message = "tag can't be NULL") final String tag
) throws IOException {
    final JsonStructure json = Json.createObjectBuilder()
        .add("tag_name", tag)
        .build();
    return this.get(
        this.request.method(Request.POST)
            .body().set(json).back()
            .fetch().as(RestResponse.class)
            .assertStatus(HttpURLConnection.HTTP_CREATED)
            .as(JsonResponse.class)
            .json().readObject().getInt("id")
    );
}
 
开发者ID:cvrebert,项目名称:typed-github,代码行数:18,代码来源:RtReleases.java


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