Monday, March 25, 2013

Snappo Instructional Video (not Programming!)

Hello Blog Readers,

This week I'm posting a quick instructional video showing how to use a small wooden toy I've provided to friends.  Please ignore this if you're looking for programming discussion!

Thank you,



Sunday, March 10, 2013

Learning Switchyard, from the inside out

My job with Red Hat is exciting.  I'm a maintenance engineer on the SOA (and sometimes BRMS) products, both of which are constantly growing and introducing new features.  Keeping up can be quite a task.

The next big change for SOA is going to be the introduction of the new 'Switchyard' infrastructure.  Learning to use Switchyard is one thing-- there are lots of videos, blogs, etc. for that.  But how do you learn how it really works?

This question is one I often describe to people with an analogy.  Using software is like learning to drive a car.  Supporting software is a superset of that-- it's more like having to know what makes the engine, transmission, etc. work.  It's impossible to help people solve their software problems without understanding what makes it all tick.

So I'm trying to learn about the innards of Switchyard.  I'll share an important technique today, one that can be re-used with different applications.  I hope you find it helpful.

First, let's decide on a use case to investigate.  Switchyard has a nice 'quickstarts' directory that you can use to see how Switchyard apps are built.  For today, I'm interested in how Switchyard transforms data so I thought I'd work with the transform-jaxb example.

This quickstart exposes a service through SOAP.  You just use maven ('mvn clean install') to package the project, deploy it to Switchyard, then invoke the application with SOAPUI or another SOAP client.  (Hint:  Sometimes you may wonder which URL to use in situations like this.  The console may not always tell you.  If you grep the log for 'wsdl' you'll often find one you can use.)

So now that we've 'learned to drive the car' (deployed an application, tested it') let's 'learn how the car works'.

STEP1:  Look over the source, pick a class that is likely to be invoked.  In this case, there is a bean used to represent the Order we input to SOAPUI.  I'm guessing the getters will need to be invoked on this class as the SOAP is marsheled on input.

STEP2:  Let's write a Byteman rule to give us a stack trace when this method is invoked.  (If you don't know about Byteman, please go find out ASAP!  Every Java programmer should know about Byteman....)
Here's the rule I cooked up:

RULE Learn about transformation
CLASS org.switchyard.quickstarts.transform.jaxb.Order
METHOD getOrderId
DO traceStack("CALLED ORDER GETTER " + "\n", 100)

STEP3: Deploy that rule (again, please be familiar with Byteman-- install Byteman into your app server, submit this rule).

STEP4:  Re-run your SOAPUI test.  Then go to your server.log for the Byteman output.  Looking over the output (included below)  we get a wealth of information.  Just in one quick pass, here's some of what we can gather: 

