public SwitchYardServiceResponse invoke ( SwitchYardServiceRequest request ) { Map < String , Object > contextOut = new HashMap < String , Object > ( ) ; Object contentOut = null ; Object fault = null ; try { QName serviceName = request . getServiceName ( ) ; if ( serviceName == null ) { throw CommonKnowledgeMessages . MESSAGES . serviceNameNull ( ) ; } else if ( Strings . trimToNull ( serviceName . getNamespaceURI ( ) ) == null ) { String tns = getTargetNamespace ( ) ; if ( tns != null ) { serviceName = XMLHelper . createQName ( tns , serviceName . getLocalPart ( ) ) ; } } ServiceDomain serviceDomain = getServiceDomain ( ) ; if ( serviceDomain == null ) { throw CommonKnowledgeMessages . MESSAGES . serviceDomainNull ( ) ; } ServiceReference serviceReference = serviceDomain . getServiceReference ( serviceName ) ; if ( serviceReference == null ) { throw CommonKnowledgeMessages . MESSAGES . serviceReferenceNull ( serviceName . toString ( ) ) ; } final Exchange exchangeIn ; FaultHandler handler = new FaultHandler ( ) ; String operationName = request . getOperationName ( ) ; if ( operationName != null ) { exchangeIn = serviceReference . createExchange ( operationName , handler ) ; } else { exchangeIn = serviceReference . createExchange ( handler ) ; } Message messageIn = exchangeIn . createMessage ( ) ; Context contextIn = exchangeIn . getContext ( messageIn ) ; for ( Map . Entry < String , Object > entry : request . getContext ( ) . entrySet ( ) ) { contextIn . setProperty ( entry . getKey ( ) , entry . getValue ( ) ) ; } Object contentIn = request . getContent ( ) ; if ( contentIn != null ) { messageIn . setContent ( contentIn ) ; } exchangeIn . send ( messageIn ) ; if ( ExchangePattern . IN_OUT . equals ( exchangeIn . getContract ( ) . getConsumerOperation ( ) . getExchangePattern ( ) ) ) { Exchange exchangeOut = handler . waitForOut ( ) ; Message messageOut = exchangeOut . getMessage ( ) ; contentOut = messageOut . getContent ( ) ; for ( Property property : exchangeOut . getContext ( messageOut ) . getProperties ( ) ) { contextOut . put ( property . getName ( ) , property . getValue ( ) ) ; } } fault = handler . getFault ( ) ; } catch ( Throwable t ) { fault = t ; } return new SwitchYardServiceResponse ( contentOut , contextOut , fault ) ; }
Invokes the request and returns the response .