Skip to main content

Posts

Showing posts from 2011

PHP PDO LIMIT

Had an issue with PDO and MySQL SELECT statement while using LIMIT in it. It threw an exception while I tried to bind the parameter like I normally do. $pdo = $db->prepare("SELECT * FROM table LIMIT :limit"); $pdo->bindValue('limit', $limit, PDO::PARAM_INT) $pdo->execute(); From here I found a solution. It is necessary to cast the parameter $limit. Like this.. $pdo->bindValue('limit', (int) $limit, PDO::PARAM_INT)

tomcat ignores a war file in webapps folder

Following happened today.. Tomcat was ignoring one single WAR file. We was able to (re)deploy all other applications in webapps folder by removing and adding WAR files from and into the folder. But for one file was completely ignored. Solution.. A developer deployed the same WAR file earlier with context.xml file in META-INF folder. Tomcat stored this file into <tomcat home>/conf/Catalina/localhost named <context of application>.xml. If you now remove the file and restart Tomcat it will  not ignore given WAR file anymore. Tomcat version we used was 5.5. There should be at least a warning message or something in log files to give a bit information why a file is getting ignored..

how to configure JNDI for jetty

I had some trouble with setting up JNDI support for jetty. Here is my solution. Hopefully someone will find it useful. jetty plugin for maven in pom.xml <plugins>   ...     <plugin>       <groupId>org.mortbay.jetty</groupId>       <artifactId>maven-jetty-plugin</artifactId>       <version>6.1.5</version>       <configuration>         ...           <jettyEnvXml>${basedir}/etc/jetty/jetty-env.xml</jettyEnvXml>         ...       </configuration>     </plugin>   ... </plugins> And jetty-env.xml itself is following <?xml version="1.0"?> <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd"> <Configure class="org.mortbay.jetty.webapp.WebAppContext">   <New id="datasource" class="org.mortbay.jetty.plus.naming.Resource">     <Arg>jdbc/d

useful for tailing logs from remote host over http

A colleague showed me a tool for tailing logs if they are for example accessible only over HTTP. Pretty useful. Just use it with following command and you have logging action running on your local terminal.. > java -jar WebTail.jar http://host/path/to/log/file.log 10 Last number (10) in row indicates how ofter log will be refreshed. Enjoy!

replace relative URLs with absolute URLs

Like heading sais, our task is to replace relative URLs in HTML string with absolute URLs. We are using Java and regular expressions to solve this task. First we create a regular expression to find URLs we want to update (href=)("|')([^http].*?)("|') What it does? It tries to match all "href" attributes which are not starting with "http". It groups a match into groups. First part is attribute name with equal sign ("href="), then quotes (both single and double quotes could be used), then value of attribute and then again quotes. Next we have to create Java code to use given reg. expression. String replaceRelativeLinksWithAbsolute(String html, String url) {     Pattern p = Pattern.compile("(href=)(\"|')([^http].*?)(\"|')");     Matcher m = p.matcher(html);     StringBuffer sb = new StringBuffer();     boolean result = m.find();     while (result) {         m.appendReplacement(sb, createReplacement(ur

how to ignore files and folders in subversion?

I always forget how to ignore files and folder if I'm adding subversion support to a project. Why do I need it? For example, I do not want to add log files or customer related content (uploaded files etc.) into repository. It's quite simple. In command line type following command: svn propedit svn:ignore ./path/to/folder It's not end of process. With this command you set up ignore property for given path / folder. It will open a text editor, where you can specify what exactly should be ignored. With a * it will ignore all files and subfolder under specified folder. It is possible to describe multiple patterns, just like that.. *.log *.class tmp_files.* Go ahead and try it out!