JAX-RS writer interceptor works for every response even with NameBinding - jax-rs

I need to intercept a response from the server that was generated for a specific API call and change it.
I used the JAX-RS 'WriterInterceptor' for this and I have created a NameBinding as well. But the server is intercepting every response out from the server. What am I doing wrong here?
Shown below is the code I have tried. Why is the name binding does not work? (I have verified that when calling other API resources the particular method that I have use name binding is not called.)
Name Binding.
package com.example.common.cm.endpoint;
#Target({ElementType.TYPE, ElementType.METHOD})
#NameBinding
#Retention(RetentionPolicy.RUNTIME)
public #interface JSONtoJWT {}
The Interceptor.
package com.example.common.cm.endpoint;
#Provider
#JSONtoJWT
public class TestInterceptor implements WriterInterceptor {
private static final Log log = LogFactory.getLog(TestInterceptor.class);
#Override
public void aroundWriteTo(WriterInterceptorContext writerInterceptorContext) throws IOException, WebApplicationException {
log.info("interceptor invoked");
OutputStream outputStream = writerInterceptorContext.getOutputStream();
outputStream.write(("{\"message\": \"Message added in the writer interceptor in the server side\"}").getBytes());
writerInterceptorContext.setOutputStream(outputStream);
writerInterceptorContext.proceed();
log.info("Proceeded");
}
}
API Resource.
package com.example.cm.endpoint.u3.acc;
#Path("/u3/some-validation")
#Consumes({ "application/json; charset=utf-8" })
#Produces({ "application/json; charset=utf-8" })
public class SomeValidationApi {
#POST
#Path("/")
#JSONtoJWT
#Consumes({ "application/json; charset=utf-8" })
#Produces({ "application/json; charset=utf-8" })
public Response someValidationPost(#ApiParam(value = "validations post" ,required=true ) SomeValidationRequestDTO someValidationConsent)
{
return delegate.someValidationPost(someValidationConsent);
}
}
beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml"/>
<context:property-placeholder/>
<context:annotation-config/>
<bean class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer"/>
<bean class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer"/>
<jaxrs:server id="services" address="/">
<jaxrs:serviceBeans>
***Some other beans here***
<bean class="com.example.cm.endpoint.u3.acc.SomeValidationApi/>
</jaxrs:serviceBeans>
<jaxrs:providers>
<bean class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"/>
<bean class="com.example.common.cm.endpoint.TestInterceptor"/>
</jaxrs:providers>
</jaxrs:server>
</beans>
When I use the above every response from the server is intercepted and the message is added. But I want only the particular resource to invoke the Interceptor.
Also, Other than JAX-RS interceptor with writerInterceptor, are there any other good alternative to achieve this?

Related

Consume soap Service in Apache Camel

i want to consume soap web serivce in apache camel using Java DSL.Any way without CXF.i have already try using CXF with spring.
Here is a simple example that used only camel http without cxf. If you need to perform some modifications of SOAP request string you can just change "constant" to something like "spel".
<setBody><constant><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<MyAction>
<myparam>ABC</myparam>
</MyAction>
</soapenv:Body>
</soapenv:Envelope>]]></constant></setBody>
<setHeader headerName="SOAPAction"><constant>MySOAPAction</constant></setHeader>
<setHeader headerName="CamelHttpMethod"><constant>POST</constant></setHeader>
<setHeader headerName="Content-Type"><constant>text/xml;charset=UTF-8</constant></setHeader>
<to uri="http://myserver:1234" />
Same with Java DSL
public class MyRouteBuilder extends RouteBuilder {
public void configure() {
from("direct:start")
.setBody(constant("")) // String SOAP content from XML example
.setHeader("SOAPAction", constant("MySOAPAction"))
.setHeader("CamelHttpMethod", constant("POST"))
.setHeader("Content-Type", constant("text/xml;charset=UTF-8"))
.to("http://myserver:1234")
.log("SOAP service called"); // Here you can process service response
}
}

Arquillian - How to debug managed Wildfly container

