public Destination getDestination(EndpointInfo ei, Bus bus) throws IOException { String address = ei.getAddress(); BindingInfo bi = ei.getBinding(); String transId = ei.getTransportId(); if (bi instanceof SoapBindingInfo) { transId = ((SoapBindingInfo) bi).getTransportURI(); if (transId == null) { transId = ei.getTransportId(); } } DestinationFactory destinationFactory; try { DestinationFactoryManager mgr = bus.getExtension(DestinationFactoryManager.class); if (StringUtils.isEmpty(address) || address.startsWith("http") || address.startsWith("jms") || address.startsWith("soap.udp") || address.startsWith("/")) { destinationFactory = mgr.getDestinationFactory(mapTransportURI(transId, address)); } else { destinationFactory = mgr.getDestinationFactoryForUri(address); } if (destinationFactory == null) { throw new IOException("Could not find destination factory for transport " + transId); } return destinationFactory.getDestination(ei, bus); } catch (BusException e) { IOException ex = new IOException("Could not find destination factory for transport " + transId); ex.initCause(e); throw ex; } }
/** * This test makes sure that a default Spring initialized bus will have the * JettyHTTPServerEngineFactory (absent of <httpj:engine-factory> configuration. */ @Test public void testMakeSureTransportFactoryHasEngineFactory() { bus = BusFactory.getDefaultBus(true); assertNotNull("Cannot get bus", bus); try { // Make sure we got the Transport Factory. DestinationFactoryManager destFM = bus.getExtension(DestinationFactoryManager.class); assertNotNull("Cannot get DestinationFactoryManager", destFM); DestinationFactory destF = destFM.getDestinationFactory("http://schemas.xmlsoap.org/soap/http"); assertNotNull("No DestinationFactory", destF); assertTrue(JettyHTTPTransportFactory.class.isInstance(destF)); } catch (BusException e) { fail("Asserting Transport Factory" + e); } // And the JettyHTTPServerEngineFactory should be there. JettyHTTPServerEngineFactory factory = bus.getExtension(JettyHTTPServerEngineFactory.class); assertNotNull("EngineFactory is not configured.", factory); }
@Before public void initialize() throws Exception { if (mep == NO_RUN) { return; } final Bus bus = BusFactory.getDefaultBus(); final LocalTransportFactory localTransport = new LocalTransportFactory(); final DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class); dfm.registerDestinationFactory("http://schemas.xmlsoap.org/soap/http", localTransport); dfm.registerDestinationFactory("http://schemas.xmlsoap.org/soap/jms", localTransport); dfm.registerDestinationFactory("http://schemas.xmlsoap.org/wsdl/soap/http", localTransport); dfm.registerDestinationFactory("http://cxf.apache.org/bindings/xformat", localTransport); dfm.registerDestinationFactory("http://cxf.apache.org/transports/local", localTransport); final ConduitInitiatorManager extension = bus.getExtension(ConduitInitiatorManager.class); extension.registerConduitInitiator("http://cxf.apache.org/transports/local", localTransport); extension.registerConduitInitiator("http://schemas.xmlsoap.org/wsdl/soap/http", localTransport); extension.registerConduitInitiator("http://schemas.xmlsoap.org/soap/http", localTransport); extension.registerConduitInitiator("http://schemas.xmlsoap.org/soap/jms", localTransport); extension.registerConduitInitiator("http://cxf.apache.org/bindings/xformat", localTransport); final WSDLServiceFactory wsdlSvcFactory = new WSDLServiceFactory(CXFBusFactory.getThreadDefaultBus(), wsdlLocation, SERVICE_NAME); final org.apache.cxf.service.Service cxfService = wsdlSvcFactory.create(); final ServiceInfo si = findServiceByName(cxfService, SERVICE_NAME); if (si == null) { throw new RuntimeException("WSDL does not contain service " + SERVICE_NAME); } final EndpointInfo ei = findEndpoint(si, PORT_NAME); if (ei == null) { throw new RuntimeException("WSDL does not contain port " + PORT_NAME); } endpointInfo = ei; callbackMap.put( "seekBookInBasementResponse", new SeekBookInBasementResponseCallback(messageTransfer)); callbackMap.put( "seekBookInBasementFault", new SeekBookInBasementFaultCallback(messageTransfer)); }
/** * @param address the address * @return a Destination for the address */ private Destination getDestination(Bus bus, String address, Message message) throws IOException { Destination destination = null; DestinationFactoryManager factoryManager = bus.getExtension(DestinationFactoryManager.class); DestinationFactory factory = factoryManager.getDestinationFactoryForUri(address); if (factory != null) { Endpoint ep = message.getExchange().getEndpoint(); EndpointInfo ei = new EndpointInfo(); ei.setName( new QName( ep.getEndpointInfo().getName().getNamespaceURI(), ep.getEndpointInfo().getName().getLocalPart() + ".decoupled")); ei.setAddress(address); destination = factory.getDestination(ei, bus); Conduit conduit = ContextUtils.getConduit(null, message); if (conduit != null) { MessageObserver ob = ((Observable) conduit).getMessageObserver(); ob = new InterposedMessageObserver(bus, ob); destination.setMessageObserver(ob); } } return destination; }
@Test public void testDestination() throws Exception { String wsdlSoapNs = "http://schemas.xmlsoap.org/wsdl/soap/"; String transportURI = "http://foo/transport"; // String location = "http://localhost/service"; ServiceInfo si = new ServiceInfo(); EndpointInfo ei = new EndpointInfo(si, wsdlSoapNs); // this code used to call "new SOAPAddressImpl()", but the test // is currently not testing anything, and needlessly ties the // code to a specific implementation of wsdl4j. When the SOAPAddress // is really needed, it should be mocked. SOAPAddress add = null; // add.setLocationURI(location); ei.addExtensor(add); SoapBindingInfo bi = new SoapBindingInfo(si, "", Soap11.getInstance()); bi.setTransportURI(transportURI); ei.setBinding(bi); IMocksControl control = EasyMock.createNiceControl(); DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class); DestinationFactory fooDF = control.createMock(DestinationFactory.class); Destination dest = control.createMock(Destination.class); EasyMock.expect(dfm.getDestinationFactory(transportURI)).andReturn(fooDF); EasyMock.expect(fooDF.getDestination(ei, null)).andStubReturn(dest); control.replay(); // SoapDestinationFactory sdf = new SoapDestinationFactory(dfm); // Destination dest2 = sdf.getDestination(ei); // assertNotNull(dest2); // TODO: doesn't pass because I don't know how to use easymock :-( // assertEquals(dest, dest2); }
protected void doInitialise() throws InitialisationException { ApplicationContext context = (ApplicationContext) muleContext.getRegistry().lookupObject(SpringRegistry.SPRING_APPLICATION_CONTEXT); if (configurationLocation != null) { bus = new SpringBusFactory(context).createBus(configurationLocation, true); } else { bus = new SpringBusFactory(context).createBus((String) null, true); } if (!initializeStaticBusInstance) { BusFactory.setDefaultBus(null); } MuleUniversalTransport transport = new MuleUniversalTransport(this); DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class); dfm.registerDestinationFactory("http://schemas.xmlsoap.org/soap/http", transport); dfm.registerDestinationFactory("http://schemas.xmlsoap.org/wsdl/soap/http", transport); dfm.registerDestinationFactory( "http://cxf.apache.org/transports/http/configuration", transport); dfm.registerDestinationFactory("http://schemas.xmlsoap.org/wsdl/http/", transport); dfm.registerDestinationFactory("http://www.w3.org/2003/05/soap/bindings/HTTP/", transport); dfm.registerDestinationFactory(MuleUniversalTransport.TRANSPORT_ID, transport); ConduitInitiatorManager extension = bus.getExtension(ConduitInitiatorManager.class); try { // Force the HTTP transport to load if available, otherwise it could // overwrite our namespaces later extension.getConduitInitiator("http://schemas.xmlsoap.org/soap/http"); } catch (BusException e1) { // If unavailable eat exception and continue } extension.registerConduitInitiator("http://schemas.xmlsoap.org/wsdl/soap/", transport); extension.registerConduitInitiator("http://schemas.xmlsoap.org/soap/http", transport); extension.registerConduitInitiator("http://schemas.xmlsoap.org/soap/http/", transport); extension.registerConduitInitiator("http://schemas.xmlsoap.org/wsdl/soap/http", transport); extension.registerConduitInitiator("http://schemas.xmlsoap.org/wsdl/http/", transport); extension.registerConduitInitiator("http://www.w3.org/2003/05/soap/bindings/HTTP/", transport); extension.registerConduitInitiator( "http://cxf.apache.org/transports/http/configuration", transport); extension.registerConduitInitiator("http://cxf.apache.org/bindings/xformat", transport); extension.registerConduitInitiator(MuleUniversalTransport.TRANSPORT_ID, transport); // Registers the listener try { muleContext.registerListener(this); } catch (Exception e) { throw new InitialisationException(e, this); } }