Skip to content

Instantly share code, notes, and snippets.

View mpellegrini's full-sized avatar

Michael Pellegrini mpellegrini

View GitHub Profile
@mpellegrini
mpellegrini / drools-printkb.java
Created August 31, 2011 00:24
Prints out JBoss Rules or Drools KnowledgeBase contents to the console
// Prints out KnowledgeBase contents to the console
Collection<KnowledgePackage> pkgs = kbase.getKnowledgePackages();
for (KnowledgePackage pkg : pkgs) {
System.out.println("* " + pkg.getName());
Collection<Rule> rules = pkg.getRules();
for (Rule rule : rules) {
System.out.println(" - " + rule.getName());
}
@mpellegrini
mpellegrini / KnowledgeAgentConfig.java
Created November 4, 2011 17:51
Configuring a Drools KnowledgeAgent
KnowledgeAgentConfiguration agentConf = KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
agentConf.setProperty("drools.agent.newInstance", "false");
// scan every second
ResourceChangeScannerConfiguration config = ResourceFactory.getResourceChangeScannerService().newResourceChangeScannerConfiguration();
config.setProperty("drools.resource.scanner.interval", "1");
ResourceFactory.getResourceChangeScannerService().configure(config);
KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent("problem", agentConf);
@mpellegrini
mpellegrini / jboss-as71_remotejndi.java
Created February 23, 2012 13:57
Remote JNDI Support in JBoss AS 7.1
// Create an initial context to perform the JNDI lookup.
final Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, org.jboss.naming.remote.client.InitialContextFactory.class.getName());
env.put(Context.PROVIDER_URL, "remote://localhost:4447");
env.put(Context.SECURITY_PRINCIPAL, "username");
env.put(Context.SECURITY_CREDENTIALS, "password");
Context context = new InitialContext(env);
// JNDI Lookups
ConnectionFactory cf = (ConnectionFactory) context.lookup("jms/RemoteConnectionFactory");
@mpellegrini
mpellegrini / JMSClient.java
Created February 23, 2012 14:40
Example JMS Client to Produce and Consume Messages
// Step 1. Create an initial context to perform the JNDI lookup.
final Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, org.jboss.naming.remote.client.InitialContextFactory.class.getName());
env.put(Context.PROVIDER_URL, "remote://localhost:4447");
env.put(Context.SECURITY_PRINCIPAL, "username");
env.put(Context.SECURITY_CREDENTIALS, "password");
Context context = new InitialContext(env);
// Step 2. Lookup the connection factory
ConnectionFactory cf = (ConnectionFactory) context.lookup("jms/RemoteConnectionFactory");
@mpellegrini
mpellegrini / pom.xml
Last active July 11, 2019 06:48
maven-jaxb21-plugin with fluent-api
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb21-plugin</artifactId>
<version>0.8.3</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
@mpellegrini
mpellegrini / maven-jaxb-schemagen-plugin.xml
Last active December 11, 2018 11:32
maven-jaxb-schemagen-plugin config
<plugin>
<groupId>com.sun.tools.jxc.maven2</groupId>
<artifactId>maven-jaxb-schemagen-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
@mpellegrini
mpellegrini / maven-jaxws-plugin_withClientJar.xml
Last active November 3, 2016 19:51
Generate WSDL First using -clientjar option. Also unzips the modified artifacts to be packaged in the WAR
<build>
<plugins>
<plugin>
<!--
Generates JAXWS classes for all of the WSDL files in $[project.base.dir}/src/wsdl.
-->
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.3</version>
<executions>
@mpellegrini
mpellegrini / JacksonJsonSchemaGenerator.java
Last active March 18, 2020 13:03
Generate JSON Schema using Jackson
public static void main(String[] args) throws Exception {
ObjectMapper mapper = new ObjectMapper();
JsonSchemaGenerator generator = new JsonSchemaGenerator(mapper);
JsonSchema jsonSchema = generator.generateSchema(Subscription.class);
StringWriter json = new StringWriter();
mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
mapper.writeValue(json, jsonSchema);
System.out.println(json.toString());
@mpellegrini
mpellegrini / CDIEventExtension.java
Created March 25, 2014 12:22
An example CDI Extension that observes all events
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.spi.AfterBeanDiscovery;
import javax.enterprise.inject.spi.AfterDeploymentValidation;
import javax.enterprise.inject.spi.BeforeBeanDiscovery;
import javax.enterprise.inject.spi.BeforeShutdown;
import javax.enterprise.inject.spi.Extension;
import javax.enterprise.inject.spi.ProcessAnnotatedType;
@mpellegrini
mpellegrini / beans.xml
Created March 25, 2014 12:27
Empty beans.xml marker resource for CDI support
<!--
For WAR files, use WEB-INF/beans.xml. In a Maven WAR module, this will be src/main/webapp/WEB-INF/beans.xml.
For EJB-JAR files or ordinary JAR files, use META-INF/beans.xml. In a Maven module, this will be src/main/resources/META-INF/beans.xml.
-->
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">