org.apache.cxf.endpoint.ServerRegistry Java Examples

The following examples show how to use org.apache.cxf.endpoint.ServerRegistry. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractWebServiceExporter.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/** 
 * This determines if the service has already been published on the CXF bus.
 * 
 * @return true if cxf server exists for this service.
 */
protected boolean isServicePublished(String serviceAddress) {
	
	ServerRegistry serverRegistry = getCXFServerRegistry();
	List<Server> servers = serverRegistry.getServers();
	
	for (Server server:servers){		
		String endpointAddress = server.getEndpoint().getEndpointInfo().getAddress();
		if (endpointAddress.contains(serviceAddress)){
			LOG.info("Service already published on CXF, not republishing: " + serviceAddress);
			return true;
		}
	}
	
	return false;
}
 
Example #2
Source File: EndpointReferenceUtils.java    From cxf with Apache License 2.0 6 votes vote down vote up
private static MultiplexDestination getMatchingMultiplexDestination(QName serviceQName, String portName,
                                                                    Bus bus) {
    MultiplexDestination destination = null;
    ServerRegistry serverRegistry = bus.getExtension(ServerRegistry.class);
    if (null != serverRegistry) {
        List<Server> servers = serverRegistry.getServers();
        for (Server s : servers) {
            QName targetServiceQName = s.getEndpoint().getEndpointInfo().getService().getName();
            if (serviceQName.equals(targetServiceQName) && portNameMatches(s, portName)) {
                Destination dest = s.getDestination();
                if (dest instanceof MultiplexDestination) {
                    destination = (MultiplexDestination)dest;
                    break;
                }
            }
        }
    } else {
        LOG.log(Level.WARNING,
                "Failed to locate service matching " + serviceQName
                + ", because the bus ServerRegistry extension provider is null");
    }
    return destination;
}
 
Example #3
Source File: RMPolicyWsdlTestBase.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void run()  {
    SpringBusFactory bf = new SpringBusFactory();
    Bus bus = bf.createBus(getConfigPath());
    BusFactory.setDefaultBus(bus);
    setBus(bus);

    ServerRegistry sr = bus.getExtension(ServerRegistry.class);
    PolicyEngine pe = bus.getExtension(PolicyEngine.class);

    List<PolicyAssertion> assertions1
        = getAssertions(pe, sr.getServers().get(0));
    assertEquals("2 assertions should be available", 2, assertions1.size());
    List<PolicyAssertion> assertions2 =
        getAssertions(pe, sr.getServers().get(1));
    assertEquals("1 assertion should be available", 1, assertions2.size());

    LOG.info("Published greeter endpoints.");
}
 
Example #4
Source File: EngineLifecycleTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpDownWithServlets() throws Exception {
    setUpBus();

    Bus bus = (Bus)applicationContext.getBean("cxf");
    ServerRegistry sr = bus.getExtension(ServerRegistry.class);
    ServerImpl si = (ServerImpl) sr.getServers().get(0);
    JettyHTTPDestination jhd = (JettyHTTPDestination) si.getDestination();
    JettyHTTPServerEngine e = (JettyHTTPServerEngine) jhd.getEngine();
    org.eclipse.jetty.server.Server jettyServer = e.getServer();

    for (Handler h : jettyServer.getChildHandlersByClass(WebAppContext.class)) {
        WebAppContext wac = (WebAppContext) h;
        if ("/jsunit".equals(wac.getContextPath())) {
            wac.addServlet("org.eclipse.jetty.servlet.DefaultServlet", "/bloop");
            break;
        }
    }

    try {
        verifyStaticHtml();
        invokeService();
    } finally {
        shutdownService();
    }
}
 
Example #5
Source File: ColocOutInterceptorTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testColocOutInvalidOperation() throws Exception {

    Bus bus = setupBus();
    ServerRegistry sr = control.createMock(ServerRegistry.class);
    EasyMock.expect(bus.getExtension(ServerRegistry.class)).andReturn(sr);

    Endpoint ep = control.createMock(Endpoint.class);
    ex.put(Endpoint.class, ep);

    control.replay();
    try {
        colocOut.handleMessage(msg);
        fail("Should have thrown a fault");
    } catch (Fault f) {
        assertEquals("Operation not found in exchange.",
                     f.getMessage());
    }
}
 