I am using Arquillian to write black box tests for my RESTful application. I am actually capable of debug the test classes, but unable to debug my application classes. I would like to know exactly how to do that.
My arquillian.xml:
<arquillian xmlns="http://jboss.org/schema/arquillian"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://jboss.org/schema/arquillian
http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
<container qualifier="jbossas-managed" default="true">
<configuration>
<property name="jbossHome">D:\desenv\arquivos\servidores\wildfly-9.0.1.Final-test</property>
<property name="allowConnectingToRunningServer">true</property>
<property name="javaVmArguments">-Dorg.apache.deltaspike.ProjectStage=IntegrationTest</property>
</configuration>
</container>
One of my test classes:
#RunAsClient
#RunWith(Arquillian.class)
public class AuthenticationBlackBoxTest extends AbstractBlackBoxTest {
#Test
public void testInvalidCredentials(#ArquillianResource URL baseURI) {
Client client = ClientBuilder.newClient();
WebTarget target = client.target(baseURI.toString()).path("api/v1/auth");
Response response = target.request(MediaType.APPLICATION_JSON)
.post(Entity.entity(new Credentials("invalid", "invalid"), MediaType.APPLICATION_JSON));
Assert.assertEquals(401, response.getStatus());
response.close();
client.close();
}
#Test
public void testValidCredentials(#ArquillianResource URL baseURI) {
Client client = ClientBuilder.newClient();
WebTarget target = client.target(baseURI.toString()).path("api/v1/auth");
Entity<Credentials> credentialsEntity = Entity.entity(new Credentials("adm#adm.com", "123"), MediaType.APPLICATION_JSON);
Response response = target.request(MediaType.APPLICATION_JSON)
.post(credentialsEntity);
Assert.assertEquals(200, response.getStatus());
response.close();
client.close();
}
}
Inside arquillian.xml for javaVmArguments element add -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y.
Then in your favourite IDE you have to define a new Remote Debug configuration where you specify the host(localhost), port(8787). Place your break point, then run your test and finally start the remote debug. Official doc here.

Red5 Live Streaming using Air to IOS client

