HttpURLConnection and GET query parameters

I regret that JAVA SE still lacks any decent native HTTP client framework! Simple use cases like GET requests with query parameters require handcrafted coding with HttpURLConnection.

This article appeared first at <techtavern.wordpress.com>.

HttpURLConnection misses methods to set query parameters. There is no URI builder facility as found on Apache HTTP Client. You are on your own.

Therefore, I wrote the applyParameter method that takes care of GET query parameters.

Comparing your Oracle databases

This article suggests an approach to compare your development, test and production databases using SQL scripts executed from a Servlet.

This article appeared first on techtavern.wordpress.com

Create a Servlet that produces following SQL statements as a text report: (replace **** with a proper value applicable to your database).

  • Tables, sequences and views: SELECT OBJECT_TYPE, OBJECT_NAME, STATUS FROM ALL_OBJECTS WHERE OWNER = ‘****’ ORDER BY OBJECT_TYPE, OBJECT_NAME
  • Columns of each table: SELECT TABLE_NAME, COLUMN_NAME, QUALIFIED_COL_NAME, DATA_TYPE, DATA_LENGTH, DATA_PRECISION, DATA_SCALE, NULLABLE, CHARACTER_SET_NAME, CHAR_COL_DECL_LENGTH, CHAR_LENGTH, CHAR_USED FROM ALL_TAB_COLS WHERE OWNER = ‘****’ ORDER BY TABLE_NAME, COLUMN_NAME
  • Constrains of each table: SELECT TABLE_NAME, CONSTRAINT_NAME, CONSTRAINT_TYPE, STATUS, SEARCH_CONDITION, R_CONSTRAINT_NAME, DELETE_RULE, DEFERRABLE, DEFERRED, VALIDATED, GENERATED FROM ALL_CONSTRAINTS WHERE OWNER = ‘****’ ORDER BY TABLE_NAME, CONSTRAINT_NAME
  • Sequences: SELECT SEQUENCE_NAME, INCREMENT_BY, MIN_VALUE, MAX_VALUE, CACHE_SIZE, CYCLE_FLAG, ORDER_FLAG FROM ALL_SEQUENCES WHERE SEQUENCE_OWNER = ‘****’ ORDER BY SEQUENCE_NAME

For security reasons, you may prefer to output them into the application log.

Update licence header without plugin

This article explains how to update license header for your java source files without any tool. It works for Notepad++, Netbeans and Eclipse and does not require installing any additional plugin.

This article appeared first at techtavern.wordpress.com.

Option 1: Using Notepad++

Open Notepad++ and navigate to Search->Find ind Files. Fill the dialog as shown below.

update-license-header-withou-any-tool-notepadplusplus

Find what: \A(.*?^package){1}
Replace with: /\\r\n \ (line 1)\r\n \* (line 2).\r\n \*/\r\npackage
Directory: The root directory of your source code.
Filters: *.java
Activate “Regular expression” and “. maches newline”.

Netbeans RCP: increasing JVM memory settings

This article explains how to increase memory limits for your Netbeans RCP application when using Ant to create a ZIP package or a Windows installer.

This article appeared originally at techtavern.wordpress.com.

Introduction

Both ZIP package and Windows installer contain an executable that reads JVM and bootstrap settings from the etc/application_name.conf file. This file is copied from the laucher configuration template at netbeans-installation\harness\etc\app.conf. The default options contains all command line parameters passed to the executable. JVM parameters are prefixed by “-J”.

Calling Objectify within DeferredTask

This article explains how to call Objectify within a DeferredTask on Google App Engine push queue.

This article appeared first on techtavern.wordpress.com

Objectify Wiki presents a clear explanation how to user ObjectifyFilter to get or inject a Objectify instance into your servlet. However there is no word using Objectify within push queues.

Solution 1: Create task with worker URLs that are mapped to your servlet

Let ObjectifyFilter inject the Objectify instance. It your responsibility to encode and handle parameters and to secure your URLs.

Google App Engine Java SDK advices

It would have been nice if I knew this beforehand about Google App Engine Java SDK

This article originally appeared on https://techtavern.wordpress.com

GAE infrastructure is a kind of Java 7 platform. You may compile your code using the current Java 8 SDK, as long as source code version is set to Java 7. You may deploy and run your application locally with Java 8, too.

However, when deploying to Google infrastructure, there are some pitfalls.

Netbeans RCP: Asking before exiting the application

This article explains how to present a confirmation dialog asking if the user really wants to close the application.

This article was originally published on techtavern.wordpress.com.

The following solution registers a callable via @OnStop annotation. The callable is an opportunity to cancel closing the application by returning false.


import java.util.concurrent.Callable;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.modules.OnStop;

@OnStop
public class ApplicationOnStop implements Callable&amp;lt;Boolean&amp;gt; {
@Override
   public Boolean call() throws Exception {
      NotifyDescriptor d = new NotifyDescriptor.Confirmation("Close application?", NotifyDescriptor.YES_NO_OPTION)
      return DialogDisplayer.getDefault().notify(d) == NotifyDescriptor.YES_OPTION; 
   } 
}

SLF4J on Netbeans RCP Applications

This article explains how to configure SLF4J logging framework for your Netbeans RCP modules.

This article was originally published on techtavern.wordpress.com

Netbeans RCP favors Java standards for a small memory footprint and to spare us from learning new APIs. For example, Netbeans uses java.util.logging instead of creating its own logging API. However, most developers prefer leaner logger APIs like SLF4J.

Context

It happens that Netbeans kept only the API and replaced most of the java.util.logging original implementation. The startup module replaces the log manager. A custom handler writes messages into the platform messages file using a custom pattern. Another handler repeats messages on the platform messages TopComponent.

Netbeans RCP: external layer.xml

A Netbeans RCP application might benefit from an additional layer.xml file stored outside of application bundles. A network directory or a http server may provide some layer.xml with centralized or corporated configuration or user profiles, maintained the network administrator.

This article was first published at techtavern.wordpress.com

There are two solutions to add an additional layer.xml file to your application. Both solutions are provided by Netbeans RCP Toys at github.

LayerProvider

Register a LayerProvider using the @ServiceProvider(service = LayerProvider.class) annotation. The platform calls all LayerProvider.registerLayers(Collection<? super URL>) to populate the collection with URLs to additional layer files. This URL may refer a local file or a remote over HTTP. As this method is called early, your application might not yet know the URL. For example, it does not work for command line argument as they have not been parsed then LayerProvider.registerLayers() is called. This approach is file as long as your URLs are declared as static constants.

SLF4J on Java Google App Engine

This article suggest a recipe to configure SLF4J on Google App Engine for Java.

This article was first published at techtavern.wordpress.com

Google App Engine for Java offers a restricted Java 6 API, which includes just the cumbersome Java Utils Logging. Fortunately, SLF4J works as well. The recipe is the standard one. Nearly no configuration is required.

Just add following SLF4J libraries into the applications WEB-INF/lib directory: slfj4-api-1.7.7.jar and slf4j-jdk14-1.7.7.jar (version number may vary). This will redirect all your SLF4J logging statements to the Java Utils Logging controlled by the App Engine.