當前位置: 首頁>>代碼示例>>Java>>正文


Java TkFixed類代碼示例

本文整理匯總了Java中org.takes.tk.TkFixed的典型用法代碼示例。如果您正苦於以下問題:Java TkFixed類的具體用法?Java TkFixed怎麽用?Java TkFixed使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TkFixed類屬於org.takes.tk包,在下文中一共展示了TkFixed類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: failsOnUnsupportedAcceptHeader

import org.takes.tk.TkFixed; //導入依賴的package包/類
/**
 * TkConsumes can fail on unsupported Content-Type header.
 * @throws IOException If some problem inside
 */
@Test(expected = HttpException.class)
public void failsOnUnsupportedAcceptHeader() throws IOException {
    final Take consumes = new TkConsumes(
        new TkFixed(new RsJson(new RsEmpty())),
        TkConsumesTest.APPLICATION_JSON
    );
    consumes.act(
        new RqFake(
            Arrays.asList(
                "GET /?TkConsumes error",
                "Content-Type: application/xml"
            ),
            ""
        )
    ).head();
}
 
開發者ID:yegor256,項目名稱:takes,代碼行數:21,代碼來源:TkConsumesTest.java

示例2: simplyWorks

import org.takes.tk.TkFixed; //導入依賴的package包/類
/**
 * FtRemote can work.
 * @throws Exception If some problem inside
 */
@Test
public void simplyWorks() throws Exception {
    new FtRemote(new TkFixed(new RsText("simple answer"))).exec(
        new FtRemote.Script() {
            @Override
            public void exec(final URI home) throws IOException {
                new JdkRequest(home)
                    .fetch()
                    .as(RestResponse.class)
                    .assertStatus(HttpURLConnection.HTTP_OK)
                    .assertBody(Matchers.startsWith("simple"));
            }
        }
    );
}
 
開發者ID:yegor256,項目名稱:takes,代碼行數:20,代碼來源:FtRemoteTest.java

示例3: justWorks

import org.takes.tk.TkFixed; //導入依賴的package包/類
/**
 * FtSecure can work.
 * @throws Exception If some problem inside
 */
@Test
public void justWorks() throws Exception {
    FtSecureTest.secure(new TkFixed("hello, world")).exec(
        new FtRemote.Script() {
            @Override
            public void exec(final URI home) throws IOException {
                new JdkRequest(home)
                    .fetch()
                    .as(RestResponse.class)
                    .assertStatus(HttpURLConnection.HTTP_OK)
                    .assertBody(Matchers.startsWith("hello"));
            }
        }
    );
}
 
開發者ID:yegor256,項目名稱:takes,代碼行數:20,代碼來源:FtSecureTest.java

示例4: main

import org.takes.tk.TkFixed; //導入依賴的package包/類
/**
 * Entry point.
 * @param args Arguments
 * @throws IOException If fails
 */
public static void main(final String... args) throws IOException {
    final String html = new StringBuilder()
        .append("<html><body>")
        .append("<p>Hello, world!</p>")
        .append("<p>Java version is ")
        .append(System.getProperty("java.version"))
        .append("</p>")
        .append("<p>This page is hosted by <a href='http://www.thindeck.com'>thindeck.com</a>.</p>")
        .append("<p>Source code is in <a href='https://github.com/yegor256/thindeck/tree/master/demo-docker-images/apache-php'>Github</a>.</p>")
        .append("</body></html>")
        .toString();
    new FtCLI(
        new Take() {
            @Override
            public Response act(final Request request) throws IOException {
                return new TkFixed(new RsHTML(html)).act(request);
            }
        },
        args
    ).start(Exit.NEVER);
}
 
開發者ID:yegor256,項目名稱:thindeck,代碼行數:27,代碼來源:App.java

示例5: acceptsCorrectContentTypeRequest

import org.takes.tk.TkFixed; //導入依賴的package包/類
/**
 * TkConsumes can accept request with certain Content-Type.
 * @throws IOException If some problem inside
 */
@Test
public void acceptsCorrectContentTypeRequest() throws IOException {
    final String contenttype = "Content-Type: application/json";
    final Take consumes = new TkConsumes(
        new TkFixed(new RsJson(new RsEmpty())),
        TkConsumesTest.APPLICATION_JSON
    );
    final Response response = consumes.act(
        new RqFake(
            Arrays.asList(
                "GET /?TkConsumes",
                contenttype
            ),
            ""
        )
    );
    MatcherAssert.assertThat(
        new RsPrint(response).print(),
        Matchers.startsWith(
            Joiner.on("\r\n").join(
                "HTTP/1.1 200 OK",
                contenttype
            )
        )
    );
}
 
開發者ID:yegor256,項目名稱:takes,代碼行數:31,代碼來源:TkConsumesTest.java

示例6: producesCorrectContentTypeResponse

import org.takes.tk.TkFixed; //導入依賴的package包/類
/**
 * TkProduce can produce correct type response.
 * @throws IOException If some problem inside
 */