Hi i have a Red5 Application Server running and a NetConnection using Air to IOS to connect to the Red5 Application Server.
But the problem is that i get an error like:
2014-07-01 04:43:04,475 [NioProcessor-6] ERROR o.r.server.service.ServiceInvoker - Method addSomething with parameters [2, 3] not found in org.red5.server.CoreHandler#ebf5a1
I understand that the Method is not being called for some reason but can understand why, can anyone help please?
CODE
SERVERSIDE
package com;
import java.util.HashMap;
import org.red5.server.adapter.ApplicationAdapter;
import org.red5.server.api.IConnection;
import org.red5.server.api.Red5;
import org.red5.server.api.scope.IScope;
import org.red5.server.api.service.*;
import static java.lang.System.*;
import java.util.Stack;
public class Application extends ApplicationAdapter{
//private static final Log log = LogFactory.getLog( Application.class );
public boolean appStart(IScope scope){
out.println("Adding: ");
return true;
}
public void appStop(){
out.println("Adding: ");
// This function fires when the app is closing
}
public double addSomething(double a, double b){
// This is a method we will call from our flash client
out.println("Adding: "+a+" + "+b);
return a+b;
}
public boolean connect(IConnection conn, IScope scope, Object[] params) {
// This is the master connection method called every time someone connects
// to the server.
out.println("Adding: ");
//ServiceUtils.invokeOnAllConnections(scope, "joinuser", null);
return true;
}
/*
* (non-Javadoc)
* #see org.red5.server.adapter.ApplicationAdapter#disconnect(org.red5.server.api.IConnection, org.red5.server.api.IScope)
* disconnect an user form the chat and notify all others users
*/
public void disconnect(IConnection conn, IScope scope) {
// Function called every time someone disconnects from the server.
//ServiceUtils.invokeOnAllConnections(scope, "removeuser",null );
super.disconnect(conn, scope);
}
}
CLIENT
------
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.events.NetStatusEvent;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.media.Camera;
import flash.media.Microphone;
import flash.media.Video;
import flash.net.Responder;
var nc:NetConnection;
var good:Boolean;
var netOut:NetStream;
var netIn:NetStream;
var cam:Camera;
var mic:Microphone;
var responder:Responder;
var r:Responder;
var vidOut:Video;
var vidIn:Video;
var outStream:String;
var inStream:String;
trace("hello");
var rtmpNow:String="rtmp://localhost/Test1";
nc=new NetConnection;
nc.client = this;
nc.connect(rtmpNow,"trik");
nc.addEventListener(NetStatusEvent.NET_STATUS,getStream);
function getStream(e:NetStatusEvent):void
{
good=e.info.code == "NetConnection.Connect.Success";
if(good)
{
trace("hello");
// Here we call functions in our Java Application
//responder=new Responder(streamNow);
r = new Responder(adder);
nc.call("addSomething",r,2,3);
//nc.call("streamer",responder,"test");
}
}
function adder (obj:Object):void{
trace("Total = ",obj.toString());
}
function streamNow(streamSelect:Object):void
{
setCam();
setMic();
setVid();
trace("We've got our object",streamSelect.toString());
switch(streamSelect.toString())
{
case "left" :
outStream="left";
inStream="right";
break;
case "right" :
outStream="right";
inStream="left";
break;
}
//Publish local video
netOut=new NetStream(nc);
netOut.attachAudio(mic);
netOut.attachCamera(cam);
vidOut.attachCamera(cam);
netOut.publish(outStream, "live");
//Play streamed video
netIn=new NetStream(nc);
vidIn.attachNetStream(netIn);
netIn.play(inStream);
}
function setCam():void
{
cam=Camera.getCamera();
cam.setMode(240,180,15);
cam.setQuality(0,85);
}
function setMic():void
{
mic=Microphone.getMicrophone();
mic.rate=11;
mic.setSilenceLevel(12,2000);
}
function setVid():void
{
vidOut=new Video(240,180);
addChild(vidOut);
vidOut.x=25;
vidOut.y=110;
vidIn=new Video(240,180);
addChild(vidIn);
vidIn.x=vidOut.x+260;
vidIn.y=110;
}
RED5 PROPERTIES FILE
--------------------
webapp.contextPath=/Test1
webapp.virtualHosts=localhost, localhost:5080
RED5 WEB XML FILE
-----------------
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:lang="http://www.springframework.org/schema/lang"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd">
<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="/WEB-INF/red5-web.properties" />
</bean>
<bean id="web.context" class="org.red5.server.Context" autowire="byType" />
<bean id="web.handler" class="com.Application" />
<bean id="web.scope" class="org.red5.server.scope.WebScope" init-method="register">
<property name="server" ref="red5.server" />
<property name="parent" ref="global.scope" />
<property name="context" ref="web.context" />
<property name="handler" ref="global.handler" />
<property name="contextPath" value="${webapp.contextPath}" />
<property name="virtualHosts" value="${webapp.virtualHosts}" />
</bean>
</beans>
RED5 WEB XML FILE
-----------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns
/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>Test1</display-name>
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>/Test1</param-value>
</context-param>
<listener>
<listener-class>org.red5.logging.ContextLoggingListener</listener-class>
</listener>
<filter>
<filter-name>LoggerContextFilter</filter-name>
<filter-class>org.red5.logging.LoggerContextFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LoggerContextFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<security-constraint>
<web-resource-collection>
<web-resource-name>Forbidden</web-resource-name>
<url-pattern>/streams/*</url-pattern>
</web-resource-collection>
<auth-constraint/>
</security-constraint>
</web-app>
The issues is that the "numbers" are not coming to the server as the expected type of "double". There are several solutions to this:
Change the parameter type on your addSomething method to int.
Send your parameters from the client with a decimal point (2.0 vs 2)

Title changed to: Issues with Mule JPA module

I am trying to integrate Hibernate with Mule. Does Mule support Hibernate Transport ?
Hi #David,
I have tried to work with Mule JPA module. But I am facing Below issues. Kindly help me.
Here is my applicationContect.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- Connection Pool -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${jdbc.driverClass}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<!-- JPA EntityManagerFactory -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:dataSource-ref="dataSource">
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="${jdbc.database}"/>
<property name="showSql" value="${jdbc.showSql}"/>
</bean>
</property>
</bean>
<!-- Transaction manager for a single JPA EntityManagerFactory (alternative to JTA) -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref="entityManagerFactory"/>
<!-- Activates various annotations to be detected in bean classes for eg #Autowired-->
<context:annotation-config/>
<!-- enable the configuration of transactional behavior based on annotations -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<!-- Property Configurator -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="jdbc.properties"/>
</bean>
<context:component-scan base-package="com.test.dao"/>
<bean id="contactService" class="com.test.service.ContactServiceImpl"/>
</beans>
and this is my mflow file
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jpa="http://www.mulesoft.org/schema/mule/jpa"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/jpa http://www.mulesoft.org/schema/mule/jpa/current/mule-jpa.xsd">
<spring:beans>
<spring:import resource="classpath:applicationContext.xml" />
</spring:beans>
<jpa:config name="Java_Persistence_API" entityManagerFactory-ref="entityManagerFactory" doc:name="Java Persistence API"/>
<flow name="jpa-exampleFlow1" doc:name="jpa-exampleFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
<!-- code to be written -->
<logger level="INFO" doc:name="Logger"/>
</flow>
</mule>
this is my entity class
package com.test.entities;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.*;
import com.test.vo.Contact;
import com.test.vo.ContactVO;
#Entity
#Table(name="contact")
public class ContactEO implements Contact{
#Transient
Contact contact;
#Transient
public Contact getContact() {
return contact;
}
public void setContact(Contact contact) {
this.contact = contact;
}
public ContactEO(){
contact = new ContactVO();
}
public ContactEO(Contact contact){
this.contact = contact;
}
#Column(name="FIRSTNAME")
public String getFirstName() {
return contact.getFirstName();
}
public void setFirstName(String firstName) {
contact.setFirstName(firstName);
}
#Column(name="LASTNAME")
public String getLastName() {
return contact.getLastName();
}
public void setLastName(String lastName) {
contact.setLastName(lastName);
}
#Column(name="EMAIL")
public String getEmail() {
return contact.getEmail();
}
public void setEmail(String email) {
contact.setEmail(email);
}
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name="ID")
public long getId() {
return contact.getId();
}
public void setId(long id) {
contact.setId(id);
}
}
Getting below Exception Please let me know the solution.
Exception in thread "main"
org.mule.module.launcher.DeploymentInitException: IllegalAccessError:
tried to access method org.hibernate.engine.CascadeStyle.()V
from class org.hibernate.engine.EJB3CascadeStyle$1 at
org.mule.module.launcher.application.DefaultMuleApplication.init(DefaultMuleApplication.java:219)
at
org.mule.module.launcher.application.ApplicationWrapper.init(ApplicationWrapper.java:64)
at
org.mule.module.launcher.DefaultMuleDeployer.deploy(DefaultMuleDeployer.java:47)
at
org.mule.tooling.server.application.ApplicationDeployer.main(ApplicationDeployer.java:127)
Caused by: org.mule.api.config.ConfigurationException: Error creating
bean with name 'entityManagerFactory' defined in class path resource
[applicationContext.xml]: Invocation of init method failed; nested
exception is java.lang.IllegalAccessError: tried to access method
org.hibernate.engine.CascadeStyle.()V from class
org.hibernate.engine.EJB3CascadeStyle$1
(org.mule.api.lifecycle.InitialisationException)
(org.mule.api.config.ConfigurationException) at
org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:52)
at
org.mule.config.builders.AbstractResourceConfigurationBuilder.configure(AbstractResourceConfigurationBuilder.java:78)
at
org.mule.context.DefaultMuleContextFactory.createMuleContext(DefaultMuleContextFactory.java:84)
at
org.mule.module.launcher.application.DefaultMuleApplication.init(DefaultMuleApplication.java:207)
... 3 more Caused by: org.mule.api.config.ConfigurationException:
Error creating bean with name 'entityManagerFactory' defined in class
path resource [applicationContext.xml]: Invocation of init method
failed; nested exception is java.lang.IllegalAccessError: tried to
access method org.hibernate.engine.CascadeStyle.()V from class
org.hibernate.engine.EJB3CascadeStyle$1
(org.mule.api.lifecycle.InitialisationException) at
org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:52)
at
org.mule.config.builders.AbstractResourceConfigurationBuilder.configure(AbstractResourceConfigurationBuilder.java:78)
at
org.mule.config.builders.AutoConfigurationBuilder.autoConfigure(AutoConfigurationBuilder.java:101)
at
org.mule.config.builders.AutoConfigurationBuilder.doConfigure(AutoConfigurationBuilder.java:57)
at
org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:46)
... 6 more Caused by: org.mule.api.lifecycle.InitialisationException:
Error creating bean with name 'entityManagerFactory' defined in class
path resource [applicationContext.xml]: Invocation of init method
failed; nested exception is java.lang.IllegalAccessError: tried to
access method org.hibernate.engine.CascadeStyle.()V from class
org.hibernate.engine.EJB3CascadeStyle$1 at
org.mule.registry.AbstractRegistry.initialise(AbstractRegistry.java:117)
at
org.mule.config.spring.SpringXmlConfigurationBuilder.createSpringRegistry(SpringXmlConfigurationBuilder.java:119)
at
org.mule.config.spring.SpringXmlConfigurationBuilder.doConfigure(SpringXmlConfigurationBuilder.java:73)
at
org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:46)
... 10 more Caused by:
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'entityManagerFactory' defined in class path
resource [applicationContext.xml]: Invocation of init method failed;
nested exception is java.lang.IllegalAccessError: tried to access
method org.hibernate.engine.CascadeStyle.()V from class
org.hibernate.engine.EJB3CascadeStyle$1 at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1486)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at
org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1117)
at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:922)
at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at
org.mule.config.spring.SpringRegistry.doInitialise(SpringRegistry.java:89)
at
org.mule.registry.AbstractRegistry.initialise(AbstractRegistry.java:109)
... 13 more Caused by: java.lang.IllegalAccessError: tried to access
method org.hibernate.engine.CascadeStyle.()V from class
org.hibernate.engine.EJB3CascadeStyle$1 at
org.hibernate.engine.EJB3CascadeStyle$1.(EJB3CascadeStyle.java:24)
at
org.hibernate.engine.EJB3CascadeStyle.(EJB3CascadeStyle.java:19)
at
org.hibernate.ejb.event.EJB3PersistEventListener.(EJB3PersistEventListener.java:19)
at
org.hibernate.ejb.EventListenerConfigurator.(EventListenerConfigurator.java:81)
at
org.hibernate.ejb.Ejb3Configuration.(Ejb3Configuration.java:136)
at
org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:130)
at
org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:225)
at
org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:308)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1545)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1483)
... 24 more
What about the JPA connector: http://www.mulesoft.org/connectors/jpa-connector ?

How to Define Prototype Interceptors with DefaultAdvisorAutoProxyCreator in Spring.NET

I am new to Spring.NET and am just playing around trying different things out. As part of my testing, I created a simple object:
public interface ICommand {
void Execute(object context);
}
with one implementation:
public class ServiceCommand : ICommand {
public ServiceCommand() {
Console.WriteLine("########## {0} ##########", GetType().Name);
}
public void Execute(object context) {
Console.WriteLine("Service implementation: {0}.{1}", GetType().Name, MethodBase.GetCurrentMethod().Name);
}
}
Finally, I've a simple before advice as follows:
public class ConsoleLoggingBeforeAdvice : IMethodBeforeAdvice {
public ConsoleLoggingBeforeAdvice() {
Console.WriteLine("########## {0} ##########", GetType().Name);
}
public void Before(MethodInfo method, object[] args, object target) {
Console.WriteLine("Intercepted call to this method: {0}", method.Name);
Console.WriteLine(" The target is : {0}", target);
Console.WriteLine(" The arguments are : ");
if (args != null) {
foreach (object arg in args) {
Console.WriteLine("\t: {0}", arg);
}
}
}
}
As you can see, much of this stuff is from the Spring.NET quick start samples.
So, I configured the ServiceCommand to be wrapped in a ConsoleLoggingBeforeAdvice via ProxyFactoryObject and marked both the objects as prototype (see config below). This works as expected: each time we request a ServiceCommand, a new instance of both the object and associated interceptor is created:
<?xml version="1.0" encoding="utf-8"?>
<objects xmlns="http://www.springframework.net">
<object id="ConsoleLoggingBeforeAdvice" type="Spring.Aop.Support.DefaultPointcutAdvisor" singleton="false">
<property name="Advice">
<object type="Spring.Examples.AopQuickStart.ConsoleLoggingBeforeAdvice"/>
</property>
</object>
<object id="ServiceCommandTarget" type="Spring.Examples.AopQuickStart.ServiceCommand" singleton="false"/>
<object id="ServiceCommand" type ="Spring.Aop.Framework.ProxyFactoryObject">
<property name="IsSingleton" value="false"/>
<property name="TargetName" value="ServiceCommandTarget"/>
<property name="InterceptorNames">
<list>
<value>ConsoleLoggingBeforeAdvice</value>
</list>
</property>
</object>
</objects>
However, when I try to achieve the same results via DefaultAdvisorAutoProxyCreator, everything works except that the interceptor is always created as Singleton (even though it's configured as singleton="false"). The config is as follows:
<?xml version="1.0" encoding="utf-8"?>
<objects xmlns="http://www.springframework.net">
<object id="ConsoleLoggingBeforeAdvice" type="Spring.Aop.Support.DefaultPointcutAdvisor" singleton="false">
<property name="Advice">
<object type="Spring.Examples.AopQuickStart.ConsoleLoggingBeforeAdvice"/>
</property>
</object>
<object id="ServiceCommand" type="Spring.Examples.AopQuickStart.ServiceCommand" singleton="false"/>
<object type="Spring.Aop.Framework.AutoProxy.DefaultAdvisorAutoProxyCreator"/>
</objects>
Now, how can I ensure that both the object and associated interceptor are treated as prototypes by DefaultAdvisorAutoProxyCreator?
OK, I've figured out that setting InterceptorNames on DefaultAdvisorAutoProxyCreator will correctly instantiate interceptors as prototypes (if they're configured so). But this somehow feels incorrect as the DefaultAdvisorAutoProxyCreator should be able to pick interceptors from advisors and honor their configuration settings.
I am still not 100% clear on how to create prototype interceptors under different scenrarios. For example, all my attempts to create thread-scoped interceptors while using DefaultAdvisorAutoProxyCreator have failed.
Anyways, here's the xml config that works for me:
<?xml version="1.0" encoding="utf-8"?>
<objects xmlns="http://www.springframework.net" default-autowire="constructor">
<object id="ConsoleLoggingBeforeAdvice" type="Spring.Aop.Support.DefaultPointcutAdvisor" singleton="false">
<property name="Advice">
<object type="Spring.Examples.AopQuickStart.ConsoleLoggingBeforeAdvice"/>
</property>
</object>
<object id="ServiceCommand" type="Spring.Examples.AopQuickStart.ServiceCommand" singleton="false"/>
<object type="Spring.Aop.Framework.AutoProxy.DefaultAdvisorAutoProxyCreator">
<property name="InterceptorNames" value="ConsoleLoggingBeforeAdvice"/>
</object>
</objects>
I am totally confused with the idea of creating prototype interceptors. Are interceptors supposed to be or recommended to be prototypes at all or should they always be singletons?