Java development blog (tips, notes, …)
"First, solve the problem. Then, write the code." (John Johnson)

    Book recommendation: MetaGame

    2017-09-13 19:00:00 +0000

    Here’s a book recommendation. A science-fiction thriller. The most interesting part was how the writer fused the world with technology. There a nanobots in this world, which send out a “ping”. They sit on everything. Multiple devices can pick up this signal and therefore pinpoint the object. Objects in displays can be overlayed with other objects. Therefor building a world on top the real world… hence meta :) :
    MetaGame: Science-Fiction Thriller

    Mapping query result to a plain java bean with @SqlResultSetMapping

    2017-09-10 19:00:00 +0000

    I needed some data from a old big oracle database. Most of the time I write or generate a entity class, and fetch the data with a Named Query. But this time I only needed two informations and I didn’t what to use a dozen primary keys and so on to find it. So I used a Native Query.. I know… messy.

    Trying to make it look a little professional, I used a SqlResultSetMapping to map the result to a plain old java bean.

    //Need to be put in an entity class. Any entity class will do
    @SqlResultSetMapping(
            name = EntityClass.RESULT_MAPPING_NAME,
            classes = {
                @ConstructorResult(
                        targetClass = MyPlainBean.class,
                        columns = {
                            @ColumnResult(name = "something"),
                            @ColumnResult(name = "someone")
                        }
                )
            }
    )
    
    //EntityClass is the name of the plain bean - NOT an entity
    
    //Some static final Strings to reference the information. Do not use the same string multiple times!
    public static final String RESULT_MAPPING_NAME  = "aVeryGoodName";
    public static final String NATIVE_SQL_QUERY  = "SELECT  column1 \"something\" column32 \"someone\" where.....";
    
    //The Native Query call
    final Query<MyPlainBean> query = session.createNativeQuery(EntityClass.NATIVE_SQL_QUERY,EntityClass.RESULT_MAPPING_NAME);

    Lychee

    2017-09-08 18:00:00 +0000

    “Lychee is a free photo-management tool, which runs on your server or web-space. Installing is a matter of seconds. Upload, manage and share photos like from a native application. Lychee comes with everything you need and all your photos are stored securely.” : https://lychee.electerious.com/

    Use a URIResolver if the stylesheets can not be found in test

    2017-09-04 19:00:00 +0000

    I use quiet a lot XSL transformations at work. Since they tend to grow rather big with every new rule I implement, I split the file up. Every file has it’s own domain/rule. This works fine. I also write a new junit test for every new xslt rule/template, to ensure that I did not break anything.

    At somepoint in every new project I get the error, that a transformation in production (src/main) does work, but in test (src/test) does not. After a few minutes of searching I come to the conclusion, that a import/include stylesheet can not be found. A few minutes later and the penny dropes… I always forget to implement the URIResolver. Every time…

    import java.io.InputStream;
    import javax.xml.transform.Source;
    import javax.xml.transform.TransformerException;
    import javax.xml.transform.URIResolver;
    import javax.xml.transform.stream.StreamSource;
    
    
    public class XsltURIResolver implements URIResolver {
    
    
        @Override
        public Source resolve(String href, String base) throws TransformerException {
            try {
                final InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(href);
                return new StreamSource(inputStream);
            } catch (Exception ex) {
                ex.printStackTrace();
                return null;
            }
        }
    }

    And they setting it:

    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    transformerFactory.setURIResolver(new XsltURIResolver()); 

    letsencrypt "Certbot doesn't know how to automatically configure the web server on this system"

    2017-08-20 19:00:00 +0000

    Had a little problem with letsencrypt, when I tried to renew the certificates, the following error showed:

    root@tsunade / # letsencrypt --renew-by-default
    Saving debug log to /var/log/letsencrypt/letsencrypt.log
    Certbot doesn't know how to automatically configure the web server on this system. However, it can still get a certificate for you. Please run "certbot certonly" to do so. You'll need to manually configure your web server to use the resulting certificate.

    So I looked in /var/log/letsencrypt/letsencrypt.log :

    2017-08-20 18:43:37,178:DEBUG:certbot.main:Root logging level set at 20
    2017-08-20 18:43:37,179:INFO:certbot.main:Saving debug log to /var/log/letsencrypt/letsencrypt.log
    2017-08-20 18:43:37,179:DEBUG:certbot.main:certbot version: 0.10.2
    2017-08-20 18:43:37,179:DEBUG:certbot.main:Arguments: ['--apache']
    2017-08-20 18:43:37,180:DEBUG:certbot.main:Discovered plugins: PluginsRegistry(PluginEntryPoint#webroot,PluginEntryPoint#null,PluginEntryPoint#manual,PluginEntryPoint#standalone)
    2017-08-20 18:43:37,180:DEBUG:certbot.plugins.selection:Requested authenticator apache and installer apache
    2017-08-20 18:43:37,180:DEBUG:certbot.plugins.selection:No candidate plugin
    2017-08-20 18:43:37,180:DEBUG:certbot.plugins.selection:Selected authenticator None and installer None

    So…. I had no clue, but a quick search on stackoverflow showed that I missed a package

    root@tsunade / # apt-get install python-certbot-apache
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    The following additional packages will be installed:
      augeas-lenses libaugeas0 python-augeas

    And all ended well. I renewed the certificates:

    root@tsunade / # letsencrypt --renew-by-default
    Saving debug log to /var/log/letsencrypt/letsencrypt.log
    Which names would you like to activate HTTPS for?
    -------------------------------------------------------------------------------                                                                                                              
    1: my domains
    ...
    -------------------------------------------------------------------------------
    Select the appropriate numbers separated by commas and/or spaces, or leave input blank to select all options shown (Enter 'c' to cancel):
    Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org 
    Renewing an existing certificate
    ...

subscribe via RSS