Example #6
Source File: EndpointCompleterSupport.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
public int complete(Session session,
                    CommandLine commandLine,
                    List<String> list) {
    StringsCompleter delegate = new StringsCompleter();
    try {
        List<Bus> busses = getBusses();

        for (Bus b : busses) {
            ServerRegistry reg = b.getExtension(ServerRegistry.class);
            List<Server> servers = reg.getServers();

            for (Server serv : servers) {
                if (acceptsFeature(serv)) {
                    String qname = serv.getEndpoint().getEndpointInfo().getName().getLocalPart();
                    delegate.getStrings().add(qname);
                }
            }
        }

    } catch (Exception e) {
        // Ignore
    }
    return delegate.complete(session, commandLine, list);
}
 
Example #7
Source File: ColocOutInterceptorTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testColocOutInvalidEndpoint() throws Exception {

    Bus bus = setupBus();
    ServerRegistry sr = control.createMock(ServerRegistry.class);
    EasyMock.expect(bus.getExtension(ServerRegistry.class)).andReturn(sr);

    control.replay();
    try {
        colocOut.handleMessage(msg);
        fail("Should have thrown a fault");
    } catch (Fault f) {
        assertEquals("Consumer Endpoint not found in exchange.",
                     f.getMessage());
    }
}
 
Example #8
Source File: JAXWSEnvironment.java    From dropwizard-jaxws with Apache License 2.0 5 votes vote down vote up
public void logEndpoints() {
    ServerRegistry sr = bus.getExtension(org.apache.cxf.endpoint.ServerRegistry.class);
    if (sr.getServers().size() > 0) {
        String endpoints = "";
        for (Server s : sr.getServers()) {
            endpoints += "    " + this.defaultPath +  s.getEndpoint().getEndpointInfo().getAddress() +
                    " (" + s.getEndpoint().getEndpointInfo().getInterface().getName() + ")\n";
        }
        log.info("JAX-WS service endpoints [" + this.defaultPath + "]:\n\n" + endpoints);
    }
    else {
        log.info("No JAX-WS service endpoints were registered.");
    }
}
 
Example #9
Source File: SpringBusFactoryTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testDefault() {
    Bus bus = new SpringBusFactory().createBus();
    assertNotNull(bus);
    BindingFactoryManager bfm = bus.getExtension(BindingFactoryManager.class);
    assertNotNull("No binding factory manager", bfm);
    assertNotNull("No configurer", bus.getExtension(Configurer.class));
    assertNotNull("No resource manager", bus.getExtension(ResourceManager.class));
    assertNotNull("No destination factory manager", bus.getExtension(DestinationFactoryManager.class));
    assertNotNull("No conduit initiator manager", bus.getExtension(ConduitInitiatorManager.class));
    assertNotNull("No phase manager", bus.getExtension(PhaseManager.class));
    assertNotNull("No workqueue manager", bus.getExtension(WorkQueueManager.class));
    assertNotNull("No lifecycle manager", bus.getExtension(BusLifeCycleManager.class));
    assertNotNull("No service registry", bus.getExtension(ServerRegistry.class));

    try {
        bfm.getBindingFactory("http://cxf.apache.org/unknown");
    } catch (BusException ex) {
        // expected
    }

    assertEquals("Unexpected interceptors", 0, bus.getInInterceptors().size());
    assertEquals("Unexpected interceptors", 0, bus.getInFaultInterceptors().size());
    assertEquals("Unexpected interceptors", 0, bus.getOutInterceptors().size());
    assertEquals("Unexpected interceptors", 0, bus.getOutFaultInterceptors().size());

}
 
Example #10
Source File: ServerRegistryImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Resource
public final void setBus(Bus bus) {
    this.bus = bus;
    if (null != bus) {
        bus.setExtension(this, ServerRegistry.class);
        lifeCycleManager = bus.getExtension(BusLifeCycleManager.class);
        if (null != lifeCycleManager) {
            lifeCycleManager.registerLifeCycleListener(this);
        }
    }
}
 
Example #11
Source File: TestUtilities.java    From cxf with Apache License 2.0 5 votes vote down vote up
public Server getServerForAddress(String address) throws WSDLException {
    ServerRegistry svrMan = bus.getExtension(ServerRegistry.class);
    for (Server s : svrMan.getServers()) {
        if (address.equals(s.getEndpoint().getEndpointInfo().getAddress())) {
            return s;
        }
    }
    return null;
}
 
Example #12
Source File: TestUtilities.java    From cxf with Apache License 2.0 5 votes vote down vote up
public Server getServerForService(QName serviceName) throws WSDLException {
    ServerRegistry svrMan = bus.getExtension(ServerRegistry.class);
    for (Server s : svrMan.getServers()) {
        Service svc = s.getEndpoint().getService();
        if (svc.getName().equals(serviceName)) {
            return s;
        }
    }
    return null;
}
 
