Search in sources :

Example 6 with RemotingServer

use of org.apache.dubbo.remoting.RemotingServer in project dubbo by alibaba.

the class NettyClientTest method testServerClose.

@Test
public void testServerClose() throws Exception {
    for (int i = 0; i < 100; i++) {
        RemotingServer aServer = Exchangers.bind(URL.valueOf("exchange://localhost:" + NetUtils.getAvailablePort(6000) + "?server=netty3"), new TelnetServerHandler());
        aServer.close();
    }
}
Also used : RemotingServer(org.apache.dubbo.remoting.RemotingServer) Test(org.junit.jupiter.api.Test)

Example 7 with RemotingServer

use of org.apache.dubbo.remoting.RemotingServer in project dubbo by alibaba.

the class WebServiceProtocol method doExport.

@Override
protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException {
    transportFactory = new SoapTransportFactory();
    destinationRegistry = new DestinationRegistryImpl();
    String addr = getAddr(url);
    ProtocolServer protocolServer = serverMap.get(addr);
    if (protocolServer == null) {
        RemotingServer remotingServer = httpBinder.bind(url, new WebServiceHandler());
        serverMap.put(addr, new ProxyProtocolServer(remotingServer));
    }
    serverFactoryBean = new ServerFactoryBean();
    serverFactoryBean.setAddress(url.getAbsolutePath());
    serverFactoryBean.setServiceClass(type);
    serverFactoryBean.setServiceBean(impl);
    serverFactoryBean.setBus(bus);
    serverFactoryBean.setDestinationFactory(transportFactory);
    serverFactoryBean.getServiceFactory().getConfigurations().add(new URLHashMethodNameSoapActionServiceConfiguration());
    server = serverFactoryBean.create();
    return new Runnable() {

        @Override
        public void run() {
            if (serverFactoryBean.getServer() != null) {
                serverFactoryBean.getServer().destroy();
            }
            if (serverFactoryBean.getBus() != null) {
                serverFactoryBean.getBus().shutdown(true);
            }
            ProtocolServer httpServer = serverMap.get(addr);
            if (httpServer != null) {
                httpServer.close();
                serverMap.remove(addr);
            }
        }
    };
}
Also used : ProtocolServer(org.apache.dubbo.rpc.ProtocolServer) RemotingServer(org.apache.dubbo.remoting.RemotingServer) ServerFactoryBean(org.apache.cxf.frontend.ServerFactoryBean) SoapTransportFactory(org.apache.cxf.binding.soap.SoapTransportFactory) DestinationRegistryImpl(org.apache.cxf.transport.http.DestinationRegistryImpl)

Example 8 with RemotingServer

use of org.apache.dubbo.remoting.RemotingServer in project dubbo by alibaba.

the class XmlRpcProtocol method doExport.

@Override
protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException {
    final URL httpUrl = url.setProtocol("http");
    String addr = httpUrl.getIp() + ":" + httpUrl.getPort();
    ProtocolServer protocolServer = serverMap.get(addr);
    if (protocolServer == null) {
        RemotingServer remotingServer = httpBinder.bind(httpUrl, new InternalHandler(httpUrl.getParameter("cors", false)));
        serverMap.put(addr, new ProxyProtocolServer(remotingServer));
    }
    final String path = httpUrl.getAbsolutePath();
    XmlRpcServletServer xmlRpcServer = new XmlRpcServletServer();
    PropertyHandlerMapping propertyHandlerMapping = new PropertyHandlerMapping();
    try {
        propertyHandlerMapping.setRequestProcessorFactoryFactory(new RequestProcessorFactoryFactory() {

            @Override
            public RequestProcessorFactory getRequestProcessorFactory(Class pClass) throws XmlRpcException {
                return new RequestProcessorFactory() {

                    @Override
                    public Object getRequestProcessor(XmlRpcRequest pRequest) throws XmlRpcException {
                        return impl;
                    }
                };
            }
        });
        propertyHandlerMapping.addHandler(XmlRpcProxyFactoryBean.replace(type.getName()), type);
    } catch (Exception e) {
        throw new RpcException(e);
    }
    xmlRpcServer.setHandlerMapping(propertyHandlerMapping);
    XmlRpcServerConfigImpl xmlRpcServerConfig = (XmlRpcServerConfigImpl) xmlRpcServer.getConfig();
    xmlRpcServerConfig.setEnabledForExceptions(true);
    xmlRpcServerConfig.setContentLengthOptional(false);
    skeletonMap.put(path, xmlRpcServer);
    return new Runnable() {

        @Override
        public void run() {
            skeletonMap.remove(path);
        }
    };
}
Also used : RequestProcessorFactoryFactory(org.apache.xmlrpc.server.RequestProcessorFactoryFactory) RemotingServer(org.apache.dubbo.remoting.RemotingServer) URL(org.apache.dubbo.common.URL) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) RpcException(org.apache.dubbo.rpc.RpcException) RemoteAccessException(org.springframework.remoting.RemoteAccessException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) SocketTimeoutException(java.net.SocketTimeoutException) PropertyHandlerMapping(org.apache.xmlrpc.server.PropertyHandlerMapping) ProtocolServer(org.apache.dubbo.rpc.ProtocolServer) XmlRpcServerConfigImpl(org.apache.xmlrpc.server.XmlRpcServerConfigImpl) RpcException(org.apache.dubbo.rpc.RpcException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) XmlRpcRequest(org.apache.xmlrpc.XmlRpcRequest) XmlRpcServletServer(org.apache.xmlrpc.webserver.XmlRpcServletServer) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 9 with RemotingServer

