This is an automated email from the ASF dual-hosted git repository.
iluo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/master by this push:
new d2f58d4 [Dubbo-5140] Make sure the address element properly populated
with 3.0.14 or higher version of cxf #5140 (#5154)
d2f58d4 is described below
commit d2f58d4b692f0b5df6a85454628c6fe7131ce30d
Author: marlinlm <[email protected]>
AuthorDate: Thu Jan 16 20:15:54 2020 +0800
[Dubbo-5140] Make sure the address element properly populated with 3.0.14
or higher version of cxf #5140 (#5154)
* 改为使用soapTransferFactory
* 改为使用soapTransferFactory作为destinationFactory
* 使用soapTransferFactory替代原来的HttpTransforFactory
* 修复codestyle检查错误
* 增加SoapAction配置的处理,使wsdl文件可以正常显示operation对应的soapAction值
* 修改SoapAction配置类的名称
Co-authored-by: sthe9 <[email protected]>
Co-authored-by: Ian Luo <[email protected]>
---
.../protocol/webservice/WebServiceProtocol.java | 366 ++++++++++++---------
1 file changed, 204 insertions(+), 162 deletions(-)
diff --git
a/dubbo-rpc/dubbo-rpc-webservice/src/main/java/org/apache/dubbo/rpc/protocol/webservice/WebServiceProtocol.java
b/dubbo-rpc/dubbo-rpc-webservice/src/main/java/org/apache/dubbo/rpc/protocol/webservice/WebServiceProtocol.java
index 8fda4ba..dff3bd1 100644
---
a/dubbo-rpc/dubbo-rpc-webservice/src/main/java/org/apache/dubbo/rpc/protocol/webservice/WebServiceProtocol.java
+++
b/dubbo-rpc/dubbo-rpc-webservice/src/main/java/org/apache/dubbo/rpc/protocol/webservice/WebServiceProtocol.java
@@ -1,162 +1,204 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.rpc.protocol.webservice;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.remoting.Constants;
-import org.apache.dubbo.remoting.RemotingServer;
-import org.apache.dubbo.remoting.http.HttpBinder;
-import org.apache.dubbo.remoting.http.HttpHandler;
-import org.apache.dubbo.remoting.http.servlet.DispatcherServlet;
-import org.apache.dubbo.rpc.ProtocolServer;
-import org.apache.dubbo.rpc.RpcContext;
-import org.apache.dubbo.rpc.RpcException;
-import org.apache.dubbo.rpc.protocol.AbstractProxyProtocol;
-
-import org.apache.cxf.bus.extension.ExtensionManagerBus;
-import org.apache.cxf.endpoint.Client;
-import org.apache.cxf.frontend.ClientProxy;
-import org.apache.cxf.frontend.ClientProxyFactoryBean;
-import org.apache.cxf.frontend.ServerFactoryBean;
-import org.apache.cxf.interceptor.Fault;
-import org.apache.cxf.transport.http.HTTPConduit;
-import org.apache.cxf.transport.http.HTTPTransportFactory;
-import org.apache.cxf.transport.http.HttpDestinationFactory;
-import org.apache.cxf.transport.servlet.ServletController;
-import org.apache.cxf.transport.servlet.ServletDestinationFactory;
-import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.net.SocketTimeoutException;
-
-import static
org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT;
-import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
-
-/**
- * WebServiceProtocol.
- */
-public class WebServiceProtocol extends AbstractProxyProtocol {
-
- public static final int DEFAULT_PORT = 80;
-
- private final ExtensionManagerBus bus = new ExtensionManagerBus();
-
- private final HTTPTransportFactory transportFactory = new
HTTPTransportFactory();
-
- private HttpBinder httpBinder;
-
- public WebServiceProtocol() {
- super(Fault.class);
- bus.setExtension(new ServletDestinationFactory(),
HttpDestinationFactory.class);
- }
-
- public void setHttpBinder(HttpBinder httpBinder) {
- this.httpBinder = httpBinder;
- }
-
- @Override
- public int getDefaultPort() {
- return DEFAULT_PORT;
- }
-
- @Override
- protected <T> Runnable doExport(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
WebServiceHandler());
- serverMap.put(addr, new ProxyProtocolServer(remotingServer));
- }
- final ServerFactoryBean serverFactoryBean = new ServerFactoryBean();
- serverFactoryBean.setAddress(url.getAbsolutePath());
- serverFactoryBean.setServiceClass(type);
- serverFactoryBean.setServiceBean(impl);
- serverFactoryBean.setBus(bus);
- serverFactoryBean.setDestinationFactory(transportFactory);
- serverFactoryBean.create();
- return new Runnable() {
- @Override
- public void run() {
- if(serverFactoryBean.getServer()!= null) {
- serverFactoryBean.getServer().destroy();
- }
- if(serverFactoryBean.getBus()!=null) {
- serverFactoryBean.getBus().shutdown(true);
- }
- }
- };
- }
-
- @Override
- @SuppressWarnings("unchecked")
- protected <T> T doRefer(final Class<T> serviceType, final URL url) throws
RpcException {
- ClientProxyFactoryBean proxyFactoryBean = new ClientProxyFactoryBean();
-
proxyFactoryBean.setAddress(url.setProtocol("http").toIdentityString());
- proxyFactoryBean.setServiceClass(serviceType);
- proxyFactoryBean.setBus(bus);
- T ref = (T) proxyFactoryBean.create();
- Client proxy = ClientProxy.getClient(ref);
- HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
- HTTPClientPolicy policy = new HTTPClientPolicy();
-
policy.setConnectionTimeout(url.getParameter(Constants.CONNECT_TIMEOUT_KEY,
Constants.DEFAULT_CONNECT_TIMEOUT));
- policy.setReceiveTimeout(url.getParameter(TIMEOUT_KEY,
DEFAULT_TIMEOUT));
- conduit.setClient(policy);
- return ref;
- }
-
- @Override
- protected int getErrorCode(Throwable e) {
- if (e instanceof Fault) {
- e = e.getCause();
- }
- if (e instanceof SocketTimeoutException) {
- return RpcException.TIMEOUT_EXCEPTION;
- } else if (e instanceof IOException) {
- return RpcException.NETWORK_EXCEPTION;
- }
- return super.getErrorCode(e);
- }
-
- private class WebServiceHandler implements HttpHandler {
-
- private volatile ServletController servletController;
-
- @Override
- public void handle(HttpServletRequest request, HttpServletResponse
response) throws IOException, ServletException {
- if (servletController == null) {
- HttpServlet httpServlet = DispatcherServlet.getInstance();
- if (httpServlet == null) {
- response.sendError(500, "No such DispatcherServlet
instance.");
- return;
- }
- synchronized (this) {
- if (servletController == null) {
- servletController = new
ServletController(transportFactory.getRegistry(),
httpServlet.getServletConfig(), httpServlet);
- }
- }
- }
- RpcContext.getContext().setRemoteAddress(request.getRemoteAddr(),
request.getRemotePort());
- servletController.invoke(request, response);
- }
-
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.rpc.protocol.webservice;
+
+import org.apache.cxf.binding.soap.SoapTransportFactory;
+import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.service.model.OperationInfo;
+import org.apache.cxf.transport.Destination;
+
+import org.apache.cxf.transport.http.HTTPConduit;
+import org.apache.cxf.transport.http.AbstractHTTPDestination;
+import org.apache.cxf.transport.http.DestinationRegistry;
+import org.apache.cxf.transport.http.DestinationRegistryImpl;
+import org.apache.cxf.transport.http.HttpDestinationFactory;
+import org.apache.cxf.wsdl.service.factory.AbstractServiceConfiguration;
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.remoting.Constants;
+import org.apache.dubbo.remoting.RemotingServer;
+import org.apache.dubbo.remoting.http.HttpBinder;
+import org.apache.dubbo.remoting.http.HttpHandler;
+import org.apache.dubbo.remoting.http.servlet.DispatcherServlet;
+import org.apache.dubbo.rpc.ProtocolServer;
+import org.apache.dubbo.rpc.RpcContext;
+import org.apache.dubbo.rpc.RpcException;
+import org.apache.dubbo.rpc.protocol.AbstractProxyProtocol;
+
+import org.apache.cxf.bus.extension.ExtensionManagerBus;
+import org.apache.cxf.endpoint.Client;
+import org.apache.cxf.frontend.ClientProxy;
+import org.apache.cxf.frontend.ClientProxyFactoryBean;
+import org.apache.cxf.frontend.ServerFactoryBean;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.transport.servlet.ServletController;
+import org.apache.cxf.transport.servlet.ServletDestinationFactory;
+import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.net.SocketTimeoutException;
+
+import static
org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT;
+import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
+
+/**
+ * WebServiceProtocol.
+ */
+public class WebServiceProtocol extends AbstractProxyProtocol {
+
+ public static final int DEFAULT_PORT = 80;
+
+ private final ExtensionManagerBus bus = new ExtensionManagerBus();
+
+ private SoapTransportFactory transportFactory = null;
+
+ private ServerFactoryBean serverFactoryBean = null;
+
+ private DestinationRegistry destinationRegistry=null;
+
+ private HttpBinder httpBinder;
+
+ private Server server = null;
+
+ public WebServiceProtocol() {
+ super(Fault.class);
+ bus.setExtension(new ServletDestinationFactory(),
HttpDestinationFactory.class);
+ }
+
+ public void setHttpBinder(HttpBinder httpBinder) {
+ this.httpBinder = httpBinder;
+ }
+
+ @Override
+ public int getDefaultPort() {
+ return DEFAULT_PORT;
+ }
+
+
+ @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);
+ }
+ }
+ };
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ protected <T> T doRefer(final Class<T> serviceType, final URL url) throws
RpcException {
+ ClientProxyFactoryBean proxyFactoryBean = new ClientProxyFactoryBean();
+
proxyFactoryBean.setAddress(url.setProtocol("http").toIdentityString());
+ proxyFactoryBean.setServiceClass(serviceType);
+ proxyFactoryBean.setBus(bus);
+ T ref = (T) proxyFactoryBean.create();
+ Client proxy = ClientProxy.getClient(ref);
+ HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
+ HTTPClientPolicy policy = new HTTPClientPolicy();
+
policy.setConnectionTimeout(url.getParameter(Constants.CONNECT_TIMEOUT_KEY,
Constants.DEFAULT_CONNECT_TIMEOUT));
+ policy.setReceiveTimeout(url.getParameter(TIMEOUT_KEY,
DEFAULT_TIMEOUT));
+ conduit.setClient(policy);
+ return ref;
+ }
+
+ @Override
+ protected int getErrorCode(Throwable e) {
+ if (e instanceof Fault) {
+ e = e.getCause();
+ }
+ if (e instanceof SocketTimeoutException) {
+ return RpcException.TIMEOUT_EXCEPTION;
+ } else if (e instanceof IOException) {
+ return RpcException.NETWORK_EXCEPTION;
+ }
+ return super.getErrorCode(e);
+ }
+
+ private class WebServiceHandler implements HttpHandler {
+
+ private volatile ServletController servletController;
+
+ @Override
+ public void handle(HttpServletRequest request, HttpServletResponse
response) throws IOException, ServletException {
+ if (servletController == null) {
+ HttpServlet httpServlet = DispatcherServlet.getInstance();
+ if (httpServlet == null) {
+ response.sendError(500, "No such DispatcherServlet
instance.");
+ return;
+ }
+ synchronized (this) {
+ if (servletController == null) {
+
+ if(server == null){
+ server =
WebServiceProtocol.this.serverFactoryBean.getServer();
+ }
+ Destination d =
WebServiceProtocol.this.transportFactory.getDestination(server.getEndpoint().getEndpointInfo(),bus);
+
destinationRegistry.addDestination((AbstractHTTPDestination) d);
+ this.servletController = new
ServletController(destinationRegistry, httpServlet.getServletConfig(),
httpServlet);
+ }
+ }
+ }
+ RpcContext.getContext().setRemoteAddress(request.getRemoteAddr(),
request.getRemotePort());
+ servletController.invoke(request, response);
+ }
+
+ }
+
+ private class URLHashMethodNameSoapActionServiceConfiguration extends
AbstractServiceConfiguration {
+ public String getAction(OperationInfo op, Method method) {
+ String uri = op.getName().getNamespaceURI();
+ String action = op.getName().getLocalPart();
+ if (StringUtils.isEmpty(action)) {
+ action = method.getName();
+ }
+ return uri+"#"+action;
+ }
+ }
+
+}