camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From boriss <bstan...@eunet.rs>
Subject Re: UnitOfWork
Date Thu, 04 Dec 2008 11:31:04 GMT

Hi Claus, thanks for the response. 

The route to reproduce this case:


import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.non_wrapper.types.GetPerson;
import org.apache.camel.non_wrapper.types.GetPersonResponse;
import org.apache.camel.processor.DelegateProcessor;
import org.apache.cxf.message.MessageContentsList;


public class RouteBuilderCxfTracer extends RouteBuilder{
    @Override
    public void configure() throws Exception {        
    	from("cxf:http://localhost:9000/PersonService/" +
    	        "?serviceClass=org.apache.camel.non_wrapper.Person" +
    	       
"&serviceName={http://camel.apache.org/non-wrapper}PersonService" +
    	        "&portName={http://camel.apache.org/non-wrapper}soap" +
    	        "&dataFormat=POJO")
    		.intercept(new MyDelegate())
    		.to("direct:something");

        from("direct:something")
            .process(new DoSomethingProcessor())
            .process(new DoNothingProcessor());
    	
    }
    
    private class DoSomethingProcessor implements Processor{
        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getOut().setBody(exchange.getIn().getBody() + "
world!");        
        }
    }
    
    private class DoNothingProcessor implements Processor{
        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getOut().setBody(exchange.getIn().getBody());        
        }
    }
    
    private class MyDelegate extends DelegateProcessor{        
        @Override
        protected void processNext(Exchange e) throws Exception {
            MessageContentsList mclIn = (MessageContentsList)
e.getIn().getBody();
            e.getIn().setBody(((GetPerson) mclIn.get(0)).getPersonId(),
String.class);
            
            super.processNext(e);           
            
            GetPersonResponse gpr = new GetPersonResponse();
            gpr.setName("Bill");
            gpr.setPersonId(e.getOut().getBody(String.class));
            gpr.setSsn("Test");
            
            MessageContentsList mclOut = new MessageContentsList();
            mclOut.set(0, gpr);
            e.getOut().setBody(mclOut, MessageContentsList.class);
        }
    }
}

the corresponding context (I have named it 'context-jira.xml'):

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:camel="http://activemq.apache.org/camel/schema/spring"
       xmlns:jaxws="http://cxf.apache.org/jaxws"
       xmlns:http="http://cxf.apache.org/transports/http/configuration"
      
xmlns:httpj="http://cxf.apache.org/transports/http-jetty/configuration"
       
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
       http://activemq.apache.org/camel/schema/spring
http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
       http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
       http://cxf.apache.org/transports/http-jetty/configuration
http://cxf.apache.org/schemas/configuration/http-jetty.xsd
       http://cxf.apache.org/transports/http/configuration
http://cxf.apache.org/schemas/configuration/http-conf.xsd
       http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
	   http://www.springframework.org/schema/lang
http://www.springframework.org/schema/lang/spring-lang-2.5.xsd
	   http://activemq.apache.org/camel/schema/spring
http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
    ">

    <camel:camelContext id="camelJiraContext">
        <camel:jmxAgent id="agent" disabled="true" />
    </camel:camelContext>

	<bean id="camelTracer"
class="org.apache.camel.processor.interceptor.Tracer">
		<property name="enabled" value="true"/>
    	<property name="traceExceptions" value="true"/>
    	<property name="traceInterceptors" value="true"/>
    	<property name="logLevel" value="INFO"/>
	</bean>
	
	<bean id="traceFormatter"
class="org.apache.camel.processor.interceptor.TraceFormatter">
    	<property name="showBody" value="true"/>
    	<property name="showBodyType" value="true"/>
    	<property name="showProperties" value="true"/>
    	<property name="showHeaders" value="true"/>
	</bean>

    <bean id="producerTemplate" 
        factory-bean="camelJiraContext"
        factory-method="createProducerTemplate">
    </bean>
  
  	<bean class="RouteBuilderCxfTracer"/>
</beans>


And finally the Testcase. Of course there should be also some log4j
configuration in the classpath.


@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/context-jira.xml" })
@TestExecutionListeners( { DependencyInjectionTestExecutionListener.class })
public class TestJiraRoute {
	

	@Test
	public void testJiraRoute() throws Exception{
        URL wsdlURL = new URL("http://localhost:9000/PersonService/?wsdl");
        PersonService ss = new PersonService(wsdlURL, new
QName("http://camel.apache.org/non-wrapper", "PersonService"));
        Person client = ss.getSoap();
        GetPerson request = new GetPerson();
        request.setPersonId("hello");
        GetPersonResponse response = client.getPerson(request);

        assertEquals("we should get the right answer from router", "Bill",
response.getName());
        assertEquals("we should get the right answer from router", "Test",
response.getSsn());
        assertEquals("we should get the right answer from router", "hello
world!", response.getPersonId());

	}
}



Cheers,
Boris


Claus Ibsen-2 wrote:
> 
> Hi
> 
> Do you mind posting the route that causes this bug?
> 
> And we should have it in JIRA so we can get it fixed.
> 
> 
> /Claus Ibsen
> Apache Camel Committer
> Blog: http://davsclaus.blogspot.com/
> 
> 
> 
> On Thu, Dec 4, 2008 at 9:48 AM, boriss <bstanoje@eunet.rs> wrote:
>>
>> Hi,
>>
>> I tried to configure my Camel-Route with TraceInterceptor, but when I use
>> it
>> I'm getting the Exception like:
>>
>> java.lang.NullPointerException
>>        at
>> org.apache.camel.processor.interceptor.TraceFormatter.getBreadCrumbID(TraceFormatter.java:150)
>>        at
>> org.apache.camel.processor.interceptor.TraceFormatter.format(TraceFormatter.java:45)
>>        at
>> org.apache.camel.processor.interceptor.TraceInterceptor.format(TraceInterceptor.java:94)
>>
>> Without Tracer everything works just fine.
>>
>> So I started to trace the problem myself, and found out that some
>> Exchange
>> implementations like CxfExchange in it's constructor doesn't copy the
>> UnitOfWork of the previous Exchange. DefaultExchange does, for example!!
>> I
>> was wondering why?? So after the (CXF)exchange comes through the pipeline
>> it
>> has lost its UnitOfWork and TraceFormatter throws this NPE.
>>
>> I'm using the Camel 1.5
>>
>> Best regards,
>> Boris
>>
>> --
>> View this message in context:
>> http://www.nabble.com/UnitOfWork-tp20829434s22882p20829434.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/UnitOfWork-tp20829434s22882p20831703.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Mime
View raw message