summaryrefslogtreecommitdiff
path: root/swext
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2015-10-07 17:40:29 +0200
committerMichael Stahl <mstahl@redhat.com>2015-10-09 10:14:19 +0200
commitf7d149a731a0284d3d7b7b1c26c736654e0712fd (patch)
tree596eeb5c2264a4f8f89a5edfd655b779f0a4d4e0 /swext
parent8e2acdbcbd3afc1777d6e68a83ebbe6d8dd77645 (diff)
swext: remove commons-httpclient dependency from Wiki Publisher
JRE 6 has sufficient HttpURLConnection etc. stuff to make this work without bundling external libraries. Change-Id: I6c71980c718169024006f02a96c442a71d798d55
Diffstat (limited to 'swext')
-rw-r--r--swext/Extension_wiki-publisher.mk2
-rw-r--r--swext/Jar_mediawiki.mk1
-rw-r--r--swext/mediawiki/src/com/sun/star/wiki/Helper.java229
-rw-r--r--swext/mediawiki/src/com/sun/star/wiki/WikiArticle.java109
-rw-r--r--swext/mediawiki/src/com/sun/star/wiki/WikiEditSettingDialog.java31
-rw-r--r--swext/mediawiki/src/com/sun/star/wiki/WikiProtocolSocketFactory.java53
6 files changed, 213 insertions, 212 deletions
diff --git a/swext/Extension_wiki-publisher.mk b/swext/Extension_wiki-publisher.mk
index ffee9acacac0..94ea40bc35e4 100644
--- a/swext/Extension_wiki-publisher.mk
+++ b/swext/Extension_wiki-publisher.mk
@@ -19,13 +19,11 @@ $(eval $(call gb_Extension_use_default_license,wiki-publisher))
ifeq ($(SYSTEM_APACHE_COMMONS),)
$(eval $(call gb_Extension_use_external_project,wiki-publisher,apache_commons_logging))
$(eval $(call gb_Extension_use_external_project,wiki-publisher,apache_commons_codec))
-$(eval $(call gb_Extension_use_external_project,wiki-publisher,apache_commons_httpclient))
$(eval $(call gb_Extension_use_external_project,wiki-publisher,apache_commons_lang))
$(eval $(call gb_Extension_add_file,wiki-publisher,$(if $(filter TRUE,$(HAVE_JAVA6)),commons-codec-1.9.jar,commons-codec-1.6.jar),\
$(call gb_UnpackedTarball_get_dir,apache_commons_codec)$(if $(filter TRUE,$(HAVE_JAVA6)),/dist/commons-codec-1.9.jar,/dist/commons-codec-1.6-SNAPSHOT.jar)\
))
-$(eval $(call gb_Extension_add_file,wiki-publisher,commons-httpclient-3.1.jar,$(call gb_UnpackedTarball_get_dir,apache_commons_httpclient)/dist/commons-httpclient.jar))
$(eval $(call gb_Extension_add_file,wiki-publisher,$(if $(filter TRUE,$(HAVE_JAVA6)),commons-lang3-3.3.1.jar,commons-lang-2.4.jar),\
$(call gb_UnpackedTarball_get_dir,apache_commons_lang)$(if $(filter TRUE,$(HAVE_JAVA6)),/target/commons-lang3-3.3.1.jar,/dist/commons-lang-2.4.jar)\
))
diff --git a/swext/Jar_mediawiki.mk b/swext/Jar_mediawiki.mk
index 2c6bc3f6e5e7..49f0a8bc2c7b 100644
--- a/swext/Jar_mediawiki.mk
+++ b/swext/Jar_mediawiki.mk
@@ -17,7 +17,6 @@ $(eval $(call gb_Jar_set_manifest,mediawiki,$(SRCDIR)/swext/mediawiki/src/com/su
$(eval $(call gb_Jar_use_externals,mediawiki,\
commons-codec \
commons-lang \
- commons-httpclient \
commons-logging \
))
diff --git a/swext/mediawiki/src/com/sun/star/wiki/Helper.java b/swext/mediawiki/src/com/sun/star/wiki/Helper.java
index 50750de76963..f5e5c4848bc8 100644
--- a/swext/mediawiki/src/com/sun/star/wiki/Helper.java
+++ b/swext/mediawiki/src/com/sun/star/wiki/Helper.java
@@ -53,18 +53,10 @@ import com.sun.star.uno.XComponentContext;
import com.sun.star.util.XChangesBatch;
import java.net.*;
import java.io.*;
+import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLException;
import javax.swing.text.html.HTMLEditorKit;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HostConfiguration;
-import org.apache.commons.httpclient.HttpMethodBase;
-import org.apache.commons.httpclient.cookie.CookiePolicy;
-import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
-import org.apache.commons.httpclient.protocol.Protocol;
-import org.apache.commons.httpclient.URI;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.methods.PostMethod;
public class Helper
{
@@ -142,8 +134,6 @@ public class Helper
private static String[] m_pConfigStrings;
- private static MultiThreadedHttpConnectionManager m_aConnectionManager;
- private static HttpClient m_aClient;
private static boolean m_bAllowConnection = true;
private static Boolean m_bShowInBrowser = null;
@@ -174,35 +164,11 @@ public class Helper
return m_pConfigStrings[nID];
}
- synchronized private static HttpClient GetHttpClient()
- throws WikiCancelException
- {
- if ( !m_bAllowConnection )
- throw new WikiCancelException();
-
- if ( m_aConnectionManager == null )
- m_aConnectionManager = new MultiThreadedHttpConnectionManager();
-
- if ( m_aClient == null )
- {
- m_aClient = new HttpClient( m_aConnectionManager );
- m_aClient.getParams().setParameter( "http.protocol.cookie-policy", CookiePolicy.BROWSER_COMPATIBILITY );
- m_aClient.getParams().setParameter( "http.protocol.single-cookie-header", Boolean.TRUE );
- m_aClient.getParams().setParameter( "http.protocol.content-charset", "UTF-8" );
- }
-
- return m_aClient;
- }
-
synchronized protected static void AllowConnection( boolean bAllow )
{
m_bAllowConnection = bAllow;
- if ( !bAllow && m_aConnectionManager != null )
- {
- m_aClient = null;
- m_aConnectionManager.shutdown();
- m_aConnectionManager = null;
- }
+ // TODO: how to shut down any pending connections?
+ // hope it doesn't matter?
}
synchronized protected static boolean IsConnectionAllowed()
@@ -282,11 +248,6 @@ public class Helper
return m_xInteractionHandler;
}
- private static Protocol GetOwnHttps( int nPort )
- {
- return new Protocol( "https", new WikiProtocolSocketFactory(), ( ( nPort < 0 ) ? 443 : nPort ) );
- }
-
protected static String GetMainURL( String sWebPage, String sVURL )
{
String sResultURL = "";
@@ -366,9 +327,6 @@ public class Helper
}
-
-
-
protected static String CreateTempFile( XComponentContext xContext )
{
String sURL = "";
@@ -579,30 +537,30 @@ public class Helper
return xNameAccess;
}
- private static void SetConfigurationProxy( HostConfiguration aHostConfig, XComponentContext xContext )
+ private static Proxy GetConfigurationProxy(URI uri, XComponentContext xContext)
{
- if ( aHostConfig == null || xContext == null )
- return;
+ assert(uri != null);
+ assert(xContext != null);
try
{
XNameAccess xNameAccess = GetConfigNameAccess( xContext, "org.openoffice.Inet/Settings" );
int nProxyType = AnyConverter.toInt( xNameAccess.getByName( "ooInetProxyType" ) );
- if ( nProxyType == 0 )
- aHostConfig.setProxyHost( null );
- else
- {
+ if ( nProxyType == 0 ) {
+ return Proxy.NO_PROXY;
+ } else {
if ( nProxyType == 1 )
{
// system proxy
+ return null;
}
else if ( nProxyType == 2 )
{
String aProxyNameProp = "ooInetHTTPProxyName";
String aProxyPortProp = "ooInetHTTPProxyPort";
- if ( aHostConfig.getProtocol().getScheme().equals( "https" ) )
+ if (uri.getScheme().equals("https"))
{
aProxyNameProp = "ooInetHTTPSProxyName";
aProxyPortProp = "ooInetHTTPSProxyPort";
@@ -620,7 +578,8 @@ public class Helper
nProxyPort = 80;
// TODO: check whether the URL is in the NoProxy list
- aHostConfig.setProxy( aProxyName, nProxyPort );
+ InetSocketAddress address = new InetSocketAddress(aProxyName, nProxyPort);
+ return new Proxy(Proxy.Type.HTTP, address);
}
}
}
@@ -628,6 +587,7 @@ public class Helper
{
e.printStackTrace();
}
+ return null; // invalid configuration value?
}
protected static void ShowURLInBrowser( XComponentContext xContext, String sURL )
@@ -648,33 +608,70 @@ public class Helper
}
}
- protected static void ExecuteMethod( HttpMethodBase aMethod, HostConfiguration aHostConfig, URI aURI, XComponentContext xContext, boolean bSetHost )
+ protected static HttpURLConnection PrepareMethod(String method, URI uri, XComponentContext xContext)
throws WikiCancelException, IOException, SSLException
{
- if ( aMethod != null && aHostConfig != null && aURI != null && xContext != null )
+ assert(method != null);
+ assert(uri != null);
+ assert(xContext != null);
+
+ if (!IsConnectionAllowed()) {
+ throw new WikiCancelException();
+ }
+
+ if (java.net.CookieHandler.getDefault() == null) {
+ // set a cookie manager so cookies don't get lost
+ // apparently it's not possible to do that on a per-connection
+ // basis but only globally?
+ java.net.CookieHandler.setDefault(new java.net.CookieManager());
+ }
+
+ Proxy proxy = GetConfigurationProxy(uri, xContext);
+ HttpURLConnection conn = null;
+ if (proxy != null) {
+ conn = (HttpURLConnection) uri.toURL().openConnection(proxy);
+ } else {
+ conn = (HttpURLConnection) uri.toURL().openConnection();
+ }
+ if (uri.getScheme().equals("https") && AllowUnknownCert(xContext, uri.getHost()))
{
- if ( bSetHost )
- {
- aHostConfig.setHost( aURI );
- SetConfigurationProxy( aHostConfig, xContext );
- }
+ // let unknown certificates be accepted
+ ((HttpsURLConnection) conn).setSSLSocketFactory(new WikiProtocolSocketFactory());
+ }
- if ( aHostConfig.getProtocol().getScheme().equals( "https" )
- && AllowUnknownCert( xContext, aURI.getHost() ) )
- {
- // let unknown certificates be accepted
- {
- {
- aHostConfig.setHost( aHostConfig.getHost(), ( aURI.getPort() < 0 ? 443 : aURI.getPort() ), Helper.GetOwnHttps( aURI.getPort() ) );
- Helper.GetHttpClient().executeMethod( aHostConfig, aMethod );
- }
+ conn.setRequestMethod(method);
+ // note: don't connect yet so that the caller can do some further setup
+
+ return conn;
+ }
+
+ protected static String ReadResponseBody(HttpURLConnection conn)
+ throws IOException
+ {
+ String ret = null;
+ InputStream stream = conn.getInputStream();
+ try {
+ // there doesn't seem to be an easier way get the content encoding
+ String type = conn.getContentType();
+ String charset = "ISO-8859-1"; // default in RFC2616
+ for (String param : type.split(";")) {
+ if (param.trim().toLowerCase().startsWith("charset=")) {
+ charset = param.trim().substring("charset=".length());
+ break;
}
}
- else
- {
- Helper.GetHttpClient().executeMethod( aHostConfig, aMethod );
+ BufferedReader br =
+ new BufferedReader(new InputStreamReader(stream, charset));
+ StringBuilder buf = new StringBuilder();
+ String line;
+ while ((line = br.readLine()) != null) {
+ buf.append(line);
}
+ ret = buf.toString();
+ } finally {
+ stream.close();
}
+ return ret;
}
private static class HTMLParse extends HTMLEditorKit
@@ -738,76 +735,74 @@ public class Helper
return sResult;
}
- protected static HostConfiguration Login( URI aMainURL, String sWikiUser, String sWikiPass, XComponentContext xContext )
- throws java.io.IOException, WikiCancelException
+ protected static boolean Login(URI aMainURL, String sWikiUser, String sWikiPass, XComponentContext xContext)
+ throws java.io.IOException, WikiCancelException, URISyntaxException
{
- HostConfiguration aHostConfig = null;
+ boolean success = false;
if ( sWikiUser != null && sWikiPass != null && xContext != null )
{
- HostConfiguration aNewHostConfig = new HostConfiguration();
-
- URI aURI = new URI( aMainURL.toString() + "index.php?title=Special:Userlogin", false );
- GetMethod aGetCookie = new GetMethod( aURI.getEscapedPathQuery() );
-
- ExecuteMethod( aGetCookie, aNewHostConfig, aURI, xContext, true );
-
- int nResultCode = aGetCookie.getStatusCode();
String sLoginPage = null;
- if ( nResultCode == 200 )
- sLoginPage = aGetCookie.getResponseBodyAsString();
-
- aGetCookie.releaseConnection();
+ URI aURI = new URI(aMainURL.toString() + "index.php?title=Special:Userlogin");
+ HttpURLConnection connGet = PrepareMethod("GET", aURI, xContext);
+ connGet.setInstanceFollowRedirects(true);
+
+ connGet.connect();
+ int nResultCode = connGet.getResponseCode();
+ if (nResultCode == 200) {
+ sLoginPage = ReadResponseBody(connGet);
+ }
if ( sLoginPage != null )
{
String sLoginToken = GetLoginToken( sLoginPage );
- PostMethod aPost = new PostMethod();
- URI aPostURI = new URI( aMainURL.getPath() + "index.php?title=Special:Userlogin&action=submitlogin", false );
- aPost.setPath( aPostURI.getEscapedPathQuery() );
+ URI aPostURI = new URI(aMainURL.toString() + "index.php?title=Special:Userlogin&action=submitlogin");
- aPost.addParameter( "wpName", sWikiUser );
- aPost.addParameter( "wpRemember", "1" );
- aPost.addParameter( "wpPassword", sWikiPass );
- if ( sLoginToken.length() > 0 )
- aPost.addParameter( "wpLoginToken", sLoginToken );
+ HttpURLConnection connPost = PrepareMethod("POST", aPostURI, xContext);
+ connPost.setInstanceFollowRedirects(true);
+ connPost.setDoInput(true);
+ connPost.setDoOutput(true);
+ connPost.connect();
+
+ OutputStreamWriter post = new OutputStreamWriter(connPost.getOutputStream());
+ post.write("wpName=");
+ post.write(URLEncoder.encode(sWikiUser, "UTF-8"));
+ post.write("&wpRemember=1");
+ post.write("&wpPassword=");
+ post.write(URLEncoder.encode(sWikiPass, "UTF-8"));
+
+ if (sLoginToken.length() > 0) {
+ post.write("&wpLoginToken=");
+ post.write(URLEncoder.encode(sLoginToken, "UTF-8"));
+ }
String[][] pArgs = GetSpecialArgs( xContext, aMainURL.getHost() );
if ( pArgs != null )
for ( int nArgInd = 0; nArgInd < pArgs.length; nArgInd++ )
if ( pArgs[nArgInd].length == 2 && pArgs[nArgInd][0] != null && pArgs[nArgInd][1] != null )
- aPost.addParameter( pArgs[nArgInd][0], pArgs[nArgInd][1] );
-
- ExecuteMethod( aPost, aNewHostConfig, aPostURI, xContext, false );
-
- nResultCode = aPost.getStatusCode();
-
- while( nResultCode >= 301 && nResultCode <= 303 || nResultCode == 307 )
- {
- String sRedirectURL = aPost.getResponseHeader( "Location" ).getValue();
- aPost.releaseConnection();
+ {
+ post.write("&");
+ post.write(URLEncoder.encode(pArgs[nArgInd][0], "UTF-8"));
+ post.write("=");
+ post.write(URLEncoder.encode(pArgs[nArgInd][0], "UTF-8"));
+ }
- aURI = new URI( sRedirectURL );
- aPost = new PostMethod();
- aPost.setPath( aURI.getEscapedPathQuery() );
- ExecuteMethod( aPost, aNewHostConfig, aURI, xContext, false );
+ post.flush();
+ post.close();
- nResultCode = aPost.getStatusCode();
- }
+ nResultCode = connPost.getResponseCode();
if ( nResultCode == 200 )
{
- String sResult = aPost.getResponseBodyAsString();
+ String sResult = ReadResponseBody(connPost);
if ( !LoginReportsError( sResult ) )
- aHostConfig = aNewHostConfig;
+ success = true;
}
-
- aPost.releaseConnection();
}
}
- return aHostConfig;
+ return success;
}
protected static String[] GetPasswordsForURLAndUser( XComponentContext xContext, String sURL, String sUserName )
diff --git a/swext/mediawiki/src/com/sun/star/wiki/WikiArticle.java b/swext/mediawiki/src/com/sun/star/wiki/WikiArticle.java
index e16db7156831..58638b5442ee 100644
--- a/swext/mediawiki/src/com/sun/star/wiki/WikiArticle.java
+++ b/swext/mediawiki/src/com/sun/star/wiki/WikiArticle.java
@@ -19,15 +19,14 @@
package com.sun.star.wiki;
import java.io.StringReader;
+import java.io.OutputStreamWriter;
import java.util.Map;
+import java.net.URLEncoder;
+import java.net.URI;
+import java.net.HttpURLConnection;
import javax.swing.text.html.HTMLEditorKit;
-import org.apache.commons.httpclient.HostConfiguration;
-import org.apache.commons.httpclient.URI;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.methods.PostMethod;
-
import com.sun.star.uno.XComponentContext;
@@ -47,12 +46,11 @@ public class WikiArticle
private final String m_sTitle;
private final URI m_aMainURI;
- private HostConfiguration m_aHostConfig;
-
+ private boolean m_isLoggedIn = false;
/** Creates a new instance of WikiArticle */
public WikiArticle( XComponentContext xContext, String sTitle, Map<String,String> wikiSettings, boolean bLogin, WikiPropDialog aPropDialog )
- throws java.net.MalformedURLException, java.io.IOException, WikiCancelException
+ throws java.net.URISyntaxException, java.io.IOException, WikiCancelException
{
m_xContext = xContext;
@@ -61,7 +59,7 @@ public class WikiArticle
m_sWikiPass = wikiSettings.get("Password");
m_sTitle = sTitle;
- m_aMainURI = new URI( sMainUrl, false );
+ m_aMainURI = new URI(sMainUrl);
if ( bLogin )
{
@@ -112,23 +110,21 @@ public class WikiArticle
private String getArticleWiki()
- throws java.io.IOException, WikiCancelException
+ throws java.net.URISyntaxException, java.io.IOException, WikiCancelException
{
String sWikiCode = null;
- if ( m_aHostConfig != null )
+ if (m_isLoggedIn)
{
- URI aURI = new URI( m_aMainURI.toString() + "index.php?title=" + m_sTitle + "&action=edit", false );
- GetMethod aRequest = new GetMethod( aURI.getEscapedPathQuery() );
+ URI aURI = new URI(m_aMainURI.toString() + "index.php?title=" + m_sTitle + "&action=edit");
+ HttpURLConnection connGet = Helper.PrepareMethod("GET", aURI, m_xContext);
+ connGet.connect();
- Helper.ExecuteMethod( aRequest, m_aHostConfig, aURI, m_xContext, false );
-
- int nResultCode = aRequest.getStatusCode();
+ int nResultCode = connGet.getResponseCode();
String sWebPage = null;
- if ( nResultCode == 200 )
- sWebPage = aRequest.getResponseBodyAsString();
-
- aRequest.releaseConnection();
+ if (nResultCode == 200) {
+ sWebPage = Helper.ReadResponseBody(connGet);
+ }
if ( sWebPage != null )
{
@@ -156,19 +152,19 @@ public class WikiArticle
}
private void InitArticleHTML()
- throws java.io.IOException, WikiCancelException
+ throws java.net.URISyntaxException, java.io.IOException, WikiCancelException
{
- if ( m_aHostConfig != null )
+ if (m_isLoggedIn)
{
- URI aURI = new URI( m_aMainURI.toString() + "index.php?title=" + m_sTitle, false );
- GetMethod aRequest = new GetMethod( aURI.getEscapedPathQuery() );
-
- Helper.ExecuteMethod( aRequest, m_aHostConfig, aURI, m_xContext, false );
+ URI uri = new URI(m_aMainURI.toString() + "index.php?title=" + m_sTitle);
+ HttpURLConnection connGet = Helper.PrepareMethod("GET", uri, m_xContext);
+ connGet.connect();
- int nResultCode = aRequest.getStatusCode();
+ int nResultCode = connGet.getResponseCode();
String sWebPage = null;
- if ( nResultCode == 200 )
- sWebPage = aRequest.getResponseBodyAsString();
+ if (nResultCode == 200) {
+ sWebPage = Helper.ReadResponseBody(connGet);
+ }
if ( sWebPage != null )
{
@@ -192,36 +188,46 @@ public class WikiArticle
}
protected boolean setArticle( String sWikiCode, String sWikiComment, boolean bMinorEdit )
- throws java.io.IOException, WikiCancelException
+ throws java.net.URISyntaxException, java.io.IOException, WikiCancelException
{
boolean bResult = false;
- if ( m_aHostConfig != null && sWikiCode != null && sWikiComment != null )
+ if (m_isLoggedIn && sWikiCode != null && sWikiComment != null)
{
// get the edit time and token
getArticleWiki();
- URI aURI = new URI( m_aMainURI.getPath() + "index.php?title=" + m_sTitle + "&action=submit", false );
- PostMethod aPost = new PostMethod();
- aPost.setPath( aURI.getEscapedPathQuery() );
-
- aPost.addParameter( "wpTextbox1", sWikiCode );
- aPost.addParameter( "wpSummary", sWikiComment );
- aPost.addParameter( "wpSection", "" );
- aPost.addParameter( "wpEdittime", m_sEditTime );
- aPost.addParameter( "wpSave", "Save page" );
- aPost.addParameter( "wpEditToken", m_sEditToken );
-
- if ( bMinorEdit )
- aPost.addParameter( "wpMinoredit", "1" );
+ URI uri = new URI(m_aMainURI.toString() + "index.php?title=" + m_sTitle + "&action=submit");
+
+ HttpURLConnection connPost = Helper.PrepareMethod("POST", uri, m_xContext);
+ connPost.setDoInput(true);
+ connPost.setDoOutput(true);
+ connPost.connect();
+
+ OutputStreamWriter post = new OutputStreamWriter(connPost.getOutputStream());
+ post.write("wpTextbox1=");
+ post.write(URLEncoder.encode(sWikiCode, "UTF-8"));
+ post.write("&wpSummary=");
+ post.write(URLEncoder.encode(sWikiComment, "UTF-8"));
+ post.write("&wpSection=");
+ post.write("&wpEdittime=");
+ post.write(URLEncoder.encode(m_sEditTime, "UTF-8"));
+ post.write("&wpSave=Save%20page");
+ post.write("&wpEditToken=");
+ post.write(URLEncoder.encode(m_sEditToken, "UTF-8"));
+
+ if (bMinorEdit) {
+ post.write("&wpMinoredit=1");
+ }
- Helper.ExecuteMethod( aPost, m_aHostConfig, aURI, m_xContext, false );
+ post.flush();
+ post.close();
- int nResultCode = aPost.getStatusCode();
+ int nResultCode = connPost.getResponseCode();
if ( nResultCode < 400 )
bResult = true;
- String aResult = aPost.getResponseBodyAsString();
+ String aResult = Helper.ReadResponseBody(connPost);
// TODO: remove the debug printing, try to detect the error
System.out.print( "nSubmitCode = " + nResultCode + "\n===\n" + aResult );
@@ -231,15 +237,12 @@ public class WikiArticle
}
private boolean Login()
- throws java.io.IOException, WikiCancelException
+ throws java.net.URISyntaxException, java.io.IOException, WikiCancelException
{
- m_aHostConfig = Helper.Login( m_aMainURI, m_sWikiUser, m_sWikiPass, m_xContext );
- return ( m_aHostConfig != null );
+ m_isLoggedIn = Helper.Login( m_aMainURI, m_sWikiUser, m_sWikiPass, m_xContext );
+ return m_isLoggedIn;
}
-
-
-
protected boolean NotExist()
{
boolean bResult = true;
diff --git a/swext/mediawiki/src/com/sun/star/wiki/WikiEditSettingDialog.java b/swext/mediawiki/src/com/sun/star/wiki/WikiEditSettingDialog.java
index aef6cb6a29b6..ad9e2ca8c1e1 100644
--- a/swext/mediawiki/src/com/sun/star/wiki/WikiEditSettingDialog.java
+++ b/swext/mediawiki/src/com/sun/star/wiki/WikiEditSettingDialog.java
@@ -21,12 +21,10 @@ package com.sun.star.wiki;
import java.util.HashMap;
import java.util.Map;
+import java.net.URI;
+import java.net.HttpURLConnection;
import javax.net.ssl.SSLException;
-import org.apache.commons.httpclient.HostConfiguration;
-import org.apache.commons.httpclient.URI;
-import org.apache.commons.httpclient.methods.GetMethod;
-
import com.sun.star.awt.XDialog;
import com.sun.star.beans.XPropertySet;
import com.sun.star.lang.EventObject;
@@ -199,8 +197,6 @@ public class WikiEditSettingDialog extends WikiDialog
String sUserName = ( String ) GetPropSet( "UsernameField" ).getPropertyValue( "Text" );
String sPassword = ( String ) GetPropSet( "PasswordField" ).getPropertyValue( "Text" );
- HostConfiguration aHostConfig = new HostConfiguration();
- boolean bInitHost = true;
boolean bAllowIndex = true;
do
@@ -213,20 +209,17 @@ public class WikiEditSettingDialog extends WikiDialog
if ( sURL.length() > 0 )
{
- URI aURI = new URI( sURL, false );
- GetMethod aRequest = new GetMethod( aURI.getEscapedPathQuery() );
- aRequest.setFollowRedirects( false );
- Helper.ExecuteMethod( aRequest, aHostConfig, aURI, m_xContext, bInitHost );
- bInitHost = false;
+ URI aURI = new URI(sURL);
+ HttpURLConnection connGet = Helper.PrepareMethod("GET", aURI, m_xContext);
+ connGet.setInstanceFollowRedirects(false);
+ connGet.connect();
- int nResultCode = aRequest.getStatusCode();
+ int nResultCode = connGet.getResponseCode();
String sWebPage = null;
if ( nResultCode == 200 )
- sWebPage = aRequest.getResponseBodyAsString();
+ sWebPage = Helper.ReadResponseBody(connGet);
else if ( nResultCode >= 301 && nResultCode <= 303 || nResultCode == 307 )
- sRedirectURL = aRequest.getResponseHeader( "Location" ).getValue();
-
- aRequest.releaseConnection();
+ sRedirectURL = connGet.getHeaderField("Location");
if ( sWebPage != null && sWebPage.length() > 0 )
{
@@ -252,10 +245,10 @@ public class WikiEditSettingDialog extends WikiDialog
}
else
{
- URI aMainURI = new URI( sMainURL, true ); // it must be an escaped URL, otherwise an exception should be thrown
+ URI aMainURI = new URI(sMainURL);
if ( ( sUserName.length() > 0 || sPassword.length() > 0 )
- && Helper.Login( aMainURI, sUserName, sPassword, m_xContext ) == null )
+ && !Helper.Login(aMainURI, sUserName, sPassword, m_xContext))
{
// a wrong login information is provided
// show error
@@ -268,7 +261,7 @@ public class WikiEditSettingDialog extends WikiDialog
}
else
{
- setting.put( "Url", aMainURI.getEscapedURI() );
+ setting.put( "Url", aMainURI.toASCIIString() );
setting.put( "Username", sUserName );
setting.put( "Password", sPassword );
if ( addMode )
diff --git a/swext/mediawiki/src/com/sun/star/wiki/WikiProtocolSocketFactory.java b/swext/mediawiki/src/com/sun/star/wiki/WikiProtocolSocketFactory.java
index b6da4a5a630c..5d7efe1cebf2 100644
--- a/swext/mediawiki/src/com/sun/star/wiki/WikiProtocolSocketFactory.java
+++ b/swext/mediawiki/src/com/sun/star/wiki/WikiProtocolSocketFactory.java
@@ -25,17 +25,14 @@ import java.net.Socket;
import java.net.UnknownHostException;
import java.security.KeyStore;
import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
-import org.apache.commons.httpclient.ConnectTimeoutException;
-import org.apache.commons.httpclient.HttpClientError;
-import org.apache.commons.httpclient.params.HttpConnectionParams;
-import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory;
-class WikiProtocolSocketFactory implements SecureProtocolSocketFactory
+class WikiProtocolSocketFactory extends SSLSocketFactory
{
private SSLContext m_aSSLContext;
@@ -105,43 +102,59 @@ class WikiProtocolSocketFactory implements SecureProtocolSocketFactory
}
if ( m_aSSLContext == null )
- throw new HttpClientError();
+ throw new RuntimeException("failed to create SSLContext");
return m_aSSLContext;
}
- public Socket createSocket( String sHost, int nPort, InetAddress clientHost, int clientPort )
- throws IOException, UnknownHostException
+ @Override
+ public Socket createSocket(InetAddress address, int port)
+ throws IOException
{
- return GetNotSoSecureSSLContext().getSocketFactory().createSocket( sHost, nPort, clientHost, clientPort );
+ return GetNotSoSecureSSLContext().getSocketFactory().createSocket(address, port);
+ }
+
+ @Override
+ public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort)
+ throws IOException
+ {
+ return GetNotSoSecureSSLContext().getSocketFactory().createSocket(address, port, localAddress, localPort);
}
- public Socket createSocket( final String sHost, final int nPort, final InetAddress aLocalAddress, final int nLocalPort, final HttpConnectionParams params )
- throws IOException, UnknownHostException, ConnectTimeoutException
+ @Override
+ public Socket createSocket( String sHost, int nPort, InetAddress clientHost, int clientPort )
+ throws IOException, UnknownHostException
{
- if ( params == null )
- return createSocket( sHost, nPort, aLocalAddress, nLocalPort );
-
- int nTimeout = params.getConnectionTimeout();
- Socket aSocket = GetNotSoSecureSSLContext().getSocketFactory().createSocket();
- aSocket.bind( new InetSocketAddress( aLocalAddress, nLocalPort ) );
- aSocket.connect( new InetSocketAddress( sHost, nPort ), nTimeout );
- return aSocket;
+ return GetNotSoSecureSSLContext().getSocketFactory().createSocket( sHost, nPort, clientHost, clientPort );
}
+ @Override
public Socket createSocket( String sHost, int nPort )
throws IOException, UnknownHostException
{
return GetNotSoSecureSSLContext().getSocketFactory().createSocket( sHost, nPort );
}
+ @Override
public Socket createSocket( Socket aSocket, String sHost, int nPort, boolean bAutoClose )
- throws IOException, UnknownHostException
+ throws IOException
{
return GetNotSoSecureSSLContext().getSocketFactory().createSocket( aSocket, sHost, nPort, bAutoClose );
}
@Override
+ public String[] getDefaultCipherSuites()
+ {
+ return GetNotSoSecureSSLContext().getSocketFactory().getDefaultCipherSuites();
+ }
+
+ @Override
+ public String[] getSupportedCipherSuites()
+ {
+ return GetNotSoSecureSSLContext().getSocketFactory().getSupportedCipherSuites();
+ }
+
+ @Override
public boolean equals(Object obj)
{
return ((obj != null) && obj.getClass().equals(WikiProtocolSocketFactory.class));