29 November 2018

Websocket examples

Websocket examples using

27 November 2018

GDPR compliance of dominant IT consumer platforms

ForbrukerRadet, the Norwegian Consumer Counsils, published a report Deceived By Design on privacy compliance with GDPR in the dominant IT consumer platforms.

24 November 2018

Refactoring 2nd Edition released

After 19 years the second edition of Martin Fowler's refactoring book sees print.
Here's an overview of the changes.

IntelliJ multiline TODO comments

After 8 years and +300 votes this feature has been implemented in the 2018.3 edition of JetBrains IntelliJ


21 November 2018

16 November 2018

Spring Data Release train names

The spring data release trains are named after famous computer scientists, some of them living! The release train is a bundle of recent compatibe Spring Data subprojects (JPA, Redis, MongoDB, Solr, REST...). Basically they all refer to the same Spring Data Commons version. The names are ordered alphabetically, clearly inspired by Android's alphabetically ordered releases named after candy, Here's the list up to this day:

2013-02: Arora
2014-02: Babbage
2014-03: Codd
2014-05: Dijkstra
2014-09: Evans
2015-03: Fowler
2015-09: Gosling
2016-04: Hopper
2017-01: Ingalls
2017-10: Kay
2018-09: Lovelace
2019-10 : Moore
              : Neumann

9 November 2018

WSDL 1.1 <definitions> and Java mapping (updated)




  • All wsdl:xxx elements are direct children of <wsdl:definitions>. 
  • Composition indicates XML child elements
  • Attributes indicate XML attributes
  • Relations are attributes referring to the name of other elements

7 November 2018

MS Office and Google Drive File Stream: Safe to edit

Google drive file stream  is now adding an real-time presence to your Microsoft Office documents.
In the bottom right corner of your documents you see a Safe to edit message to indicate no one else is working in the file.
You will also see who is editing and be able to merge after simultaneous editing.
You need to have the Drive File Stream Client installed for this feature to be active. Google is doing this without any Office plugin. When you launch the office document from your synced drive the Drive Client monitors it and displays the messages on top. Nice work Google!




5 November 2018

Spring Web Flow and Spring Boot DevTools problem: SpelEvaluationException: EL1004E: Method call:cannot be found

When calling a method with arguments using the <evaluate>  tag in a spring webflow XML definition I get the error SpelEvaluationException: EL1004E: Method call: xxx cannot be found.
I am using Spring Boot Devtools for automatic server restart upon changes.
The embedded LiveReload server uses two classloaders, and thinks the the classes of the parameters supplied by spel in the XML are different from the (same) classes in your Java code.
Hence the method is not found, and an exception is thrown.
Possible Solutions:

  • Do not use Spring Boot Devtools for Spring Web Flow projects
  • Follow the guidance in the description of the bug

25 October 2018

Powerpoint zoom notes text

Sometimes I work in a powerpoint where the text in the notes view is too small or too big.
Setting the font size does nothing.
Moving the zoom slider does nothing (I wish Microsoft would fix this).

The solution: while positioning your cursor in the notes pane, you have to select the View > Zoom menu, that one works.

8 September 2018

Saving powerpoint as PDF loses image transparency (solved)

When you save a powerpoint as PDF, transparent parts of images (e.g. png) appear as black regions in the PDF.
The solution?

  1. When in the Save as... diaglog you select Browse, an explorer window pops up
  2. Choose Save as type: PDF (*.pdf)  
  3. An Options... button appears. Click this button.
  4.  At the bottom of the window uncheck PDF/A compliant
Your preference will be saved with the document, so next time you don't have to go through this again.

7 September 2018

Using MS Word master / sub documents feature

There are two kinds of Master Documents: Those that are corrupt and those that will be corrupt soon.
       John McGie

youronlinechoices.com: an industry funded joke

With GDPR in operation, a lot of sites refer to youronlinechoices.com to manage your advertising cookies. On the homepage of the site you can select your country and language and then go to your advertising preferences. Sometimes you are directed to the preferences page directly.

The site lists (for me) 116 advertising sites, with for each company an on/off status. The site is a self-regulating, industry funded site.
Only... it does not work. For the 116 sites, only 14 show a response, the rest time out.

