List of usage examples for java.lang.reflect InvocationTargetException getTargetException
public Throwable getTargetException()
From source file:org.jlibrary.servlet.service.HTTPStreamingServlet.java
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { if (logger.isDebugEnabled()) { logger.debug("Received a POST request"); }//from ww w. j a v a 2 s . c o m try { InputStream stream = req.getInputStream(); byte[] count = read(stream, 4); int messageNameSize = ByteUtils.byteArrayToInt(count); byte[] messageNameBuffer = read(stream, messageNameSize); String callMethodName = new String(messageNameBuffer); Object returnValue = null; boolean streamOutput = false; boolean streamInput = false; if (callMethodName.equals("stream-input")) { // Streaming request. Re-read call method name streamInput = true; count = read(stream, 4); messageNameSize = ByteUtils.byteArrayToInt(count); messageNameBuffer = read(stream, messageNameSize); callMethodName = new String(messageNameBuffer); } else if (callMethodName.equals("stream-output")) { // Streaming request. Re-read call method name streamOutput = true; count = read(stream, 4); messageNameSize = ByteUtils.byteArrayToInt(count); messageNameBuffer = read(stream, messageNameSize); callMethodName = new String(messageNameBuffer); } if (logger.isDebugEnabled()) { logger.debug("Calling method: " + callMethodName); } // Handle request count = read(stream, 4); int parameters = ByteUtils.byteArrayToInt(count); Object[] params = new Object[parameters]; if (!streamInput && !streamOutput) { params = new Object[parameters]; } else { params = new Object[parameters + 1]; if (streamInput) { params[parameters] = stream; } else if (streamOutput) { params[parameters] = resp.getOutputStream(); } } for (int i = 0; i < parameters; i++) { count = read(stream, 4); int parameterSize = ByteUtils.byteArrayToInt(count); byte[] parameterBuffer = read(stream, parameterSize); params[i] = SerializationUtils.deserialize(parameterBuffer); } try { if (!streamInput && !streamOutput) { returnValue = handleRequest(req, callMethodName, params); } else if (streamInput) { returnValue = handleRequest(req, callMethodName, params, InputStream.class); } else if (streamOutput) { returnValue = handleRequest(req, callMethodName, params, OutputStream.class); } } catch (InvocationTargetException ite) { returnValue = ite.getCause(); if (returnValue == null) { returnValue = ite.getTargetException(); } } catch (Exception e) { returnValue = e; } if (!streamOutput) { handleReturnValue(resp, returnValue); } } catch (IOException e) { logger.error("IOException in doPost", e); } catch (Exception e) { logger.error("Exception in doPost", e); } finally { if (logger.isDebugEnabled()) { logger.debug("POST request handled successfully"); } } }
From source file:org.jtwig.render.RenderContext.java
public Object executeFunction(String name, InputParameters parameters) throws FunctionException { try {/*from www. ja v a 2 s . co m*/ Optional<Executable> resolve = functionResolver.resolve(name, parameters); if (resolve.isPresent()) return resolve.get().execute(); String message = "Unable to find function with name '" + name + "'"; if (parameters.length() > 0) { message += ", and parameters: "; List<String> params = new ArrayList<>(); for (int i = 0; i < parameters.length(); i++) { params.add(parameters.valueAt(i).getClass().getName()); } message += StringUtils.join(params, ", "); } throw new FunctionNotFoundException(message); } catch (InvocationTargetException e) { throw new FunctionException(e.getTargetException()); } catch (IllegalAccessException e) { throw new FunctionException(e); } }
From source file:org.jumpmind.db.util.CallbackClosure.java
/** * {@inheritDoc}/*from w w w .ja v a 2 s. co m*/ */ public void execute(Object obj) throws DdlException { LinkedList queue = new LinkedList(); queue.add(obj.getClass()); while (!queue.isEmpty()) { Class type = (Class) queue.removeFirst(); Method callback = (Method) _callbacks.get(type); if (callback != null) { try { _parameters[_callbackTypePos] = obj; callback.invoke(_callee, _parameters); return; } catch (InvocationTargetException ex) { throw new DdlException(ex.getTargetException()); } catch (IllegalAccessException ex) { throw new DdlException(ex); } } if ((type.getSuperclass() != null) && !type.getSuperclass().equals(Object.class)) { queue.add(type.getSuperclass()); } Class[] baseInterfaces = type.getInterfaces(); if (baseInterfaces != null) { for (int idx = 0; idx < baseInterfaces.length; idx++) { queue.add(baseInterfaces[idx]); } } } }
From source file:org.kalypso.ui.rrm.internal.conversion.to12_02.CalcCasesConverter.java
@Override protected void doExecute(final IProgressMonitor monitor) throws InterruptedException { try {/*from ww w . j av a 2 s . c o m*/ /* Monitor. */ final SubMonitor progress = SubMonitor.convert(monitor, Messages.getString("CalcCasesConverter_1"), //$NON-NLS-1$ 101); /* Find all calc cases. */ final CalcCaseConvertWalker walker = new CalcCaseConvertWalker(m_globalData.getSourceDir()); final File[] calcCases = walker.execute(); /* Monitor. */ ProgressUtilities.worked(progress, 1); progress.setWorkRemaining(calcCases.length); /* Convert all calc cases into scenarios. */ for (int i = 0; i < calcCases.length; i++) { /* Monitor. */ progress.subTask(String.format(Messages.getString("CalcCasesConverter_2"), calcCases[i].getName(), //$NON-NLS-1$ i + 1, calcCases.length)); /* Determine the directories. */ final File sourceDir = calcCases[i]; final File targetDir = determineTargetDir(sourceDir); try { /* Convert the calc case to a scenario. */ final CalcCaseConverter calcCaseConverter = new CalcCaseConverter(sourceDir, targetDir, m_globalData); final IStatus status = calcCaseConverter.execute(progress.newChild(1)); getLog().add(status); } catch (final CoreException ce) { final IStatus status = ce.getStatus(); if (status.matches(IStatus.CANCEL)) throw new InterruptedException(Messages.getString("CalcCasesConverter_3")); //$NON-NLS-1$ getLog().add(status); } catch (final InvocationTargetException e) { getLog().add(IStatus.ERROR, Messages.getString("CalcCasesConverter_4"), e.getTargetException(), //$NON-NLS-1$ calcCases[i].getName()); } catch (final Throwable e) { getLog().add(IStatus.ERROR, Messages.getString("CalcCasesConverter_4"), e, //$NON-NLS-1$ calcCases[i].getName()); } } } catch (final IOException e) { e.printStackTrace(); getLog().add(IStatus.ERROR, Messages.getString("CalcCasesConverter_5"), e); //$NON-NLS-1$ } }
From source file:org.kchine.rpf.MainServer.java
public static void main(String[] args) throws Exception { PoolUtils.initLog4J();// ww w .j a va 2 s .c o m PoolUtils.ensurePublicIPIsUsedForRMI(); PoolUtils.noGui(); try { if (System.getSecurityManager() == null) { System.setSecurityManager(new YesSecurityManager()); } boolean isNodeProvided = System.getProperty("node") != null && !System.getProperty("node").equals(""); if (isNodeProvided) { NodeDataDB nodeData = null; try { rmiRegistry = ServerDefaults.getRmiRegistry(); nodeData = ((DBLayerInterface) rmiRegistry) .getNodeData("NODE_NAME='" + System.getProperty("node") + "'").elementAt(0); } catch (Exception e) { log.info("Couldn't retrieve Node Info for node <" + System.getProperty("node") + ">"); e.printStackTrace(); return; } System.setProperty("autoname", "true"); _servantPoolPrefix = nodeData.getPoolPrefix(); System.out.println("nodedata:" + nodeData); } if (System.getProperty("autoname") != null && System.getProperty("autoname").equalsIgnoreCase("true")) { log.info("Instantiating " + _mainServantClassName + " with autonaming, prefix " + _servantPoolPrefix); servantName = null; } else { // no autonaming, check the name here if (System.getProperty("name") != null && !System.getProperty("name").equals("")) { servantName = System.getProperty("name"); } log.info("Instantiating " + _mainServantClassName + " with name " + servantName + " , prefix " + _servantPoolPrefix); } if (rmiRegistry == null) rmiRegistry = ServerDefaults.getRmiRegistry(); System.out.println("### code base:" + System.getProperty("java.rmi.server.codebase")); ClassLoader cl = new URLClassLoader(PoolUtils.getURLS(System.getProperty("java.rmi.server.codebase")), MainServer.class.getClassLoader()); Thread.currentThread().setContextClassLoader(cl); System.out.println(Arrays.toString(PoolUtils.getURLS(System.getProperty("java.rmi.server.codebase")))); mainServantClass = cl.loadClass(_mainServantClassName); boolean isPrivateServant = !isNodeProvided && ((System.getProperty("private") != null && System.getProperty("private").equalsIgnoreCase("true"))); String servantCreationListenerStub = System.getProperty("listener.stub"); if (servantCreationListenerStub != null && !servantCreationListenerStub.equals("")) { servantCreationListener = (ServantCreationListener) PoolUtils .hexToObject(servantCreationListenerStub); } if (!isPrivateServant) { mservant = (ManagedServant) mainServantClass .getConstructor(new Class[] { String.class, String.class, Registry.class }) .newInstance(new Object[] { servantName, _servantPoolPrefix, rmiRegistry }); } else { mservant = (ManagedServant) mainServantClass .getConstructor(new Class[] { String.class, String.class, Registry.class }) .newInstance(new Object[] { null, "PRIVATE_", rmiRegistry }); } //System.out.println("clone:"+mservant.cloneServer()); if (servantCreationListener != null) { PoolUtils.callBack(servantCreationListener, mservant, null); } String sname = mservant.getServantName(); log.info("sname :::" + sname); if (rmiRegistry instanceof DBLayerInterface) { if (System.getProperty("node") != null && !System.getProperty("node").equalsIgnoreCase("")) { ((DBLayerInterface) rmiRegistry).updateServantNodeName(sname, System.getProperty("node")); } else { Vector<NodeDataDB> nodes = ((DBLayerInterface) rmiRegistry).getNodeData(""); for (int i = 0; i < nodes.size(); ++i) { String nodeName = nodes.elementAt(i).getNodeName(); String nodeIp = nodes.elementAt(i).getHostIp(); String nodePrefix = nodes.elementAt(i).getPoolPrefix(); if (sname.startsWith(nodePrefix) && nodeIp.equals(PoolUtils.getHostIp())) { ((DBLayerInterface) rmiRegistry).updateServantNodeName(sname, nodeName); break; } } } HashMap<String, Object> attributes = new HashMap<String, Object>(); Enumeration<Object> sysPropKeys = (Enumeration<Object>) System.getProperties().keys(); while (sysPropKeys.hasMoreElements()) { String key = (String) sysPropKeys.nextElement(); if (key.startsWith("attr.")) { attributes.put(key, System.getProperty(key)); } } ((DBLayerInterface) rmiRegistry).updateServantAttributes(sname, attributes); } //log.info("*************************$$$$$$$$$$$$"); log.info("Servant " + sname + " instantiated successfully."); } catch (InvocationTargetException ite) { if (servantCreationListener != null) { PoolUtils.callBack(servantCreationListener, null, new RemoteException("", ite.getTargetException())); } throw new Exception(PoolUtils.getStackTraceAsString(ite.getTargetException())); } catch (Exception e) { log.info("----------------------"); log.info(PoolUtils.getStackTraceAsString(e)); e.printStackTrace(); log.error(e); if (servantCreationListener != null) { PoolUtils.callBack(servantCreationListener, null, new RemoteException("", e)); } System.exit(1); } }
From source file:org.kie.server.controller.websocket.management.KieServerMgmtCommandServiceImpl.java
@Override public KieServerControllerServiceResponse executeCommand(final KieServerControllerDescriptorCommand command) { if (command == null) { return new KieServerControllerServiceResponse(ResponseType.FAILURE, "Command can not be null"); }//from w w w .java 2 s. com try { Object result = null; Object handler = null; // find out the handler to call to process given command if (SpecManagementService.class.getName().equals(command.getService())) { handler = specManagementService; } else if (RuntimeManagementService.class.getName().equals(command.getService())) { handler = runtimeManagementService; } else if (RuleCapabilitiesService.class.getName().equals(command.getService())) { handler = ruleCapabilitiesService; } else { throw new IllegalStateException("Unable to find handler for " + command.getService() + " service"); } LOGGER.debug("Service handler: {}", handler); LOGGER.debug("Command arguments size: {}", command.getArguments().size()); List<Object> arguments = new ArrayList<>(); // process and unwrap arguments for (Object arg : command.getArguments()) { LOGGER.debug("Before :: Argument with type {} and value {}", arg == null ? "null" : arg.getClass(), arg); if (arg instanceof Wrapped) { arg = ((Wrapped) arg).unwrap(); } LOGGER.debug("After :: Argument with type {} and value {}", arg == null ? "null" : arg.getClass(), arg); arguments.add(arg); } LOGGER.debug("About to execute {} operation on {} with args {}", command.getMethod(), handler, arguments); // process command via reflection and handler result = MethodUtils.invokeMethod(handler, command.getMethod(), arguments.toArray()); LOGGER.debug("Handler {} returned response {}", handler, result); // return successful result return new KieServerControllerServiceResponse(ResponseType.SUCCESS, "", result); } catch (InvocationTargetException e) { LOGGER.error("Failed to invoke service method", e); return new KieServerControllerServiceResponse(ResponseType.FAILURE, e.getTargetException().getMessage()); } catch (Throwable e) { LOGGER.error("Error while processing {} command", command, e); // return failure result return new KieServerControllerServiceResponse(ResponseType.FAILURE, e.getMessage()); } }
From source file:org.kie.server.services.casemgmt.CaseKieContainerCommandServiceImpl.java
@Override public ServiceResponsesList executeScript(CommandScript commands, MarshallingFormat marshallingFormat, String classType) {// ww w .ja v a 2 s . co m List<ServiceResponse<? extends Object>> responses = new ArrayList<ServiceResponse<? extends Object>>(); for (KieServerCommand command : commands.getCommands()) { if (!(command instanceof DescriptorCommand)) { logger.warn("Unsupported command '{}' given, will not process it", command.getClass().getName()); continue; } try { Object result = null; Object handler = null; DescriptorCommand descriptorCommand = (DescriptorCommand) command; // find out the handler to call to process given command if ("CaseService".equals(descriptorCommand.getService())) { handler = caseManagementServiceBase; } else if ("CaseQueryService".equals(descriptorCommand.getService())) { handler = caseManagementRuntimeDataService; } else if ("CaseAdminService".equals(descriptorCommand.getService())) { handler = caseAdminServiceBase; } else { throw new IllegalStateException( "Unable to find handler for " + descriptorCommand.getService() + " service"); } List<Object> arguments = new ArrayList(); // process and unwrap arguments for (Object arg : descriptorCommand.getArguments()) { logger.debug("Before :: Argument with type {} and value {}", arg.getClass(), arg); if (arg instanceof Wrapped) { arg = ((Wrapped) arg).unwrap(); } logger.debug("After :: Argument with type {} and value {}", arg.getClass(), arg); arguments.add(arg); } if (descriptorCommand.getPayload() != null && !descriptorCommand.getPayload().isEmpty()) { arguments.add(descriptorCommand.getPayload()); } if (descriptorCommand.getMarshallerFormat() != null && !descriptorCommand.getMarshallerFormat().isEmpty()) { arguments.add(descriptorCommand.getMarshallerFormat()); } logger.debug("About to execute {} operation on {} with args {}", descriptorCommand.getMethod(), handler, arguments); // process command via reflection and handler result = MethodUtils.invokeMethod(handler, descriptorCommand.getMethod(), arguments.toArray()); logger.debug("Handler {} returned response {}", handler, result); // return successful result responses.add(new ServiceResponse(ServiceResponse.ResponseType.SUCCESS, "", result)); } catch (InvocationTargetException e) { responses.add(new ServiceResponse(ServiceResponse.ResponseType.FAILURE, e.getTargetException().getMessage())); } catch (Throwable e) { logger.error("Error while processing {} command", command, e); // return failure result responses.add(new ServiceResponse(ServiceResponse.ResponseType.FAILURE, e.getMessage())); } } logger.debug("About to return responses '{}'", responses); return new ServiceResponsesList(responses); }
From source file:org.kie.server.services.dmn.DMNKieContainerCommandServiceImpl.java
@Override public ServiceResponsesList executeScript(CommandScript commands, MarshallingFormat marshallingFormat, String classType) {/*from ww w. j a v a 2s . c om*/ List<ServiceResponse<? extends Object>> responses = new ArrayList<ServiceResponse<? extends Object>>(); for (KieServerCommand command : commands.getCommands()) { if (!(command instanceof DescriptorCommand)) { LOG.warn("Unsupported command '{}' given, will not process it", command.getClass().getName()); continue; } try { ServiceResponse<?> result = null; Object handler = null; DescriptorCommand descriptorCommand = (DescriptorCommand) command; // find out the handler to call to process given command if ("DMNService".equals(descriptorCommand.getService())) { handler = modelEvaluatorServiceBase; } else { throw new IllegalStateException( "Unable to find handler for " + descriptorCommand.getService() + " service"); } List<Object> arguments = new ArrayList(); // process and unwrap arguments for (Object arg : descriptorCommand.getArguments()) { LOG.debug("Before :: Argument with type {} and value {}", arg.getClass(), arg); if (arg instanceof Wrapped) { arg = ((Wrapped) arg).unwrap(); } LOG.debug("After :: Argument with type {} and value {}", arg.getClass(), arg); arguments.add(arg); } if (descriptorCommand.getPayload() != null && !descriptorCommand.getPayload().isEmpty()) { arguments.add(descriptorCommand.getPayload()); } if (descriptorCommand.getMarshallerFormat() != null && !descriptorCommand.getMarshallerFormat().isEmpty()) { arguments.add(descriptorCommand.getMarshallerFormat()); } LOG.debug("About to execute {} operation on {} with args {}", descriptorCommand.getMethod(), handler, arguments); // process command via reflection and handler result = (ServiceResponse<?>) MethodUtils.invokeMethod(handler, descriptorCommand.getMethod(), arguments.toArray()); LOG.debug("Handler {} returned response {}", handler, result); // return successful result responses.add(result); } catch (InvocationTargetException e) { responses.add(new ServiceResponse(ServiceResponse.ResponseType.FAILURE, e.getTargetException().getMessage())); } catch (Throwable e) { LOG.error("Error while processing {} command", command, e); // return failure result responses.add(new ServiceResponse(ServiceResponse.ResponseType.FAILURE, e.getMessage())); } } LOG.debug("About to return responses '{}'", responses); return new ServiceResponsesList(responses); }
From source file:org.kie.server.services.jbpm.JBPMKieContainerCommandServiceImpl.java
@Override public ServiceResponsesList executeScript(CommandScript commands, MarshallingFormat marshallingFormat, String classType) {/*www .j a v a 2s . c om*/ List<ServiceResponse<? extends Object>> responses = new ArrayList<ServiceResponse<? extends Object>>(); for (KieServerCommand command : commands.getCommands()) { if (!(command instanceof DescriptorCommand)) { logger.warn("Unsupported command '{}' given, will not process it", command.getClass().getName()); continue; } boolean wrapResults = false; try { Object result = null; Object handler = null; DescriptorCommand descriptorCommand = (DescriptorCommand) command; // find out the handler to call to process given command if ("DefinitionService".equals(descriptorCommand.getService())) { handler = definitionServiceBase; } else if ("ProcessService".equals(descriptorCommand.getService())) { handler = processServiceBase; } else if ("UserTaskService".equals(descriptorCommand.getService())) { handler = userTaskServiceBase; } else if ("QueryService".equals(descriptorCommand.getService())) { handler = runtimeDataServiceBase; } else if ("JobService".equals(descriptorCommand.getService())) { handler = executorServiceBase; } else if ("QueryDataService".equals(descriptorCommand.getService())) { handler = queryDataServiceBase; // enable wrapping as in case of embedded objects jaxb does not properly parse it due to possible unknown types (List<?> etc) if (marshallingFormat.equals(MarshallingFormat.JAXB)) { wrapResults = true; } } else if ("DocumentService".equals(descriptorCommand.getService())) { handler = documentServiceBase; } else if ("ProcessAdminService".equals(descriptorCommand.getService())) { handler = processAdminServiceBase; } else if ("UserTaskAdminService".equals(descriptorCommand.getService())) { handler = userTaskAdminServiceBase; } else { throw new IllegalStateException( "Unable to find handler for " + descriptorCommand.getService() + " service"); } List<Object> arguments = new ArrayList(); // process and unwrap arguments for (Object arg : descriptorCommand.getArguments()) { logger.debug("Before :: Argument with type {} and value {}", arg.getClass(), arg); if (arg instanceof Wrapped) { arg = ((Wrapped) arg).unwrap(); } logger.debug("After :: Argument with type {} and value {}", arg.getClass(), arg); arguments.add(arg); } if (descriptorCommand.getPayload() != null && !descriptorCommand.getPayload().isEmpty()) { arguments.add(descriptorCommand.getPayload()); } if (descriptorCommand.getMarshallerFormat() != null && !descriptorCommand.getMarshallerFormat().isEmpty()) { arguments.add(descriptorCommand.getMarshallerFormat()); } logger.debug("About to execute {} operation on {} with args {}", descriptorCommand.getMethod(), handler, arguments); // process command via reflection and handler result = MethodUtils.invokeMethod(handler, descriptorCommand.getMethod(), arguments.toArray()); logger.debug("Handler {} returned response {}", handler, result); if (wrapResults) { result = ModelWrapper.wrap(result); logger.debug("Wrapped response is {}", result); } // return successful result responses.add(new ServiceResponse(ServiceResponse.ResponseType.SUCCESS, "", result)); } catch (InvocationTargetException e) { logger.error("Error while processing {} command", command, e); responses.add(new ServiceResponse(ServiceResponse.ResponseType.FAILURE, e.getTargetException().getMessage())); } catch (Throwable e) { logger.error("Error while processing {} command", command, e); // return failure result responses.add(new ServiceResponse(ServiceResponse.ResponseType.FAILURE, e.getMessage())); } } logger.debug("About to return responses '{}'", responses); return new ServiceResponsesList(responses); }
From source file:org.kie.server.services.jbpm.ui.JBPMUIKieContainerCommandServiceImpl.java
@Override public ServiceResponsesList executeScript(CommandScript commands, MarshallingFormat marshallingFormat, String classType) {/* www . j av a2 s . c o m*/ List<ServiceResponse<? extends Object>> responses = new ArrayList<ServiceResponse<? extends Object>>(); for (KieServerCommand command : commands.getCommands()) { if (!(command instanceof DescriptorCommand)) { logger.warn("Unsupported command '{}' given, will not process it", command.getClass().getName()); continue; } try { Object result = null; Object handler = null; DescriptorCommand descriptorCommand = (DescriptorCommand) command; // find out the handler to call to process given command if ("FormService".equals(descriptorCommand.getService())) { handler = formServiceBase; } else if ("ImageService".equals(descriptorCommand.getService())) { handler = imageServiceBase; } else if ("FormRendererService".equals(descriptorCommand.getService())) { handler = formRendererBase; } else { throw new IllegalStateException( "Unable to find handler for " + descriptorCommand.getService() + " service"); } List<Object> arguments = new ArrayList(); // process and unwrap arguments for (Object arg : descriptorCommand.getArguments()) { logger.debug("Before :: Argument with type {} and value {}", arg.getClass(), arg); if (arg instanceof Wrapped) { arg = ((Wrapped) arg).unwrap(); } logger.debug("After :: Argument with type {} and value {}", arg.getClass(), arg); arguments.add(arg); } logger.debug("About to execute {} operation on {} with args {}", descriptorCommand.getMethod(), handler, arguments); // process command via reflection and handler result = MethodUtils.invokeMethod(handler, descriptorCommand.getMethod(), arguments.toArray()); logger.debug("Handler {} returned response {}", handler, result); // return successful result responses.add(new ServiceResponse(ServiceResponse.ResponseType.SUCCESS, "", result)); } catch (InvocationTargetException e) { responses.add(new ServiceResponse(ServiceResponse.ResponseType.FAILURE, e.getTargetException().getMessage())); } catch (Throwable e) { logger.error("Error while processing {} command", command, e); // return failure result responses.add(new ServiceResponse(ServiceResponse.ResponseType.FAILURE, e.getMessage())); } } logger.debug("About to return responses '{}'", responses); return new ServiceResponsesList(responses); }