/** Load the given class name with the given class loader. */ public static Class loadClass( String className, ClassLoader loader, boolean throwExceptionIfNotFound, MetadataProject project) { Class candidateClass = null; try { candidateClass = loader.loadClass(className); } catch (ClassNotFoundException exc) { if (throwExceptionIfNotFound) { throw PersistenceUnitLoadingException.exceptionLoadingClassWhileLookingForAnnotations( className, exc); } else { AbstractSessionLog.getLog() .log( AbstractSessionLog.WARNING, "persistence_unit_processor_error_loading_class", exc.getClass().getName(), exc.getLocalizedMessage(), className); } } catch (NullPointerException npe) { // Bug 227630: If any weavable class is not found in the temporary // classLoader - disable weaving AbstractSessionLog.getLog() .log( AbstractSessionLog.WARNING, AbstractSessionLog.WEAVER, "persistence_unit_processor_error_loading_class_weaving_disabled", loader, project.getPersistenceUnitInfo().getPersistenceUnitName(), className); // Disable weaving (for 1->1 and many->1)only if the classLoader // returns a NPE on loadClass() project.disableWeaving(); } catch (Exception exception) { AbstractSessionLog.getLog() .log( AbstractSessionLog.WARNING, AbstractSessionLog.WEAVER, "persistence_unit_processor_error_loading_class", exception.getClass().getName(), exception.getLocalizedMessage(), className); } catch (Error error) { AbstractSessionLog.getLog() .log( AbstractSessionLog.WARNING, AbstractSessionLog.WEAVER, "persistence_unit_processor_error_loading_class", error.getClass().getName(), error.getLocalizedMessage(), className); throw error; } return candidateClass; }
public void doDownload(HttpServletRequest req, HttpServletResponse resp, int hc) throws IOException { FileTransfer ft = FileTransfer.get(hc); if (ft == null) { resp.sendError(HttpServletResponse.SC_NOT_FOUND); return; } resp.setContentType(ft.mimeType); if (ft.size > 0) resp.setContentLength((int) ft.size); /*if (ft.filename != null) { resp.setHeader("Content-Disposition", (ft.inline ? "inline" : "attachment") + ";filename=" + ft.filename); }*/ resp.setHeader( "Content-Disposition", (ft.inline ? "inline" : "attachment") + (ft.filename != null ? ";filename=" + ft.filename : "")); if (ft.size < 0) resp.setHeader("Transfer-Encoding", "chunked"); else resp.setHeader("Content-Transfer-Encoding", "binary"); resp.setHeader("Expires", "0"); resp.setHeader("Cache-Control", "must-revalidate"); InputStream in = null; OutputStream out = null; try { in = ft.getInputStream(); out = resp.getOutputStream(); boolean te = ft.size < 0; byte[] buffer = new byte[4096]; while (true) { int n = in.read(buffer); if (n <= 0) break; if (te) { out.write(Integer.toHexString(n).getBytes()); out.write(13); out.write(10); } out.write(buffer, 0, n); if (te) { out.write(13); out.write(10); } } if (te) out.write("0\r\n\r\n".getBytes()); out.flush(); } catch (Error er) { logger.log(Level.SEVERE, er.getLocalizedMessage()); } finally { if (in != null) in.close(); if (out != null) out.close(); } }
public Response serviceRequest(Command cmd, byte[]... args) throws RedisException { /* if(start ==-1) start = System.currentTimeMillis(); */ if (!isConnected()) throw new NotConnectedException("Not connected!"); Request request = null; Response response = null; ResponseStatus status = null; try { // 1 - Request // try { request = Assert.notNull( protocolHandler.createRequest(cmd, args), "request object from handler", ProviderException.class); request.write(super.getOutputStream()); } catch (ProviderException bug) { throw bug; } catch (ClientRuntimeException problem) { Throwable rootProblem = problem.getCause(); if (null != rootProblem && rootProblem instanceof SocketException) { Log.log( "[TODO -- attempt reconnect] serviceRequest() -- " + "unrecovered %s in Request phase <Cmd: %s>", rootProblem, cmd.code); } throw problem; // TODO: reconnect here ... } catch (RuntimeException everythingelse) { String msg = "For <Cmd: " + cmd.code + "> Possible bug in provider code: " + everythingelse.getClass().getSimpleName() + " => " + everythingelse.getLocalizedMessage(); Log.error("serviceRequest() -- Request phase -- " + msg); throw new ProviderException(msg, everythingelse); } // 2 - Response // try { response = Assert.notNull( protocolHandler.createResponse(cmd), "response object from handler", ProviderException.class); response.read(super.getInputStream()); } catch (ProviderException bug) { throw bug; } catch (ClientRuntimeException problem) { Throwable rootProblem = problem.getCause(); if (null != rootProblem) { if (rootProblem instanceof SocketException) { Log.log( "[NET] [TODO (attempt reconnect?)] serviceRequest(%s) -- " + "problem in Response phase <rootProblem: %s>", cmd.code, rootProblem); } else if (rootProblem instanceof IOException) { Log.log( "[IO] [TODO (attempt reconnect?)] serviceRequest(%s) -- " + "problem in Response phase <rootProblem: %s>", cmd.code, rootProblem); } } throw problem; // this is caught below under ClientR.. } // 3 - Status // // sending response didn't cause any problems // check for redis errors // status = Assert.notNull( response.getStatus(), "status from response object", ProviderException.class); if (status.isError()) { // Log.error ("Request resulted in error: cmd: " + cmd.code + " " + status.message()); Log.error(cmd.code + " => " + status.message()); throw new RedisException(cmd, status.message()); } else if (status.code() == ResponseStatus.Code.CIAO) { // Log.log ("serviceRequest() -- Response status is CIAO."); // Log.log ("serviceRequest() -- closing connection ..."); disconnect(); } } catch (ProviderException bug) { Log.bug("serviceRequest() -- ProviderException: " + bug.getLocalizedMessage()); Log.log("serviceRequest() -- closing connection ..."); // now we must close the connection if we can disconnect(); throw bug; } catch (ClientRuntimeException problem) { Log.problem( "serviceRequest() -- Unrecovered ClientRuntimeException: " + problem.getLocalizedMessage()); Log.log("serviceRequest() -- closing connection ..."); // now we must close the connection if we can disconnect(); throw problem; } catch (RuntimeException surprise) { surprise.printStackTrace(); // TODO: Log.log it ... Log.bug( "serviceRequest() -- *unexpected* RuntimeException: " + surprise.getLocalizedMessage()); Log.log("serviceRequest() -- closing connection ..."); // now we must close the connection if we can disconnect(); throw new ClientRuntimeException( "unexpected runtime exeption: " + surprise.getLocalizedMessage(), surprise); } catch (Error disaster) { disaster.printStackTrace(); // TODO: Log.log it ... Log.bug( "serviceRequest() -- *unforseen* Java System Error: " + disaster.getLocalizedMessage()); Log.log("serviceRequest() -- closing connection ..."); // now we must close the connection if we can disconnect(); throw new ClientRuntimeException( "unexpected system error: " + disaster.getLocalizedMessage(), disaster); } finally { } /* - temp benchmarking request service throughput serviceCount ++; if(serviceCount > gate) { delta = System.currentTimeMillis() - start; start = System.currentTimeMillis(); throughput = (serviceCount * 1000) / (float) delta; System.out.format ("<%s> - %8.2f /sec | serviced %d requests at %d msecs\n", Thread.currentThread().getName(), throughput, serviceCount, delta ); serviceCount = 0; } */ return response; }