List of usage examples for java.lang Throwable toString
public String toString()
From source file:com.vmware.photon.controller.api.client.resource.VmRestApiTest.java
@Test public void testGetVmTasksAsync() throws IOException, InterruptedException { Task task1 = new Task(); task1.setId("task1"); Task task2 = new Task(); task2.setId("task2"); final ResourceList<Task> taskResourceList = new ResourceList<>(Arrays.asList(task1, task2)); ObjectMapper mapper = new ObjectMapper(); String serialized = mapper.writeValueAsString(taskResourceList); setupMocks(serialized, HttpStatus.SC_OK); VmApi vmApi = new VmRestApi(restClient); final CountDownLatch latch = new CountDownLatch(1); vmApi.getTasksForVmAsync("foo", new FutureCallback<ResourceList<Task>>() { @Override//from w w w.ja v a 2s . c o m public void onSuccess(@Nullable ResourceList<Task> result) { assertEquals(result.getItems(), taskResourceList.getItems()); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:com.mirth.connect.client.ui.LibraryResourcesDialog.java
public LibraryResourcesDialog(Channel channel) { super(PlatformUI.MIRTH_FRAME, true); selectedResourceIds = new HashMap<Integer, Set<String>>(); Set<String> channelResourceIds = channel.getProperties().getResourceIds(); if (channelResourceIds == null) { channelResourceIds = new LinkedHashSet<String>(); }/*from w w w . j a v a 2s.c om*/ selectedResourceIds.put(null, new LinkedHashSet<String>(channelResourceIds)); Set<String> sourceResourceIds = ((SourceConnectorPropertiesInterface) channel.getSourceConnector() .getProperties()).getSourceConnectorProperties().getResourceIds(); if (sourceResourceIds == null) { sourceResourceIds = new LinkedHashSet<String>(); } selectedResourceIds.put(channel.getSourceConnector().getMetaDataId(), new LinkedHashSet<String>(sourceResourceIds)); for (Connector destinationConnector : channel.getDestinationConnectors()) { Set<String> destinationResourceIds = ((DestinationConnectorPropertiesInterface) destinationConnector .getProperties()).getDestinationConnectorProperties().getResourceIds(); if (destinationResourceIds == null) { destinationResourceIds = new LinkedHashSet<String>(); } selectedResourceIds.put(destinationConnector.getMetaDataId(), new LinkedHashSet<String>(destinationResourceIds)); } initComponents(channel); setPreferredSize(new Dimension(450, 444)); setDefaultCloseOperation(DISPOSE_ON_CLOSE); setTitle("Library Resources"); pack(); setLocationRelativeTo(PlatformUI.MIRTH_FRAME); okButton.setEnabled(false); final String workingId = PlatformUI.MIRTH_FRAME.startWorking("Loading library resources..."); SwingWorker<List<LibraryProperties>, Void> worker = new SwingWorker<List<LibraryProperties>, Void>() { @Override public List<LibraryProperties> doInBackground() throws ClientException { List<ResourceProperties> resourceProperties = PlatformUI.MIRTH_FRAME.mirthClient.getResources(); List<LibraryProperties> libraryProperties = new ArrayList<LibraryProperties>(); for (ResourceProperties resource : resourceProperties) { if (resource instanceof LibraryProperties) { libraryProperties.add((LibraryProperties) resource); } } return libraryProperties; } @Override public void done() { try { List<LibraryProperties> resources = get(); if (resources == null) { resources = new ArrayList<LibraryProperties>(); } Object[][] data = new Object[resources.size()][3]; int i = 0; for (LibraryProperties properties : resources) { data[i][SELECTED_COLUMN] = null; data[i][PROPERTIES_COLUMN] = properties; data[i][TYPE_COLUMN] = properties.getType(); i++; } ((RefreshTableModel) resourceTable.getModel()).refreshDataVector(data); treeTable.getSelectionModel().setSelectionInterval(0, 0); treeTable.getTreeSelectionModel().setSelectionPath(treeTable.getPathForRow(0)); okButton.setEnabled(true); } catch (Throwable t) { if (t instanceof ExecutionException) { t = t.getCause(); } PlatformUI.MIRTH_FRAME.alertThrowable(PlatformUI.MIRTH_FRAME, t, "Error loading library resources: " + t.toString()); } finally { PlatformUI.MIRTH_FRAME.stopWorking(workingId); } } }; worker.execute(); setVisible(true); }
From source file:com.vmware.photon.controller.api.client.resource.VmApiTest.java
@Test public void testSetVmMetadataAsync() throws IOException, InterruptedException { final Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); VmApi vmApi = new VmApi(restClient); Map<String, String> metadata = new HashMap<>(); metadata.put("key", "value"); VmMetadata vmMetadata = new VmMetadata(); vmMetadata.setMetadata(metadata);//from w w w.java 2 s .c om final CountDownLatch latch = new CountDownLatch(1); vmApi.setMetadataAsync("foo", vmMetadata, new FutureCallback<Task>() { @Override public void onSuccess(@Nullable Task result) { assertEquals(result, responseTask); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:com.vmware.photon.controller.api.client.resource.VmRestApiTest.java
@Test public void testSetVmMetadataAsync() throws IOException, InterruptedException { final Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); VmApi vmApi = new VmRestApi(restClient); Map<String, String> metadata = new HashMap<>(); metadata.put("key", "value"); VmMetadata vmMetadata = new VmMetadata(); vmMetadata.setMetadata(metadata);/*w w w.j a v a2 s .com*/ final CountDownLatch latch = new CountDownLatch(1); vmApi.setMetadataAsync("foo", vmMetadata, new FutureCallback<Task>() { @Override public void onSuccess(@Nullable Task result) { assertEquals(result, responseTask); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:ch.rasc.wampspring.config.WampSubProtocolHandler.java
/** * Handle incoming WebSocket messages from clients. *//*from w ww. j av a 2 s . c o m*/ @Override public void handleMessageFromClient(WebSocketSession session, WebSocketMessage<?> webSocketMessage, MessageChannel outputChannel) { Assert.isInstanceOf(TextMessage.class, webSocketMessage); WampMessage wampMessage = null; try { wampMessage = WampMessage.fromJson(session, this.jsonFactory, ((TextMessage) webSocketMessage).getPayload()); } catch (Throwable ex) { if (logger.isErrorEnabled()) { logger.error("Failed to parse " + webSocketMessage + " in session " + session.getId() + ".", ex); } return; } try { WampSessionContextHolder.setAttributesFromMessage(wampMessage); outputChannel.send(wampMessage); } catch (Throwable ex) { logger.error("Failed to send client message to application via MessageChannel" + " in session " + session.getId() + ".", ex); if (wampMessage != null && wampMessage instanceof CallMessage) { CallErrorMessage callErrorMessage = new CallErrorMessage((CallMessage) wampMessage, "", ex.toString()); try { String json = callErrorMessage.toJson(this.jsonFactory); session.sendMessage(new TextMessage(json)); } catch (Throwable t) { // Could be part of normal workflow (e.g. browser tab closed) logger.debug("Failed to send error to client.", t); } } } finally { WampSessionContextHolder.resetAttributes(); } }
From source file:com.vmware.photon.controller.api.client.resource.VmApiTest.java
@Test public void testGetVmTasksAsyncForPagination() throws IOException, InterruptedException { Task task1 = new Task(); task1.setId("task1"); Task task2 = new Task(); task2.setId("task2"); Task task3 = new Task(); task3.setId("task3"); String nextPageLink = "nextPageLink"; ResourceList<Task> taskResourceList = new ResourceList<>(Arrays.asList(task1, task2), nextPageLink, null); ResourceList<Task> taskResourceListNextPage = new ResourceList<>(Arrays.asList(task3)); ObjectMapper mapper = new ObjectMapper(); String serialized = mapper.writeValueAsString(taskResourceList); String serializedNextPage = mapper.writeValueAsString(taskResourceListNextPage); setupMocksForPagination(serialized, serializedNextPage, nextPageLink, HttpStatus.SC_OK); VmApi vmApi = new VmApi(restClient); final CountDownLatch latch = new CountDownLatch(1); vmApi.getTasksForVmAsync("foo", new FutureCallback<ResourceList<Task>>() { @Override/*from w w w .j ava 2 s . c om*/ public void onSuccess(@Nullable ResourceList<Task> result) { assertEquals(result.getItems().size(), taskResourceList.getItems().size() + taskResourceListNextPage.getItems().size()); assertTrue(result.getItems().containsAll(taskResourceList.getItems())); assertTrue(result.getItems().containsAll(taskResourceListNextPage.getItems())); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:com.vmware.photon.controller.api.client.resource.VmRestApiTest.java
@Test public void testGetVmTasksAsyncForPagination() throws IOException, InterruptedException { Task task1 = new Task(); task1.setId("task1"); Task task2 = new Task(); task2.setId("task2"); Task task3 = new Task(); task3.setId("task3"); String nextPageLink = "nextPageLink"; ResourceList<Task> taskResourceList = new ResourceList<>(Arrays.asList(task1, task2), nextPageLink, null); ResourceList<Task> taskResourceListNextPage = new ResourceList<>(Arrays.asList(task3)); ObjectMapper mapper = new ObjectMapper(); String serialized = mapper.writeValueAsString(taskResourceList); String serializedNextPage = mapper.writeValueAsString(taskResourceListNextPage); setupMocksForPagination(serialized, serializedNextPage, nextPageLink, HttpStatus.SC_OK); VmApi vmApi = new VmRestApi(restClient); final CountDownLatch latch = new CountDownLatch(1); vmApi.getTasksForVmAsync("foo", new FutureCallback<ResourceList<Task>>() { @Override/*from w w w . j av a 2 s.c om*/ public void onSuccess(@Nullable ResourceList<Task> result) { assertEquals(result.getItems().size(), taskResourceList.getItems().size() + taskResourceListNextPage.getItems().size()); assertTrue(result.getItems().containsAll(taskResourceList.getItems())); assertTrue(result.getItems().containsAll(taskResourceListNextPage.getItems())); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:com.haulmont.cuba.web.log.AppLog.java
@SuppressWarnings("ThrowableResultOfMethodCallIgnored") public void log(ErrorEvent event) { Throwable t = event.getThrowable(); if (t instanceof SilentException) return;/* w w w.jav a 2 s.c o m*/ if (t instanceof Validator.InvalidValueException) return; if (t instanceof SocketException || ExceptionUtils.getRootCause(t) instanceof SocketException) { // Most likely client browser closed socket LogItem item = new LogItem(LogLevel.WARNING, "SocketException in CommunicationManager. Most likely client (browser) closed socket.", null); log(item); return; } // Support Tomcat 8 ClientAbortException if (StringUtils.contains(ExceptionUtils.getMessage(t), "ClientAbortException")) { // Most likely client browser closed socket LogItem item = new LogItem(LogLevel.WARNING, "ClientAbortException on write response to client. Most likely client (browser) closed socket.", null); log(item); return; } Throwable rootCause = ExceptionUtils.getRootCause(t); if (rootCause == null) rootCause = t; Logging annotation = rootCause.getClass().getAnnotation(Logging.class); Logging.Type loggingType = annotation == null ? Logging.Type.FULL : annotation.value(); if (loggingType == Logging.Type.NONE) return; // Finds the original source of the error/exception AbstractComponent component = DefaultErrorHandler.findAbstractComponent(event); StringBuilder msg = new StringBuilder(); msg.append("Exception"); if (component != null) msg.append(" in ").append(component.getClass().getName()); msg.append(": "); if (loggingType == Logging.Type.BRIEF) { error(msg + rootCause.toString()); } else { LogItem item = new LogItem(LogLevel.ERROR, msg.toString(), t); log(item); } }
From source file:com.mirth.connect.client.ui.SettingsPanelResources.java
private void updateResourcesTable(List<ResourceProperties> resources, int selectedRow, boolean clearSaveEnabled) { try {/*w w w.j a va2 s . c om*/ cachedResources = resources; ResourceProperties defaultResource = null; for (ResourceProperties properties : resources) { if (properties.getId().equals(ResourceProperties.DEFAULT_RESOURCE_ID)) { defaultResource = properties; } } Object[][] data = new Object[resources.size()][4]; data[0][PROPERTIES_COLUMN] = defaultResource; data[0][NAME_COLUMN] = defaultResource.getName(); data[0][TYPE_COLUMN] = defaultResource.getType(); data[0][GLOBAL_SCRIPTS_COLUMN] = defaultResource.isIncludeWithGlobalScripts(); int i = 1; for (ResourceProperties properties : resources) { if (!properties.getId().equals(ResourceProperties.DEFAULT_RESOURCE_ID)) { data[i][PROPERTIES_COLUMN] = properties; data[i][NAME_COLUMN] = properties.getName(); data[i][TYPE_COLUMN] = properties.getType(); data[i][GLOBAL_SCRIPTS_COLUMN] = properties.isIncludeWithGlobalScripts(); i++; } } this.selectedRow = -1; changePropertiesPanel(null); ((RefreshTableModel) resourceTable.getModel()).refreshDataVector(data); if (selectedRow > -1 && selectedRow < resourceTable.getRowCount()) { resourceTable.setRowSelectionInterval(selectedRow, selectedRow); } else if (resourceTable.getRowCount() > 0) { resourceTable.setRowSelectionInterval(0, 0); } if (clearSaveEnabled) { getFrame().setSaveEnabled(false); } } catch (Throwable t) { if (t instanceof ExecutionException) { t = t.getCause(); } getFrame().alertThrowable(getFrame(), t, "Error loading resources: " + t.toString()); } }
From source file:com.haulmont.cuba.gui.xml.layout.loaders.AbstractComponentLoader.java
protected Formatter loadFormatter(Element element) { final Element formatterElement = element.element("formatter"); if (formatterElement != null) { final String className = formatterElement.attributeValue("class"); if (StringUtils.isEmpty(className)) { throw new GuiDevelopmentException("Formatter's attribute 'class' is not specified", context.getCurrentFrameId()); }//w ww. j a v a2s.com Class<?> aClass = scripting.loadClass(className); if (aClass == null) { throw new GuiDevelopmentException(String.format("Class %s is not found", className), context.getFullFrameId()); } try { final Constructor<?> constructor = aClass.getConstructor(Element.class); try { return (Formatter) constructor.newInstance(formatterElement); } catch (Throwable e) { throw new GuiDevelopmentException( "Unable to instatiate class " + className + ": " + e.toString(), context.getFullFrameId()); } } catch (NoSuchMethodException e) { try { return (Formatter) aClass.newInstance(); } catch (Exception e1) { throw new GuiDevelopmentException( "Unable to instatiate class " + className + ": " + e1.toString(), context.getFullFrameId()); } } } else { return null; } }