Mischiefblog
I make apps for other people

Fixing the Unknown Source error in Java

Posted by Chris Jones
On September 19th, 2016 at 16:32

Permalink | Trackback | Links In |

Comments Off on Fixing the Unknown Source error in Java
Posted in General

Given a Maven Java project with dependencies, you might come across a project (like I did) with very old dependencies.  In my case, I found references to OpenSAML 1.1b, a never really released POM that was included with older (2012 and earlier) versions of Aspero JASIG CAS.  While testing my replacement for the CAS server, I encountered cryptic DOM parsing errors.
Caused by: org.opensaml.SAMLException
at org.opensaml.SAMLException.getInstance(Unknown Source)
at org.opensaml.SAMLResponse.fromDOM(Unknown Source)
at org.opensaml.SAMLResponse.<init>(Unknown Source)
at org.jasig.cas.client.validation.Saml11TicketValidator.parseResponseFromServer(Saml11TicketValidator.java:51)

Neither running the server with a debugger attached nor running a unit test which duplicated the exception helped:  the breakpoints were ignored because the debugging symbols were stripped by the original ant build which produced the JAR.

(more…)

How I code Python with tests

Posted by Chris Jones
On November 19th, 2015 at 13:25

Permalink | Trackback | Links In |

Comments Off on How I code Python with tests
Posted in Python

Setting up the project and where to put the code

  1. Project creation

    I use virtualenv to create the project. If I’m using a different version of Python than the system default, I can specify the interpreter version when creating the environment.

    $ virtualenv -p /opt/local/bin/python2.7 my_project

  2. Environment activation

    Before I can do anything with the environment, I need to activate the environment.

    $ source myproject/bin/activate

  3. Installation of modules

    By default, virtualenv installs pip to allow me to download and install Python libraries in my environment. Depending on what I’m writing, I need to pick out libraries that are needed to complete the project.

    (more…)

HTTPS and self-signed certificates in Java

Posted by Chris Jones
On November 13th, 2015 at 07:02

Permalink | Trackback | Links In |

Comments Off on HTTPS and self-signed certificates in Java
Posted in Java
  1. You need a copy of the self-signed server certificate, typically an arm file.
  2. You need to add this certificate to a Java truststore (keystore)

        keytool -import -trustcacerts -file cert.arm -keystore clienttrust.jks

    Make a note about the password. You’ll be including it in the startup script so don’t reuse a personal password.

  3. Modify startup script to look to the truststore (with the password you set in the previous step)

        java -classpath ".:lib/*" $JVM_ARGS -Dlog4j.configuration=config/log4j.xml \
        -Djavax.net.ssl.trustStore=/path/clienttrust.jks -Djavax.net.ssl.trustStorePassword=password \
        -Djavax.net.ssl.trustStoreType=jks \
        com.company.path.ClassName "$@"

Troubleshooting

If you’re having HTTPS connection problems, add the following parameter to your startup script’s java command line:

    -Djavax.net.debug=ssl

Capturing CD-ROM insert events in Linux

Posted by Chris Jones
On March 24th, 2015 at 20:26

Permalink | Trackback | Links In |

Comments Off on Capturing CD-ROM insert events in Linux
Posted in Tech

I’ve been looking into how to capture CD-ROM (music CD) insert events for . . . reasons. Like I’ve got a big collection of CDs and I’d really like to rip them to FLAC files before jukeboxing the media. Now, I’ve looked into doing this on OS X (using the Disk Arbitration framework — this is relatively easy in Swift and Objective C but a bit harder from Go), and I’ve also considered how to capture the events in DBus on Linux/GNOME systems. However, I’m a stick in the mud when it comes to GNOME and I’ve pulled it off more than one machine because of the GNOME keystore and problems encountered because of that, so I’m reluctant to write anything that requires DBus when there’s a perfectly UI independent solution available: udev.
(more…)

Resizing or shrinking KVM virtual machine filesystems and disk images

Posted by Chris Jones
On September 16th, 2014 at 11:22

Permalink | Trackback | Links In |

Comments Off on Resizing or shrinking KVM virtual machine filesystems and disk images
Posted in General

Most everyone wants to increase the size of their disk images, filesystems, or virtual machines (VM). It’s common to create a small, minimal machine (2 GB in size) and increase it depending on the flavor or configuration of the deployed VM.