The site allows you to switch advertising on/off for individual companies. As it is not practical to click 116 buttons, there is a handy option to switch them all on or off.
Only... it does not work. Just like you could expect, the operation times out.

Most companies have an edaa certified label. You can click on the label to see the certification the advertising company received.
Only... it does not work. This is what you get:

Sorry, the page you are looking for either doesn't exist or something has gone wrong. Please go back to the home page and try again. Thank you.
At the bottom of the page there is a feedback mail adress. I signaled the problems to them.
Only... it does not work. After more then a month i did not even get a mail confirming the receipt of my message.

So much for industry self regulation.

I'll start listing companies using this bogus site to manage your privacy here:
- rabobank.be

RD EE6 webservices module 9: alternate lab instructions

  1. Create a new web project Publisher
  2.  Create a new java bean class domain.Address with properties street, number, postalCode, City
  3.  Create a new java bean class domain.Publisher with properties id, name, address
    1. Make sure JAXB can convert this bean from/to XML 
  4. Create a new Soap WebService service.PublisherService. Do not wrap the service in a SessionBean (it will work as a servlet)
    1. We will not save the data to a database. To store the publishers in memory, add this attribute to PublisherService
    2. private static Map<Integer,Publisher> publisherDao = new
      HashMap<Integer,Publisher>(); 
      
    3. Add a webservice method create(String name,Address address) to the PublisherService
      1. In the method create a new Publisher. For the id, take the size of the publisherDao + 1.
      2. Add the Publisher to the publisherDao map. Use its id as the key in the map.
    4. Add a webservice method querySingle(int id). It should return the publisher with this id.
    5. Add a webservice method QueryAll. It should return all publishers
    6. Test and correct any errors
  5. Make sure a SOAP Fault is returned when creating a publisher with invalid parameters
  6. Advanced (Optional)
    1. Customize the Fault to add a detail child element with one or more reasons explaining why the creation failed.
      <detail>
         <canNotCreatePublisher >
           <reason>No address</reason>
           <reason>No name</reason>
         <canNotCreatePublisher> 
      </detail>
      
      Note: the canNotCreatePublisher element may contain some extra namespace information.
    2. Make an ErrorInfo bean class that contains a list of reasons. Make sure objects of the class can be transferred from/to XML using JAXB
    3. Make a CreateException class that inherits from Exception. The class should have an attribute
      private ErrorInfo faultInfo;
      1. Add accessor methods for the attribute and a constructor with the attribute as an argument
      2. Add an @WebFault annotation to the CreateException class
    4. In the create webservice check for the validity of the parameters. If there are invalid parameters throw a CreateException with an error message for each invalid parameter.

RD EE6 webservices module 10: lab cookbook

  1. Start from the BookOrderWSService.wsdl in the lab directory
    1. OR (Alternative):
      1. start from the order.wsdl you created in module 3
      2. modify the order ComplexType to match the exercise instruction
      3. modify the orderId SimpleType to String
  2. Generate java classes from the WSDL
    1. Create a src and class directory
    2. run wsimport in the location where you have created these folders. wsimport should
      1. generate all classes in the service package
      2. put generated .class files in the class directory
      3. put generated  .java files in the src directory
  3. Create a new Java Web Application project called bookOrder
  4. Copy the wsimport files to your project
    1. copy the src/service directory to the src directory of your project
    2. Move the bookOrder class to a newly created package domain
    3. Make a new directory wsdl in the WEB-INF directory (WEB-INF is under Web Pages) and copy the WSDL you obtained in step 1 here.
  5.  Add constructors to domain.Orders
    1. add a constructor that takes all attributes as parameters
    2. add a constructor without parameters
  6. Implement the BookOrderService interface in a class BookOderWS
  7. Add these extra attributes
    • endpointInterface
    • wsdlLocation = "WEB-INF/wsdl/BookOrderWSService.wsdl"
    • serviceName
    • portName
    • targetNamespace
  8. Add a static Map to BookOrderWS , which will act as a datastore: 
    1. private static Map<String,Order> orderDao = new HashMap<String,Order>();
      
    2. add a static block to the class in which you add some test data to orderDao. Use the orderID from the Order also as a key in the Map.
  9. Implement the orderBook method.
  10. Test and correct until everything works

