Java Code Examples for org.apache.cxf.Bus.getExtension()

The following are Jave code examples for showing how to use getExtension() of the org.apache.cxf.Bus class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: steve-plugsurfing   File: MediatorInInterceptor.java   Source Code and License Vote up 6 votes
/**
 * Iterate over all available servers registered on the bus and build a map
 * consisting of (namespace, server) pairs for later lookup, so we can
 * redirect to the version-specific implementation according to the namespace
 * of the incoming message.
 */
private void initServerLookupMap(SoapMessage message) {
    Bus bus = message.getExchange().getBus();

    ServerRegistry serverRegistry = bus.getExtension(ServerRegistry.class);
    if (serverRegistry == null) {
        return;
    }

    List<Server> temp = serverRegistry.getServers();
    for (Server server : temp) {
        EndpointInfo info = server.getEndpoint().getEndpointInfo();
        String address = info.getAddress();

        // exclude the 'dummy' routing server
        if (CONFIG.getRouterEndpointPath().equals(address)) {
            continue;
        }

        String serverNamespace = info.getName().getNamespaceURI();
        actualServers.put(serverNamespace, server);
    }
}
 
Example 2
Project: Camel   File: CxfCustomerStartStopTest.java   Source Code and License Vote up 6 votes
@Test
public void startAndStopService() throws Exception {
    CamelContext context = new DefaultCamelContext();
    // start a server    
    context.addRoutes(new RouteBuilder() {
        public void configure() {
            from("cxf:http://localhost:" + PORT1 + "/test?serviceClass=org.apache.camel.component.cxf.HelloService")
                .to("log:endpoint");
        }
    });
    
    context.start();
    Thread.sleep(300);
    context.stop();
    Bus bus = BusFactory.getDefaultBus();
    JettyHTTPServerEngineFactory factory = bus.getExtension(JettyHTTPServerEngineFactory.class);
    JettyHTTPServerEngine engine = factory.retrieveJettyHTTPServerEngine(PORT1);
    assertNotNull("Jetty engine should be found there", engine);
    // Need to call the bus shutdown ourselves.
    String orig = System.setProperty("org.apache.cxf.transports.http_jetty.DontClosePort", "false");
    bus.shutdown(true);
    System.setProperty("org.apache.cxf.transports.http_jetty.DontClosePort",
                       orig == null ? "true" : "false");
    engine = factory.retrieveJettyHTTPServerEngine(PORT1);
    assertNull("Jetty engine should be removed", engine);
}
 
Example 3
Project: Camel   File: CxfCustomerStartStopTest.java   Source Code and License Vote up 6 votes
@Test
public void startAndStopServiceFromSpring() throws Exception {
    System.setProperty("CamelCxfConsumerContext.port2", Integer.toString(PORT2));
    
    ClassPathXmlApplicationContext applicationContext = 
        new ClassPathXmlApplicationContext("org/apache/camel/component/cxf/CamelCxfConsumerContext.xml");
    Bus bus = applicationContext.getBean("cxf", Bus.class);
    // Bus shutdown will be called when the application context is closed.
    String orig = System.setProperty("org.apache.cxf.transports.http_jetty.DontClosePort", "false");
    IOHelper.close(applicationContext);
    System.setProperty("org.apache.cxf.transports.http_jetty.DontClosePort",
                       orig == null ? "true" : "false");
    JettyHTTPServerEngineFactory factory = bus.getExtension(JettyHTTPServerEngineFactory.class);
    // test if the port is still used
    JettyHTTPServerEngine engine = factory.retrieveJettyHTTPServerEngine(PORT2);
    assertNull("Jetty engine should be removed", engine);
}
 
Example 4
Project: jbossws-cxf   File: HTTPConduitTestCase.java   Source Code and License Vote up 6 votes
@Test
@RunAsClient
public void testDefaultWrapperInstalled() throws Exception {
   Bus bus = BusFactory.newInstance().createBus();
   try {
      HTTPConduitFactory hcf = bus.getExtension(HTTPConduitFactory.class);
      assertNotNull(hcf);
      assertTrue(hcf instanceof DefaultHTTPConduitFactoryWrapper);
      
      URL wsdlURL = new URL(baseURL + "/ServiceOne" + "?wsdl");
      Service service = Service.create(wsdlURL, new QName("http://org.jboss.ws.jaxws.cxf/httpConduit", "ServiceOne"));
      EndpointOne port = service.getPort(new QName("http://org.jboss.ws.jaxws.cxf/httpConduit", "EndpointOnePort"), EndpointOne.class);
      assertEquals("Foo", port.echo("Foo"));
   } finally {
      bus.shutdown(true);
   }
}
 