However, there are some cases where machines will need to be moved from large disk flavors to smaller flavors. Assuming the filesystem isn’t full or is minimal in size, you may be able to successfully resize the disk image so that it will fit on a smaller VM.
(more…)

nginx, Python 3 pyvenv, uwsgi, Flask, and OS X with MacPorts

Posted by Chris Jones
On August 26th, 2014 at 14:53

Permalink | Trackback | Links In |

Comments Off on nginx, Python 3 pyvenv, uwsgi, Flask, and OS X with MacPorts
Posted in Python

Given a working Flask web application called RarToZip (served from the built in HTTP server), this is the configuration I used on my MacBook to get nginx working as a proxy for uWSGI and Flask.
(more…)

Example cgo (Golang) app that calls a native library with a C structure

Posted by Chris Jones
On June 26th, 2014 at 12:47

Permalink | Trackback | Links In |

Comments Off on Example cgo (Golang) app that calls a native library with a C structure
Posted in General

Here’s a sample Go application that calls a native library. This uses cgo to link to the native library, pass a pointer to a C structure to a native function, and does it all from Go.

This example includes:

  • a Go main
  • a Go package
  • a static C library (shared libraries on OS X require tweaks to dyld)
  • instructions for compilation

(more…)

A Go (cgo) gotcha

Posted by Chris Jones
On June 24th, 2014 at 16:24

Permalink | Trackback | Links In |

Comments Off on A Go (cgo) gotcha
Posted in General

If you get a lot of errors like:

37: error: use of undeclared identifier 'create_message'

in your Go interface to a C library, double check your imports. You can’t use imports in the style:

/*
* #cgo CFLAGS: -I../libdir
* #cgo LDFLAGS: -L../libdir -lmylib
* #include "mylib.h"
*/
import (
"C"
"unsafe"
)

Instead, use each import on a separate line, or make the first import “C” so that cgo will pick up the header include:

/*
* #cgo CFLAGS: -I../libdir
* #cgo LDFLAGS: -L../libdir -lmylib
* #include "mylib.h"
*/
import "C"
import "unsafe"

Also, make sure that if you’re using a local shared library (.so) that you symlink it to a .so name:

$ gcc -c -fPIC mylib.c -o mylib.o
$ gcc -shared -W1,-soname,libmylib.so.1 -o libmylib.so.1.0.0 mylib.o
$ ln -s libmylib.so.1.0.0 libmylib.so

OMG Eclipse

Posted by Chris Jones
On March 19th, 2014 at 09:02

Permalink | Trackback | Links In |

Comments Off on OMG Eclipse
Posted in Java

I haven’t been using Eclipse since I worked at Amazon, except for a few short stints pulling configuration values from one project to another at Overstock. Now that I’m at IBM, the corporate home of the Eclipse Project, and on a project that requires it (because I can’t get the IntelliJ IDEA Rational Team Concert (RTC) plug-in to install correctly) I’m getting a chance to see just how bad parts of Eclipse are.

I’m missing:
* Search everywhere
* Being able to click a button to point to the current file in the project/workspace
* When creating new files, being able to scroll around and reference other files to maintain consistency in naming
* Find a file by name (not just a class name). I’ve got over 24,000 files in this project . . .

I can adapt to the keystrokes well enough, but I’d hate to see how Eclipse would dog on any less of a machine than the Lenovo W530 I’m using.

Mint VM setup

Posted by Chris Jones
On December 30th, 2013 at 13:13

Permalink | Trackback | Links In |

Comments Off on Mint VM setup
Posted in Java, Tech

On Windows, use VMWare. I’ve run into problems with Oracle VirtualBox and Windows networking, although it works very well on Linux.

On the Thinkpad T420s I needed to enable VT-x (Virtualization support) in the BIOS setup under the Security-Virtualization menu.

VM Configuration
For a Core i5 vPro with four cores, I assign:

  • Four GB of RAM
  • Two processors
  • 32 GB of disk in a single file

Distribution Choice
On my hardware (Thinkpad T420s) I’ve had problems with Fedora. Ubuntu derived distributions work fine, including Linux Mint. I’ll assume that you’re using Linux Mint 16 Petra 64-bit.

I’ll download the .iso version via BitTorrent. Both VMWare and VirtualBox can mount and use ISO files for VM installation, plus it boots significantly faster than physical media.
(more…)