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


Java Methods类代码示例

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


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

示例1: greeting

import io.undertow.util.Methods; //导入依赖的package包/类
/**
 * Receive a GET request for a Greeting.
 *
 * @param request the request
 * @param name    the string containing the name
 * @return a Greeting
 */
@RequestMapping("/greeting")
public Greeting greeting(
    ServletRequest request,
    @RequestParam(value = "name", defaultValue = "World") String name) {

  HttpServletRequestImpl httpServletRequest = (HttpServletRequestImpl) request;
  HttpServerExchange exchange = httpServletRequest.getExchange();
  exchange
      .getConnection()
      .pushResource("/push-greeting?name=push", Methods.GET, exchange.getRequestHeaders());
  LOG.info("undertow pushBuilder has pushed resource.");

  PushBuilder pushBuilder = httpServletRequest.newPushBuilder();
  if (pushBuilder != null) {
    pushBuilder.path("/push-greeting?name=push");
    pushBuilder.push();
  } else {
    LOG.info("No servlet4 pushBuilder!");
  }

  return new Greeting(counter.incrementAndGet(),
      String.format(template, name));
}
 
开发者ID:janweinschenker,项目名称:servlet4-demo,代码行数:31,代码来源:GreetingController.java

示例2: getParameter

import io.undertow.util.Methods; //导入依赖的package包/类
@Override
public String getParameter(final String name) {
    if(queryParameters == null) {
        queryParameters = exchange.getQueryParameters();
    }
    Deque<String> params = queryParameters.get(name);
    if (params == null) {
        if (exchange.getRequestMethod().equals(Methods.POST)) {
            final FormData parsedFormData = parseFormData();
            if (parsedFormData != null) {
                FormData.FormValue res = parsedFormData.getFirst(name);
                if (res == null || res.isFile()) {
                    return null;
                } else {
                    return res.getValue();
                }
            }
        }
        return null;
    }
    return params.getFirst();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:HttpServletRequestImpl.java

示例3: getParameterNames

import io.undertow.util.Methods; //导入依赖的package包/类
@Override
public Enumeration<String> getParameterNames() {
    if (queryParameters == null) {
        queryParameters = exchange.getQueryParameters();
    }
    final Set<String> parameterNames = new HashSet<>(queryParameters.keySet());
    if (exchange.getRequestMethod().equals(Methods.POST)) {
        final FormData parsedFormData = parseFormData();
        if (parsedFormData != null) {
            Iterator<String> it = parsedFormData.iterator();
            while (it.hasNext()) {
                String name = it.next();
                for(FormData.FormValue param : parsedFormData.get(name)) {
                    if(!param.isFile()) {
                        parameterNames.add(name);
                        break;
                    }
                }
            }
        }
    }
    return new IteratorEnumeration<>(parameterNames.iterator());
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:HttpServletRequestImpl.java

示例4: prepareResponseChannel

import io.undertow.util.Methods; //导入依赖的package包/类
private void prepareResponseChannel(ClientResponse response, ClientExchange exchange) {
    String encoding = response.getResponseHeaders().getLast(TRANSFER_ENCODING);
    boolean chunked = encoding != null && Headers.CHUNKED.equals(new HttpString(encoding));
    String length = response.getResponseHeaders().getFirst(CONTENT_LENGTH);
    if (exchange.getRequest().getMethod().equals(Methods.HEAD)) {
        connection.getSourceChannel().setConduit(new FixedLengthStreamSourceConduit(connection.getSourceChannel().getConduit(), 0, responseFinishedListener));
    } else if (chunked) {
        connection.getSourceChannel().setConduit(new ChunkedStreamSourceConduit(connection.getSourceChannel().getConduit(), pushBackStreamSourceConduit, bufferPool, responseFinishedListener, exchange));
    } else if (length != null) {
        try {
            long contentLength = Long.parseLong(length);
            connection.getSourceChannel().setConduit(new FixedLengthStreamSourceConduit(connection.getSourceChannel().getConduit(), contentLength, responseFinishedListener));
        } catch (NumberFormatException e) {
            handleError(new IOException(e));
            throw e;
        }
    } else if (response.getProtocol().equals(Protocols.HTTP_1_1)) {
        connection.getSourceChannel().setConduit(new FixedLengthStreamSourceConduit(connection.getSourceChannel().getConduit(), 0, responseFinishedListener));
    } else {
        state |= CLOSE_REQ;
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:HttpClientConnection.java

示例5: sendRequestedBlobs

import io.undertow.util.Methods; //导入依赖的package包/类
/**
 * Serve static resource for the directory listing
 *
 * @param exchange The exchange
 * @return true if resources were served
 */
public static boolean sendRequestedBlobs(HttpServerExchange exchange) {
    ByteBuffer buffer = null;
    String type = null;
    if ("css".equals(exchange.getQueryString())) {
        buffer = Blobs.FILE_CSS_BUFFER.duplicate();
        type = "text/css";
    } else if ("js".equals(exchange.getQueryString())) {
        buffer = Blobs.FILE_JS_BUFFER.duplicate();
        type = "application/javascript";
    }

    if (buffer != null) {
        exchange.getResponseHeaders().put(Headers.CONTENT_LENGTH, String.valueOf(buffer.limit()));
        exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, type);
        if (Methods.HEAD.equals(exchange.getRequestMethod())) {
            exchange.endExchange();
            return true;
        }
        exchange.getResponseSender().send(buffer);

        return true;
    }

    return false;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:32,代码来源:DirectoryUtils.java

示例6: wrap

import io.undertow.util.Methods; //导入依赖的package包/类
@Override
public StreamSinkConduit wrap(final ConduitFactory<StreamSinkConduit> factory, final HttpServerExchange exchange) {
    if (exchange.getResponseHeaders().contains(Headers.CONTENT_ENCODING)) {
        //already encoded
        return factory.create();
    }
    //if this is a zero length response we don't want to encode
    if (exchange.getResponseContentLength() != 0
            && exchange.getResponseCode() != StatusCodes.NO_CONTENT
            && exchange.getResponseCode() != StatusCodes.NOT_MODIFIED) {
        EncodingMapping encoding = getEncoding();
        if (encoding != null) {
            exchange.getResponseHeaders().put(Headers.CONTENT_ENCODING, encoding.getName());
            if (exchange.getRequestMethod().equals(Methods.HEAD)) {
                //we don't create an actual encoder for HEAD requests, but we set the header
                return factory.create();
            } else {
                return encoding.getEncoding().getResponseWrapper().wrap(factory, exchange);
            }
        }
    }
    return factory.create();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:AllowedContentEncodings.java

示例7: handleRequest

import io.undertow.util.Methods; //导入依赖的package包/类
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
    if(exchange.getRequestMethod().equals(Methods.TRACE)) {
        exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "message/http");
        StringBuilder body = new StringBuilder("TRACE ");
        body.append(exchange.getRequestURI());
        if(!exchange.getQueryString().isEmpty()) {
            body.append('?');
            body.append(exchange.getQueryString());
        }
        body.append(exchange.getProtocol().toString());
        body.append("\r\n");
        for(HeaderValues header : exchange.getRequestHeaders()) {
            for(String value : header) {
                body.append(header.getHeaderName());
                body.append(": ");
                body.append(value);
                body.append("\r\n");
            }
        }
        body.append("\r\n");
        exchange.getResponseSender().send(body.toString());
    } else {
        handler.handleRequest(exchange);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:HttpTraceHandler.java

示例8: getPetStoreHandler

import io.undertow.util.Methods; //导入依赖的package包/类
RoutingHandler getPetStoreHandler() {
    return Handlers.routing()
            .add(Methods.POST, "/v1/pets", exchange -> exchange.getResponseSender().send("addPet"))
            .add(Methods.GET, "/v1/pets/{petId}", exchange -> exchange.getResponseSender().send("getPetById"))
            .add(Methods.DELETE, "/v1/pets/{petId}", exchange -> exchange.getResponseSender().send("deletePetById"))
            .add(Methods.GET, "/v1/pets", exchange -> exchange.getResponseSender().send("getPets"));
}
 
开发者ID:networknt,项目名称:light-rest-4j,代码行数:8,代码来源:ValidatorHandlerTest.java

示例9: getTestHandler

import io.undertow.util.Methods; //导入依赖的package包/类
static RoutingHandler getTestHandler() {
    return Handlers.routing()
            .add(Methods.GET, "/get", exchange -> {
                SessionManager sessionManager = SingletonServiceFactory.getBean(SessionManager.class);
                Session session = sessionManager.getSession(exchange);
                if(session == null) {
                    session = sessionManager.createSession(exchange);
                    session.setAttribute(COUNT, 0);
                    logger.debug("first time access create a session and count is 0 sessionId = " + session.getId());
                }
                Integer count = (Integer) session.getAttribute(COUNT);
                logger.debug("not the first time, get count from session = " + count + " sessionId = " + session.getId());
                exchange.getResponseHeaders().add(new HttpString(COUNT), count.toString());
                session.setAttribute(COUNT, ++count);
            });
}
 
开发者ID:networknt,项目名称:light-session-4j,代码行数:17,代码来源:JdbcSessionMultipleTest.java

示例10: testHttp2Post

import io.undertow.util.Methods; //导入依赖的package包/类
/**
 * This is an example for post request. Please note that you need to set header TRANSFER_ENCODING
 * and pass the request body into the callback function.
 *
 * @throws Exception
 */
public void testHttp2Post() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    final ClientConnection connection = client.connect(new URI("https://localhost:8443"), Http2Client.WORKER, Http2Client.SSL, Http2Client.POOL, OptionMap.create(UndertowOptions.ENABLE_HTTP2, true)).get();
    final AtomicReference<ClientResponse> reference = new AtomicReference<>();
    try {
        final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/post");
        if(securityEnabled) {
            // call OAuth 2.0 provider service to get a JWT access token here and
            // put it into the request header. Optionally, you can put a traceabilityId
            // into the header.

        }
        request.getRequestHeaders().put(Headers.TRANSFER_ENCODING, "chunked");
        connection.sendRequest(request, client.createClientCallback(reference, latch, "post"));
        latch.await(100, TimeUnit.MILLISECONDS);
    } finally {
        IoUtils.safeClose(connection);
    }
    System.out.println("testHttp2Post: statusCode = " + reference.get().getResponseCode() + " body = " + reference.get().getAttachment(Http2Client.RESPONSE_BODY));
}
 
开发者ID:networknt,项目名称:light-example-4j,代码行数:27,代码来源:Http2ClientExample.java

示例11: toCamelMessage

import io.undertow.util.Methods; //导入依赖的package包/类
@Override
public Message toCamelMessage(HttpServerExchange httpExchange, Exchange exchange) throws Exception {
    Message result = new DefaultMessage();

    populateCamelHeaders(httpExchange, result.getHeaders(), exchange);

    //extract body if the method is allowed to have one
    //body is extracted as byte[] then auto TypeConverter kicks in
    if (Methods.POST.equals(httpExchange.getRequestMethod()) || Methods.PUT.equals(httpExchange.getRequestMethod())) {
        result.setBody(readFromChannel(httpExchange.getRequestChannel()));
    } else {
        result.setBody(null);
    }

    return result;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:DefaultUndertowHttpBinding.java

示例12: testMultipleHttp2Get

import io.undertow.util.Methods; //导入依赖的package包/类
public void testMultipleHttp2Get(int round) throws Exception {
    final Http2Client client = Http2Client.getInstance();
    final List<AtomicReference<ClientResponse>> references = new CopyOnWriteArrayList<>();
    final CountDownLatch latch = new CountDownLatch(round);
    final ClientConnection connection = client.connect(new URI("https://localhost:8443"), Http2Client.WORKER, Http2Client.SSL, Http2Client.POOL, OptionMap.create(UndertowOptions.ENABLE_HTTP2, true)).get();
    try {
        connection.getIoThread().execute(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < round; i++) {
                    AtomicReference<ClientResponse> reference = new AtomicReference<>();
                    references.add(i, reference);
                    final ClientRequest request = new ClientRequest().setMethod(Methods.GET).setPath("/get");
                    request.getRequestHeaders().put(Headers.HOST, "localhost");
                    connection.sendRequest(request, client.createClientCallback(reference, latch));
                }
            }
        });
        latch.await(10, TimeUnit.SECONDS);
        /*
        for (final AtomicReference<ClientResponse> reference : references) {
            System.out.println(reference.get().getAttachment(Http2Client.RESPONSE_BODY));
            System.out.println(reference.get().getProtocol().toString());
        }
        */
    } finally {
        IoUtils.safeClose(connection);
    }
}
 
开发者ID:networknt,项目名称:http2client-benchmark,代码行数:30,代码来源:Http2ClientExample.java

示例13: testMultipleHttp2Post

import io.undertow.util.Methods; //导入依赖的package包/类
public void testMultipleHttp2Post(int round) throws Exception {
    final Http2Client client = Http2Client.getInstance();
    final List<AtomicReference<ClientResponse>> references = new CopyOnWriteArrayList<>();
    final CountDownLatch latch = new CountDownLatch(round);
    final ClientConnection connection = client.connect(new URI("https://localhost:8443"), Http2Client.WORKER, Http2Client.SSL, Http2Client.POOL, OptionMap.create(UndertowOptions.ENABLE_HTTP2, true)).get();
    try {
        connection.getIoThread().execute(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < round; i++) {
                    AtomicReference<ClientResponse> reference = new AtomicReference<>();
                    references.add(i, reference);
                    final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/post");
                    request.getRequestHeaders().put(Headers.TRANSFER_ENCODING, "chunked");
                    request.getRequestHeaders().put(Headers.HOST, "localhost");
                    connection.sendRequest(request, client.createClientCallback(reference, latch, "post"));
                }
            }
        });
        latch.await(10, TimeUnit.SECONDS);
        /*
        for (final AtomicReference<ClientResponse> reference : references) {
            System.out.println(reference.get().getAttachment(Http2Client.RESPONSE_BODY));
            System.out.println(reference.get().getProtocol().toString());
        }
        */
    } finally {
        IoUtils.safeClose(connection);
    }
}
 
开发者ID:networknt,项目名称:http2client-benchmark,代码行数:31,代码来源:Http2ClientExample.java

示例14: getHandler

import io.undertow.util.Methods; //导入依赖的package包/类
@Override
public HttpHandler getHandler() {
    return Handlers.routing()
            .add(Methods.GET, GraphqlUtil.config.getPath(), new GraphqlGetHandler())
            .add(Methods.POST, GraphqlUtil.config.getPath(), new GraphqlPostHandler())
            .add(Methods.GET, "/server/info", new ServerInfoGetHandler())
            ;
}
 
开发者ID:networknt,项目名称:light-graphql-4j,代码行数:9,代码来源:GraphqlRouter.java

示例15: getTestHandler

import io.undertow.util.Methods; //导入依赖的package包/类
static RoutingHandler getTestHandler() {
    return Handlers.routing()
            .add(Methods.GET, "/v2/pet/{petId}", exchange -> {
                Map<String, Object> examples = new HashMap<>();
                examples.put("application/xml", StringEscapeUtils.unescapeHtml4("&lt;Pet&gt;  &lt;id&gt;123456&lt;/id&gt;  &lt;name&gt;doggie&lt;/name&gt;  &lt;photoUrls&gt;    &lt;photoUrls&gt;string&lt;/photoUrls&gt;  &lt;/photoUrls&gt;  &lt;tags&gt;  &lt;/tags&gt;  &lt;status&gt;string&lt;/status&gt;&lt;/Pet&gt;"));
                examples.put("application/json", StringEscapeUtils.unescapeHtml4("{  &quot;photoUrls&quot; : [ &quot;aeiou&quot; ],  &quot;name&quot; : &quot;doggie&quot;,  &quot;id&quot; : 123456789,  &quot;category&quot; : {    &quot;name&quot; : &quot;aeiou&quot;,    &quot;id&quot; : 123456789  },  &quot;tags&quot; : [ {    &quot;name&quot; : &quot;aeiou&quot;,    &quot;id&quot; : 123456789  } ],  &quot;status&quot; : &quot;aeiou&quot;}"));
                if(examples.size() > 0) {
                    exchange.getResponseHeaders().add(new HttpString("Content-Type"), "application/json");
                    exchange.getResponseSender().send((String)examples.get("application/json"));
                } else {
                    exchange.endExchange();
                }
            })
            .add(Methods.GET, "/v2/pet", exchange -> exchange.getResponseSender().send("get"));
}
 
开发者ID:networknt,项目名称:light-graphql-4j,代码行数:16,代码来源:JwtVerifyHandlerTest.java


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