Kaydet (Commit) f7d149a7 authored tarafından Michael Stahl's avatar Michael Stahl

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
üst 8e2acdbc
...@@ -19,13 +19,11 @@ $(eval $(call gb_Extension_use_default_license,wiki-publisher)) ...@@ -19,13 +19,11 @@ $(eval $(call gb_Extension_use_default_license,wiki-publisher))
ifeq ($(SYSTEM_APACHE_COMMONS),) 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_logging))
$(eval $(call gb_Extension_use_external_project,wiki-publisher,apache_commons_codec)) $(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_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),\ $(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)\ $(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),\ $(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)\ $(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)\
)) ))
......
...@@ -17,7 +17,6 @@ $(eval $(call gb_Jar_set_manifest,mediawiki,$(SRCDIR)/swext/mediawiki/src/com/su ...@@ -17,7 +17,6 @@ $(eval $(call gb_Jar_set_manifest,mediawiki,$(SRCDIR)/swext/mediawiki/src/com/su
$(eval $(call gb_Jar_use_externals,mediawiki,\ $(eval $(call gb_Jar_use_externals,mediawiki,\
commons-codec \ commons-codec \
commons-lang \ commons-lang \
commons-httpclient \
commons-logging \ commons-logging \
)) ))
......
...@@ -19,15 +19,14 @@ ...@@ -19,15 +19,14 @@
package com.sun.star.wiki; package com.sun.star.wiki;
import java.io.StringReader; import java.io.StringReader;
import java.io.OutputStreamWriter;
import java.util.Map; import java.util.Map;
import java.net.URLEncoder;
import java.net.URI;
import java.net.HttpURLConnection;
import javax.swing.text.html.HTMLEditorKit; 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; import com.sun.star.uno.XComponentContext;
...@@ -47,12 +46,11 @@ public class WikiArticle ...@@ -47,12 +46,11 @@ public class WikiArticle
private final String m_sTitle; private final String m_sTitle;
private final URI m_aMainURI; private final URI m_aMainURI;
private HostConfiguration m_aHostConfig; private boolean m_isLoggedIn = false;
/** Creates a new instance of WikiArticle */ /** Creates a new instance of WikiArticle */
public WikiArticle( XComponentContext xContext, String sTitle, Map<String,String> wikiSettings, boolean bLogin, WikiPropDialog aPropDialog ) 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; m_xContext = xContext;
...@@ -61,7 +59,7 @@ public class WikiArticle ...@@ -61,7 +59,7 @@ public class WikiArticle
m_sWikiPass = wikiSettings.get("Password"); m_sWikiPass = wikiSettings.get("Password");
m_sTitle = sTitle; m_sTitle = sTitle;
m_aMainURI = new URI( sMainUrl, false ); m_aMainURI = new URI(sMainUrl);
if ( bLogin ) if ( bLogin )
{ {
...@@ -112,23 +110,21 @@ public class WikiArticle ...@@ -112,23 +110,21 @@ public class WikiArticle
private String getArticleWiki() private String getArticleWiki()
throws java.io.IOException, WikiCancelException throws java.net.URISyntaxException, java.io.IOException, WikiCancelException
{ {
String sWikiCode = null; 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 ); URI aURI = new URI(m_aMainURI.toString() + "index.php?title=" + m_sTitle + "&action=edit");
GetMethod aRequest = new GetMethod( aURI.getEscapedPathQuery() ); HttpURLConnection connGet = Helper.PrepareMethod("GET", aURI, m_xContext);
connGet.connect();
Helper.ExecuteMethod( aRequest, m_aHostConfig, aURI, m_xContext, false ); int nResultCode = connGet.getResponseCode();
int nResultCode = aRequest.getStatusCode();
String sWebPage = null; String sWebPage = null;
if ( nResultCode == 200 ) if (nResultCode == 200) {
sWebPage = aRequest.getResponseBodyAsString(); sWebPage = Helper.ReadResponseBody(connGet);
}
aRequest.releaseConnection();
if ( sWebPage != null ) if ( sWebPage != null )
{ {
...@@ -156,19 +152,19 @@ public class WikiArticle ...@@ -156,19 +152,19 @@ public class WikiArticle
} }
private void InitArticleHTML() 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 ); URI uri = new URI(m_aMainURI.toString() + "index.php?title=" + m_sTitle);
GetMethod aRequest = new GetMethod( aURI.getEscapedPathQuery() ); HttpURLConnection connGet = Helper.PrepareMethod("GET", uri, m_xContext);
connGet.connect();
Helper.ExecuteMethod( aRequest, m_aHostConfig, aURI, m_xContext, false );
int nResultCode = aRequest.getStatusCode(); int nResultCode = connGet.getResponseCode();
String sWebPage = null; String sWebPage = null;
if ( nResultCode == 200 ) if (nResultCode == 200) {
sWebPage = aRequest.getResponseBodyAsString(); sWebPage = Helper.ReadResponseBody(connGet);
}
if ( sWebPage != null ) if ( sWebPage != null )
{ {
...@@ -192,36 +188,46 @@ public class WikiArticle ...@@ -192,36 +188,46 @@ public class WikiArticle
} }
protected boolean setArticle( String sWikiCode, String sWikiComment, boolean bMinorEdit ) 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; boolean bResult = false;
if ( m_aHostConfig != null && sWikiCode != null && sWikiComment != null ) if (m_isLoggedIn && sWikiCode != null && sWikiComment != null)
{ {
// get the edit time and token // get the edit time and token
getArticleWiki(); getArticleWiki();
URI aURI = new URI( m_aMainURI.getPath() + "index.php?title=" + m_sTitle + "&action=submit", false ); URI uri = new URI(m_aMainURI.toString() + "index.php?title=" + m_sTitle + "&action=submit");
PostMethod aPost = new PostMethod();
aPost.setPath( aURI.getEscapedPathQuery() ); HttpURLConnection connPost = Helper.PrepareMethod("POST", uri, m_xContext);
connPost.setDoInput(true);
aPost.addParameter( "wpTextbox1", sWikiCode ); connPost.setDoOutput(true);
aPost.addParameter( "wpSummary", sWikiComment ); connPost.connect();
aPost.addParameter( "wpSection", "" );
aPost.addParameter( "wpEdittime", m_sEditTime ); OutputStreamWriter post = new OutputStreamWriter(connPost.getOutputStream());
aPost.addParameter( "wpSave", "Save page" ); post.write("wpTextbox1=");
aPost.addParameter( "wpEditToken", m_sEditToken ); post.write(URLEncoder.encode(sWikiCode, "UTF-8"));
post.write("&wpSummary=");
if ( bMinorEdit ) post.write(URLEncoder.encode(sWikiComment, "UTF-8"));
aPost.addParameter( "wpMinoredit", "1" ); 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 ) if ( nResultCode < 400 )
bResult = true; bResult = true;
String aResult = aPost.getResponseBodyAsString(); String aResult = Helper.ReadResponseBody(connPost);
// TODO: remove the debug printing, try to detect the error // TODO: remove the debug printing, try to detect the error
System.out.print( "nSubmitCode = " + nResultCode + "\n===\n" + aResult ); System.out.print( "nSubmitCode = " + nResultCode + "\n===\n" + aResult );
...@@ -231,15 +237,12 @@ public class WikiArticle ...@@ -231,15 +237,12 @@ public class WikiArticle
} }
private boolean Login() 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 ); m_isLoggedIn = Helper.Login( m_aMainURI, m_sWikiUser, m_sWikiPass, m_xContext );
return ( m_aHostConfig != null ); return m_isLoggedIn;
} }
protected boolean NotExist() protected boolean NotExist()
{ {
boolean bResult = true; boolean bResult = true;
......
...@@ -21,12 +21,10 @@ package com.sun.star.wiki; ...@@ -21,12 +21,10 @@ package com.sun.star.wiki;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.net.URI;
import java.net.HttpURLConnection;
import javax.net.ssl.SSLException; 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.awt.XDialog;
import com.sun.star.beans.XPropertySet; import com.sun.star.beans.XPropertySet;
import com.sun.star.lang.EventObject; import com.sun.star.lang.EventObject;
...@@ -199,8 +197,6 @@ public class WikiEditSettingDialog extends WikiDialog ...@@ -199,8 +197,6 @@ public class WikiEditSettingDialog extends WikiDialog
String sUserName = ( String ) GetPropSet( "UsernameField" ).getPropertyValue( "Text" ); String sUserName = ( String ) GetPropSet( "UsernameField" ).getPropertyValue( "Text" );
String sPassword = ( String ) GetPropSet( "PasswordField" ).getPropertyValue( "Text" ); String sPassword = ( String ) GetPropSet( "PasswordField" ).getPropertyValue( "Text" );
HostConfiguration aHostConfig = new HostConfiguration();
boolean bInitHost = true;
boolean bAllowIndex = true; boolean bAllowIndex = true;
do do
...@@ -213,20 +209,17 @@ public class WikiEditSettingDialog extends WikiDialog ...@@ -213,20 +209,17 @@ public class WikiEditSettingDialog extends WikiDialog
if ( sURL.length() > 0 ) if ( sURL.length() > 0 )
{ {
URI aURI = new URI( sURL, false ); URI aURI = new URI(sURL);
GetMethod aRequest = new GetMethod( aURI.getEscapedPathQuery() ); HttpURLConnection connGet = Helper.PrepareMethod("GET", aURI, m_xContext);
aRequest.setFollowRedirects( false ); connGet.setInstanceFollowRedirects(false);
Helper.ExecuteMethod( aRequest, aHostConfig, aURI, m_xContext, bInitHost ); connGet.connect();
bInitHost = false;
int nResultCode = aRequest.getStatusCode(); int nResultCode = connGet.getResponseCode();
String sWebPage = null; String sWebPage = null;
if ( nResultCode == 200 ) if ( nResultCode == 200 )
sWebPage = aRequest.getResponseBodyAsString(); sWebPage = Helper.ReadResponseBody(connGet);
else if ( nResultCode >= 301 && nResultCode <= 303 || nResultCode == 307 ) else if ( nResultCode >= 301 && nResultCode <= 303 || nResultCode == 307 )
sRedirectURL = aRequest.getResponseHeader( "Location" ).getValue(); sRedirectURL = connGet.getHeaderField("Location");
aRequest.releaseConnection();
if ( sWebPage != null && sWebPage.length() > 0 ) if ( sWebPage != null && sWebPage.length() > 0 )
{ {
...@@ -252,10 +245,10 @@ public class WikiEditSettingDialog extends WikiDialog ...@@ -252,10 +245,10 @@ public class WikiEditSettingDialog extends WikiDialog
} }
else 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 ) 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 // a wrong login information is provided
// show error // show error
...@@ -268,7 +261,7 @@ public class WikiEditSettingDialog extends WikiDialog ...@@ -268,7 +261,7 @@ public class WikiEditSettingDialog extends WikiDialog
} }
else else
{ {
setting.put( "Url", aMainURI.getEscapedURI() ); setting.put( "Url", aMainURI.toASCIIString() );
setting.put( "Username", sUserName ); setting.put( "Username", sUserName );
setting.put( "Password", sPassword ); setting.put( "Password", sPassword );
if ( addMode ) if ( addMode )
......
...@@ -25,17 +25,14 @@ import java.net.Socket; ...@@ -25,17 +25,14 @@ import java.net.Socket;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.security.KeyStore; import java.security.KeyStore;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory; import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager; import javax.net.ssl.X509TrustManager;
import java.security.cert.CertificateException; import java.security.cert.CertificateException;
import java.security.cert.X509Certificate; 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; private SSLContext m_aSSLContext;
...@@ -105,42 +102,58 @@ class WikiProtocolSocketFactory implements SecureProtocolSocketFactory ...@@ -105,42 +102,58 @@ class WikiProtocolSocketFactory implements SecureProtocolSocketFactory
} }
if ( m_aSSLContext == null ) if ( m_aSSLContext == null )
throw new HttpClientError(); throw new RuntimeException("failed to create SSLContext");
return m_aSSLContext; return m_aSSLContext;
} }
public Socket createSocket( String sHost, int nPort, InetAddress clientHost, int clientPort ) @Override
throws IOException, UnknownHostException 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 ) @Override
throws IOException, UnknownHostException, ConnectTimeoutException public Socket createSocket( String sHost, int nPort, InetAddress clientHost, int clientPort )
throws IOException, UnknownHostException
{ {
if ( params == null ) return GetNotSoSecureSSLContext().getSocketFactory().createSocket( sHost, nPort, clientHost, clientPort );
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;
} }
@Override
public Socket createSocket( String sHost, int nPort ) public Socket createSocket( String sHost, int nPort )
throws IOException, UnknownHostException throws IOException, UnknownHostException
{ {
return GetNotSoSecureSSLContext().getSocketFactory().createSocket( sHost, nPort ); return GetNotSoSecureSSLContext().getSocketFactory().createSocket( sHost, nPort );
} }
@Override
public Socket createSocket( Socket aSocket, String sHost, int nPort, boolean bAutoClose ) public Socket createSocket( Socket aSocket, String sHost, int nPort, boolean bAutoClose )
throws IOException, UnknownHostException throws IOException
{ {
return GetNotSoSecureSSLContext().getSocketFactory().createSocket( aSocket, sHost, nPort, bAutoClose ); 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 @Override
public boolean equals(Object obj) public boolean equals(Object obj)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment