本文整理汇总了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);
}
示例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"
);
}
示例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);
}
示例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;
}
示例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
)
);
}
示例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"
)
)
);
}
示例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"
)
)
);
}
示例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();
}
}
示例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();
}
}
示例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);
}
示例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);
}
}
示例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();
}
示例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")
);
}
示例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()
);
}
示例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")
);
}