Search in sources :

Example 6 with ProtocolServer

use of org.apache.dubbo.rpc.ProtocolServer in project dubbo by alibaba.

the class HttpProtocol method doExport.

@Override
protected <T> Runnable doExport(final T impl, Class<T> type, URL url) throws RpcException {
    String addr = getAddr(url);
    ProtocolServer protocolServer = serverMap.get(addr);
    if (protocolServer == null) {
        RemotingServer remotingServer = httpBinder.bind(url, new InternalHandler(url.getParameter("cors", false)));
        serverMap.put(addr, new ProxyProtocolServer(remotingServer));
    }
    final String path = url.getAbsolutePath();
    final String genericPath = path + "/" + GENERIC_KEY;
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    JsonRpcServer skeleton = new JsonRpcServer(mapper, impl, type);
    JsonRpcServer genericServer = new JsonRpcServer(mapper, impl, GenericService.class);
    skeletonMap.put(path, skeleton);
    skeletonMap.put(genericPath, genericServer);
    return () -> {
        skeletonMap.remove(path);
        skeletonMap.remove(genericPath);
    };
}
Also used : ProtocolServer(org.apache.dubbo.rpc.ProtocolServer) JsonRpcServer(com.googlecode.jsonrpc4j.JsonRpcServer) RemotingServer(org.apache.dubbo.remoting.RemotingServer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 7 with ProtocolServer

use of org.apache.dubbo.rpc.ProtocolServer in project dubbo by alibaba.

the class GrpcProtocol method doExport.

@Override
protected <T> Runnable doExport(T proxiedImpl, Class<T> type, URL url) throws RpcException {
    String key = url.getAddress();
    ProtocolServer protocolServer = serverMap.computeIfAbsent(key, k -> {
        DubboHandlerRegistry registry = new DubboHandlerRegistry();
        NettyServerBuilder builder = NettyServerBuilder.forPort(url.getPort()).fallbackHandlerRegistry(registry);
        Server originalServer = GrpcOptionsUtils.buildServerBuilder(url, builder).build();
        GrpcRemotingServer remotingServer = new GrpcRemotingServer(originalServer, registry);
        return new ProxyProtocolServer(remotingServer);
    });
    GrpcRemotingServer grpcServer = (GrpcRemotingServer) protocolServer.getRemotingServer();
    ServiceRepository serviceRepository = ApplicationModel.getServiceRepository();
    ProviderModel providerModel = serviceRepository.lookupExportedService(url.getServiceKey());
    if (providerModel == null) {
        throw new IllegalStateException("Service " + url.getServiceKey() + "should have already been stored in service repository, " + "but failed to find it.");
    }
    Object originalImpl = providerModel.getServiceInstance();
    Class<?> implClass = originalImpl.getClass();
    try {
        Method method = implClass.getMethod("setProxiedImpl", type);
        method.invoke(originalImpl, proxiedImpl);
    } catch (Exception e) {
        throw new IllegalStateException("Failed to set dubbo proxied service impl to stub, please make sure your stub " + "was generated by the dubbo-protoc-compiler.", e);
    }
    grpcServer.getRegistry().addService((BindableService) originalImpl, url.getServiceKey());
    if (!grpcServer.isStarted()) {
        grpcServer.start();
    }
    return () -> grpcServer.getRegistry().removeService(url.getServiceKey());
}
Also used : NettyServerBuilder(io.grpc.netty.NettyServerBuilder) ProtocolServer(org.apache.dubbo.rpc.ProtocolServer) Server(io.grpc.Server) Method(java.lang.reflect.Method) ServiceRepository(org.apache.dubbo.rpc.model.ServiceRepository) IOException(java.io.IOException) RpcException(org.apache.dubbo.rpc.RpcException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ProtocolServer(org.apache.dubbo.rpc.ProtocolServer) ProviderModel(org.apache.dubbo.rpc.model.ProviderModel)

Example 8 with ProtocolServer

use of org.apache.dubbo.rpc.ProtocolServer in project dubbo by alibaba.

the class PortTelnetHandler method telnet.

@Override
public String telnet(Channel channel, String message) {
    StringBuilder buf = new StringBuilder();
    String port = null;
    boolean detail = false;
    if (message.length() > 0) {
        String[] parts = message.split("\\s+");
        for (String part : parts) {
            if ("-l".equals(part)) {
                detail = true;
            } else {
                if (!StringUtils.isInteger(part)) {
                    return "Illegal port " + part + ", must be integer.";
                }
                port = part;
            }
        }
    }
    if (port == null || port.length() == 0) {
        for (ProtocolServer server : DubboProtocol.getDubboProtocol().getServers()) {
            if (buf.length() > 0) {
                buf.append("\r\n");
            }
            if (detail) {
                buf.append(server.getUrl().getProtocol()).append("://").append(server.getUrl().getAddress());
            } else {
                buf.append(server.getUrl().getPort());
            }
        }
    } else {
        int p = Integer.parseInt(port);
        ProtocolServer protocolServer = null;
        for (ProtocolServer s : DubboProtocol.getDubboProtocol().getServers()) {
            if (p == s.getUrl().getPort()) {
                protocolServer = s;
                break;
            }
        }
        if (protocolServer != null) {
            ExchangeServer server = (ExchangeServer) protocolServer.getRemotingServer();
            Collection<ExchangeChannel> channels = server.getExchangeChannels();
            for (ExchangeChannel c : channels) {
                if (buf.length() > 0) {
                    buf.append("\r\n");
                }
                if (detail) {
                    buf.append(c.getRemoteAddress()).append(" -> ").append(c.getLocalAddress());
                } else {
                    buf.append(c.getRemoteAddress());
                }
            }
        } else {
            buf.append("No such port ").append(port);
        }
    }
    return buf.toString();
}
Also used : ProtocolServer(org.apache.dubbo.rpc.ProtocolServer) ExchangeServer(org.apache.dubbo.remoting.exchange.ExchangeServer) ExchangeChannel(org.apache.dubbo.remoting.exchange.ExchangeChannel)

Example 9 with ProtocolServer

use of org.apache.dubbo.rpc.ProtocolServer 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 10 with ProtocolServer

use of org.apache.dubbo.rpc.ProtocolServer 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)

Aggregations

ProtocolServer (org.apache.dubbo.rpc.ProtocolServer)13 RemotingServer (org.apache.dubbo.remoting.RemotingServer)6 IOException (java.io.IOException)2 RpcException (org.apache.dubbo.rpc.RpcException)2 HessianSkeleton (com.caucho.hessian.server.HessianSkeleton)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 JsonRpcServer (com.googlecode.jsonrpc4j.JsonRpcServer)1 Server (io.grpc.Server)1 NettyServerBuilder (io.grpc.netty.NettyServerBuilder)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 SocketTimeoutException (java.net.SocketTimeoutException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)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 URL (org.apache.dubbo.common.URL)1