use of org.eclipse.jetty.server.AbstractHttpConnection in project BeyondUPnP by kevinshine.
the class AndroidJettyServletContainer method isConnectionOpen.
public static boolean isConnectionOpen(HttpServletRequest request, byte[] heartbeat) {
Request jettyRequest = (Request) request;
AbstractHttpConnection connection = jettyRequest.getConnection();
Socket socket = (Socket) connection.getEndPoint().getTransport();
if (log.isLoggable(Level.FINE))
log.fine("Checking if client connection is still open: " + socket.getRemoteSocketAddress());
try {
socket.getOutputStream().write(heartbeat);
socket.getOutputStream().flush();
return true;
} catch (IOException ex) {
if (log.isLoggable(Level.FINE))
log.fine("Client connection has been closed: " + socket.getRemoteSocketAddress());
return false;
}
}
use of org.eclipse.jetty.server.AbstractHttpConnection in project jena by apache.
the class FusekiErrorHandler method handle.
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException {
AbstractHttpConnection connection = AbstractHttpConnection.getCurrentConnection();
connection.getRequest().setHandled(true);
String method = request.getMethod();
if (!method.equals(HttpMethods.GET) && !method.equals(HttpMethods.POST) && !method.equals(HttpMethods.HEAD))
return;
response.setContentType(MimeTypes.TEXT_PLAIN_UTF_8);
response.setHeader(HttpHeaders.CACHE_CONTROL, "must-revalidate,no-cache,no-store");
ByteArrayOutputStream bytes = new ByteArrayOutputStream(1024);
//String writer = IO.UTF8(null) ;
try (Writer writer = new OutputStreamWriter(bytes, "UTF-8")) {
handleErrorPage(request, writer, connection.getResponse().getStatus(), connection.getResponse().getReason());
if (!Fuseki.VERSION.equalsIgnoreCase("development")) {
writer.write("\n");
writer.write("\n");
writer.write(format("Fuseki - version %s (Build date: %s)\n", Fuseki.VERSION, Fuseki.BUILD_DATE));
}
writer.flush();
}
response.setContentLength(bytes.size());
// Copy
response.getOutputStream().write(bytes.toByteArray());
}
use of org.eclipse.jetty.server.AbstractHttpConnection in project processdash by dtuma.
the class LocalConnector method getResponse.
public ByteArrayBuffer getResponse(String uri, int port, Map extraEnv) throws Exception {
// get the current, previously active connection if one exists
AbstractHttpConnection conn = AbstractHttpConnection.getCurrentConnection();
// Identify the effective server name for this request
Request parentRequest = (conn == null ? null : conn.getRequest());
String host = (//
parentRequest == null ? //
"localhost:" + port : parentRequest.getHeader("Host"));
// construct an HTTP request for this data
StringBuilder requestHeader = new StringBuilder();
requestHeader.append("GET ").append(uri).append(" HTTP/1.0\r\n").append("Host: ").append(host).append("\r\n").append("Connection: close\r\n").append("Content-Length: 0\r\n\r\n");
// execute the request and retrieve the responses
ByteArrayBuffer requestBuffer = new ByteArrayBuffer(requestHeader.toString(), StringUtil.__ISO_8859_1);
LocalRequest request = new LocalRequest(requestBuffer, extraEnv, parentRequest, false);
AccessController.doPrivileged(request);
return request.getResponsesBuffer();
}
use of org.eclipse.jetty.server.AbstractHttpConnection in project elasticsearch-jetty by sonian.
the class JettyHttpServerErrorHandler method handle.
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException {
AbstractHttpConnection connection = AbstractHttpConnection.getCurrentConnection();
connection.getRequest().setHandled(true);
String method = request.getMethod();
response.setContentType(MimeTypes.TEXT_PLAIN_8859_1);
ByteArrayISO8859Writer writer = new ByteArrayISO8859Writer(4096);
writer.write(request.getAttribute(Dispatcher.ERROR_STATUS_CODE) + " " + request.getAttribute(Dispatcher.ERROR_MESSAGE) + " " + request.getAttribute(Dispatcher.ERROR_REQUEST_URI));
writer.flush();
response.setContentLength(writer.size());
writer.writeTo(response.getOutputStream());
writer.destroy();
}
use of org.eclipse.jetty.server.AbstractHttpConnection in project cdap by caskdata.
the class JAASLoginService method login.
/* ------------------------------------------------------------ */
public UserIdentity login(final String username, final Object credentials) {
try {
CallbackHandler callbackHandler = null;
if (callbackHandlerClass == null) {
callbackHandler = new CallbackHandler() {
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (Callback callback : callbacks) {
if (callback instanceof NameCallback) {
((NameCallback) callback).setName(username);
} else if (callback instanceof PasswordCallback) {
((PasswordCallback) callback).setPassword(credentials.toString().toCharArray());
} else if (callback instanceof ObjectCallback) {
((ObjectCallback) callback).setObject(credentials);
} else if (callback instanceof RequestParameterCallback) {
AbstractHttpConnection connection = AbstractHttpConnection.getCurrentConnection();
Request request = (connection == null ? null : connection.getRequest());
if (request != null) {
RequestParameterCallback rpc = (RequestParameterCallback) callback;
rpc.setParameterValues(Arrays.asList(request.getParameterValues(rpc.getParameterName())));
}
} else {
throw new UnsupportedCallbackException(callback);
}
}
}
};
} else {
Class clazz = Loader.loadClass(getClass(), callbackHandlerClass);
callbackHandler = (CallbackHandler) clazz.newInstance();
}
//set up the login context
//TODO jaspi requires we provide the Configuration parameter
Subject subject = new Subject();
LoginContext loginContext = new LoginContext(loginModuleName, subject, callbackHandler, configuration);
loginContext.login();
//login success
JAASUserPrincipal userPrincipal = new JAASUserPrincipal(getUserName(callbackHandler), subject, loginContext);
subject.getPrincipals().add(userPrincipal);
return identityService.newUserIdentity(subject, userPrincipal, getGroups(subject));
} catch (LoginException e) {
LOG.debug(e);
} catch (IOException e) {
LOG.info(e.getMessage());
LOG.debug(e);
} catch (UnsupportedCallbackException e) {
LOG.info(e.getMessage());
LOG.debug(e);
} catch (InstantiationException e) {
LOG.info(e.getMessage());
LOG.debug(e);
} catch (IllegalAccessException e) {
LOG.info(e.getMessage());
LOG.debug(e);
} catch (ClassNotFoundException e) {
LOG.info(e.getMessage());
LOG.debug(e);
}
return null;
}
Aggregations