本文整理汇总了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));
}
示例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();
}
示例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());
}
示例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;
}
}
示例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;
}
示例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();
}
示例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);
}
}
示例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"));
}
示例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);
});
}
示例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));
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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())
;
}
示例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("<Pet> <id>123456</id> <name>doggie</name> <photoUrls> <photoUrls>string</photoUrls> </photoUrls> <tags> </tags> <status>string</status></Pet>"));
examples.put("application/json", StringEscapeUtils.unescapeHtml4("{ "photoUrls" : [ "aeiou" ], "name" : "doggie", "id" : 123456789, "category" : { "name" : "aeiou", "id" : 123456789 }, "tags" : [ { "name" : "aeiou", "id" : 123456789 } ], "status" : "aeiou"}"));
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"));
}