Example 5
Project: jbossws-cxf   File: PolicyInterceptorProviderTestCase.java   Source Code and License Vote up 6 votes
/**
 * Verifies the policy-enabled client can be configured to ignore a given policy in the wsdl contract
 * 
 * @throws Exception
 */
@Test
@RunAsClient
public void testUnsupportedPolicy() throws Exception
{
   Bus bus = BusFactory.newInstance().createBus();
   try
   {
      BusFactory.setThreadDefaultBus(bus);
      
      PolicyInterceptorProviderRegistry reg = bus.getExtension(PolicyInterceptorProviderRegistry.class);
      reg.register(new IgnorablePolicyInterceptorProvider(new QName("http://my.custom.org/policy", "MyPolicy")));
      
      URL wsdlURL = new URL(baseURL + "/jaxws-cxf-policy/PIPService/PIPEndpoint?wsdl");
      QName serviceName = new QName("http://policy.cxf.jaxws.ws.test.jboss.org/", "PIPService");
      Service service = Service.create(wsdlURL, serviceName, new UseThreadBusFeature());
      QName portQName = new QName("http://policy.cxf.jaxws.ws.test.jboss.org/", "PIPEndpointPort");
      PIPEndpoint port = (PIPEndpoint)service.getPort(portQName, PIPEndpoint.class);

      assertEquals("foo", port.echo("foo"));
   }
   finally
   {
      bus.shutdown(true);
   }
}
 
Example 6
Project: jbossws-cxf   File: ClientServerLifeCycleTestCase.java   Source Code and License Vote up 6 votes
@Test
@RunAsClient
public void testCustomClientLifeCycleListener() throws Exception
{
   Bus bus = BusFactory.newInstance().createBus();
   BusFactory.setThreadDefaultBus(bus);
   try {
      URL wsdlOneURL = new URL(baseURL + "/ServiceOne/EndpointOne?wsdl");
      QName serviceOneName = new QName("http://org.jboss.ws.jaxws.cxf/jbws3098", "ServiceOne");
      Service serviceOne = Service.create(wsdlOneURL, serviceOneName, new UseThreadBusFeature());
      CustomClientLifeCycleListener listener = new CustomClientLifeCycleListener();
      ClientLifeCycleManager mgr = bus.getExtension(ClientLifeCycleManager.class);
      try {
         mgr.registerListener(listener);
         assertEquals(0, listener.getCount());
         EndpointOne portOne = (EndpointOne)serviceOne.getPort(EndpointOne.class);
         assertEquals(1, listener.getCount());
         assertEquals("Foo", portOne.echo("Foo"));
      } finally {
         mgr.unRegisterListener(listener);
      }
   } finally {
      bus.shutdown(true);
   }
}
 
Example 7
Project: jbossws-cxf   File: Helper.java   Source Code and License Vote up 6 votes
/**
 * Setup binding customization on client side using the JBossWSConfigurer
 *
 * @throws Exception
 */
@SuppressWarnings("unchecked")
private Bus setBindingCustomizationOnClientSide() throws Exception
{
   BindingCustomization jaxbCustomizations = new JAXBBindingCustomization();
   if (jaxbIntroUrl == null)
   {
      jaxbIntroUrl = Thread.currentThread().getContextClassLoader().getResource("jaxb-intros.xml");
   }
   BindingCustomizationFactory.populateBindingCustomization(jaxbIntroUrl.openStream(), jaxbCustomizations);

   Bus bus = BusFactory.newInstance().createBus();
   BusFactory.setThreadDefaultBus(bus);
   JBossWSConfigurer configurer = (JBossWSConfigurer)bus.getExtension(Configurer.class);
   configurer.getCustomizer().setBindingCustomization(jaxbCustomizations);
   return bus;
}
 
