Search in sources :

Example 1 with RequestProcessorFactoryFactory

use of org.apache.xmlrpc.server.RequestProcessorFactoryFactory 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

IOException (java.io.IOException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 ServletException (javax.servlet.ServletException)1 URL (org.apache.dubbo.common.URL)1 RemotingServer (org.apache.dubbo.remoting.RemotingServer)1 ProtocolServer (org.apache.dubbo.rpc.ProtocolServer)1 RpcException (org.apache.dubbo.rpc.RpcException)1 XmlRpcException (org.apache.xmlrpc.XmlRpcException)1 XmlRpcRequest (org.apache.xmlrpc.XmlRpcRequest)1 PropertyHandlerMapping (org.apache.xmlrpc.server.PropertyHandlerMapping)1 RequestProcessorFactoryFactory (org.apache.xmlrpc.server.RequestProcessorFactoryFactory)1 XmlRpcServerConfigImpl (org.apache.xmlrpc.server.XmlRpcServerConfigImpl)1 XmlRpcServletServer (org.apache.xmlrpc.webserver.XmlRpcServletServer)1 RemoteAccessException (org.springframework.remoting.RemoteAccessException)1