- This work is being done on an http thread (http--
- CXF is handling the web-servicey stuff
- There's a Switchyard 'ExchangeImpl' being used.  (We should expect this!)
- Apache Camel is involved early on.  Camel users will recognize the 'Producer'

From here, I'll look for other classes and methods to use in Byteman rules to learn about how Switchyard is going about it's work.  Since we're working with high-quality open source software, we can also look at the classes and methods cited in this stacktrace. 

A stack trace like this (or better yet, a few of them taken off the same user use-case) can tell us a lot about what's going on under the hood.

Happy learning!

:19,729 INFO  [] (DeploymentScanner-threads - 2) JBAS018559: Deployed "switchyard-quickstart-transform-jaxb.jar"
14:38:51,432 INFO  [stdout] (http-- CALLED ORDER GETTER
14:38:51,433 INFO  [stdout] (http-- org.switchyard.quickstarts.transform.jaxb.Order.getOrderId(
14:38:51,434 INFO  [stdout] (http-- org.switchyard.quickstarts.transform.jaxb.OrderServiceBean.submitOrder(
14:38:51,434 INFO  [stdout] (http-- sun.reflect.NativeMethodAccessorImpl.invoke0(
14:38:51,435 INFO  [stdout] (http-- sun.reflect.NativeMethodAccessorImpl.invoke(
14:38:51,436 INFO  [stdout] (http-- sun.reflect.DelegatingMethodAccessorImpl.invoke(
14:38:51,436 INFO  [stdout] (http-- java.lang.reflect.Method.invoke(
14:38:51,436 INFO  [stdout] (http-- org.switchyard.component.bean.ServiceProxyHandler.handle(
14:38:51,437 INFO  [stdout] (http-- org.switchyard.component.bean.ServiceProxyHandler.handleMessage(
14:38:51,437 INFO  [stdout] (http-- org.switchyard.bus.camel.processors.ProviderProcessor.process(
14:38:51,438 INFO  [stdout] (http-- org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(
14:38:51,438 INFO  [stdout] (http-- org.apache.camel.util.AsyncProcessorHelper.process(
14:38:51,439 INFO  [stdout] (http-- org.apache.camel.processor.DelegateAsyncProcessor.processNext(
14:38:51,439 INFO  [stdout] (http-- org.apache.camel.processor.DelegateAsyncProcessor.process(
14:38:51,440 INFO  [stdout] (http-- org.apache.camel.util.AsyncProcessorHelper.process(
14:38:51,440 INFO  [stdout] (http-- org.apache.camel.processor.DelegateAsyncProcessor.processNext(
14:38:51,441 INFO  [stdout] (http-- org.apache.camel.processor.DelegateAsyncProcessor.process(
14:38:51,441 INFO  [stdout] (http--
14:38:51,441 INFO  [stdout] (http-- org.apache.camel.util.AsyncProcessorHelper.process(
14:38:51,442 INFO  [stdout] (http-- org.apache.camel.processor.DelegateAsyncProcessor.processNext(
14:38:51,442 INFO  [stdout] (http-- org.apache.camel.processor.DelegateAsyncProcessor.process(
14:38:51,443 INFO  [stdout] (http-- org.apache.camel.processor.interceptor.TraceInterceptor.process(
14:38:51,443 INFO  [stdout] (http-- org.apache.camel.util.AsyncProcessorHelper.process(
14:38:51,444 INFO  [stdout] (http-- org.apache.camel.processor.DelegateAsyncProcessor.processNext(
14:38:51,444 INFO  [stdout] (http-- org.apache.camel.processor.DelegateAsyncProcessor.process(
14:38:51,445 INFO  [stdout] (http-- org.switchyard.bus.camel.audit.FaultProcessor.process(
14:38:51,446 INFO  [stdout] (http-- org.apache.camel.util.AsyncProcessorHelper.process(
14:38:51,446 INFO  [stdout] (http-- org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(
14:38:51,447 INFO  [stdout] (http-- org.apache.camel.processor.RedeliveryErrorHandler.process(
14:38:51,447 INFO  [stdout] (http-- org.apache.camel.processor.RouteContextProcessor.processNext(
14:38:51,448 INFO  [stdout] (http-- org.apache.camel.processor.DelegateAsyncProcessor.process(
14:38:51,449 INFO  [stdout] (http-- org.apache.camel.processor.interceptor.DefaultChannel.process(
14:38:51,449 INFO  [stdout] (http-- org.apache.camel.util.AsyncProcessorHelper.process(
14:38:51,450 INFO  [stdout] (http-- org.apache.camel.processor.Pipeline.process(
14:38:51,450 INFO  [stdout] (http-- org.apache.camel.processor.Pipeline.process(
14:38:51,451 INFO  [stdout] (http-- org.apache.camel.processor.RouteContextProcessor.processNext(
14:38:51,451 INFO  [stdout] (http-- org.apache.camel.processor.DelegateAsyncProcessor.process(
14:38:51,452 INFO  [stdout] (http-- org.apache.camel.processor.UnitOfWorkProcessor.process(
14:38:51,453 INFO  [stdout] (http-- org.apache.camel.processor.RouteInflightRepositoryProcessor.processNext(
14:38:51,453 INFO  [stdout] (http-- org.apache.camel.processor.DelegateAsyncProcessor.process(
14:38:51,454 INFO  [stdout] (http-- org.apache.camel.util.AsyncProcessorHelper.process(
14:38:51,454 INFO  [stdout] (http-- org.apache.camel.processor.DelegateAsyncProcessor.processNext(
14:38:51,455 INFO  [stdout] (http-- org.apache.camel.processor.DelegateAsyncProcessor.process(
14:38:51,456 INFO  [stdout] (http--
14:38:51,456 INFO  [stdout] (http-- org.apache.camel.util.AsyncProcessorHelper.process(
14:38:51,457 INFO  [stdout] (http--
14:38:51,457 INFO  [stdout] (http-- org.apache.camel.processor.UnitOfWorkProcessor.processAsync(
14:38:51,458 INFO  [stdout] (http-- org.apache.camel.processor.UnitOfWorkProcessor.process(
14:38:51,459 INFO  [stdout] (http-- org.apache.camel.util.AsyncProcessorHelper.process(
14:38:51,459 INFO  [stdout] (http-- org.apache.camel.processor.DelegateAsyncProcessor.process(
14:38:51,460 INFO  [stdout] (http-- org.apache.camel.processor.UnitOfWorkProducer.process(
14:38:51,460 INFO  [stdout] (http-- org.apache.camel.impl.ProducerCache$2.doInProducer(
14:38:51,461 INFO  [stdout] (http-- org.apache.camel.impl.ProducerCache$2.doInProducer(
14:38:51,461 INFO  [stdout] (http-- org.apache.camel.impl.ProducerCache.doInProducer(
14:38:51,462 INFO  [stdout] (http-- org.apache.camel.impl.ProducerCache.sendExchange(
14:38:51,462 INFO  [stdout] (http-- org.apache.camel.impl.ProducerCache.send(
14:38:51,463 INFO  [stdout] (http-- org.apache.camel.impl.DefaultProducerTemplate.send(
14:38:51,464 INFO  [stdout] (http-- org.apache.camel.impl.DefaultProducerTemplate.send(
14:38:51,464 INFO  [stdout] (http-- org.switchyard.bus.camel.ExchangeDispatcher.dispatch(
14:38:51,465 INFO  [stdout] (http-- org.switchyard.internal.ExchangeImpl.sendInternal(
14:38:51,467 INFO  [stdout] (http-- org.switchyard.internal.ExchangeImpl.send(
14:38:51,468 INFO  [stdout] (http-- org.switchyard.component.soap.InboundHandler.invoke(
14:38:51,470 INFO  [stdout] (http-- org.switchyard.component.soap.endpoint.BaseWebService.invoke(
14:38:51,470 INFO  [stdout] (http-- org.switchyard.component.soap.endpoint.BaseWebService.invoke(
14:38:51,470 INFO  [stdout] (http-- sun.reflect.NativeMethodAccessorImpl.invoke0(
14:38:51,472 INFO  [stdout] (http-- sun.reflect.NativeMethodAccessorImpl.invoke(
14:38:51,473 INFO  [stdout] (http-- sun.reflect.DelegatingMethodAccessorImpl.invoke(
14:38:51,474 INFO  [stdout] (http-- java.lang.reflect.Method.invoke(
14:38:51,474 INFO  [stdout] (http--
14:38:51,475 INFO  [stdout] (http-- org.jboss.wsf.stack.cxf.JBossWSInvoker._invokeInternal(
14:38:51,475 INFO  [stdout] (http-- org.jboss.wsf.stack.cxf.JBossWSInvoker.invoke(
14:38:51,476 INFO  [stdout] (http-- org.apache.cxf.interceptor.ServiceInvokerInterceptor$
14:38:51,476 INFO  [stdout] (http-- java.util.concurrent.Executors$
14:38:51,477 INFO  [stdout] (http-- java.util.concurrent.FutureTask$Sync.innerRun(
14:38:51,477 INFO  [stdout] (http--
14:38:51,478 INFO  [stdout] (http-- org.apache.cxf.workqueue.SynchronousExecutor.execute(
14:38:51,478 INFO  [stdout] (http-- org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(
14:38:51,479 INFO  [stdout] (http-- org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(
14:38:51,480 INFO  [stdout] (http-- org.apache.cxf.transport.ChainInitiationObserver.onMessage(
14:38:51,480 INFO  [stdout] (http-- org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(
14:38:51,481 INFO  [stdout] (http-- org.jboss.wsf.stack.cxf.RequestHandlerImpl.handleHttpRequest(
14:38:51,481 INFO  [stdout] (http-- org.jboss.wsf.stack.cxf.transport.ServletHelper.callRequestHandler(
14:38:51,482 INFO  [stdout] (http-- org.jboss.wsf.stack.cxf.CXFServletExt.invoke(
14:38:51,482 INFO  [stdout] (http-- org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(
14:38:51,483 INFO  [stdout] (http-- org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(
14:38:51,484 INFO  [stdout] (http-- javax.servlet.http.HttpServlet.service(
14:38:51,484 INFO  [stdout] (http-- org.jboss.wsf.stack.cxf.CXFServletExt.service(
14:38:51,484 INFO  [stdout] (http-- org.jboss.wsf.spi.deployment.WSFServlet.service(
14:38:51,485 INFO  [stdout] (http-- javax.servlet.http.HttpServlet.service(
14:38:51,485 INFO  [stdout] (http-- org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
14:38:51,486 INFO  [stdout] (http-- org.apache.catalina.core.ApplicationFilterChain.doFilter(
14:38:51,487 INFO  [stdout] (http-- org.apache.catalina.core.StandardWrapperValve.invoke(
14:38:51,487 INFO  [stdout] (http-- org.apache.catalina.core.StandardContextValve.invoke(
14:38:51,488 INFO  [stdout] (http-- org.apache.catalina.core.StandardHostValve.invoke(
14:38:51,488 INFO  [stdout] (http-- org.apache.catalina.valves.ErrorReportValve.invoke(
14:38:51,489 INFO  [stdout] (http-- org.apache.catalina.core.StandardEngineValve.invoke(
14:38:51,489 INFO  [stdout] (http-- org.apache.catalina.connector.CoyoteAdapter.service(
14:38:51,490 INFO  [stdout] (http-- org.apache.coyote.http11.Http11Processor.process(
14:38:51,491 INFO  [stdout] (http-- org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(
14:38:51,491 INFO  [stdout] (http--$
14:38:51,492 INFO  [stdout] (http--