Example 8
Project: SecureBPMN   File: CxfWSDLImporter.java   Source Code and License Vote up 6 votes
public void importFrom(String url) {
  this.wsServices.clear();
  this.wsOperations.clear();
  this.structures.clear();

  this.wsdlLocation = url;

  try {
    Bus bus = BusFactory.getDefaultBus();
    WSDLManager wsdlManager = bus.getExtension(WSDLManager.class);
    Definition def = wsdlManager.getDefinition(url);
    WSDLServiceBuilder builder = new WSDLServiceBuilder(bus);
    List<ServiceInfo> services = builder.buildServices(def);
    
    for (ServiceInfo service : services) {
      WSService wsService = this.importService(service);
      this.wsServices.put(this.namespace + wsService.getName(), wsService);
    }
    
    this.importTypes(def.getTypes());
  } catch (WSDLException e) {
    e.printStackTrace();
  }
}
 
Example 9
Project: Camel   File: SpringBusFactoryBeanTest.java   Source Code and License Vote up 5 votes
@Test
public void getTheBusInstance() {
    Bus bus = ctx.getBean("cxfBus", Bus.class);
    assertNotNull("The bus should not be null", bus);
    
    bus = ctx.getBean("myBus", Bus.class);
    assertNotNull("The bus should not be null", bus);

    SoapBindingFactory soapBindingFactory = bus.getExtension(SoapBindingFactory.class);
    assertNotNull("You should find the factory here", soapBindingFactory);
}
 
Example 10
Project: kc-rice   File: KSBDispatcherServlet.java   Source Code and License Vote up 5 votes
@Override
protected void initFrameworkServlet() throws ServletException, BeansException {
	this.httpInvokerHandler = new KSBHttpInvokerHandler();
	
       Bus bus = KSBServiceLocator.getCXFBus();

       List<Interceptor<? extends Message>> inInterceptors = KSBServiceLocator.getInInterceptors();
       if(inInterceptors != null) {
       	List<Interceptor<? extends Message>> busInInterceptors = bus.getInInterceptors();
       	busInInterceptors.addAll(inInterceptors);
       }
      
       List<Interceptor<? extends Message>> outInterceptors = KSBServiceLocator.getOutInterceptors();
       if(outInterceptors != null) {
       	List<Interceptor<? extends Message>> busOutInterceptors = bus.getOutInterceptors();
       	busOutInterceptors.addAll(outInterceptors);
       }


	HTTPTransportFactory transportFactory = bus.getExtension(HTTPTransportFactory.class);
       if (transportFactory == null) {
           throw new IllegalStateException("Failed to locate HTTPTransportFactory extension on Apache CXF Bus");
       }

       DestinationRegistry destinationRegistry = transportFactory.getRegistry();


	this.cxfServletController = new ServletController(destinationRegistry, getCXFServletConfig(
               this.getServletConfig()), new ServiceListGeneratorServlet(destinationRegistry, bus));

	this.setPublishEvents(false);
}
 
Example 11
Project: jbossws-cxf   File: OasisCatalogHelloWSTestCase.java   Source Code and License Vote up 5 votes
@Test
@RunAsClient
public void testCatalogOnClientSide() throws Exception
{
   Bus bus = BusFactory.newInstance().createBus();
   try {
      BusFactory.setThreadDefaultBus(bus);

      URL archiveURL =  JBossWSTestHelper.getArchiveURL("jaxws-cxf-catalog.war");

      // add archive to classpath
      ClassLoader currentThreadClassLoader = Thread.currentThread().getContextClassLoader();
      URLClassLoader urlClassLoader
         = new URLClassLoader(new URL[]{archiveURL}, currentThreadClassLoader);
      Thread.currentThread().setContextClassLoader(urlClassLoader);

      QName serviceName = new QName(
         org.jboss.test.ws.jaxws.cxf.catalog.HelloWs.TARGET_NAMESPACE,
         org.jboss.test.ws.jaxws.cxf.catalog.HelloWs.NAME);
      URL wsdlURL = new URL(baseURL + "HelloService?wsdl");
      Service service = Service.create(wsdlURL, serviceName);

      OASISCatalogManager catalogManager = bus.getExtension(OASISCatalogManager.class);
      assertNotNull("OASISCatalogManager not provided ", catalogManager);

      String xsd = "http://org.jboss.ws/cxf/catalogclient/ws-addr.xsd";
      String resolvedSchemaLocation = catalogManager.resolveSystem(xsd);
      assertEquals("http://org.foo.bar/client/ws-addr.xsd", resolvedSchemaLocation);

   } finally {
      bus.shutdown(true);
   }
}
 