@Test
public void producesCorrectContentTypeResponse() throws IOException {
    final Take produces = new TkProduces(
        new TkFixed(new RsJson(new RsEmpty())),
        "text/json"
    );
    final Response response = produces.act(
        new RqFake(
            Arrays.asList(
                "GET /hz09",
                "Host: as.example.com",
                "Accept: text/json"
            ),
            ""
        )
    );
    MatcherAssert.assertThat(
        new RsPrint(response).print(),
        Matchers.equalTo(
            Joiner.on("\r\n").join(
                "HTTP/1.1 200 OK",
                "Content-Type: application/json",
                "",
                ""
            )
        )
    );
}
 
開發者ID:yegor256,項目名稱:takes,代碼行數:33,代碼來源:TkProducesTest.java

示例7: reactsToCorrectStatus

import org.takes.tk.TkFixed; //導入依賴的package包/類
/**
 * FbStatus can react to correct status.
 * @throws Exception If some problem inside
 */
@Test
public void reactsToCorrectStatus() throws Exception {
    final int status = HttpURLConnection.HTTP_NOT_FOUND;
    final RqFallback req = new RqFallback.Fake(status);
    MatcherAssert.assertThat(
        new RsPrint(
            new FbStatus(
                status,
                new TkFixed(new RsText("not found response"))
            ).route(req).get()
        ).printBody(),
        Matchers.startsWith("not found")
    );
}
 
開發者ID:yegor256,項目名稱:takes,代碼行數:19,代碼來源:FbStatusTest.java

示例8: ignoresDifferentStatus

import org.takes.tk.TkFixed; //導入依賴的package包/類
/**
 * FbStatus can ignore different status.
 * @throws Exception If some problem inside
 */
@Test
public void ignoresDifferentStatus() throws Exception {
    final RqFallback req = new RqFallback.Fake(
        HttpURLConnection.HTTP_NOT_FOUND
    );
    MatcherAssert.assertThat(
        new FbStatus(
            HttpURLConnection.HTTP_UNAUTHORIZED,
            new TkFixed(new RsText("unauthorized"))
        ).route(req).has(),
        Matchers.equalTo(false)
    );
}
 
開發者ID:yegor256,項目名稱:takes,代碼行數:18,代碼來源:FbStatusTest.java

示例9: fallback

import org.takes.tk.TkFixed; //導入依賴的package包/類
/**
 * Fallback.
 * @param take Original take
 * @return Take with fallback
 */
private static Take fallback(final Take take) {
    return new TkFallback(
        take,
        new FbChain(
            // @checkstyle MagicNumberCheck (1 line)
            new FbStatus(404, new TkFixed(new RsNotFound())),
            new FbError()
        )
    );
}
 
開發者ID:libreio,項目名稱:libre,代碼行數:16,代碼來源:TkApp.java

示例10: FkRegex

import org.takes.tk.TkFixed; //導入依賴的package包/類
/**
 * Ctor.
 * @param ptn Pattern
 * @param rsp Response
 * @since 0.16
 */
public FkRegex(final String ptn, final Response rsp) {
    this(ptn, new TkFixed(rsp));
}
 
開發者ID:yegor256,項目名稱:takes,代碼行數:10,代碼來源:FkRegex.java

示例11: FkMethods

import org.takes.tk.TkFixed; //導入依賴的package包/類
/**
 * Ctor.
 * @param mtd Method
 * @param rsp Response
 * @since 0.22
 */
public FkMethods(final String mtd, final Response rsp) {
    this(mtd, new TkFixed(rsp));
}
 
開發者ID:yegor256,項目名稱:takes,代碼行數:10,代碼來源:FkMethods.java

示例12: FkContentType

import org.takes.tk.TkFixed; //導入依賴的package包/類
/**
 * Ctor.
 * @param atype Accepted type
 * @param response Response to return
 */
public FkContentType(final String atype, final Response response) {
    this(atype, new TkFixed(response));
}
 
開發者ID:yegor256,項目名稱:takes,代碼行數:9,代碼來源:FkContentType.java

示例13: FbFixed

import org.takes.tk.TkFixed; //導入依賴的package包/類
/**
 * Ctor.
 * @param response Response to return
 */
public FbFixed(final Response response) {
    this(new TkFixed(response));
}
 
開發者ID:yegor256,項目名稱:takes,代碼行數:8,代碼來源:FbFixed.java

示例14: FbStatus

import org.takes.tk.TkFixed; //導入依賴的package包/類
/**
 * Ctor.
 * @param code HTTP status code
 * @param response Response
 * @since 0.14
 */
public FbStatus(final int code, final Response response) {
    this(code, new TkFixed(response));
}
 
開發者ID:yegor256,項目名稱:takes,代碼行數:10,代碼來源:FbStatus.java

示例15: main

import org.takes.tk.TkFixed; //導入依賴的package包/類
/**
 * Main entry point.
 * @param args Command line args
 * @throws IOException If fails
 */
public static void main(final String... args) throws IOException {
    new FtCli(new TkFixed("works fine!"), args).start(Exit.NEVER);
}
 
開發者ID:yegor256,項目名稱:takes,代碼行數:9,代碼來源:MainRemoteTest.java


注:本文中的org.takes.tk.TkFixed類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。