Search in sources :

Example 91 with RequestDispatcher

use of javax.servlet.RequestDispatcher in project narayana by jbosstm.

the class TestServlet method doPost.

/**
 * Execute the test
 * @param request The HTTP servlet request.
 * @param response The HTTP servlet response.
 */
protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
    final String serviceURI = request.getParameter(TestConstants.PARAM_SERVICE_URI);
    final String test = request.getParameter(TestConstants.PARAM_TEST);
    final String testTimeoutValue = request.getParameter(TestConstants.PARAM_TEST_TIMEOUT);
    // final String asyncTestValue = request.getParameter(TestConstants.PARAM_ASYNC_TEST) ;
    String resultPageAddress = request.getParameter(TestConstants.PARAM_RESULT_PAGE);
    if (resultPageAddress == null || resultPageAddress.length() == 0) {
        resultPageAddress = TestConstants.DEFAULT_RESULT_PAGE_ADDRESS;
    }
    final int serviceURILength = (serviceURI == null ? 0 : serviceURI.length());
    final int testLength = (test == null ? 0 : test.length());
    long testTimeout = 0;
    boolean testTimeoutValid = false;
    if ((testTimeoutValue != null) && (testTimeoutValue.length() > 0)) {
        try {
            testTimeout = Long.parseLong(testTimeoutValue);
            testTimeoutValid = true;
        }// ignore
         catch (final NumberFormatException nfe) {
        }
    }
    // final boolean asyncTest = (asyncTestValue != null) ;
    final boolean asyncTest = true;
    if ((serviceURILength == 0) || (testLength == 0) || !testTimeoutValid) {
        final RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/invalidParameters.html");
        dispatcher.forward(request, response);
        return;
    }
    final HttpSession session = request.getSession();
    final String id = session.getId();
    final int logCount = getLogCount(session);
    final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
    final String date = format.format(new Date());
    final String logName = date + "-" + id + "-" + logCount;
    session.setAttribute(TestConstants.ATTRIBUTE_TEST_RESULT, null);
    session.setAttribute(TestConstants.ATTRIBUTE_TEST_VALIDATION, null);
    session.setAttribute(TestConstants.ATTRIBUTE_LOG_NAME, null);
    final String threadLog;
    try {
        final TestResult result = TestRunner.execute(serviceURI, testTimeout, asyncTest, test);
        if (result != null) {
            session.setAttribute(TestConstants.ATTRIBUTE_TEST_RESULT, result);
            threadLog = MessageLogging.getThreadLog();
            try {
                TestLogController.writeLog(logName, threadLog);
                session.setAttribute(TestConstants.ATTRIBUTE_LOG_NAME, logName);
            } catch (final IOException ioe) {
                log("Unexpected IOException writing message log", ioe);
            }
        } else {
            threadLog = null;
        }
    } finally {
        MessageLogging.clearThreadLog();
    }
    if ((threadLog != null) && (threadLog.length() > 0)) {
        try {
            final String testValidation = transform(threadLog);
            session.setAttribute(TestConstants.ATTRIBUTE_TEST_VALIDATION, testValidation);
        } catch (final Throwable th) {
            log("Unexpected throwable transforming message log", th);
        }
    }
    final RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(resultPageAddress);
    dispatcher.forward(request, response);
}
Also used : HttpSession(javax.servlet.http.HttpSession) TestResult(junit.framework.TestResult) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat) RequestDispatcher(javax.servlet.RequestDispatcher) Date(java.util.Date)

Example 92 with RequestDispatcher

use of javax.servlet.RequestDispatcher in project plantuml-server by plantuml.

the class PlantUmlServlet method doGet.

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    request.setCharacterEncoding("UTF-8");
    String text = request.getParameter("text");
    String metadata = request.getParameter("metadata");
    if (metadata != null) {
        InputStream img = null;
        try {
            img = getImage(new URL(metadata));
            MetadataTag metadataTag = new MetadataTag(img, "plantuml");
            String data = metadataTag.getData();
            if (data != null) {
                text = data;
            }
        } finally {
            if (img != null) {
                img.close();
            }
        }
    }
    try {
        text = getTextFromUrl(request, text);
    } catch (Exception e) {
        e.printStackTrace();
    }
    // no Text form has been submitted
    if (text == null || text.trim().isEmpty()) {
        redirectNow(request, response, DEFAULT_ENCODED_TEXT);
        return;
    }
    final String encoded = getTranscoder().encode(text);
    request.setAttribute("decoded", text);
    request.setAttribute("encoded", encoded);
    // check if an image map is necessary
    if (text != null && PlantumlUtils.hasCMapData(text)) {
        request.setAttribute("mapneeded", Boolean.TRUE);
    }
    // forward to index.jsp
    final RequestDispatcher dispatcher = request.getRequestDispatcher("/index.jsp");
    dispatcher.forward(request, response);
}
Also used : InputStream(java.io.InputStream) MetadataTag(net.sourceforge.plantuml.png.MetadataTag) URL(java.net.URL) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 93 with RequestDispatcher

use of javax.servlet.RequestDispatcher in project plantuml-server by plantuml.

