javax.servlet.http.HttpUpgradeHandler Java Examples

The following examples show how to use javax.servlet.http.HttpUpgradeHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestUpgrade.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
private void doTestMessages (
        Class<? extends HttpUpgradeHandler> upgradeHandlerClass)
        throws Exception {
    UpgradeConnection uc = doUpgrade(upgradeHandlerClass);
    PrintWriter pw = new PrintWriter(uc.getWriter());
    BufferedReader reader = uc.getReader();

    pw.println(MESSAGE);
    pw.flush();

    Thread.sleep(500);

    pw.println(MESSAGE);
    pw.flush();

    uc.shutdownOutput();

    // Note: BufferedReader.readLine() strips new lines
    //       ServletInputStream.readLine() does not strip new lines
    String response = reader.readLine();
    Assert.assertEquals(MESSAGE, response);
    response = reader.readLine();
    Assert.assertEquals(MESSAGE, response);

    uc.shutdownInput();
}
 
Example #2
Source File: AbstractHttp11Protocol.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
protected Processor createUpgradeProcessor(
        SocketWrapperBase<?> socket,
        UpgradeToken upgradeToken) {
    HttpUpgradeHandler httpUpgradeHandler = upgradeToken.getHttpUpgradeHandler();
    if (httpUpgradeHandler instanceof InternalHttpUpgradeHandler) {
        return new UpgradeProcessorInternal(socket, upgradeToken);
    } else {
        return new UpgradeProcessorExternal(socket, upgradeToken);
    }
}
 
Example #3
Source File: Request.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @since Servlet 3.1
 */
@SuppressWarnings("unchecked")
@Override
public <T extends HttpUpgradeHandler> T upgrade(
        Class<T> httpUpgradeHandlerClass) throws java.io.IOException, ServletException {
    T handler;
    InstanceManager instanceManager = null;
    try {
        // Do not go through the instance manager for internal Tomcat classes since they don't
        // need injection
        if (InternalHttpUpgradeHandler.class.isAssignableFrom(httpUpgradeHandlerClass)) {
            handler = httpUpgradeHandlerClass.getConstructor().newInstance();
        } else {
            instanceManager = getContext().getInstanceManager();
            handler = (T) instanceManager.newInstance(httpUpgradeHandlerClass);
        }
    } catch (InstantiationException | IllegalAccessException | InvocationTargetException |
            NamingException | IllegalArgumentException | NoSuchMethodException |
            SecurityException e) {
        throw new ServletException(e);
    }
    UpgradeToken upgradeToken = new UpgradeToken(handler,
            getContext(), instanceManager);

    coyoteRequest.action(ActionCode.UPGRADE, upgradeToken);

    // Output required by RFC2616. Protocol specific headers should have
    // already been set.
    response.setStatus(HttpServletResponse.SC_SWITCHING_PROTOCOLS);

    return handler;
}
 
Example #4
Source File: TestUpgrade.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
private void doTestCheckClosed(
        Class<? extends HttpUpgradeHandler> upgradeHandlerClass)
                throws Exception {
    UpgradeConnection conn = doUpgrade(upgradeHandlerClass);

    Reader r = conn.getReader();
    int c = r.read();

    Assert.assertEquals(-1, c);
}
 
Example #5
Source File: TestUpgrade.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
private void doTestFixedResponse(
        Class<? extends HttpUpgradeHandler> upgradeHandlerClass)
                throws Exception {
    UpgradeConnection conn = doUpgrade(upgradeHandlerClass);

    Reader r = conn.getReader();
    int c = r.read();

    Assert.assertEquals(FixedResponseNonBlocking.FIXED_RESPONSE, c);
}
 
Example #6
Source File: HttpServletRequestImpl.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@Override
    public <T extends HttpUpgradeHandler> T upgrade(final Class<T> handlerClass) throws IOException {
        throw new IOException("NYI");
//
//        try {
//            InstanceFactory<T> factory = servletContext.getDeployment().getDeploymentInfo().getClassIntrospecter().createInstanceFactory(handlerClass);
//            final InstanceHandle<T> instance = factory.createInstance();
//            //exchange.upgradeChannel(new ServletUpgradeListener(instance, servletContext.getDeployment(), exchange));
//            return instance.getInstance();
//        } catch (InstantiationException e) {
//            throw new RuntimeException(e);
//        } catch (NoSuchMethodException e) {
//            throw new RuntimeException(e);
//        }
    }
 
Example #7
Source File: DefaultWebApplicationRequest.java    From piranha with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Upgrade the request.
 *
 * @param <T> the type.
 * @param handlerClass the handler class.
 * @return the upgrade handler.
 * @throws IOException when an I/O error occurs.
 * @throws ServletException when a serious error occurs.
 */
@Override
public <T extends HttpUpgradeHandler> T upgrade(Class<T> handlerClass) throws IOException, ServletException {
    try {
        upgradeHandler = handlerClass.newInstance();
    } catch (InstantiationException | IllegalAccessException ie) {
        throw new ServletException(ie);
    }
    setUpgraded(true);
    return (T) upgradeHandler;
}
 
Example #8
Source File: FakeHttpServletRequest.java    From selenium with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends HttpUpgradeHandler> T upgrade(Class<T> handlerClass) {
  throw new UnsupportedOperationException();
}
 
