JSF and PDF’s

This is a quick snipped on transmitting a PDF in a JSF context: byte[] bytes = getPDFStreamAsArray(); FacesContext faces = FacesContext.getCurrentInstance(); HttpServletResponse response = (HttpServletResponse) faces.getExternalContext() .getResponse(); response.reset(); response.setContentType(“application/pdf”); response.setContentLength(bytes.length); response.setHeader(“Content-disposition”, “inline;filename=”file.pdf””); // inline or attachment response.setHeader(“Cache-Control”, “cache, must-revalidate”); ServletOutputStream out = response.getOutputStream(); out.write(bytes); faces.responseComplete();

Java RMI quick and dirty

Your object which will be accessible through RMI must meet the following requirements: have its own interfaces which extends java.rmi.Remote all methods must “throws RemoteException“ all returned returned objects must implement java.io.Serializable Starting a RMI server: Set system property: System.setProperty(“java.rmi.server.hostname”, “hostname”); create registry: Registry registry = LocateRegistry.createRegistry(1099); export Object: RemotableObject stub = (RemotableObject) UnicastRemoteObject.exportObject(remoteObject, 0);… Continue reading “Java RMI quick and dirty”

Apache Tomcat 6.0 configuration for developers

Just a quick blog on configuring some specific Tomcat 6.0 settings: Memory Heap Size on a unix based system Open the file %tomcat_install_folder%/bin/startup.sh Add the line: export CATALINA_OPTS=”-Xms256m -Xmx512m” before the line: exec “$PRGDIR”/”$EXECUTABLE” start “$@” to have a memory heap of at least 256mb and max of 512mb. Memory Heap Size on a Windows… Continue reading “Apache Tomcat 6.0 configuration for developers”

Simple Configuration for Log4j

Ever wanted to use Log4j, but didn’t know how to configure it? Or you don’t remember how to configure it in a jiffy? Just add the following two lines in your application, like say in the main()-method and then your’re done: BasicConfigurator.configure(new ConsoleAppender(new PatternLayout(“%d %5p [%t] %C{1} %M – %m%n”))); Logger.getRootLogger().setLevel(Level.INFO); The first line sets… Continue reading “Simple Configuration for Log4j”

MySQL new user SQL statements

A quick and dirty explanation to create a new MySQL datbase with a user Create the user: CREATE USER ‘hibtest’@’localhost’ IDENTIFIED BY ‘*******’; Set some permissions: GRANT USAGE ON * . * TO ‘hibtest’@’localhost’ IDENTIFIED BY ‘*******’ WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0MAX_USER_CONNECTIONS 0 ; Create the database: CREATE DATABASE IF NOT EXISTS `hibtest`… Continue reading “MySQL new user SQL statements”

Apache and redirecting a url

This is a quick blog for me to remember how to do a proxy in apache: <VirtualHost *:80> ServerName www.someurl.com ServerAlias www.someurl.com ServerAdmin someone@someurl.com ProxyPreserveHost On ProxyRequests Off <Proxy *> Order deny,allow Allow from all </Proxy> ProxyPass / http://999.888.777.666:8080/ ProxyPassReverse / http://999.888.777.666:8080/ </VirtualHost>