Changeset 9430 for extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/session/SessionManager.java
- Timestamp:
- Feb 28, 2011, 7:40:53 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/session/SessionManager.java
r9394 r9430 8 8 import org.apache.commons.httpclient.HostConfiguration; 9 9 import org.apache.commons.httpclient.HttpClient; 10 import org.apache.commons.httpclient.HttpException;11 10 import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; 12 11 import org.apache.commons.httpclient.UsernamePasswordCredentials; … … 18 17 19 18 import fr.mael.jiwigo.transverse.enumeration.MethodsEnum; 19 import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException; 20 20 import fr.mael.jiwigo.transverse.util.Tools; 21 21 … … 125 125 /** 126 126 * 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() { 130 133 Document doc; 131 134 //configures the proxy … … 139 142 } 140 143 } 144 // try { 141 145 try { 142 146 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; 144 154 } catch (Exception e) { 145 LOG.error(Tools.getStackTrace(e)); 146 } 147 return false; 155 LOG.debug(Tools.getStackTrace(e)); 156 return 1; 157 } 158 148 159 } 149 160 … … 154 165 * @return the result 155 166 * @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 { 158 171 if (parametres.length % 2 != 0 && !(parametres == null)) { 159 172 try { … … 174 187 method.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8"); 175 188 //end 176 177 189 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 } 179 194 InputStream streamResponse = method.getResponseBodyAsStream(); 180 195 // System.out.println(Outil.readInputStreamAsString(streamResponse)); … … 183 198 LOG.debug(toReturn); 184 199 return toReturn; 185 } catch (HttpException e) {186 // TODO Auto-generated catch block187 LOG.error(Tools.getStackTrace(e));188 200 } 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 195 202 } 196 203 return null; … … 204 211 * @return the result 205 212 * @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 { 208 217 try { 209 return Tools.stringToDocument(executeReturnString(methode, parametres)); 218 String returnedString = executeReturnString(methode, parametres); 219 return Tools.stringToDocument(returnedString); 210 220 } catch (JDOMException e) { 211 221 // TODO Auto-generated catch block … … 220 230 * @param methode the method to execute 221 231 * @return the result 222 */ 223 public Document executeReturnDocument(String methode) { 232 * @throws ProxyAuthenticationException 233 */ 234 public Document executeReturnDocument(String methode) throws ProxyAuthenticationException { 224 235 try { 225 236 return Tools.stringToDocument(executeReturnString(methode));
Note: See TracChangeset
for help on using the changeset viewer.