Example #9
Source File: MockHttpRequest.java    From glowroot with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends HttpUpgradeHandler> T upgrade(Class<T> handlerClass)
        throws IOException, ServletException {
    return null;
}
 
Example #10
Source File: WebSocketUndertowServletRequest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends HttpUpgradeHandler> T upgrade(Class<T> arg0) throws IOException, ServletException {
    throw new UnsupportedOperationException();
}
 
Example #11
Source File: HttpServletRequestMock.java    From vraptor4 with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends HttpUpgradeHandler> T upgrade(Class<T> handlerClass) throws IOException, ServletException {
	return wrapper.upgrade(handlerClass);
}
 
Example #12
Source File: ThreadLocalHttpServletRequest.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends HttpUpgradeHandler> T upgrade(final Class<T> httpUpgradeHandlerClass) throws IOException, ServletException {
    return get().upgrade(httpUpgradeHandlerClass);
}
 
Example #13
Source File: HttpRequestImpl.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends HttpUpgradeHandler> T upgrade(final Class<T> httpUpgradeHandlerClass) throws IOException, ServletException {
    throw new UnsupportedOperationException("upgrade not supported");
}
 
Example #14
Source File: ServletRequestAdapter.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends HttpUpgradeHandler> T upgrade(final Class<T> httpUpgradeHandlerClass) throws IOException, ServletException {
    return request.upgrade(httpUpgradeHandlerClass);
}
 
Example #15
Source File: MockHttpServletRequest.java    From everrest with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public <T extends HttpUpgradeHandler> T upgrade(Class<T> handlerClass) throws IOException, ServletException {
    return null;
}
 
Example #16
Source File: InMemoryRequest.java    From component-runtime with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends HttpUpgradeHandler> T upgrade(final Class<T> aClass) {
    return null;
}
 
Example #17
Source File: WebSocketVirtualServletRequest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends HttpUpgradeHandler> T upgrade(Class<T> arg0) throws IOException, ServletException {
    throw new UnsupportedOperationException();
}
 
Example #18
Source File: HttpServletPortletRequestWrapper.java    From portals-pluto with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends HttpUpgradeHandler> T upgrade(Class<T> httpUpgradeHandlerClass) throws IOException,
      ServletException {
   throw new ServletException("Not Supported");
}
 
Example #19
Source File: HttpServletRequestAdapter.java    From portals-pluto with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends HttpUpgradeHandler> T upgrade(Class<T> aClass) throws IOException, ServletException {
	throw new UnsupportedOperationException();
}
 
Example #20
Source File: MockHttpServletRequest.java    From knox with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends HttpUpgradeHandler> T upgrade( Class<T> aClass ) throws IOException, ServletException {
  throw new UnsupportedOperationException();
}
 
Example #21
Source File: StandardDavRequest.java    From cosmo with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends HttpUpgradeHandler> T upgrade(Class<T> handlerClass) throws IOException, ServletException {
    return null;
}
 
Example #22
Source File: TestGetRequestTimeout.java    From database with GNU General Public License v2.0 4 votes vote down vote up
@Override
public <T extends HttpUpgradeHandler> T upgrade(Class<T> handlerClass)
		throws IOException, ServletException {
	// TODO Auto-generated method stub
	return null;
}
 
Example #23
Source File: HttpServletRequestFake.java    From takes with MIT License 4 votes vote down vote up
@Override
public <T extends HttpUpgradeHandler> T upgrade(
    final Class<T> cls
) throws IOException, ServletException {
    throw new UnsupportedOperationException("#upgrade()");
}
 
Example #24
Source File: LocalServletRequest.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends HttpUpgradeHandler> T upgrade(Class<T> handlerClass) throws IOException, ServletException {
    throw new IllegalStateException("Not supported");
}
 
Example #25
Source File: MultipartRequestWrapper.java    From lastaflute with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends HttpUpgradeHandler> T upgrade(Class<T> handlerClass) throws IOException, ServletException {
    return wrapped.upgrade(handlerClass);
}
 
Example #26
Source File: HttpServletRequestStub.java    From development with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends HttpUpgradeHandler> T upgrade(Class<T> arg0)
        throws IOException, ServletException {
    // TODO Auto-generated method stub
    return null;
}
 
Example #27
Source File: MockHttpServletRequest.java    From athenz with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends HttpUpgradeHandler> T upgrade(Class<T> handlerClass) throws IOException, ServletException {
    // Auto-generated method stub
    return null;
}
 
Example #28
Source File: MockHttpServletRequest.java    From athenz with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends HttpUpgradeHandler> T upgrade(Class<T> handlerClass) throws IOException, ServletException {
    // Auto-generated method stub
    return null;
}
 
Example #29
Source File: MockHttpServletRequest.java    From athenz with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends HttpUpgradeHandler> T upgrade(Class<T> arg0)
        throws IOException, ServletException {
    return null;
}
 
Example #30
Source File: MockHttpServletRequest.java    From athenz with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends HttpUpgradeHandler> T upgrade(Class<T> arg0)
        throws IOException, ServletException {
    return null;
}