Watch out when you pool things!

Last two weeks our operations team had to do daily restarts of a site that has between 800K to 1M hits per day. At a certain point, the webservers couldn’t take more connections, died and had to be restarted.

To detect the problem they tried to simulate the same behaviour on an a staging environment but we never succeeded in bringing those down. It took the team two weeks to simulate the exact same behaviour. Which in fact was a combination of a back end search service that performed a re-indexing operation and a bug in the client used to request data from that engine. ( A search request to the search engine happens with 7 on 10 of the hits)
At a certain point of the indexing the search engine started to spit out exceptions responses instead of the only expected result response. The application code that requests data from that search engine was recently changed to use a pool of JAXB Unmarshallers from javax.xml.bind.JAXBContext instead of creating new unmarshallers on the fly.
As you may know, or may not know and then you know now, Continue reading “Watch out when you pool things!”

A small survey about logging in Java

Help me conduct a small survey about logging in the Java Eco System!

Fill in the survey! Results will be published in the next month.

Swagger JAXB

JAXB XJC Plugin for automatically adding annotations from Swagger to generated classes from an XSD. I’ve created this when I noticed that for very complex schemas when there are references that stack the Swagger UI Javascript gave Stackoverflow errors, adding the annotations manually to the generated classes fixed it. But: you don’t want to change generated code huh! Thus swagger-jaxb emerged from the need to add swagger annotations automatically.

Please note this plugin is in development phase !! Currently only available with maven through the sonatype snapshot repositories. It is not complete and there are some open issues, but you can already use it.

Is all going well ?

Tests run in separate project, but do they work ? see here for the code https://github.com/redlab/swagger-jaxb-tck

How to use it?

  • build the plugin with maven and install it in your local repo or get it from an external repo like sonatypes snapshot repository
  • add the plugin to your classpath and use -swaggify on your jaxb command line or use it with jaxb2-maven-plugin
<plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>jaxb2-maven-plugin</artifactId>
        <version>1.5</version>
        <executions>
                <execution>
                <id>internal.generate</id>
                <goals>
                    <goal>xjc</goal>
                </goals>
                <configuration>
                    <arguments>-swaggerify</arguments>
                    <clearOutputDir>true</clearOutputDir>
                    <schemaDirectory>${project.basedir}/src/main/resources/xsd//api</schemaDirectory>
                    <packageName>com.example.api.model</packageName>
                    <staleFile>${project.build.directory}/generated-sources/jaxb/.api.internal</staleFile>
                </configuration>
            </execution>
        </executions>
        <dependencies>
            <dependency>
                <groupId>javax.xml.parsers</groupId>
                <artifactId>jaxp-api</artifactId>
                <version>1.4.5</version>
            </dependency>
            <dependency>
                <groupId>com.sun.xml.parsers</groupId>
                <artifactId>jaxp-ri</artifactId>
                <version>1.4.5</version>
            </dependency>
            <dependency>
                <groupId>com.sun.xml.bind</groupId>
                <artifactId>jaxb-xjc</artifactId>
                <version>2.2.7-b53</version>
            </dependency>
            <dependency>
                <groupId>com.sun.xml.bind</groupId>
                <artifactId>jaxb-impl</artifactId>
                <version>2.2.7-b53</version>
            </dependency>
            <dependency>
                <groupId>be.redlab.jaxb</groupId>
                <artifactId>swagger-jaxb</artifactId>
                <version>0.0.1-SNAPSHOT</version>
            </dependency>
        </dependencies>
    </plugin>

The plugin dependencies are needed until the JAXB2 plugin is updated to use the latest version of jaxb-xjc and jaxp. Otherwise the code generation will fail due to missing methods. Note: I think this will change the generated code for boolean getters/setters, not fully sure I must verify it to be sure 🙂

post an issue at github if you really want dev version in Maven Central.