Search in sources :

Example 21 with Session

use of org.apache.tapestry5.http.services.Session in project tapestry-5 by apache.

the class SSOEntity method getPersistedEntityClassName.

public String getPersistedEntityClassName() {
    final Session session = request.getSession(true);
    final Object value = session.getAttribute("sso:" + User.class.getName());
    return value.getClass().getName();
}
Also used : Session(org.apache.tapestry5.http.services.Session)

Example 22 with Session

use of org.apache.tapestry5.http.services.Session in project tapestry-5 by apache.

the class SSOEntity method getPersistedEntityClassName.

public String getPersistedEntityClassName() {
    final Session session = request.getSession(true);
    final Object value = session.getAttribute("sso:" + User.class.getName());
    return value.getClass().getName();
}
Also used : Session(org.apache.tapestry5.http.services.Session)

Example 23 with Session

use of org.apache.tapestry5.http.services.Session in project tapestry-5 by apache.

the class KaptchaImage method onImage.

Object onImage() throws IOException {
    if (captchaText == null) {
        return new HttpError(HttpServletResponse.SC_NOT_FOUND, "Session expired.");
    }
    return new StreamResponse() {

        @Override
        public String getContentType() {
            return "image/jpeg";
        }

        @Override
        public InputStream getStream() throws IOException {
            BufferedImage image = producer.createImage(captchaText);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ImageIO.write(image, "jpg", baos);
            return new ByteArrayInputStream(baos.toByteArray());
        }

        @Override
        public void prepareResponse(Response response) {
            response.setDateHeader("Expires", 0);
            // Set standard HTTP/1.1 no-cache headers.
            response.addHeader("Cache-Control", "no-store, no-cache, must-revalidate");
            // Set IE extended HTTP/1.1 no-cache headers (use addHeader).
            response.addHeader("Cache-Control", "post-check=0, pre-check=0");
            // Set standard HTTP/1.0 no-cache header.
            response.setHeader("Pragma", "no-cache");
        }
    };
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(org.apache.tapestry5.http.services.Response) StreamResponse(org.apache.tapestry5.StreamResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) StreamResponse(org.apache.tapestry5.StreamResponse) HttpError(org.apache.tapestry5.services.HttpError) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedImage(java.awt.image.BufferedImage)

Example 24 with Session

use of org.apache.tapestry5.http.services.Session in project tapestry-5 by apache.

the class ExceptionReportWriterImpl method writeReport.

@Override
public void writeReport(final PrintWriter writer, ExceptionAnalysis analysis) {
    writer.printf("EXCEPTION STACK:%n%n");
    // Figure out what all the property names are so that we can set the width of the column that lists
    // property names.
    Flow<String> propertyNames = F.flow(analysis.getExceptionInfos()).mapcat(EXCEPTION_INFO_TO_PROPERTY_NAMES).append("Exception", "Message");
    PropertyWriter pw = newPropertyWriter(writer, propertyNames);
    boolean first = true;
    for (ExceptionInfo info : analysis.getExceptionInfos()) {
        if (first) {
            writer.println();
            first = false;
        }
        pw.write("Exception", info.getClassName());
        pw.write("Message", info.getMessage());
        for (String name : info.getPropertyNames()) {
            pw.write(name, info.getProperty(name));
        }
        if (!info.getStackTrace().isEmpty()) {
            writer.printf("%n  Stack trace:%n%n");
            for (StackTraceElement e : info.getStackTrace()) {
                writer.printf("  - %s%n", e.toString());
            }
        }
        writer.println();
    }
    Request request = requestGlobals.getRequest();
    if (request != null) {
        // New PropertyWriter based on the lengths of parameter names and header names, and a sample of
        // the literal keys.
        pw = newPropertyWriter(writer, F.flow(request.getParameterNames()).concat(request.getHeaderNames()).append("serverName", "removeHost"));
        writer.printf("REQUEST:%n%nBasic Information:%n%n");
        List<String> flags = CollectionFactory.newList();
        if (request.isXHR()) {
            flags.add("XHR");
        }
        if (request.isRequestedSessionIdValid()) {
            flags.add("requestedSessionIdValid");
        }
        if (request.isSecure()) {
            flags.add("secure");
        }
        pw.write("contextPath", contextPath);
        if (!flags.isEmpty()) {
            pw.write("flags", InternalUtils.joinSorted(flags));
        }
        pw.write("method", request.getMethod());
        pw.write("path", request.getPath());
        pw.write("locale", request.getLocale());
        pw.write("serverName", request.getServerName());
        pw.write("remoteHost", request.getRemoteHost());
        writer.printf("%nHeaders:%n%n");
        for (String name : request.getHeaderNames()) {
            pw.write(name, request.getHeader(name));
        }
        if (!request.getParameterNames().isEmpty()) {
            writer.printf("%nParameters:%n");
            for (String name : request.getParameterNames()) {
                // TODO: Support multi-value parameters
                pw.write(name, request.getParameters(name));
            }
        }
        Session session = request.getSession(false);
        if (session != null) {
            pw = newPropertyWriter(writer, session.getAttributeNames());
            writer.printf("%nSESSION:%n%n");
            for (String name : session.getAttributeNames()) {
                pw.write(name, session.getAttribute(name));
            }
        }
    }
    writer.printf("%nSYSTEM INFORMATION:");
    Runtime runtime = Runtime.getRuntime();
    writer.printf("%n%nMemory:%n  %,15d bytes free%n  %,15d bytes total%n  %,15d bytes max%n", runtime.freeMemory(), runtime.totalMemory(), runtime.maxMemory());
    Thread[] threads = TapestryInternalUtils.getAllThreads();
    int maxThreadNameLength = 0;
    for (Thread t : threads) {
        maxThreadNameLength = Math.max(maxThreadNameLength, t.getName().length());
    }
    String format = "%n%s %" + maxThreadNameLength + "s %s";
    writer.printf("%n%,d Threads:", threads.length);
    for (Thread t : threads) {
        writer.printf(format, Thread.currentThread() == t ? "*" : " ", t.getName(), t.getState().name());
        if (t.isDaemon()) {
            writer.write(", daemon");
        }
        if (!t.isAlive()) {
            writer.write(", NOT alive");
        }
        if (t.isInterrupted()) {
            writer.write(", interrupted");
        }
        if (t.getPriority() != Thread.NORM_PRIORITY) {
            writer.printf(", priority %d", t.getPriority());
        }
    }
    // Finish the final line.
    writer.println();
}
Also used : Request(org.apache.tapestry5.http.services.Request) ExceptionInfo(org.apache.tapestry5.ioc.services.ExceptionInfo) Session(org.apache.tapestry5.http.services.Session)

Example 25 with Session

use of org.apache.tapestry5.http.services.Session in project tapestry-5 by apache.

the class SessionApplicationStatePersistenceStrategy method getOrCreate.

protected <T> Object getOrCreate(Class<T> ssoClass, ApplicationStateCreator<T> creator) {
    Session session = getSession();
    String key = buildKey(ssoClass);
    Object sso = session.getAttribute(key);
    if (sso == null) {
        sso = creator.create();
        set(ssoClass, (T) sso);
    }
    return sso;
}
Also used : Session(org.apache.tapestry5.http.services.Session)

Aggregations

Test (org.testng.annotations.Test)31 Session (org.apache.tapestry5.http.services.Session)30 Request (org.apache.tapestry5.http.services.Request)14 HttpSession (javax.servlet.http.HttpSession)10 Logger (org.slf4j.Logger)8 ClusteredSessionImpl (org.apache.tapestry5.http.internal.services.ClusteredSessionImpl)7 Session (org.hibernate.Session)7 SessionImpl (org.apache.tapestry5.http.internal.services.SessionImpl)6 ApplicationStatePersistenceStrategy (org.apache.tapestry5.services.ApplicationStatePersistenceStrategy)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 Resource (org.apache.tapestry5.commons.Resource)5 SessionLock (org.apache.tapestry5.http.internal.services.SessionLock)5 MutableComponentModel (org.apache.tapestry5.model.MutableComponentModel)5 HibernateEntityValueEncoder (org.apache.tapestry5.hibernate.web.internal.HibernateEntityValueEncoder)4 ReadOnlyBean (org.apache.tapestry5.internal.transform.pages.ReadOnlyBean)4 EntityPersistentFieldStrategy (org.apache.tapestry5.hibernate.web.internal.EntityPersistentFieldStrategy)3 RequestImpl (org.apache.tapestry5.http.internal.services.RequestImpl)3 TapestrySessionFactory (org.apache.tapestry5.http.internal.services.TapestrySessionFactory)3 PersistentFieldChange (org.apache.tapestry5.services.PersistentFieldChange)3 Enumeration (java.util.Enumeration)2