Example 12
Project: jbossws-cxf   File: OasisCatalogHelloWSTestCase.java   Source Code and License Vote up 5 votes
@Test
@RunAsClient
public void testCatalogInJbosswsCxfClientJar() throws Exception
{
   Bus bus = BusFactory.newInstance().createBus();
   try {
      BusFactory.setThreadDefaultBus(bus);

      QName serviceName = new QName(
         org.jboss.test.ws.jaxws.cxf.catalog.HelloWs.TARGET_NAMESPACE,
         org.jboss.test.ws.jaxws.cxf.catalog.HelloWs.NAME);
      URL wsdlURL = new URL(baseURL + "HelloService?wsdl");
      Service service = Service.create(wsdlURL, serviceName);

      // jbossws-cxf-client.Jar is on the classpath by default.
      // cxf processed it during service creation.
      OASISCatalogManager catalogManager = bus.getExtension(OASISCatalogManager.class);
      assertNotNull("OASISCatalogManager not provided ", catalogManager);

      String xsd = "http://ws-i.org/profiles/basic/1.1/ws-addr.xsd";
      String resolvedSchemaLocation = catalogManager.resolveSystem(xsd);
      assertEquals("classpath:/schemas/wsdl/ws-addr.xsd", resolvedSchemaLocation);

   } finally {
      bus.shutdown(true);
   }
}
 
Example 13
Project: jbossws-cxf   File: HTTPConduitTestCase.java   Source Code and License Vote up 5 votes
private DefaultHTTPConduitFactoryWrapper replaceWrapper(Map<String, Object> args, Bus bus)
{
   HTTPConduitFactory hcf = bus.getExtension(HTTPConduitFactory.class);
   //replace wrapper
   DefaultHTTPConduitFactoryWrapper w = new DefaultHTTPConduitFactoryWrapper(args, false,
         ((AbstractHTTPConduitFactoryWrapper) hcf).getDelegate());
   bus.setExtension(w, HTTPConduitFactory.class);
   return w;
}
 
Example 14
Project: jbossws-cxf   File: CXFServiceObjectFactoryJAXWS.java   Source Code and License Vote up 5 votes
private Bus createNewBus(final UnifiedServiceRefMetaData serviceRefMD)
{
   final Bus bus;
   Bus threadBus = BusFactory.getThreadDefaultBus(false);
   bus = threadBus != null ? threadBus : BusFactory.newInstance().createBus();

   Configurer configurer = bus.getExtension(Configurer.class);
   bus.setExtension(new CXFServiceRefStubPropertyConfigurer(serviceRefMD, configurer), Configurer.class);

   return bus;
}
 
Example 15
Project: jbossws-cxf   File: SOAPConnectionImpl.java   Source Code and License Vote up 5 votes
private ConduitInitiator getConduitInitiator(String address) throws SOAPException 
{
   ConduitInitiator ci = null;
   try 
   {
      //do not use getThreadDefaultBus(true) in order to avoid getting the default bus
      Bus bus = BusFactory.getThreadDefaultBus(false);
      if (bus == null)
      {
         bus = BusFactory.newInstance().createBus();
      }
      ConduitInitiatorManager mgr = bus.getExtension(ConduitInitiatorManager.class);
        
      if (address.startsWith("http")) 
      {
         ci = mgr.getConduitInitiator("http://cxf.apache.org/transports/http");
      } 
      if (ci == null) 
      {
         ci = mgr.getConduitInitiatorForUri(address);
      }
        
   } 
   catch (Exception ex) 
   {
      throw MESSAGES.noConduitInitiatorAvailableFor2(address, ex);
   }
    
   if (ci == null) 
   {
      throw MESSAGES.noConduitInitiatorAvailableFor(address);
   }
   return ci;
}
 
Example 16
Project: jbossws-cxf   File: RequestHandlerImpl.java   Source Code and License Vote up 5 votes
private static DestinationRegistry getDestinationRegistryFromBus(Bus bus) throws ServletException {
   DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);
   try {
       DestinationFactory df = dfm
           .getDestinationFactory("http://cxf.apache.org/transports/http/configuration");
       if (df instanceof HTTPTransportFactory) {
           HTTPTransportFactory transportFactory = (HTTPTransportFactory)df;
           return transportFactory.getRegistry();
       }
   } catch (BusException e) {
       throw Messages.MESSAGES.cannotObtainDestinationFactoryForHttpTransport(e);
   }
   return null;
}
 
