19. February 2012

Tomcat 7 and curl – SSL23_GET_SERVER_HELLO:tlsv1 alert internal error

There is very annoying bug in Open SSL 1.0 which affects curl. When you try to access Tomcat 7 with https with curl you’ll get fancy error:

curl: (35) error:14077438:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert internal error

-k parameter is not working at all

You’re not able to invoke any request against Tomcat 7 with https in default configuration.

The solution is to restrict available ciphers in Tomcat’s https connector:

ciphers="SSL_RSA_WITH_RC4_128_SHA"

Restart Tomcat and curl will work.

10. January 2012

Debian Tomcat 7 – the trustAnchors parameter must be non-empty

I was deploying application on Tomcat7/OpenJDK. This application was accessing further secure services like SMTPS and HTTPS.

Tomcat was complaining that certificates are not correct (PKIX): the trustAnchors parameter must be non-empty.

Solution for Debian was quite easy after I found correct path to cacerts. Java cacerts for OpenJDK are stored in file: /etc/ssl/certs/java/cacerts.

To import certificate it is sufficient to use keytool:

keytool -import -keystore /etc/ssl/certs/java/cacerts -file cert.pem \
-alias ci.sinusgear.com

Then I restarted Tomcat and problem with trustAnchors disappeared.

28. December 2011

CGI server? Bash one-liner!

Author: Lordrat

By now you know, that when you need simple server to serve static pages just for you to play, you use Python’s SimpleHTTPServer.

But this time I wanted more: I wanted to to able to use serve images caught by my webcam. CGI server would be quick answer. While there is class in python doing that, I did not wanted to play with it. I needed something quick to do and maybe I was just little lazy to do so this day.

First thought: one window while cycle with cam-grabber, in the other window SimpleHTTPServer. Well, the solution lacked elegance, as it was not one-liner-styled enough. And then it occurred to me: why not use Netcat?

Building Blocks

 

At first, I needed to get data from camera. I had figured how to do that some time ago.

vgrabbj -i vga -d /dev/video0 -a -z 10 -q 100

Let’s just elaborate on that a little bit. vgrabbj takes `640×480` image from video4linux device `/dev/video0`, with enabled brightness adjustment, taking 10 images just to adjust, and using 100% quality of JPEG, and sending it to stdout.

Another building block is “server” to serve something that returned command. NetCat is our fiend. Little-bit of HTTP-fu is needed, but not much.

{ echo -ne 'HTTP/1.0 200 OK\r\nConnection: Close\r\n\r\n'; cat file; } | nc -l 1234

We will be serving JPEG, so we add appropriate HTTP header (unless you can see things in binary garbage).

Content-Type: image/jpeg

It may happen that file-size of image will cripple user’s comfort over slower network. What about speeding it up by sending response gzipped? We will need header

Content-Encoding: gzip

and we will have to use… you guessed it: gzip.

gzip -f

However, gzip will not reduce the size of JPEG much, as it already has entropy quite high. We can decrease quality of image i.g. by switch -q of vgrabbj, but in this case I would prefer ImageMagick for reasons that will become clear in a moment. Another possibility how to deal with this issue is scaling image down, which can be done here as well.

convert - -quality 75 -

It will also be nice to have a non-crippled copy of served file. Can do that: tee.

Serving repeatedly can be done by i.e. by while loop. Small functional enhancement: it will be nice to have so called “auto-refresh”. Adding one HTTP header will do that for us. Say every 5 seconds.

Refresh: 5

Some cooling enhancements? Server header:

Server: CoolServer!

Assembling

 

And now just put it all together.

while :; do { echo -ne 'HTTP/1.0 200 OK\r\nServer: Kwak!\r\nConnection: Close'\
'\r\nRefresh: 5\r\nContent-Type: image/jpeg\r\nContent-Encoding: gzip\r\n\r\n'\
; vgrabbj -i vga -d /dev/video0 -a -z 10 -q 100 | tee omg-`date +'%Y-%m-%d-%H'\
'%M%S'`.jpg | convert - -quality 75 - | gzip -f; } | nc -l 1234; done

Feel free to unwrap it ;-) .
And a non-one-liner (little bit more readable) version:

#!/bin/bash
PORT=1234
QUALITY=75
REFRESH=5
HEADER='HTTP/1.0 200 OK\r\n'
HEADER=$HEADER'Server: CoolServer!\r\n'
HEADER=$HEADER"Refresh: $REFRESH\r\n"
HEADER=$HEADER'Connection: Close\r\n'
HEADER=$HEADER'Content-Type: image/jpeg\r\n'
HEADER=$HEADER'Content-Encoding: gzip\r\n'
HEADER=$HEADER'\r\n'
while :; do
    {
        echo -ne "$HEADER"
        vgrabbj -i vga -d /dev/video0 -a -z 10 -q 100 \
        | tee omg-`date +'%Y-%m-%d-%H%M%S'`.jpg \
        | convert - -quality "$QUALITY" - \
        | gzip -f
    } \
    | nc -l "$PORT"
done

Notes

 

  • Some versions of nc may need to be called more like `nc -l -p 1234`.
  • First photo will be served from time you started script, every other from time the last shoot was taken. (Exercise for patient reader: why it is so? ;-) ). This might not be issue, as it speeds up reading of photo on request.
  • Previous can be solved by creating script, that can be called by nc on connection. That way you can create even interactive “CGI” script, that will read (and parse) input from std in and write response to stdout. Not all versions of nc are able to do that.
  • Another exercise: Will you be able to secure your communication using stunnel.

