问题描述
我正在尝试更改cxf HTTPTransportFactory
使用的 HttpURLConnection
.
I'm trying to change the HttpURLConnection
that the cxf HTTPTransportFactory
uses.
Cxf(版本2.7.3)对HTTP/https请求使用 HTTPTransportFactory
. HTTPTransportFactory
使用类型为 URLConnectionHTTPConduit
的管道. URLConnectionHTTPConduit
具有方法: createConnection
,该方法返回 HttpURLConnection
.我需要用自己的自定义变量替换 HttpURLConnection
,让我们将其命名为 CustomHttpURLConnection
.
Cxf (version 2.7.3) uses HTTPTransportFactory
for http/https request.The HTTPTransportFactory
uses Conduit of type URLConnectionHTTPConduit
.URLConnectionHTTPConduit
has method: createConnection
which returns HttpURLConnection
.I need to replace HttpURLConnection
with my own custom one, lets call it CustomHttpURLConnection
.
我设法通过以下方式更改cxf使用的 TransportFactory
:
I managed to change the TransportFactory
that cxf uses by:
-
创建扩展
HTTPTransportFactory
的类:CustomHTTPTransportFactory
(现在此类为空):
Creating class that extends
HTTPTransportFactory
:CustomHTTPTransportFactory
(Right now this class is empty):
public class CustomTransportFactory extends HTTPTransportFactory{
}
将 CustomTransportFactory
注册到正确的传输ID:在这种情况下, http://schemas.xmlsoap.org/soap/http
Register CustomTransportFactory
to the right Transport Id: in this case http://schemas.xmlsoap.org/soap/http
这是我的XML:
<beans:bean id="tranpo" class="CustomTransportFactory" lazy-init="false">
<beans:property name="transportIds">
<beans:list>
<beans:value>"http://schemas.xmlsoap.org/soap/http"</beans:value>
</beans:list>
</beans:property>
</beans:bean>
但是,我需要能够将 CustomHttpURLConnection
注册到cxf传输 HTTPTransportFactory
.
However, I need to be able to register my CustomHttpURLConnection
to the cxf transport HTTPTransportFactory
.
有人知道如何解决这个问题吗?
Does anyone has any idea how to solve this problem?
推荐答案
创建一个HTTPConduitFactory并将其注册到上下文中.然后,HTTPTransportFactory将使用它来创建管道,而不是创建基于默认URLConnection的管道.这就是基于HTTP Commons Async的管道的创建和使用方式.
Create a HTTPConduitFactory and register that in the context. The HTTPTransportFactory will then use that to create the conduit instead of creating the default URLConnection based one. This is how the HTTP Commons Async based conduit gets created and used.
这篇关于更改HttpTransportFactory cxf 2.7.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!