use of org.apache.dubbo.remoting.RemotingServer in project dubbo by alibaba.

the class ServerStatusChecker method check.

@Override
public Status check() {
    List<ProtocolServer> servers = DubboProtocol.getDubboProtocol().getServers();
    if (servers == null || servers.isEmpty()) {
        return new Status(Status.Level.UNKNOWN);
    }
    Status.Level level = Status.Level.OK;
    StringBuilder buf = new StringBuilder();
    for (ProtocolServer protocolServer : servers) {
        RemotingServer server = protocolServer.getRemotingServer();
        if (!server.isBound()) {
            level = Status.Level.ERROR;
            buf.setLength(0);
            buf.append(server.getLocalAddress());
            break;
        }
        if (buf.length() > 0) {
            buf.append(",");
        }
        buf.append(server.getLocalAddress());
        buf.append("(clients:");
        buf.append(server.getChannels().size());
        buf.append(")");
    }
    return new Status(level, buf.toString());
}
Also used : Status(org.apache.dubbo.common.status.Status) ProtocolServer(org.apache.dubbo.rpc.ProtocolServer) RemotingServer(org.apache.dubbo.remoting.RemotingServer)

Example 10 with RemotingServer

use of org.apache.dubbo.remoting.RemotingServer in project dubbo by alibaba.

the class NettyTransporterTest method shouldAbleToBindNetty4.

@Test
public void shouldAbleToBindNetty4() throws Exception {
    int port = NetUtils.getAvailablePort();
    URL url = new URL("telnet", "localhost", port, new String[] { Constants.BIND_PORT_KEY, String.valueOf(port) });
    RemotingServer server = new NettyTransporter().bind(url, new ChannelHandlerAdapter());
    assertThat(server.isBound(), is(true));
}
Also used : ChannelHandlerAdapter(org.apache.dubbo.remoting.transport.ChannelHandlerAdapter) RemotingServer(org.apache.dubbo.remoting.RemotingServer) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Aggregations

RemotingServer (org.apache.dubbo.remoting.RemotingServer)10 ProtocolServer (org.apache.dubbo.rpc.ProtocolServer)6 URL (org.apache.dubbo.common.URL)3 Test (org.junit.jupiter.api.Test)3 ChannelHandlerAdapter (org.apache.dubbo.remoting.transport.ChannelHandlerAdapter)2 HessianSkeleton (com.caucho.hessian.server.HessianSkeleton)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 JsonRpcServer (com.googlecode.jsonrpc4j.JsonRpcServer)1 IOException (java.io.IOException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ServletException (javax.servlet.ServletException)1 SoapTransportFactory (org.apache.cxf.binding.soap.SoapTransportFactory)1 ServerFactoryBean (org.apache.cxf.frontend.ServerFactoryBean)1 DestinationRegistryImpl (org.apache.cxf.transport.http.DestinationRegistryImpl)1 Status (org.apache.dubbo.common.status.Status)1 RpcException (org.apache.dubbo.rpc.RpcException)1 GenericService (org.apache.dubbo.rpc.service.GenericService)1 XmlRpcException (org.apache.xmlrpc.XmlRpcException)1