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


Java HttpServerExchange.setResponseCode方法代码示例

本文整理汇总了Java中io.undertow.server.HttpServerExchange.setResponseCode方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServerExchange.setResponseCode方法的具体用法?Java HttpServerExchange.setResponseCode怎么用?Java HttpServerExchange.setResponseCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.undertow.server.HttpServerExchange的用法示例。


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

示例1: doAuthorize

import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public void doAuthorize(HttpServerExchange exchange) throws  ServerError{
	Map<String, Deque<String>> queryParams = exchange.getQueryParameters();
       Deque<String> parameter = queryParams.get("apiKey");
       String apiKey = parameter.getFirst();

       
	String path = exchange.getRequestPath();
	String threescaleMethod = getThreescaleMethodName(path);
	
	AuthorizeResponse auth = pluginService.authRep(apiKey, threescaleMethod);

	if (auth!=null && (!auth.success())){
		//TODO find non-deprecated way of doing this.
		exchange.setResponseCode(403);
   	}
}
 
开发者ID:tnscorcoran,项目名称:light-4-j-plugin-wrapper,代码行数:18,代码来源:PluginWrapperClient.java

示例2: handleRequest

import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    if (isConfidential(exchange) || !confidentialityRequired(exchange)) {
        next.handleRequest(exchange);
    } else {
        try {
            URI redirectUri = getRedirectURI(exchange);

            exchange.setResponseCode(StatusCodes.FOUND);
            exchange.getResponseHeaders().put(Headers.LOCATION, redirectUri.toString());
        } catch (Exception e) {
            UndertowLogger.REQUEST_LOGGER.exceptionProcessingRequest(e);
            exchange.setResponseCode(StatusCodes.INTERNAL_SERVER_ERROR);
        }
        exchange.endExchange();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:AbstractConfidentialityHandler.java

示例3: sendContinueResponseBlocking

import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
/**
 * Sends a continue response using blocking IO
 *
 * @param exchange The exchange
 */
public static void sendContinueResponseBlocking(final HttpServerExchange exchange) throws IOException {
    if (!exchange.isResponseChannelAvailable()) {
        throw UndertowMessages.MESSAGES.cannotSendContinueResponse();
    }
    if(exchange.getAttachment(ALREADY_SENT) != null) {
        return;
    }
    HttpServerExchange newExchange = exchange.getConnection().sendOutOfBandResponse(exchange);
    exchange.putAttachment(ALREADY_SENT, true);
    newExchange.setResponseCode(StatusCodes.CONTINUE);
    newExchange.getResponseHeaders().put(Headers.CONTENT_LENGTH, 0);
    newExchange.startBlocking();
    newExchange.getOutputStream().close();
    newExchange.getInputStream().close();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:HttpContinue.java

示例4: cancel

import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
void cancel(final HttpServerExchange exchange) {
    final ProxyConnection connectionAttachment = exchange.getAttachment(CONNECTION);
    if (connectionAttachment != null) {
        ClientConnection clientConnection = connectionAttachment.getConnection();
        UndertowLogger.REQUEST_LOGGER.timingOutRequest(clientConnection.getPeerAddress() + "" + exchange.getRequestURI());
        IoUtils.safeClose(clientConnection);
    } else {
        UndertowLogger.REQUEST_LOGGER.timingOutRequest(exchange.getRequestURI());
    }
    if (exchange.isResponseStarted()) {
        IoUtils.safeClose(exchange.getConnection());
    } else {
        exchange.setResponseCode(StatusCodes.SERVICE_UNAVAILABLE);
        exchange.endExchange();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:ProxyHandler.java

示例5: handleRequest

import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
    InetSocketAddress peer = exchange.getSourceAddress();
    if (isAllowed(peer.getAddress())) {
        next.handleRequest(exchange);
    } else {
        exchange.setResponseCode(denyResponseCode);
        exchange.endExchange();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:11,代码来源:IPAddressAccessControlHandler.java

示例6: handleRequest

import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
    if (disallowedMethods.contains(exchange.getRequestMethod())) {
        exchange.setResponseCode(StatusCodes.METHOD_NOT_ALLOWED);
        exchange.endExchange();
    } else {
        next.handleRequest(exchange);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:DisallowedMethodsHandler.java

示例7: handleRequest

import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    activeRequestsUpdater.incrementAndGet(this);
    if (shutdown) {
        decrementRequests();
        exchange.setResponseCode(StatusCodes.SERVICE_UNAVAILABLE);
        exchange.endExchange();
        return;
    }
    exchange.addExchangeCompleteListener(listener);
    next.handleRequest(exchange);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:GracefulShutdownHandler.java

示例8: handleRequest

import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
    if (exchange.getRequestMethod().equals(Methods.GET) ||
            exchange.getRequestMethod().equals(Methods.POST)) {
        serveResource(exchange, true);
    } else if (exchange.getRequestMethod().equals(Methods.HEAD)) {
        serveResource(exchange, false);
    } else {
        exchange.setResponseCode(StatusCodes.METHOD_NOT_ALLOWED);
        exchange.endExchange();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:ResourceHandler.java

示例9: couldNotResolveBackend

import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public void couldNotResolveBackend(HttpServerExchange exchange) {
    if (exchange.isResponseStarted()) {
        IoUtils.safeClose(exchange.getConnection());
    } else {
        exchange.setResponseCode(StatusCodes.SERVICE_UNAVAILABLE);
        exchange.endExchange();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:ProxyHandler.java

示例10: handleRequest

import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
    if (allowedMethods.contains(exchange.getRequestMethod())) {
        next.handleRequest(exchange);
    } else {
        exchange.setResponseCode(StatusCodes.METHOD_NOT_ALLOWED);
        exchange.endExchange();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:AllowedMethodsHandler.java

示例11: handleRequest

import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
    String attribute = this.attribute.readAttribute(exchange);
    if (isAllowed(attribute)) {
        next.handleRequest(exchange);
    } else {
        exchange.setResponseCode(StatusCodes.FORBIDDEN);
        exchange.endExchange();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:11,代码来源:AccessControlListHandler.java

示例12: handleRequest

import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
    exchange.setResponseCode(responseCode);
    if(traceEnabled) {
        log.tracef("Setting response code %s for exchange %s", responseCode, exchange);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:ResponseCodeHandler.java

示例13: writeAttribute

import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public void writeAttribute(final HttpServerExchange exchange, final String newValue) throws ReadOnlyAttributeException {
    exchange.setResponseCode(Integer.parseInt(newValue));
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:5,代码来源:ResponseCodeAttribute.java

示例14: handleRequest

import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public void handleRequest(final HttpServerExchange exchange) throws IOException, ServletException {
    if (managedServlet.isPermanentlyUnavailable()) {
        UndertowServletLogger.REQUEST_LOGGER.debugf("Returning 404 for servlet %s due to permanent unavailability", managedServlet.getServletInfo().getName());
        exchange.setResponseCode(StatusCodes.NOT_FOUND);
        return;
    }

    long until = unavailableUntil;
    if (until != 0) {
        UndertowServletLogger.REQUEST_LOGGER.debugf("Returning 503 for servlet %s due to temporary unavailability", managedServlet.getServletInfo().getName());
        if (System.currentTimeMillis() < until) {
            exchange.setResponseCode(StatusCodes.SERVICE_UNAVAILABLE);
            return;
        } else {
            unavailableUntilUpdater.compareAndSet(this, until, 0);
        }
    }
    if(!managedServlet.getServletInfo().isAsyncSupported()) {
        exchange.putAttachment(AsyncContextImpl.ASYNC_SUPPORTED, false);
    }
    final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
    ServletRequest request = servletRequestContext.getServletRequest();
    ServletResponse response = servletRequestContext.getServletResponse();
    InstanceHandle<? extends Servlet> servlet = null;
    try {
        servlet = managedServlet.getServlet();
        servlet.getInstance().service(request, response);

        //according to the spec we have to call AsyncContext.complete() at this point
        //straight after the service method
        //not super sure about this, surely it would make more sense to do this when the request has returned to the container, however the spec is quite clear wording wise
        //todo: should we actually enable this? Apparently other containers do not do it
        //if(!request.isAsyncStarted()) {
        //    AsyncContextImpl existingAsyncContext = servletRequestContext.getOriginalRequest().getAsyncContextInternal();
        //    if (existingAsyncContext != null) {
        //        existingAsyncContext.complete();
        //    }
        //}
    } catch (UnavailableException e) {
        if (e.isPermanent()) {
            UndertowServletLogger.REQUEST_LOGGER.stoppingServletDueToPermanentUnavailability(managedServlet.getServletInfo().getName(), e);
            managedServlet.stop();
            managedServlet.setPermanentlyUnavailable(true);
            exchange.setResponseCode(StatusCodes.NOT_FOUND);
        } else {
            unavailableUntilUpdater.set(this, System.currentTimeMillis() + e.getUnavailableSeconds() * 1000);
            UndertowServletLogger.REQUEST_LOGGER.stoppingServletUntilDueToTemporaryUnavailability(managedServlet.getServletInfo().getName(), new Date(until), e);
            exchange.setResponseCode(StatusCodes.SERVICE_UNAVAILABLE);
        }
    } finally {
        if(servlet != null) {
            servlet.release();
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:57,代码来源:ServletHandler.java

示例15: handleFirstRequest

import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
public void handleFirstRequest(final HttpServerExchange exchange, final ServletChain servletChain, final ServletRequestContext servletRequestContext, final ServletRequest request, final ServletResponse response) throws Exception {

        ThreadSetupAction.Handle handle = setupAction.setup(exchange);
        try {
            servletRequestContext.setRunningInsideHandler(true);
            try {
                listeners.requestInitialized(request);
                next.handleRequest(exchange);
                //
                if(servletRequestContext.getErrorCode() > 0) {
                    servletRequestContext.getOriginalResponse().doErrorDispatch(servletRequestContext.getErrorCode(), servletRequestContext.getErrorMessage());
                }
            } catch (Throwable t) {

                //by default this will just log the exception
                boolean handled = exceptionHandler.handleThrowable(exchange, request, response, t);

                if(handled) {
                    exchange.endExchange();
                } else if (request.isAsyncStarted() || request.getDispatcherType() == DispatcherType.ASYNC) {
                    exchange.unDispatch();
                    servletRequestContext.getOriginalRequest().getAsyncContextInternal().handleError(t);
                } else {
                    if (!exchange.isResponseStarted()) {
                        response.reset();                       //reset the response
                        exchange.setResponseCode(StatusCodes.INTERNAL_SERVER_ERROR);
                        exchange.getResponseHeaders().clear();
                        String location = servletContext.getDeployment().getErrorPages().getErrorLocation(t);
                        if (location == null) {
                            location = servletContext.getDeployment().getErrorPages().getErrorLocation(StatusCodes.INTERNAL_SERVER_ERROR);
                        }
                        if (location != null) {
                            RequestDispatcherImpl dispatcher = new RequestDispatcherImpl(location, servletContext);
                            try {
                                dispatcher.error(servletRequestContext, request, response, servletChain.getManagedServlet().getServletInfo().getName(), t);
                            } catch (Exception e) {
                                UndertowLogger.REQUEST_LOGGER.exceptionGeneratingErrorPage(e, location);
                            }
                        } else {
                            if (servletRequestContext.displayStackTraces()) {
                                ServletDebugPageHandler.handleRequest(exchange, servletRequestContext, t);
                            } else {
                                servletRequestContext.getOriginalResponse().doErrorDispatch(StatusCodes.INTERNAL_SERVER_ERROR, StatusCodes.INTERNAL_SERVER_ERROR_STRING);
                            }
                        }
                    }
                }

            } finally {
                servletRequestContext.setRunningInsideHandler(false);
                listeners.requestDestroyed(request);
            }
            //if it is not dispatched and is not a mock request
            if (!exchange.isDispatched() && !(exchange.getConnection() instanceof MockServerConnection)) {
                servletRequestContext.getOriginalResponse().responseDone();
                servletRequestContext.getOriginalRequest().clearAttributes();
            }
            if(!exchange.isDispatched()) {
                AsyncContextImpl ctx = servletRequestContext.getOriginalRequest().getAsyncContextInternal();
                if(ctx != null) {
                    ctx.complete();
                }
            }
        } finally {
            handle.tearDown();
        }
    }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:68,代码来源:ServletInitialHandler.java


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