Example 17
Project: jbossws-cxf   File: InstrumentationManagerExtImpl.java   Source Code and License Vote up 5 votes
@Override
public void init()
{
   Bus bus = getBus();
   if (null != bus)
   {
      bus.setExtension(this, InstrumentationManager.class);
      BusLifeCycleManager blcm = bus.getExtension(BusLifeCycleManager.class);
      if (null != blcm)
      {
         blcm.registerLifeCycleListener(this);
      }
   }
}
 
Example 18
Project: jbossws-cxf   File: ProviderImpl.java   Source Code and License Vote up 4 votes
private void setDisableCacheSchema(Bus bus) {
    if (bus.getExtension(WSDLManager.class) instanceof WSDLManagerImpl) {
            WSDLManagerImpl wsdlManangerImpl = (WSDLManagerImpl)bus.getExtension(WSDLManager.class);
            wsdlManangerImpl.setDisableSchemaCache(SecurityActions.getBoolean(JBWS_CXF_DISABLE_SCHEMA_CACHE, true));
    }
}
 
Example 19
Project: jbossws-cxf   File: JBossWSBusFactory.java   Source Code and License Vote up 4 votes
protected void initializeBus(Bus bus) {
   super.initializeBus(bus);
   final ResourceManager resourceManager = bus.getExtension(ResourceManager.class);
   resourceManager.addResourceResolver(JBossWSResourceInjectionResolver.getInstance());
   SecurityProviderConfig.setup(bus);
}
 
Example 20
Project: jbossws-cxf   File: DefaultHTTPConduitFactoryWrapper.java   Source Code and License Vote up 4 votes
public static void install(Bus bus)
{
   HTTPConduitFactory delegate = bus.getExtension(HTTPConduitFactory.class);
   bus.setExtension(new DefaultHTTPConduitFactoryWrapper(delegate), HTTPConduitFactory.class);
}
 
Example 21
Project: techytax-zk   File: PolicyVerificationInInterceptor.java   Source Code and License Vote up 4 votes
/** 
     * Determines the effective policy, and checks if one of its alternatives  
     * is supported.
     *  
     * @param message
     * @throws PolicyException if none of the alternatives is supported
     */
    protected void handle(Message message) {
        
        AssertionInfoMap aim = message.get(AssertionInfoMap.class);
        if (null == aim) {
            return;
        }

        Exchange exchange = message.getExchange();
        BindingOperationInfo boi = exchange.get(BindingOperationInfo.class);
        if (null == boi) {
            LOG.fine("No binding operation info.");
            return;
        }
        
        Endpoint e = exchange.get(Endpoint.class);
        if (null == e) {
            LOG.fine("No endpoint.");
            return;
        } 
        EndpointInfo ei = e.getEndpointInfo();

        Bus bus = exchange.get(Bus.class);
        PolicyEngine pe = bus.getExtension(PolicyEngine.class);
        if (null == pe) {
            return;
        }
        
        if (MessageUtils.isPartialResponse(message)) {
            LOG.fine("Not verifying policies on inbound partial response.");
            return;
        }
        
        getTransportAssertions(message);  
        
        EffectivePolicy effectivePolicy = message.get(EffectivePolicy.class);
        if (effectivePolicy == null) {
            if (MessageUtils.isRequestor(message)) {
                effectivePolicy = pe.getEffectiveClientResponsePolicy(ei, boi);
            } else {
                effectivePolicy = pe.getEffectiveServerRequestPolicy(ei, boi);
            }
        }
        try {
//            List<List<Assertion>> usedAlternatives = aim.checkEffectivePolicy(effectivePolicy.getPolicy());
//            if (usedAlternatives != null && !usedAlternatives.isEmpty() && message.getExchange() != null) {
//                message.getExchange().put("ws-policy.validated.alternatives", usedAlternatives);
//            }
        } catch (PolicyException ex) {
            //To check if there is ws addressing policy violation and throw WSA specific 
            //exception to pass jaxws2.2 tests
            if (ex.getMessage().indexOf("Addressing") > -1) {
                throw new Fault("A required header representing a Message Addressing Property " 
                                    + "is not present", LOG)
                    .setFaultCode(new QName("http://www.w3.org/2005/08/addressing", 
                                              "MessageAddressingHeaderRequired"));
            }
            throw ex;
        }
        LOG.fine("Verified policies for inbound message.");
    }
 
Example 22
Project: respiro   File: WSDLManagerDefinitionCacheCleaner.java   Source Code and License Vote up 2 votes
public WSDLManagerDefinitionCacheCleaner(Bus bus) {


        wsdlManager = bus.getExtension(WSDLManager.class);
    }