Kaydet (Commit) 81d31dc3 authored tarafından Michael Stahl's avatar Michael Stahl Kaydeden (comit) Andras Timar

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
(cherry picked from commit f7d149a7)
üst c45c2c8f
......@@ -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)\
))
......
......@@ -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 \
))
......
......@@ -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;
......
......@@ -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 )
......
......@@ -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,42 +102,58 @@ 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)
{
......
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