the class Welcome method doGet.

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    // set the sample
    request.setAttribute("decoded", "Bob -> Alice : hello");
    request.setAttribute("encoded", "SyfFKj2rKt3CoKnELR1Io4ZDoSa70000");
    // forward to index.jsp
    RequestDispatcher dispatcher = request.getRequestDispatcher("/index.jsp");
    dispatcher.forward(request, response);
}
Also used : RequestDispatcher(javax.servlet.RequestDispatcher)

Example 94 with RequestDispatcher

use of javax.servlet.RequestDispatcher in project ma-core-public by infiniteautomation.

the class StartupContextHandler method handle.

@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    if (restRequestMatcher.matches(request)) {
        // Return options response
        response.setStatus(HttpStatus.SERVICE_UNAVAILABLE_503);
        response.setContentLength(0);
        IMangoLifecycle lifecycle = Providers.get(IMangoLifecycle.class);
        Float progress = lifecycle.getStartupProgress();
        int state = lifecycle.getLifecycleState();
        response.setHeader("Mango-Startup-Progress", String.format("%d", progress.intValue()));
        response.setHeader("Mango-Startup-State", this.statusServlet.getLifecycleStateMessage(state));
        baseRequest.setHandled(true);
    } else if (statusRequestMatcher.matches(request)) {
        statusServlet.handleRequest(request, response);
        baseRequest.setHandled(true);
    } else if (resourceRequestMatcher.matches(request)) {
        super.handle(target, baseRequest, request, response);
    } else if (pageRequestMatcher.matches(request)) {
        // Check to see if there are any default pages defined for this
        String uri = DefaultPagesDefinition.getStartupUri(request, response);
        if (uri != null) {
            RequestDispatcher dispatcher = request.getRequestDispatcher(uri);
            dispatcher.forward(request, response);
        } else {
            response.setContentType("text/html;charset=utf-8");
            response.setStatus(HttpStatus.SERVICE_UNAVAILABLE_503);
            baseRequest.setHandled(true);
            // Load page template
            byte[] fileData = Files.readAllBytes(Paths.get(Common.MA_HOME + "/" + Constants.DIR_WEB + "/" + STARTUP_PAGE_TEMPLATE));
            pageTemplate = new String(fileData, Common.UTF8_CS);
            String processedTemplate = pageTemplate;
            response.getWriter().write(processedTemplate);
        }
    } else {
        response.sendError(HttpStatus.SERVICE_UNAVAILABLE_503);
    }
}
Also used : IMangoLifecycle(com.serotonin.m2m2.IMangoLifecycle) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 95 with RequestDispatcher

use of javax.servlet.RequestDispatcher in project spring-cloud-netflix by spring-cloud.

the class SendErrorFilter method run.

@Override
public Object run() {
    try {
        RequestContext ctx = RequestContext.getCurrentContext();
        ZuulException exception = findZuulException(ctx.getThrowable());
        HttpServletRequest request = ctx.getRequest();
        request.setAttribute("javax.servlet.error.status_code", exception.nStatusCode);
        log.warn("Error during filtering", exception);
        request.setAttribute("javax.servlet.error.exception", exception);
        if (StringUtils.hasText(exception.errorCause)) {
            request.setAttribute("javax.servlet.error.message", exception.errorCause);
        }
        RequestDispatcher dispatcher = request.getRequestDispatcher(this.errorPath);
        if (dispatcher != null) {
            ctx.set(SEND_ERROR_FILTER_RAN, true);
            if (!ctx.getResponse().isCommitted()) {
                ctx.setResponseStatusCode(exception.nStatusCode);
                dispatcher.forward(request, ctx.getResponse());
            }
        }
    } catch (Exception ex) {
        ReflectionUtils.rethrowRuntimeException(ex);
    }
    return null;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ZuulException(com.netflix.zuul.exception.ZuulException) RequestContext(com.netflix.zuul.context.RequestContext) RequestDispatcher(javax.servlet.RequestDispatcher) ZuulRuntimeException(org.springframework.cloud.netflix.zuul.util.ZuulRuntimeException) ZuulException(com.netflix.zuul.exception.ZuulException)

Aggregations

RequestDispatcher (javax.servlet.RequestDispatcher)354 ServletException (javax.servlet.ServletException)98 HttpSession (javax.servlet.http.HttpSession)97 IOException (java.io.IOException)74 HttpServletRequest (javax.servlet.http.HttpServletRequest)56 HttpServletResponse (javax.servlet.http.HttpServletResponse)44 SQLException (java.sql.SQLException)31 User (com.zyf.bean.User)28 ServletContext (javax.servlet.ServletContext)26 Properties (java.util.Properties)14 Test (org.junit.Test)14 RelatorioDAO (br.senac.tads3.pi03b.gruposete.dao.RelatorioDAO)13 RelatorioMudancas (br.senac.tads3.pi03b.gruposete.models.RelatorioMudancas)12 PrintWriter (java.io.PrintWriter)12 RequestDispatcherOptions (org.apache.sling.api.request.RequestDispatcherOptions)11 Resource (org.apache.sling.api.resource.Resource)11 ArrayList (java.util.ArrayList)9 Map (java.util.Map)9 GenericValue (org.apache.ofbiz.entity.GenericValue)9 WebUser (org.compiere.util.WebUser)9