Ignore:
Timestamp:
Feb 28, 2011, 7:40:53 PM (13 years ago)
Author:
mlg
Message:

Modifications to handle proxy error.
Two types of error are handled : proxy address error and proxy authentication error.
Connecting to jiwigo via a proxy seems to work (tried with my own server... gonna have to try with an external server).
version is 0.13.1.1

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/session/SessionManager.java

    r9394 r9430  
    88import org.apache.commons.httpclient.HostConfiguration;
    99import org.apache.commons.httpclient.HttpClient;
    10 import org.apache.commons.httpclient.HttpException;
    1110import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
    1211import org.apache.commons.httpclient.UsernamePasswordCredentials;
     
    1817
    1918import fr.mael.jiwigo.transverse.enumeration.MethodsEnum;
     19import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException;
    2020import fr.mael.jiwigo.transverse.util.Tools;
    2121
     
    125125    /**
    126126     * Connection method
    127      * @return true if successful
    128      */
    129     public boolean processLogin() {
     127     *
     128     * @return 0 if Ok, 1 if not Ok (reason not specified), 2 if proxy error
     129     *
     130     *
     131     */
     132    public int processLogin() {
    130133        Document doc;
    131134        //configures the proxy
     
    139142            }
    140143        }
     144        //      try {
    141145        try {
    142146            doc = executeReturnDocument(MethodsEnum.LOGIN.getLabel(), "username", login, "password", password);
    143             return Tools.checkOk(doc);
     147            return (Tools.checkOk(doc) ? 0 : 1);
     148        } catch (IOException e) {
     149            LOG.debug(Tools.getStackTrace(e));
     150            return 1;
     151        } catch (ProxyAuthenticationException e) {
     152            LOG.debug(Tools.getStackTrace(e));
     153            return 2;
    144154        } catch (Exception e) {
    145             LOG.error(Tools.getStackTrace(e));
    146         }
    147         return false;
     155            LOG.debug(Tools.getStackTrace(e));
     156            return 1;
     157        }
     158
    148159    }
    149160
     
    154165     * @return the result
    155166     * @throws UnsupportedEncodingException
    156      */
    157     public String executeReturnString(String methode, String... parametres) throws UnsupportedEncodingException {
     167     * @throws ProxyAuthenticationException
     168     */
     169    public String executeReturnString(String methode, String... parametres) throws UnsupportedEncodingException,
     170            ProxyAuthenticationException {
    158171        if (parametres.length % 2 != 0 && !(parametres == null)) {
    159172            try {
     
    174187        method.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
    175188        //end
    176 
    177189        try {
    178             client.executeMethod(method);
     190            int test = client.executeMethod(method);
     191            if (test == 407) {
     192                throw new ProxyAuthenticationException("Proxy configuration exception. Check username and password");
     193            }
    179194            InputStream streamResponse = method.getResponseBodyAsStream();
    180195            //      System.out.println(Outil.readInputStreamAsString(streamResponse));
     
    183198            LOG.debug(toReturn);
    184199            return toReturn;
    185         } catch (HttpException e) {
    186             // TODO Auto-generated catch block
    187             LOG.error(Tools.getStackTrace(e));
    188200        } catch (IOException e) {
    189             // TODO Auto-generated catch block
    190             LOG.error(Tools.getStackTrace(e));
    191         } catch (IllegalArgumentException e) {
    192             LOG.error(Tools.getStackTrace(e));
    193         } finally {
    194             method.releaseConnection();
     201
    195202        }
    196203        return null;
     
    204211     * @return the result
    205212     * @throws IOException
    206      */
    207     public Document executeReturnDocument(String methode, String... parametres) throws IOException {
     213     * @throws ProxyAuthenticationException
     214     */
     215    public Document executeReturnDocument(String methode, String... parametres) throws IOException,
     216            ProxyAuthenticationException {
    208217        try {
    209             return Tools.stringToDocument(executeReturnString(methode, parametres));
     218            String returnedString = executeReturnString(methode, parametres);
     219            return Tools.stringToDocument(returnedString);
    210220        } catch (JDOMException e) {
    211221            // TODO Auto-generated catch block
     
    220230     * @param methode the method to execute
    221231     * @return the result
    222      */
    223     public Document executeReturnDocument(String methode) {
     232     * @throws ProxyAuthenticationException
     233     */
     234    public Document executeReturnDocument(String methode) throws ProxyAuthenticationException {
    224235        try {
    225236            return Tools.stringToDocument(executeReturnString(methode));
Note: See TracChangeset for help on using the changeset viewer.