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);
    }
  }
}