Example #13
Source File: AbstractAegisTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected Definition getWSDLDefinition(String string) throws WSDLException {
    ServerRegistry svrMan = getBus().getExtension(ServerRegistry.class);
    for (Server s : svrMan.getServers()) {
        Service svc = s.getEndpoint().getService();
        if (svc.getName().getLocalPart().equals(string)) {
            ServiceWSDLBuilder builder = new ServiceWSDLBuilder(bus, svc.getServiceInfos());
            return builder.build();
        }
    }
    return null;

}
 
Example #14
Source File: StopEndpointCommand.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public Object execute() throws Exception {
    Bus b = getBus(busName);
    ServerRegistry reg = b.getExtension(ServerRegistry.class);
    List<Server> servers = reg.getServers();
    for (Server serv : servers) {
        if (endpoint.equals(serv.getEndpoint().getEndpointInfo().getName().getLocalPart())) {
            serv.stop();
        }
    }
    return null;
}
 
Example #15
Source File: StartEndpointCommand.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public Object execute() throws Exception {
    Bus b = getBus(busName);
    ServerRegistry reg = b.getExtension(ServerRegistry.class);
    List<Server> servers = reg.getServers();
    for (Server serv : servers) {
        if (endpoint.equals(serv.getEndpoint().getEndpointInfo().getName().getLocalPart())) {
            serv.start();
        }
    }
    return null;
}
 
Example #16
Source File: NoSpringServletClientTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void startServer() {
    ServerRegistry reg = serverBus.getExtension(ServerRegistry.class);
    List<Server> servers = reg.getServers();
    for (Server serv : servers) {
        serv.start();
    }
}
 
Example #17
Source File: NoSpringServletClientTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void stopServer() {
    ServerRegistry reg = serverBus.getExtension(ServerRegistry.class);
    List<Server> servers = reg.getServers();
    for (Server serv : servers) {
        serv.stop();
    }
}
 
Example #18
Source File: SpringBusFactoryTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void checkOtherCoreExtensions(Bus bus) throws BusException {
    assertNotNull("No wsdl manager", bus.getExtension(WSDLManager.class));
    assertNotNull("No phase manager", bus.getExtension(PhaseManager.class));
    assertNotNull("No workqueue manager", bus.getExtension(WorkQueueManager.class));
    assertNotNull("No lifecycle manager", bus.getExtension(BusLifeCycleManager.class));
    assertNotNull("No service registry", bus.getExtension(ServerRegistry.class));

}
 
Example #19
Source File: ColocOutInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void handleMessage(Message message) throws Fault {
    if (bus == null) {
        bus = message.getExchange().getBus();
        if (bus == null) {
            bus = BusFactory.getDefaultBus(false);
        }
        if (bus == null) {
            throw new Fault(new org.apache.cxf.common.i18n.Message("BUS_NOT_FOUND", BUNDLE));
        }
    }

    ServerRegistry registry = bus.getExtension(ServerRegistry.class);

    if (registry == null) {
        throw new Fault(new org.apache.cxf.common.i18n.Message("SERVER_REGISTRY_NOT_FOUND", BUNDLE));
    }

    Exchange exchange = message.getExchange();
    Endpoint senderEndpoint = exchange.getEndpoint();

    if (senderEndpoint == null) {
        throw new Fault(new org.apache.cxf.common.i18n.Message("ENDPOINT_NOT_FOUND",
                                                               BUNDLE));
    }

    BindingOperationInfo boi = exchange.getBindingOperationInfo();

    if (boi == null) {
        throw new Fault(new org.apache.cxf.common.i18n.Message("OPERATIONINFO_NOT_FOUND",
                                                               BUNDLE));
    }

    Server srv = isColocated(registry.getServers(), senderEndpoint, boi);

    if (srv != null) {
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Operation:" + boi.getName() + " dispatched as colocated call.");
        }

        InterceptorChain outChain = message.getInterceptorChain();
        outChain.abort();
        exchange.put(Bus.class, bus);
        message.put(COLOCATED, Boolean.TRUE);
        message.put(Message.WSDL_OPERATION, boi.getName());
        message.put(Message.WSDL_INTERFACE, boi.getBinding().getInterface().getName());
        invokeColocObserver(message, srv.getEndpoint());
        if (!exchange.isOneWay()) {
            invokeInboundChain(exchange, senderEndpoint);
        }
    } else {
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Operation:" + boi.getName() + " dispatched as remote call.");
        }

        message.put(COLOCATED, Boolean.FALSE);
    }
}
 
