Rak*_*esh 5 java axis apache-commons-httpclient
由于一些漏洞,我们需要从 commons-httpclient-3.1.jar 移动到 httpclient-4.5.2.jar
现在有一个之前在 3.1 上工作的代码库,但这些方法在 4.5.2 中已弃用。您对如何克服这些错误有任何想法或遇到过
我得到的错误是 1) 无法解析导入 org.apache.commons.httpclient.HostConfiguration 2) 方法 getState() 对于 HttpClient 类型未定义
这是源代码。如果您有任何信息,请告诉我。
import org.apache.axis.MessageContext;
import org.apache.axis.components.net.TransportClientProperties;
import org.apache.axis.components.net.TransportClientPropertiesFactory;
import org.apache.http.auth.Credentials;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.http.client.HttpClient;
import org.apache.http.auth.NTCredentials;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.auth.AuthScope;
import java.net.URL;
public class CommonsHTTPSender extends
org.apache.axis.transport.http.CommonsHTTPSender {
public static final String PROPERTY_PROXY_HOST = "https.proxyHost";
public static final String PROPERTY_PROXY_PORT = "https.proxyPort";
public static final String PROPERTY_PROXY_USERNAME = "https.proxyUser";
public static final String PROPERTY_PROXY_PASSWORD = "https.proxyPassword";
public CommonsHTTPSender() {
}
protected HostConfiguration getHostConfiguration(HttpClient client,
MessageContext context, URL targetURL) {
HostConfiguration config = new HostConfiguration();
if ( targetURL.getProtocol().equalsIgnoreCase("https") )
{
//Jli: our changes start from here. There is a defect in the DefaultHTTPSTransportClientProperties.
// The class is only called once to get the proxy setttings from the system properties. If users
// Change the proxy settings, the class will not pick up the changes. On our DMDI GUI, users
// can make the changes as often as they can. This will create an issue that when the apache axis
// reconnect, it only picks up the proxy setup that users put in the GUI the first time.
// We only use the HTTPS, so this change is only valid for the https.
int urlPort = targetURL.getPort();
if (urlPort == -1) {
urlPort = 443; // default port for https being 443
}
String proxyHost = (String)System.getProperty(PROPERTY_PROXY_HOST);
String proxyPort = (String)System.getProperty(PROPERTY_PROXY_PORT);
String proxyUsername = (String)System.getProperty(PROPERTY_PROXY_USERNAME);
String proxyPassword = (String)System.getProperty(PROPERTY_PROXY_PASSWORD);
if ( proxyHost == null || proxyPort == null ||
proxyHost.length() == 0 || proxyPort.length() == 0) {
config.setHost(targetURL.getHost(), urlPort, targetURL
.getProtocol());
} else {
if ( proxyUsername != null && proxyPassword != null && proxyUsername.length() != 0) {
Credentials proxyCred = new UsernamePasswordCredentials(proxyUsername,
proxyPassword);
// if the username is in the form "user\domain"
// then use NTCredentials instead.
int domainIndex = proxyUsername.indexOf("\\");
if (domainIndex > 0) {
String domain = proxyUsername.substring(0,
domainIndex);
if (proxyUsername.length() > domainIndex + 1) {
String user = proxyUsername.substring(
domainIndex + 1);
proxyCred = new NTCredentials(user, proxyPassword, proxyHost,
domain);
}
}
client.getState().setProxyCredentials(AuthScope.ANY,
proxyCred);
}
int proxyPortInt = new Integer(proxyPort).intValue();
config.setProxy(proxyHost, proxyPortInt);
}
}
else
{
config = super.getHostConfiguration(client, context, targetURL);
}
return config;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1544 次 |
| 最近记录: |