6 September 2018

RD EE6 Web Services module 12 alternate lab: Logging Handler

 Make a copy of the project you made in module08 and work in that copy.
 Add a SOAPHandler that logs every message to System.out for the BookWS webservice.

  1. Write a class handler.LoggingHandler that implements SOAPHandler. For each message
    • Log if it is a REQUEST or a RESPONSE
    • Log the SOAP message using
       context.getMessage().writeTo(System.out);
    • catch any Exceptions and return true
  2. Annotate the BookService with @HandlerChain, and refer to the "../../handlers.xml" file
  3. Write the handlers.xml file and put it in the WEB-INF directory
  4. Test and correct until it works
Note: you can achieve a similar result by passing this property to your server
-Dcom.sun.xml.ws.transport.http.HttpAdapter.dump=true

1 September 2018

RD EE6 Web Services module 21 lab using JAX-RS 2

Create a JAX-RS 2 REST client application for your createAuthor and findAuthorById service.

  1. Make a REST client prject
    1. Make a new rsClient java application project  in Netbeans
    2. Make sure your Author webservice server project is open as well
    3. Add a new webservice client to the client project (File > new > Webservices > RESTful Java client)
      1. Select the REST resource, browse for your server project and select the Author REST service 
      2. Finish
        1. This creates you a project with the JAX-RS libraries and client sample code.
          1. You can use the sample code for your inspiration, but write your own client code
    4. Copy the domain classes of your server project + the JAXB adapters to the client project
  2. Call the createAuthor service
    1. In the main method of your client project create a javax.ws.rs.client.Client object
    2. Create a request that expects an XML or JSON reply
    3. Create a new Author object, without an id
    4. POST the author object in the body as a XML or JSON Entity. Example of the creation of a JSON entity: javax.ws.rs.client.Entity.json(author)
  3. Call the findAuthorById service to retrieve the Author you just created from the server
    1. If the createAuthor service is well written, the Location header in the javax.ws.rs.core.Response should contain the URL of the newly created Author (including the generated author id). Retrieve the URL from the Location header in the Response.
    2. Use the URL to retrieve the author, converted by the Client to an Author object
    3. Print the Author object to the console

JAX-RS 2.0 client example: Client class

public class MyClient {
  public static void main(String[] args) {
    System.out.println("What's the name of this author?: ");
    String authorId = new Scanner(System.in).next();
    
    Client client = ClientBuilder.newClient();
    WebTarget resource = client.target("http://localhost:8080/myrest/webresources");
    Response response = resource
            .path("author")
            .path(authorId)
            .request(MediaType.APPLICATION_JSON)
            .get();

     // historically getStatus returns an int, not a Response.Status
    if (response.getStatus() == Response.Status.OK.getStatusCode()) {
      Author author = response.readEntity(Author.class);
      System.out.println("Found author: " + author.getFirstName() + " " + author.getLastName());
    }else{
      String body = response.readEntity(String.class);
      System.out.println("Not correct (" + response.getStatusInfo().getReasonPhrase() + ")\n " +body);
    }
  }
}

31 August 2018

JAXB custom conversion using @XmlJavaTypeAdapter

To provide your own conversion implementation of a JAXB property, annotate the property in your JAXB class with javax.xml.bind.annotation.adapters.@XmlJavaTypeAdapter:

    @XmlJavaTypeAdapter(MyAdapter.class)
   
public void setFrom(LocalDate from) {
       
this.from = from;
    }

 
Then write your Adapter marshalling your LocalDate attribute to an XML value String and unmarshalling it:

    public class MyDateAdapter extends XmlAdapter<String, LocalDate> {
   
public LocalDate unmarshal(String myString) throws Exception {
     
return LocalDate.parse(myString);
    }

   
public String marshal(LocalDate myDate) throws Exception {
     
return myDate.toString();
    }

  }

30 August 2018

Glassfish console log timestamps

By default glassfish does not add timestamps to console logging messages and that allways leaves me wondering wether I'm looking at an old message or a new one.
To add timestamps edit $GLASSFISH_INSTALL/glassfish/domains/domain1/config/logging.properties
Replace domain1 with the domain your domainin the above,  if you are not using the default domain.
change:
java.util.logging.ConsoleHandler.formatter=com.sun.enterprise.server.logging.UniformLogFormatter
to:
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter

The default format is fine for me, but you can customize the format using:
java.util.logging.SimpleFormatter.format="your %format string"

The javadoc contains some format string examples.
Then (re)start the server.

23 August 2018

Java EE component versions overview (updated)

The table below lists the components in latest versions of the Java Enterprise Edition.
Many of the Java EE projects live on github.
After Java EE8, Java EE is moving to the EE4J project (Eclipse Enterprise For Java) aka Jakarta.

  • I put the most important changes in red.
  • Components with a [version number] between brackets are  proposed for removal in a future release.
  • An x indicates a technology is removed from the specification
    • JSR's are shown as hyperlinked numbers.
    • SE indicates that an API was moved to the standard edition 
      • eventually followed with the version number
      • Java SE version history is in a separate post 
      • These API's will be removed from Java SE again with Java 11
    • Web technologies are in a separate post
    • EJB history is in a separate post
    • I added some application servers at the bottom of the table. 
    Technologies151
    J2EE 1.4

    2003
    244
    Java EE5

    2006
    316
    Java EE6

    2009
    342
    Java EE7

    4/2013
    366
    Java EE8
    Java SE59 1.4176 5270 6336 7337 8
    EJB153 2.1220 3.0318 3.1345 3.2
    Servlet/JSP2.42.53.03.14.0
    EE Management77 1.0



    JMS 914 1.1

    343 2.0368 2.1
    JTA 9071.01.1
    1.2
    JavaMail 9191.31.41.51.6
    Connector (JCA)112 1.51.5322 1.61.7
    Java Activation Framework (JAF) 9251.01.1SE:1.1.1
    Web Services 1091.11.21.3
    1.4
    Web Services Metadata 181
    2.0SESE:2.1
    JAX-WS (SOAP) 101 JAX-RPC 1.1 224 2.0SE:2.0SE:2.2
    JAX-RS (REST)

    311 1.1
    339 2.0370 2.1
    JAXB 222
    2.0SE:2.2
    JSON-P  353 1.03741.1
    JSON-B 367
     1.0
    JAXR (UDDI Registry)1.0
    [1.0]x
    SOAP w attachments (SAAJ) 671.21.3SE
    StAX 173
    1.0SE
    JMX1.2SESE
    container authorisation (JACC) 1151.01.11.41.5
    container authentication (JASPIC) 196

    1.01.1
    Security 375



    1.0
    Common annotations 250
    1.01.11.21.3
    Java Persistence (JPA)
    1.0317 2.0338 2.12.2
    Bean Validation

    303 1.0349 1.1380 2.0
    Managed Beans

    1.0
    Interceptors
    1.01.11.2
    CDI for Java EE

    299 1.0346 1.1365 2.0
    DI for Java 330

    1.0
    Concurrency utilities 236


    1.0
    State management 350


    1.0
    Batch  352


    1.01.1
    Servers
    Sun JSAS89.1
    Glassfish23 (12/09)4 (5/13)5 (9/17)
    JBoss / WildFly457 (7/11)8 (2/14)12 (2/18)
    IBM Websphere678 (6/11)9 (10/17)
    Oracle Weblogic91012.1.1
    (12/11)
    12.2.1 (11/15)
    Apache Geronimo123 (7/12)-
    Apache Tommee+

    1.5 (9/12)7 (3/16)
    • J2EE 1.3(2001) introduced
      • Message Driven  Beans
      • Local interfaces
    • Profiles are a subset of the spec.
      • Java EE Web profile (only profile currently defined)
        • contents
          • java SE
          • web technologies, JTA, common annotations, JPA, validation, managed beans, interceptors, CDI, DI
          • EJB Lite
            • Stateless, Stateful, and Singleton session beans
              • asynchronous session beans (EJB 3.2)
            • only local EJB interfaces or no interfaces
            • interceptors
            • security
            • transactions
            • non persistent timer only (EJB 3.2)
            • No Message Driven beans and remote invocation.
          • JAX-RS (Java EE7)
        • implemented by
          • Resin 4
          • Apache TomEE 

        19 August 2018

        Securely opening tabs to other sites from your webpage

        You can use a link on your webpage to open a page from another site in another tab, using

        <a ref="https://othersite/otherpage.html" target="_blank">
          to  other page
        </a>
        Your browser typically opens the other page in a new tab, but this page retains a relation with your webpage and can do some priviliged actions like redirecting the tab of your webpage to another URL.
        To prevent this, break the opener and referer links the foreign page has to your webpage by using
        <a ref="https://othersite/otherpage.html" target="_blank" rel ="noopener noreferer"> 
           to  other page 
        </a>
        more...

        7 June 2018

        Java EE web technology version history (updated)


        JSR numbers are included as links.
        Servers are webcontainers.Take care, web containers do not include JSF. You have to add it yourself or use an enterprise application server. Enterprise application servers are included in the
        complete Java EE version overview.

        Java EEservletJSP     ELJSTLJSF    WebSocketMVCServer       What’s new
        2.1
        1.0

        iPlanet
        jetty 1
        ServletContext, RequestDispatcher
        1.2
        2.2
        1.1
        tomcat 3.3
        jetty 3
        war
        1.3
        53 2.3
        53 1.2
        tomcat 4.1
        jetty 4
        filters
        1.4
        154 2.4
        152 2.0
        1.0
        52 1.1
        tomcat 5.5
        jetty 5
        5
        2.5
        245 2.1
        2.1
        1.2
        127 1.2

        tomcat 6
        jetty 6
        annotations
        6
        315 3.0
        2.2
        2.2

        314 2.0

        tomcat 7
        jetty 8
        asynchronous servlets, EL method calls, more...
        7
        340 3.1
         341 3.0

        344 2.2
        356 1.0

        tomcat 8
        jetty 9.1
        HTML 5, non blocking (Listener) servlet IO
        8
        369 4.0


        372 2.3
        1.1
        371 1.0tomcat 9 HTTP/2

        3 May 2018

        windows 10 logon/logoff tracking by filtering system events

        When I'm late filling in my timesheets, it always is a headache to remember which hours I spent working. My windows event viewer (eventvwr.msc) can be a help but the logs are too crowded.
        The events related to logon/logoff are polluted with plenty of events from system services.
        So I ventured to create a filter only showing the events relating to my user. This requires XML filtering based on XPATH.

        1.  Create a new custom event view
          1.  right click the security category and select Create Custom View...
          2.  enter the event ID's you want to filter. For logon/logoff these are 4624, 4634 and 4647
            1. You can get the id's by examining your events or from this MSDN page.
        UPDATE: I'm often not logging off when I'm away, and this method does not log system sleep. Instead of monitoring logon/logoff I made a new filter that logs By source on event source Power-Troubleshooter. The details in the logs show the time the system went to sleep and woke up. The time in the details are in Zulu time (UTC+0), so they are some hours of from the real time, but given that the event time is correct, this is easy to deal with. The post remains interesting as a general explanation of event filtering, so I just added this update, and did not modify the general procedure
        1. Modify the base filter. 
          1. There is a field for filtering on the user name in the filter definition form, but that did not work. By clicking the XML tab we can edit the XML filter definition. Take care: you will not be able to edit the filter using the graphical user interface anymore after that.
          2. I added user filtering in the XML. This is my filter
          3. <QueryList>
              <Query Id="0" Path="Security">
                <Select Path="Security">
                  *[System[( EventID=4624 or EventID=4634 or EventID=4647)] 
                    and EventData[Data[@Name='TargetUsername']='jan']]
                </Select>
              </Query>
            </QueryList>
            
          4. I saved the filter and provided a name for the new custom filter. 
        2. We're done
        Now you might wonder where I got the name of the field I needed to filter on from.  You can get the XML element names by examining the event in your logs
        1. In eventviewer, pick a logon event of logon type 2. More info on logon events...
        2. Select the event and in the bottom  half of the window you see the details
        3. Select the Details Tab, then the XML view button. This shows you the name/value pairs on which you can filter. I  want to filter on my user, so I'll need the SubjectUserName field.
        On this Micorosoft technet page you find more info on XML event filtering.