use of org.apache.pivot.serialization.SerializationException in project pivot by apache.
the class ExpensesWindow method initialize.
@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
expenseTableView = (TableView) namespace.get("expenseTableView");
activityIndicator = (ActivityIndicator) namespace.get("activityIndicator");
activityIndicatorBoxPane = (BoxPane) namespace.get("activityIndicatorBoxPane");
// Load the add/edit sheet
try {
BXMLSerializer bxmlSerializer = new BXMLSerializer();
expenseSheet = (ExpenseSheet) bxmlSerializer.readObject(ExpenseSheet.class, "expense_sheet.bxml", true);
} catch (IOException exception) {
throw new RuntimeException(exception);
} catch (SerializationException exception) {
throw new RuntimeException(exception);
}
// Create the delete confirmation prompt
ArrayList<String> options = new ArrayList<>((String) resources.get("ok"), (String) resources.get("cancel"));
deleteConfirmationPrompt = new Prompt(MessageType.QUESTION, (String) resources.get("confirmDelete"), options);
// Attach event listeners
expenseTableView.getTableViewSelectionListeners().add(new TableViewSelectionListener() {
@Override
public void selectedRowChanged(TableView tableView, Object previousSelectedRow) {
int selectedIndex = expenseTableView.getSelectedIndex();
editSelectedExpenseAction.setEnabled(selectedIndex != -1);
deleteSelectedExpenseAction.setEnabled(selectedIndex != -1);
}
});
}
use of org.apache.pivot.serialization.SerializationException in project pivot by apache.
the class QueryServlet method doPut.
@Override
protected final void doPut(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
Path path = getPath(request);
boolean created = false;
try {
validate(Query.Method.PUT, path);
Object value = null;
if (request.getContentLength() > 0) {
Serializer<?> serializer = createSerializer(Query.Method.PUT, path);
value = serializer.readObject(request.getInputStream());
}
created = doPut(path, value);
} catch (SerializationException exception) {
throw new ServletException(exception);
} catch (QueryException exception) {
response.setStatus(exception.getStatus());
response.flushBuffer();
}
if (!response.isCommitted()) {
response.setStatus(created ? Query.Status.CREATED : Query.Status.NO_CONTENT);
setResponseHeaders(response);
response.setContentLength(0);
response.flushBuffer();
}
}
use of org.apache.pivot.serialization.SerializationException in project pivot by apache.
the class Query method execute.
@SuppressWarnings("unchecked")
protected Object execute(final Method method, final Object value) throws QueryException {
Object result = value;
URL location = getLocation();
HttpURLConnection connection = null;
Serializer<Object> serializerLocal = (Serializer<Object>) this.serializer;
bytesSent.set(0);
bytesReceived.set(0);
bytesExpected = -1;
status = 0;
String message = null;
try {
// Clear any properties from a previous response
responseHeaders.clear();
// Open a connection
if (proxy == null) {
connection = (HttpURLConnection) location.openConnection();
} else {
connection = (HttpURLConnection) location.openConnection(proxy);
}
connection.setRequestMethod(method.toString());
connection.setAllowUserInteraction(false);
connection.setInstanceFollowRedirects(false);
connection.setUseCaches(false);
if (connection instanceof HttpsURLConnection && hostnameVerifier != null) {
HttpsURLConnection httpsConnection = (HttpsURLConnection) connection;
httpsConnection.setHostnameVerifier(hostnameVerifier);
}
// Set the request headers
if (result != null) {
connection.setRequestProperty("Content-Type", serializerLocal.getMIMEType(result));
}
for (String key : requestHeaders) {
for (int i = 0, n = requestHeaders.getLength(key); i < n; i++) {
if (i == 0) {
connection.setRequestProperty(key, requestHeaders.get(key, i));
} else {
connection.addRequestProperty(key, requestHeaders.get(key, i));
}
}
}
// Set the input/output state
connection.setDoInput(true);
connection.setDoOutput(result != null);
// Connect to the server
connection.connect();
queryListeners.connected(this);
// Write the request body
if (result != null) {
try (OutputStream outputStream = connection.getOutputStream()) {
serializerLocal.writeObject(result, new MonitoredOutputStream(outputStream));
}
}
// Notify listeners that the request has been sent
queryListeners.requestSent(this);
// Set the response info
status = connection.getResponseCode();
message = connection.getResponseMessage();
// Record the content length
bytesExpected = connection.getContentLengthLong();
// NOTE Header indexes start at 1, not 0
int i = 1;
for (String key = connection.getHeaderFieldKey(i); key != null; key = connection.getHeaderFieldKey(++i)) {
responseHeaders.add(key, connection.getHeaderField(i));
}
// If the response was anything other than 2xx, throw an exception
int statusPrefix = status / 100;
if (statusPrefix != 2) {
queryListeners.failed(this);
throw new QueryException(status, message);
}
// Read the response body
if (method == Method.GET && status == Query.Status.OK) {
try (InputStream inputStream = connection.getInputStream()) {
result = serializerLocal.readObject(new MonitoredInputStream(inputStream));
}
}
// Notify listeners that the response has been received
queryListeners.responseReceived(this);
} catch (IOException exception) {
queryListeners.failed(this);
throw new QueryException(exception);
} catch (SerializationException exception) {
queryListeners.failed(this);
throw new QueryException(exception);
} catch (RuntimeException exception) {
queryListeners.failed(this);
throw exception;
}
return result;
}
use of org.apache.pivot.serialization.SerializationException in project pivot by apache.
the class Pivot714 method getWindow.
public Window getWindow(final Window ownerArgument) {
this.owner = ownerArgument;
final BXMLSerializer bxmlSerializer = new BXMLSerializer();
try {
result = (Dialog) bxmlSerializer.readObject(Pivot714.class.getResource("pivot_714.bxml"));
} catch (IOException e) {
e.printStackTrace();
} catch (SerializationException e) {
e.printStackTrace();
}
final ListButton motif = (ListButton) bxmlSerializer.getNamespace().get("motif");
ArrayList<String> al = new ArrayList<>();
al.add("One");
al.add("Two");
motif.setListData(al);
CalendarButton cbDate = (CalendarButton) bxmlSerializer.getNamespace().get("date");
dcl = (new DialogCloseListener() {
@Override
public void dialogClosed(Dialog dialog, boolean modal) {
// empty block
}
});
cbDate.getCalendarButtonSelectionListeners().add(new CalendarButtonSelectionListener() {
@Override
public void selectedDateChanged(CalendarButton calendarButton, CalendarDate previousSelectedDate) {
// empty block
}
});
return result;
}
use of org.apache.pivot.serialization.SerializationException in project pivot by apache.
the class JavascriptConsoleTest method loadWindowFromURL.
/**
* Load (and returns) a Window, given its URL and serializer to use <p> Note
* that if public this method could be called even from JS in a bxml file
* (but a reference to the current application has to be put in serializer
* namespace). <p> Note that all Exceptions are catched inside this method,
* to not expose them to JS code.
*
* @param urlString the URL of the bxml file to load, as a String
* @param bxmlSerializer the serializer to use, or if null a new one will be created
* @return the Window instance
*/
public Window loadWindowFromURL(String urlString, final BXMLSerializer bxmlSerializer) {
logObject("loadWindow from \"" + urlString + "\", with the serializer " + bxmlSerializer);
BXMLSerializer serializer = bxmlSerializer;
if (serializer == null) {
serializer = new BXMLSerializer();
}
Window loadedWindow = null;
try {
URL url = new URL(urlString);
// force the location, so it will be possible to decode resources
// like labels ...
serializer.setLocation(url);
loadedWindow = (Window) serializer.readObject(url);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (SerializationException e) {
e.printStackTrace();
}
return loadedWindow;
}
Aggregations