Skip to content

Instantly share code, notes, and snippets.

View iocanel's full-sized avatar

Ioannis Canellos iocanel

View GitHub Profile
@iocanel
iocanel / gist:1980361
Created March 5, 2012 18:59
Endpoint Manger delegation
HttpEndpoint endpoint;
public void setLocationURI(String locationURI) {
endpoint.setLocationURI(locationURI);
}
public String getLocationURI() {
return endpoint.getLocationURI();
}
@iocanel
iocanel / gist:1980371
Created March 5, 2012 19:00
Exporting managed attributes
@ManagedAttribute(description="Location URI")
public void setLocationURI(String locationURI) {
endpoint.setLocationURI(locationURI);
}
@ManagedAttribute
public String getLocationURI() {
return endpoint.getLocationURI();
}
@iocanel
iocanel / gist:1980379
Created March 5, 2012 19:01
JMX Managed Http Endpoint Manager
package net.iocanel.blog.servicemix.management;
import org.apache.servicemix.http.HttpEndpoint;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.jmx.export.annotation.ManagedAttribute;
import org.springframework.jmx.export.annotation.ManagedOperation;
import org.springframework.jmx.export.annotation.ManagedResource;
/**
* A simple spring bean that gets injected an HttpEndpoint and exposes it to jmx
@iocanel
iocanel / gist:1980387
Created March 5, 2012 19:02
Creating a table for endpoint configuration
CREATE TABLE `ENDPOINT_CONFIGURATION` (
`ENDPOINT_ID` varchar(80) NOT NULL,
`CONFIGURATION` text NOT NULL,
PRIMARY KEY (`ENDPOINT_ID`)
)
@iocanel
iocanel / gist:1980388
Created March 5, 2012 19:03
Endpoint configuration entity
package net.iocanel.blog.management.support.persistence;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;
@iocanel
iocanel / gist:1980393
Created March 5, 2012 19:04
Endpoint configuration persistence.xml
<persistence version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/persistence" xsi:schemalocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="ServiceMixManagementPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>net.iocanel.blog.management.support.persistence.EndpointConfiguration</class>
<properties>
<property name="hibernate.connection.username" value="username_here"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.password" value="password_here"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/blog"/>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
@iocanel
iocanel / gist:1980396
Created March 5, 2012 19:05
Endpoint configuration dao
package net.iocanel.blog.management.support.persistence;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.transaction.annotation.Transactional;
/**
*
* @author iocanel
@iocanel
iocanel / gist:1980401
Created March 5, 2012 19:07
Persisting endpoint to database as xml
protected ConfigurationDao configurationDao;
protected JAXBContext context;
@ManagedOperation(description = "Persist the endpoint configuration")
public void saveConfiguration() {
try {
StringWriter writer = new StringWriter();
BeanUtils.copyProperties(endpoint, data,ignore);
context.createMarshaller().marshal(data, writer);
configuration.setEndpointId(endpoint.getKey());
@iocanel
iocanel / gist:1980407
Created March 5, 2012 19:07
Interceptin endpoint start
/**
* Endpoint Start Interceptor
* Intercepts start method, load the configuration data of the endpoint and applies them to the endpoint.
* @param pjp
*/
@Around("execution(* start() )") //For the shake of simplicity
public void interceptEndpointStart(ProceedingJoinPoint pjp) {
if (pjp.getThis() instanceof Endpoint) {
try {
@iocanel
iocanel / gist:1980416
Created March 5, 2012 19:10
A generic Endpoint Manager
package net.iocanel.blog.management.support;
import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import net.iocanel.blog.management.support.persistence.ConfigurationDao;
import net.iocanel.blog.management.support.persistence.EndpointConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;