Changeset 9430


Ignore:
Timestamp:
Feb 28, 2011, 7:40:53 PM (14 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

Location:
extensions/jiwigo-ws-api
Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • extensions/jiwigo-ws-api/pom.xml

    r9392 r9430  
    33  <groupId>fr.mael.jiwigo</groupId>
    44  <artifactId>jiwigo-ws-api</artifactId>
    5   <version>0.13.1</version>
     5  <version>0.13.1.1</version>
    66
    77
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/CategoryDao.java

    r9392 r9430  
    1111import fr.mael.jiwigo.transverse.enumeration.CategoryEnum;
    1212import fr.mael.jiwigo.transverse.enumeration.MethodsEnum;
     13import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException;
    1314import fr.mael.jiwigo.transverse.session.SessionManager;
    1415import fr.mael.jiwigo.transverse.util.Tools;
     
    8182     * @return the list of categories
    8283     * @throws IOException
     84     * @throws ProxyAuthenticationException
    8385     */
    84     public List<Category> list(boolean recursive) throws IOException {
     86    public List<Category> list(boolean recursive) throws IOException, ProxyAuthenticationException {
    8587        Document doc = sessionManager.executeReturnDocument(MethodsEnum.LISTER_CATEGORIES.getLabel(), "recursive",
    8688                String.valueOf(recursive));
     
    112114     * @param category the category to create
    113115     * @return true if the category is successfully created
     116     * @throws ProxyAuthenticationException
    114117     */
    115     public boolean create(Category category) {
     118    public boolean create(Category category) throws ProxyAuthenticationException {
    116119        try {
    117120            if (category.getDirectParent() != null) {
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/CommentDao.java

    r9392 r9430  
    1010import fr.mael.jiwigo.om.Comment;
    1111import fr.mael.jiwigo.transverse.enumeration.MethodsEnum;
     12import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException;
    1213import fr.mael.jiwigo.transverse.session.SessionManager;
    1314import fr.mael.jiwigo.transverse.util.Tools;
     
    8081     * @return list of comments
    8182     * @throws IOException
     83     * @throws ProxyAuthenticationException
    8284     */
    83     public List<Comment> list(Integer idImage) throws IOException {
     85    public List<Comment> list(Integer idImage) throws IOException, ProxyAuthenticationException {
    8486        Document doc = (sessionManager.executeReturnDocument(MethodsEnum.GET_INFO.getLabel(), "image_id", String
    85                 .valueOf(idImage)));
     87                .valueOf(idImage), "comments_per_page", "100"));
    8688        Element element = doc.getRootElement().getChild("image").getChild("comments");
    8789        List<Element> listElement = (List<Element>) element.getChildren("comment");
     
    103105     * @return the key
    104106     * @throws IOException
     107     * @throws ProxyAuthenticationException
    105108     */
    106     public String getKey(Integer idImage) throws IOException {
     109    public String getKey(Integer idImage) throws IOException, ProxyAuthenticationException {
    107110        Document doc = (sessionManager.executeReturnDocument(MethodsEnum.GET_INFO.getLabel(), "image_id", String
    108111                .valueOf(idImage)));
     
    116119     * @return true if the comment is successfully added
    117120     * @throws IOException
     121     * @throws ProxyAuthenticationException
    118122     */
    119     public boolean create(Comment commentaire) throws IOException {
     123    public boolean create(Comment commentaire) throws IOException, ProxyAuthenticationException {
    120124        String key = getKey(commentaire.getImageId());
    121125        try {
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/ImageDao.java

    r9394 r9430  
    1313import fr.mael.jiwigo.om.Image;
    1414import fr.mael.jiwigo.transverse.enumeration.MethodsEnum;
     15import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException;
    1516import fr.mael.jiwigo.transverse.exception.WrongChunkSizeException;
    1617import fr.mael.jiwigo.transverse.session.SessionManager;
     
    9899     * @return the list of images
    99100     * @throws IOException
    100      */
    101     public List<Image> list(boolean refresh) throws IOException {
     101     * @throws ProxyAuthenticationException
     102     */
     103    public List<Image> list(boolean refresh) throws IOException, ProxyAuthenticationException {
    102104        return listByCategory(null, refresh);
    103105    }
     
    108110     * @return the list of images
    109111     * @throws IOException
    110      */
    111     public List<Image> listByCategory(Integer categoryId, boolean refresh) throws IOException {
     112     * @throws ProxyAuthenticationException
     113     */
     114    public List<Image> listByCategory(Integer categoryId, boolean refresh) throws IOException,
     115            ProxyAuthenticationException {
    112116        if (refresh || cache.get(categoryId) == null) {
    113117            Document doc = null;
     
    207211     * @param tagId ids of the tags
    208212     * @throws IOException
    209      */
    210     public boolean addTags(Integer imageId, String tagId) throws IOException {
     213     * @throws ProxyAuthenticationException
     214     */
     215    public boolean addTags(Integer imageId, String tagId) throws IOException, ProxyAuthenticationException {
    211216        Document doc = sessionManager.executeReturnDocument(MethodsEnum.SET_INFO.getLabel(), "image_id", String
    212217                .valueOf(imageId), "tag_ids", tagId);
     
    248253     * @return the list of images matching the string
    249254     * @throws IOException
    250      */
    251     public List<Image> search(String searchString) throws IOException {
     255     * @throws ProxyAuthenticationException
     256     */
     257    public List<Image> search(String searchString) throws IOException, ProxyAuthenticationException {
    252258        Document doc = sessionManager.executeReturnDocument(MethodsEnum.SEARCH.getLabel(), "query", searchString);
    253259        LOG.debug(doc);
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/TagDao.java

    r9392 r9430  
    1212import fr.mael.jiwigo.transverse.enumeration.MethodsEnum;
    1313import fr.mael.jiwigo.transverse.enumeration.TagEnum;
     14import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException;
    1415import fr.mael.jiwigo.transverse.session.SessionManager;
    1516import fr.mael.jiwigo.transverse.util.Tools;
     
    5354     * @return the list of tags
    5455     * @throws IOException
     56     * @throws ProxyAuthenticationException
    5557     */
    56     public List<Tag> list() throws IOException {
     58    public List<Tag> list() throws IOException, ProxyAuthenticationException {
    5759        Document doc = sessionManager.executeReturnDocument(MethodsEnum.TAGS_ADMIN_LIST.getLabel());
    5860        //      System.out.println(Outil.documentToString(doc));
     
    8486     * @param tag the tag to create
    8587     * @return true if the tag as been successfully created
     88     * @throws ProxyAuthenticationException
    8689     */
    87     public boolean create(Tag tag) {
     90    public boolean create(Tag tag) throws ProxyAuthenticationException {
    8891        try {
    8992            return Tools.checkOk(sessionManager.executeReturnDocument(MethodsEnum.ADD_TAG.getLabel(), "name", tag
     
    100103     * @return the tags list
    101104     * @throws IOException
     105     * @throws ProxyAuthenticationException
    102106     */
    103     public List<Tag> tagsForImage(Image image) throws IOException {
     107    public List<Tag> tagsForImage(Image image) throws IOException, ProxyAuthenticationException {
    104108        Document doc = sessionManager.executeReturnDocument(MethodsEnum.GET_INFO.getLabel(), "image_id", String
    105109                .valueOf(image.getIdentifier()));
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/CategoryService.java

    r9392 r9430  
    66import fr.mael.jiwigo.dao.CategoryDao;
    77import fr.mael.jiwigo.om.Category;
     8import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException;
    89import fr.mael.jiwigo.transverse.session.SessionManager;
    910
     
    7677     * @return the list of categories
    7778     * @throws IOException
     79     * @throws ProxyAuthenticationException
    7880     */
    79     public List<Category> list(boolean recursive) throws IOException {
     81    public List<Category> list(boolean recursive) throws IOException, ProxyAuthenticationException {
    8082        return CategoryDao.getInstance(sessionManager).list(recursive);
    8183    }
     
    8587     * @return list of categories
    8688     * @throws IOException
     89     * @throws ProxyAuthenticationException
    8790     */
    88     public List<Category> makeTree() throws IOException {
     91    public List<Category> makeTree() throws IOException, ProxyAuthenticationException {
    8992        List<Category> list = CategoryDao.getInstance(sessionManager).list(true);
    9093        for (Category category : list) {
     
    109112     * @param parent parent category
    110113     * @return true if successful
     114     * @throws ProxyAuthenticationException
    111115     */
    112     public boolean create(String nom, Integer parent) {
     116    public boolean create(String nom, Integer parent) throws ProxyAuthenticationException {
    113117        Category category = new Category();
    114118        category.setDirectParent(parent);
     
    121125     * @param nom name of the category
    122126     * @return true if successful
     127     * @throws ProxyAuthenticationException
    123128     */
    124     public boolean create(String nom) {
     129    public boolean create(String nom) throws ProxyAuthenticationException {
    125130        Category category = new Category();
    126131        category.setName(nom);
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/CommentService.java

    r9392 r9430  
    66import fr.mael.jiwigo.dao.CommentDao;
    77import fr.mael.jiwigo.om.Comment;
     8import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException;
    89import fr.mael.jiwigo.transverse.session.SessionManager;
    910
     
    7576     * @return the list of comments
    7677     * @throws IOException
     78     * @throws ProxyAuthenticationException
    7779     */
    78     public List<Comment> list(Integer imageId) throws IOException {
     80    public List<Comment> list(Integer imageId) throws IOException, ProxyAuthenticationException {
    7981        return CommentDao.getInstance(sessionManager).list(imageId);
    8082    }
     
    8789     * @return true if successful
    8890     * @throws IOException
     91     * @throws ProxyAuthenticationException
    8992     */
    90     public boolean create(String content, Integer imageId, String auteur) throws IOException {
     93    public boolean create(String content, Integer imageId, String auteur) throws IOException,
     94            ProxyAuthenticationException {
    9195        Comment comment = new Comment();
    9296        comment.setContent(content);
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/ImageService.java

    r9394 r9430  
    77import fr.mael.jiwigo.dao.ImageDao;
    88import fr.mael.jiwigo.om.Image;
     9import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException;
    910import fr.mael.jiwigo.transverse.session.SessionManager;
    1011import fr.mael.jiwigo.transverse.util.ImagesUtil;
     
    8081     * @return the list of images
    8182     * @throws IOException
     83     * @throws ProxyAuthenticationException
    8284     */
    83     public List<Image> listByCategory(Integer categoryId, boolean rafraichir) throws IOException {
     85    public List<Image> listByCategory(Integer categoryId, boolean rafraichir) throws IOException,
     86            ProxyAuthenticationException {
    8487        return ImageDao.getInstance(sessionManager).listByCategory(categoryId, rafraichir);
    8588    }
     
    139142     * @return true if successful
    140143     * @throws IOException
     144     * @throws ProxyAuthenticationException
    141145     */
    142     public boolean addTags(Image image, String tagId) throws IOException {
     146    public boolean addTags(Image image, String tagId) throws IOException, ProxyAuthenticationException {
    143147        return ImageDao.getInstance(sessionManager).addTags(image.getIdentifier(), tagId);
    144148    }
     
    149153     * @return images matching the string
    150154     * @throws IOException
     155     * @throws ProxyAuthenticationException
    151156     */
    152     public List<Image> search(String queryString) throws IOException {
     157    public List<Image> search(String queryString) throws IOException, ProxyAuthenticationException {
    153158        return ImageDao.getInstance(sessionManager).search(queryString);
    154159    }
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/TagService.java

    r9392 r9430  
    77import fr.mael.jiwigo.om.Image;
    88import fr.mael.jiwigo.om.Tag;
     9import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException;
    910import fr.mael.jiwigo.transverse.session.SessionManager;
    1011
     
    7677     * @return le list of tags
    7778     * @throws IOException
     79     * @throws ProxyAuthenticationException
    7880     */
    79     public List<Tag> list() throws IOException {
     81    public List<Tag> list() throws IOException, ProxyAuthenticationException {
    8082        return TagDao.getInstance(sessionManager).list();
    8183    }
     
    8688     * @return true if the tag is created
    8789     * @throws IOException
     90     * @throws ProxyAuthenticationException
    8891     */
    89     public boolean create(String nom) throws IOException {
     92    public boolean create(String nom) throws IOException, ProxyAuthenticationException {
    9093        Tag tag = new Tag();
    9194        tag.setName(nom);
     
    98101     * @return the list of tags
    99102     * @throws IOException
     103     * @throws ProxyAuthenticationException
    100104     */
    101     public List<Tag> tagsForImage(Image image) throws IOException {
     105    public List<Tag> tagsForImage(Image image) throws IOException, ProxyAuthenticationException {
    102106        return TagDao.getInstance(sessionManager).tagsForImage(image);
    103107    }
  • 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.