Enjoy ;-)

22. December 2011

How to disable stealing of focus by Console in Eclipse

There is one very annoying issue in Eclipse: stealing of focus by Console window.

Console window is displayed when you run application.

When you set focus to some other window like Search results and application prints something on output then Eclipse will automatically switch to Console window. Your search results are gone.

There is simple way how to get rid of such a behavior.

Go to Window -> Preferences -> Run/Debug -> Console. Uncheck options:

  • Show when program writes to standard out
  • Show when program writes to standard error

18. December 2011

WordPress TV

Good news for WordPress fans! WordPress has its own TV. :-)

Check out WordPress.TV.

Do you want to join some WordPress events around the world? Then check out WordCamp.org Central.

15. December 2011

How to define C++ macro with string content and pass it to MSbuild

Imagine that we have C++ project e.g. for Visual Studio 2008. It is possible to build this project just by msbuild command:

msbuild MyProject.vcproj /p:Configuration="Release"

Let say that we want to use #define in the source code. It is necessary to define it in Configuration Properties > C++ > Command Line:

/DSIMPLE_DEFINE

This just pass SIMPLE_DEFINE as flag.

How to deal with string define which should behave like string? E.g.:

#define URL "http://georgik.sinusgear.com"

The trick is in escaping quotes. We can add following define to Command Line:

/DURL=\"http://georgik.sinusgear.com\"

It will transform into .vcproj file:

AdditionalOptions="/DURL=\"http://georgik.sinusgear.com\""

Let’s make one more step.

How to acquire such a define from environment variable? E.g. with following build.bat file:

set URL="http://georgik.sinusgear.com"
msbuild MyProject.vcproj /p:Configuration="Release"

It requires only small modification of .vcproj file:

AdditionalOptions="/DURL=\"$(URL)\""

;-)

Small recap of flow: set env variable – pass it to XML – pass it compiler – pass it to code

11. December 2011

How to find conference?

There are many conferences around the world and it is hard to monitor them all.

I found useful site ConfRadar.com.

You just need to specify your favorite tags and you’ll get e-mail notification about conferences.

23. November 2011

Mintty – resizable terminal for Windows

Update 31.12. 2012: new version of Mintty (see discussion).

Cygwin is great tool for Windows.

E.g. You can create shell script to access windows share via //computer/share_name. This saves a lot of time when you’re domain admin and you need to maintain many computers.

The only BIG drawback of Cygwin for Windows was terminal window. When you work on Mac or Linux you can resize terminal window as you need. Terminal (CMD) for Windows sucks. In default installation you can resize just in one direction. The other option would be to mix Cygwin with PowerShell, but then many things are not working at all.

Good news! Great news! There is new terminal window in Cygwin 1.7.x. It’s application mintty.

Installer will create link to this app with name Cygwin Terminal. It will launch mintty process and you can resize window without problem.

It works fantastic! After so many yeaars it is now possible to use full power of Windows and Linux together in one bundle. (Yes, I know about other terminals like rxvt or X-based stuff, but it required always some extra steps).

Some computers were complaining that /Cygwin-Terminal.ico was not found and I was not able to launch terminal. Solution was easy. Right click on launcher icon and remove icon parameters from Target. The result target command should look like: C:\cygwin\bin\mintty.exe

Hooray! BIG thank you goes to authors of mintty for Windows.

Follow Mintty T.

14. November 2011

How to compare 2 or 3 directories on Windows

Sometimes you need to find out what is the difference between two or three directories.

This is quite easy task when you’re Linux user. You just start Kdiff3 and it’s done.

Good news! This incredibly worthy tool is available also for Windows.

Just download installer. Install application. Select two or three directories, invoke context menu by right click in file explorer and select KDiff3 – Compare.

:-)

13. November 2011

Apache Tomcat 7 Maven plugin

I was searching for Apache Tomcat 7 Maven plugin. I found only messages that no such thing exists and that I have to use some workaround. Finally I found link at StackOwerflow that pointed me to the testing version of  such a plugin.

You just need to configure repository and update mojo definition.

 <repositories>
    <repository>
      <id>people.apache.snapshots</id>
      <url>http://repository.apache.org/content/groups/snapshots-group/</url>
      <releases>
        <enabled>false</enabled>
      </releases>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </repository>
  </repositories>

  <pluginRepositories>
    <pluginRepository>
      <id>apache.snapshots</id>
      <name>Apache Snapshots</name>
      <url>http://repository.apache.org/content/groups/snapshots-group/</url>
      <releases>
        <enabled>false</enabled>
      </releases>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </pluginRepository>
  </pluginRepositories>
...
<plugin>
      <groupId>org.apache.tomcat.maven</groupId>
      <artifactId>tomcat7-maven-plugin</artifactId>
      <version>2.0-SNAPSHOT</version>
      <configuration>
        <path>/</path>
      </configuration>
    </plugin>

You can run Tomcat7 by: mvn tomcat7:run

You can read more about this new version of Tomcat Maven plugin at tomcat.apache.org.

This plugin is still under development.

BTW: List Maven plugins hosted at Apache.org is available at maven.apache.org/plugins.

  • Babel fish

      Translate from:

      Translate to:

  • Where’s the fish?

  • Starfish

  • Fish for you

  • Further info

  • Badges

  • Video channel

  • Learning

    Grow your brain.
  • Tags

  • Topics

  •  

    February 2012
    M T W T F S S
    « Jan    
     12345
    6789101112
    13141516171819
    20212223242526
    272829  
  • Comments