Example #20
Source File: ColocOutInterceptorTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testColocOutIsColocatedPropertySet() throws Exception {
    colocOut = new TestColocOutInterceptor1();

    Bus bus = setupBus();
    ServerRegistry sr = control.createMock(ServerRegistry.class);
    EasyMock.expect(bus.getExtension(ServerRegistry.class)).andReturn(sr);

    //Funtion Param
    Server s1 = control.createMock(Server.class);
    List<Server> list = new ArrayList<>();
    list.add(s1);
    Endpoint sep = control.createMock(Endpoint.class);
    ex.put(Endpoint.class, sep);
    QName op = new QName("E", "F");
    QName intf = new QName("G", "H");
    BindingInfo sbi = control.createMock(BindingInfo.class);
    ServiceInfo ssi = new ServiceInfo();
    InterfaceInfo sii = new InterfaceInfo(ssi, intf);
    sii.addOperation(op);
    OperationInfo soi = sii.getOperation(op);
    ServiceInfo rsi = new ServiceInfo();
    InterfaceInfo rii = new InterfaceInfo(rsi, intf);
    rii.addOperation(op);
    OperationInfo roi = rii.getOperation(op);
    BindingOperationInfo sboi = control.createMock(BindingOperationInfo.class);
    BindingOperationInfo rboi = control.createMock(BindingOperationInfo.class);

    ex.put(BindingOperationInfo.class, sboi);
    //Local var
    Service ses = control.createMock(Service.class);
    EndpointInfo sei = control.createMock(EndpointInfo.class);

    Endpoint rep = control.createMock(Endpoint.class);
    Service res = control.createMock(Service.class);
    BindingInfo rbi = control.createMock(BindingInfo.class);
    EndpointInfo rei = control.createMock(EndpointInfo.class);

    EasyMock.expect(sr.getServers()).andReturn(list);
    EasyMock.expect(sep.getService()).andReturn(ses);
    EasyMock.expect(sep.getEndpointInfo()).andReturn(sei);
    EasyMock.expect(s1.getEndpoint()).andReturn(rep);
    EasyMock.expect(rep.getService()).andReturn(res);
    EasyMock.expect(rep.getEndpointInfo()).andReturn(rei);
    EasyMock.expect(ses.getName()).andReturn(new QName("A", "B"));
    EasyMock.expect(res.getName()).andReturn(new QName("A", "B"));
    EasyMock.expect(rei.getName()).andReturn(new QName("C", "D"));
    EasyMock.expect(sei.getName()).andReturn(new QName("C", "D"));
    EasyMock.expect(rei.getBinding()).andReturn(rbi);

    EasyMock.expect(sboi.getName()).andReturn(op).anyTimes();
    EasyMock.expect(sboi.getOperationInfo()).andReturn(soi);
    EasyMock.expect(rboi.getName()).andReturn(op).anyTimes();
    EasyMock.expect(rboi.getOperationInfo()).andReturn(roi);
    EasyMock.expect(rbi.getOperation(op)).andReturn(rboi);

    InterceptorChain chain = control.createMock(InterceptorChain.class);
    msg.setInterceptorChain(chain);
    EasyMock.expect(sboi.getBinding()).andReturn(sbi);
    EasyMock.expect(sbi.getInterface()).andReturn(sii);

    control.replay();
    colocOut.handleMessage(msg);
    assertTrue("COLOCATED property should be set", (Boolean)msg.get(COLOCATED));
    assertEquals("Message.WSDL_OPERATION property should be set",
                 op, msg.get(Message.WSDL_OPERATION));
    assertEquals("Message.WSDL_INTERFACE property should be set",
                 intf, msg.get(Message.WSDL_INTERFACE));

    control.verify();
}
 
Example #21
Source File: BusExtensionLoadingTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
private static void assertNotNullExtensions(Bus bus) {
    assertNotNull(bus.getExtension(WSDLManager.class));
    assertNotNull(bus.getExtension(ServerRegistry.class));
    assertNotNull(bus.getExtension(HeaderManager.class));
}
 
Example #22
Source File: AbstractWebServiceExporter.java    From rice with Educational Community License v2.0 4 votes vote down vote up
protected ServerRegistry getCXFServerRegistry() {
	return getCXFBus().getExtension(ServerRegistry.class);
}
 
Example #23
Source File: ServiceExportManagerImpl.java    From rice with Educational Community License v2.0 4 votes vote down vote up
/**
    * @deprecated setting ServerRegistry here has no effect, the ServerRegistry extension on the CXF Bus is used instead
    */
   @Deprecated
public void setCxfServerRegistry(ServerRegistry cxfServerRegistry) {
       // no-op, see deprecation information
}