Changeset 9430
- Timestamp:
- Feb 28, 2011, 7:40:53 PM (14 years ago)
- Location:
- extensions/jiwigo-ws-api
- Files:
-
- 1 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/jiwigo-ws-api/pom.xml
r9392 r9430 3 3 <groupId>fr.mael.jiwigo</groupId> 4 4 <artifactId>jiwigo-ws-api</artifactId> 5 <version>0.13.1 </version>5 <version>0.13.1.1</version> 6 6 7 7 -
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/CategoryDao.java
r9392 r9430 11 11 import fr.mael.jiwigo.transverse.enumeration.CategoryEnum; 12 12 import fr.mael.jiwigo.transverse.enumeration.MethodsEnum; 13 import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException; 13 14 import fr.mael.jiwigo.transverse.session.SessionManager; 14 15 import fr.mael.jiwigo.transverse.util.Tools; … … 81 82 * @return the list of categories 82 83 * @throws IOException 84 * @throws ProxyAuthenticationException 83 85 */ 84 public List<Category> list(boolean recursive) throws IOException {86 public List<Category> list(boolean recursive) throws IOException, ProxyAuthenticationException { 85 87 Document doc = sessionManager.executeReturnDocument(MethodsEnum.LISTER_CATEGORIES.getLabel(), "recursive", 86 88 String.valueOf(recursive)); … … 112 114 * @param category the category to create 113 115 * @return true if the category is successfully created 116 * @throws ProxyAuthenticationException 114 117 */ 115 public boolean create(Category category) {118 public boolean create(Category category) throws ProxyAuthenticationException { 116 119 try { 117 120 if (category.getDirectParent() != null) { -
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/CommentDao.java
r9392 r9430 10 10 import fr.mael.jiwigo.om.Comment; 11 11 import fr.mael.jiwigo.transverse.enumeration.MethodsEnum; 12 import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException; 12 13 import fr.mael.jiwigo.transverse.session.SessionManager; 13 14 import fr.mael.jiwigo.transverse.util.Tools; … … 80 81 * @return list of comments 81 82 * @throws IOException 83 * @throws ProxyAuthenticationException 82 84 */ 83 public List<Comment> list(Integer idImage) throws IOException {85 public List<Comment> list(Integer idImage) throws IOException, ProxyAuthenticationException { 84 86 Document doc = (sessionManager.executeReturnDocument(MethodsEnum.GET_INFO.getLabel(), "image_id", String 85 .valueOf(idImage) ));87 .valueOf(idImage), "comments_per_page", "100")); 86 88 Element element = doc.getRootElement().getChild("image").getChild("comments"); 87 89 List<Element> listElement = (List<Element>) element.getChildren("comment"); … … 103 105 * @return the key 104 106 * @throws IOException 107 * @throws ProxyAuthenticationException 105 108 */ 106 public String getKey(Integer idImage) throws IOException {109 public String getKey(Integer idImage) throws IOException, ProxyAuthenticationException { 107 110 Document doc = (sessionManager.executeReturnDocument(MethodsEnum.GET_INFO.getLabel(), "image_id", String 108 111 .valueOf(idImage))); … … 116 119 * @return true if the comment is successfully added 117 120 * @throws IOException 121 * @throws ProxyAuthenticationException 118 122 */ 119 public boolean create(Comment commentaire) throws IOException {123 public boolean create(Comment commentaire) throws IOException, ProxyAuthenticationException { 120 124 String key = getKey(commentaire.getImageId()); 121 125 try { -
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/ImageDao.java
r9394 r9430 13 13 import fr.mael.jiwigo.om.Image; 14 14 import fr.mael.jiwigo.transverse.enumeration.MethodsEnum; 15 import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException; 15 16 import fr.mael.jiwigo.transverse.exception.WrongChunkSizeException; 16 17 import fr.mael.jiwigo.transverse.session.SessionManager; … … 98 99 * @return the list of images 99 100 * @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 { 102 104 return listByCategory(null, refresh); 103 105 } … … 108 110 * @return the list of images 109 111 * @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 { 112 116 if (refresh || cache.get(categoryId) == null) { 113 117 Document doc = null; … … 207 211 * @param tagId ids of the tags 208 212 * @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 { 211 216 Document doc = sessionManager.executeReturnDocument(MethodsEnum.SET_INFO.getLabel(), "image_id", String 212 217 .valueOf(imageId), "tag_ids", tagId); … … 248 253 * @return the list of images matching the string 249 254 * @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 { 252 258 Document doc = sessionManager.executeReturnDocument(MethodsEnum.SEARCH.getLabel(), "query", searchString); 253 259 LOG.debug(doc); -
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/dao/TagDao.java
r9392 r9430 12 12 import fr.mael.jiwigo.transverse.enumeration.MethodsEnum; 13 13 import fr.mael.jiwigo.transverse.enumeration.TagEnum; 14 import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException; 14 15 import fr.mael.jiwigo.transverse.session.SessionManager; 15 16 import fr.mael.jiwigo.transverse.util.Tools; … … 53 54 * @return the list of tags 54 55 * @throws IOException 56 * @throws ProxyAuthenticationException 55 57 */ 56 public List<Tag> list() throws IOException {58 public List<Tag> list() throws IOException, ProxyAuthenticationException { 57 59 Document doc = sessionManager.executeReturnDocument(MethodsEnum.TAGS_ADMIN_LIST.getLabel()); 58 60 // System.out.println(Outil.documentToString(doc)); … … 84 86 * @param tag the tag to create 85 87 * @return true if the tag as been successfully created 88 * @throws ProxyAuthenticationException 86 89 */ 87 public boolean create(Tag tag) {90 public boolean create(Tag tag) throws ProxyAuthenticationException { 88 91 try { 89 92 return Tools.checkOk(sessionManager.executeReturnDocument(MethodsEnum.ADD_TAG.getLabel(), "name", tag … … 100 103 * @return the tags list 101 104 * @throws IOException 105 * @throws ProxyAuthenticationException 102 106 */ 103 public List<Tag> tagsForImage(Image image) throws IOException {107 public List<Tag> tagsForImage(Image image) throws IOException, ProxyAuthenticationException { 104 108 Document doc = sessionManager.executeReturnDocument(MethodsEnum.GET_INFO.getLabel(), "image_id", String 105 109 .valueOf(image.getIdentifier())); -
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/CategoryService.java
r9392 r9430 6 6 import fr.mael.jiwigo.dao.CategoryDao; 7 7 import fr.mael.jiwigo.om.Category; 8 import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException; 8 9 import fr.mael.jiwigo.transverse.session.SessionManager; 9 10 … … 76 77 * @return the list of categories 77 78 * @throws IOException 79 * @throws ProxyAuthenticationException 78 80 */ 79 public List<Category> list(boolean recursive) throws IOException {81 public List<Category> list(boolean recursive) throws IOException, ProxyAuthenticationException { 80 82 return CategoryDao.getInstance(sessionManager).list(recursive); 81 83 } … … 85 87 * @return list of categories 86 88 * @throws IOException 89 * @throws ProxyAuthenticationException 87 90 */ 88 public List<Category> makeTree() throws IOException {91 public List<Category> makeTree() throws IOException, ProxyAuthenticationException { 89 92 List<Category> list = CategoryDao.getInstance(sessionManager).list(true); 90 93 for (Category category : list) { … … 109 112 * @param parent parent category 110 113 * @return true if successful 114 * @throws ProxyAuthenticationException 111 115 */ 112 public boolean create(String nom, Integer parent) {116 public boolean create(String nom, Integer parent) throws ProxyAuthenticationException { 113 117 Category category = new Category(); 114 118 category.setDirectParent(parent); … … 121 125 * @param nom name of the category 122 126 * @return true if successful 127 * @throws ProxyAuthenticationException 123 128 */ 124 public boolean create(String nom) {129 public boolean create(String nom) throws ProxyAuthenticationException { 125 130 Category category = new Category(); 126 131 category.setName(nom); -
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/CommentService.java
r9392 r9430 6 6 import fr.mael.jiwigo.dao.CommentDao; 7 7 import fr.mael.jiwigo.om.Comment; 8 import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException; 8 9 import fr.mael.jiwigo.transverse.session.SessionManager; 9 10 … … 75 76 * @return the list of comments 76 77 * @throws IOException 78 * @throws ProxyAuthenticationException 77 79 */ 78 public List<Comment> list(Integer imageId) throws IOException {80 public List<Comment> list(Integer imageId) throws IOException, ProxyAuthenticationException { 79 81 return CommentDao.getInstance(sessionManager).list(imageId); 80 82 } … … 87 89 * @return true if successful 88 90 * @throws IOException 91 * @throws ProxyAuthenticationException 89 92 */ 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 { 91 95 Comment comment = new Comment(); 92 96 comment.setContent(content); -
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/ImageService.java
r9394 r9430 7 7 import fr.mael.jiwigo.dao.ImageDao; 8 8 import fr.mael.jiwigo.om.Image; 9 import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException; 9 10 import fr.mael.jiwigo.transverse.session.SessionManager; 10 11 import fr.mael.jiwigo.transverse.util.ImagesUtil; … … 80 81 * @return the list of images 81 82 * @throws IOException 83 * @throws ProxyAuthenticationException 82 84 */ 83 public List<Image> listByCategory(Integer categoryId, boolean rafraichir) throws IOException { 85 public List<Image> listByCategory(Integer categoryId, boolean rafraichir) throws IOException, 86 ProxyAuthenticationException { 84 87 return ImageDao.getInstance(sessionManager).listByCategory(categoryId, rafraichir); 85 88 } … … 139 142 * @return true if successful 140 143 * @throws IOException 144 * @throws ProxyAuthenticationException 141 145 */ 142 public boolean addTags(Image image, String tagId) throws IOException {146 public boolean addTags(Image image, String tagId) throws IOException, ProxyAuthenticationException { 143 147 return ImageDao.getInstance(sessionManager).addTags(image.getIdentifier(), tagId); 144 148 } … … 149 153 * @return images matching the string 150 154 * @throws IOException 155 * @throws ProxyAuthenticationException 151 156 */ 152 public List<Image> search(String queryString) throws IOException {157 public List<Image> search(String queryString) throws IOException, ProxyAuthenticationException { 153 158 return ImageDao.getInstance(sessionManager).search(queryString); 154 159 } -
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/service/TagService.java
r9392 r9430 7 7 import fr.mael.jiwigo.om.Image; 8 8 import fr.mael.jiwigo.om.Tag; 9 import fr.mael.jiwigo.transverse.exception.ProxyAuthenticationException; 9 10 import fr.mael.jiwigo.transverse.session.SessionManager; 10 11 … … 76 77 * @return le list of tags 77 78 * @throws IOException 79 * @throws ProxyAuthenticationException 78 80 */ 79 public List<Tag> list() throws IOException {81 public List<Tag> list() throws IOException, ProxyAuthenticationException { 80 82 return TagDao.getInstance(sessionManager).list(); 81 83 } … … 86 88 * @return true if the tag is created 87 89 * @throws IOException 90 * @throws ProxyAuthenticationException 88 91 */ 89 public boolean create(String nom) throws IOException {92 public boolean create(String nom) throws IOException, ProxyAuthenticationException { 90 93 Tag tag = new Tag(); 91 94 tag.setName(nom); … … 98 101 * @return the list of tags 99 102 * @throws IOException 103 * @throws ProxyAuthenticationException 100 104 */ 101 public List<Tag> tagsForImage(Image image) throws IOException {105 public List<Tag> tagsForImage(Image image) throws IOException, ProxyAuthenticationException { 102 106 return TagDao.getInstance(sessionManager).tagsForImage(image); 103 107 } -
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.