- Timestamp:
- 10/21/14 19:01:09 (10 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/branches/Jersey-2.12-adaptation/annotator-backend
- Files:
-
- 2 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/branches/Jersey-2.12-adaptation/annotator-backend/pom.xml
r5693 r5739 31 31 <version>2.5</version> 32 32 <scope>provided</scope> 33 </dependency> 34 <!--<dependency>35 <groupId> com.sun.jersey</groupId>36 <artifactId>j ersey-server-linking</artifactId>37 <version> 1.9.1</version>38 </dependency> -->39 <dependency> 40 <groupId> com.sun.jersey</groupId>33 </dependency> 34 <!-- <dependency> 35 <groupId>javax.ws.rs</groupId> 36 <artifactId>javax.ws.rs-api</artifactId> 37 <version>2.12</version> 38 </dependency> 39 <dependency> 40 <groupId>org.glassfish.jersey</groupId> 41 41 <artifactId>jersey-servlet</artifactId> 42 42 <version>${jersey.version}</version> 43 </dependency> 44 <dependency> 45 <groupId>com.sun.jersey</groupId> 46 <artifactId>jersey-json</artifactId> 43 </dependency> --> 44 <dependency> 45 <groupId>org.glassfish.jersey.media</groupId> 46 <artifactId>jersey-media-multipart</artifactId> 47 <version>${jersey.version}</version> 48 </dependency> 49 <dependency> 50 <groupId>org.glassfish.jersey.security</groupId> 51 <artifactId>oauth1-signature</artifactId> 52 <version>${jersey.version}</version> 53 </dependency> 54 <dependency> 55 <groupId>org.glassfish.jersey.test-framework</groupId> 56 <artifactId>jersey-test-framework-core</artifactId> 57 <version>${jersey.version}</version> 58 </dependency> 59 <dependency> 60 <groupId>org.glassfish.jersey.test-framework.providers</groupId> 61 <artifactId>jersey-test-framework-provider-grizzly2</artifactId> 62 <version>${jersey.version}</version> 63 </dependency> 64 <dependency> 65 <groupId>org.glassfish.jersey.core</groupId> 66 <artifactId>jersey-client</artifactId> 67 <version>${jersey.version}</version> 68 </dependency> 69 <dependency> 70 <groupId>org.glassfish.jersey.core</groupId> 71 <artifactId>jersey-server</artifactId> 72 <version>${jersey.version}</version> 73 </dependency> 74 <dependency> 75 <groupId>org.glassfish.jersey.ext</groupId> 76 <artifactId>jersey-spring3</artifactId> 47 77 <version>${jersey.version}</version> 48 78 <scope>test</scope> 49 </dependency>50 <dependency>51 <groupId>com.sun.jersey</groupId>52 <artifactId>jersey-client</artifactId>53 <version>${jersey.version}</version>54 <scope>test</scope>55 </dependency>56 <dependency>57 <groupId>com.sun.jersey.jersey-test-framework</groupId>58 <artifactId>jersey-test-framework-grizzly2</artifactId>59 <version>${jersey.version}</version>60 79 <exclusions> 61 80 <exclusion> 81 <groupId>org.springframework</groupId> 82 <artifactId>spring-core</artifactId> 83 </exclusion> 84 <exclusion> 85 <groupId>org.springframework</groupId> 86 <artifactId>spring-web</artifactId> 87 </exclusion> 88 <exclusion> 89 <groupId>org.springframework</groupId> 90 <artifactId>spring-beans</artifactId> 91 </exclusion> 92 </exclusions> 93 </dependency> 94 95 <!-- <exclusion> 62 96 <artifactId>javax.servlet</artifactId> 63 97 <groupId>org.glassfish</groupId> 64 98 </exclusion> 65 </exclusions> 66 </dependency>67 <dependency> 68 <groupId> com.sun.jersey.contribs</groupId>99 </exclusions>--> 100 <!-- </dependency> 101 <dependency> 102 <groupId>org.glassfish.jersey.contribs</groupId> 69 103 <artifactId>jersey-spring</artifactId> 70 104 <version>${jersey.version}</version> … … 77 111 </dependency> 78 112 <dependency> 79 <groupId> com.sun.jersey.contribs</groupId>113 <groupId>org.glassfish.jersey.contribs</groupId> 80 114 <artifactId>jersey-multipart</artifactId> 81 115 <version>${jersey.version}</version> 82 </dependency> 116 </dependency>--> 83 117 <dependency> 84 118 <groupId>org.jmock</groupId> … … 172 206 </exclusion> 173 207 </exclusions> 208 </dependency> 209 <dependency> 210 <groupId>javax</groupId> 211 <artifactId>javaee-web-api</artifactId> 212 <version>7.0</version> 213 <scope>test</scope> 174 214 </dependency> 175 215 </dependencies> … … 272 312 <dependencies> 273 313 <dependency> 274 <groupId> com.sun.jersey</groupId>314 <groupId>org.glassfish.jersey</groupId> 275 315 <artifactId>jersey-servlet</artifactId> 276 316 <version>3.0</version> … … 393 433 394 434 <properties> 395 <jersey.version> 1.17.1</jersey.version>435 <jersey.version>2.12</jersey.version> 396 436 <spring.version>3.2.0.RELEASE</spring.version> 397 437 <slf4j.version>1.7.5</slf4j.version> … … 413 453 <name>MPI LAT Repository/</name> 414 454 <url>http://lux15.mpi.nl/nexus/content/repositories/MPI-Snapshots</url> 415 </repository> 455 </repository> 416 456 </repositories> 417 457 -
DASISH/t5.6/backend/annotator-backend/branches/Jersey-2.12-adaptation/annotator-backend/src/main/java/eu/dasish/annotation/backend/MyResource.java
r4603 r5739 33 33 */ 34 34 @GET 35 @Path("test") 35 36 @Produces("text/plain") 36 37 public String getIt() { -
DASISH/t5.6/backend/annotator-backend/branches/Jersey-2.12-adaptation/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AutheticationResource.java
r5385 r5739 73 73 } 74 74 } 75 76 @GET 77 @Produces(MediaType.TEXT_HTML) 78 @Path("logintest") 79 @Transactional(readOnly = true) 80 public String logintest() { 81 return "ok"; 82 } 75 83 76 84 @GET -
DASISH/t5.6/backend/annotator-backend/branches/Jersey-2.12-adaptation/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/CachedRepresentationResource.java
r5693 r5739 1 /* 2 * Copyright (C) 2013 DASISH 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License 6 * as published by the Free Software Foundation; either version 2 7 * of the License, or (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 */ 1 18 /* 2 19 * Copyright (C) 2013 DASISH … … 18 35 package eu.dasish.annotation.backend.rest; 19 36 20 import com.sun.jersey.multipart.BodyPartEntity;21 import com.sun.jersey.multipart.MultiPart;37 import org.glassfish.jersey.media.multipart.MultiPart; 38 import org.glassfish.jersey.media.multipart.BodyPartEntity; 22 39 import eu.dasish.annotation.backend.BackendConstants; 23 40 import eu.dasish.annotation.backend.ForbiddenException; … … 71 88 Map params = new HashMap(); 72 89 try { 73 CachedRepresentationInfo result = (CachedRepresentationInfo) (new RequestWrappers(this)).wrapRequestResource(params, new GetCachedRepresentationInfo(), Resource.CACHED_REPRESENTATION, ResourceAction.READ, externalId);90 CachedRepresentationInfo result = (CachedRepresentationInfo) (new RequestWrappers(this)).wrapRequestResource(params, new CachedRepresentationResource.GetCachedRepresentationInfo(), Resource.CACHED_REPRESENTATION, ResourceAction.READ, externalId); 74 91 if (result != null) { 75 92 return (new ObjectFactory()).createCachedRepresentationInfo(result); … … 103 120 Map params = new HashMap(); 104 121 try { 105 InputStream result = (InputStream) (new RequestWrappers(this)).wrapRequestResource(params, new GetCachedRepresentationInputStream(), Resource.CACHED_REPRESENTATION, ResourceAction.READ, externalId);122 InputStream result = (InputStream) (new RequestWrappers(this)).wrapRequestResource(params, new CachedRepresentationResource.GetCachedRepresentationInputStream(), Resource.CACHED_REPRESENTATION, ResourceAction.READ, externalId); 106 123 if (result != null) { 107 124 ImageIO.setUseCache(false); … … 135 152 Map params = new HashMap(); 136 153 try { 137 return (InputStream) (new RequestWrappers(this)).wrapRequestResource(params, new GetCachedRepresentationInputStream(), Resource.CACHED_REPRESENTATION, ResourceAction.READ, externalId);154 return (InputStream) (new RequestWrappers(this)).wrapRequestResource(params, new CachedRepresentationResource.GetCachedRepresentationInputStream(), Resource.CACHED_REPRESENTATION, ResourceAction.READ, externalId); 138 155 } catch (NotInDataBaseException e1) { 139 156 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e1.getMessage()); … … 165 182 params.put("stream", bpe.getInputStream()); 166 183 try { 167 Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateCachedBlob(), Resource.CACHED_REPRESENTATION, ResourceAction.WRITE, cachedIdentifier);184 Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new CachedRepresentationResource.UpdateCachedBlob(), Resource.CACHED_REPRESENTATION, ResourceAction.WRITE, cachedIdentifier); 168 185 if (result != null) { 169 186 return result + "rows are updated"; … … 199 216 params.put("stream", input); 200 217 try { 201 Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateCachedBlob(), Resource.CACHED_REPRESENTATION, ResourceAction.WRITE, cachedIdentifier);218 Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new CachedRepresentationResource.UpdateCachedBlob(), Resource.CACHED_REPRESENTATION, ResourceAction.WRITE, cachedIdentifier); 202 219 input.close(); 203 220 if (result != null) { … … 240 257 params.put("info", cachedInfo); 241 258 try { 242 Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateCachedMetadata(), Resource.CACHED_REPRESENTATION, ResourceAction.WRITE_W_METAINFO, cachedInfo.getId());259 Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new CachedRepresentationResource.UpdateCachedMetadata(), Resource.CACHED_REPRESENTATION, ResourceAction.WRITE_W_METAINFO, cachedInfo.getId()); 243 260 if (result != null) { 244 261 return result + "rows are updated"; -
DASISH/t5.6/backend/annotator-backend/branches/Jersey-2.12-adaptation/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/ResourceResource.java
r5468 r5739 56 56 57 57 public Number getPrincipalID() throws IOException { 58 59 58 dbDispatcher.setResourcesPaths(this.getRelativeServiceURI()); 60 59 String remotePrincipal = httpServletRequest.getRemoteUser(); … … 104 103 105 104 protected String getRelativeServiceURI(){ 106 return httpServletRequest.getContextPath()+httpServletRequest.getServletPath(); 105 String ctxtPath = (httpServletRequest.getContextPath() != null) ? httpServletRequest.getContextPath() : ""; 106 String srvPath = (httpServletRequest.getServletPath() != null) ? httpServletRequest.getServletPath() : ""; 107 return ctxtPath+srvPath; 107 108 } 108 109 } -
DASISH/t5.6/backend/annotator-backend/branches/Jersey-2.12-adaptation/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/TargetResource.java
r5693 r5739 18 18 package eu.dasish.annotation.backend.rest; 19 19 20 import com.sun.jersey.multipart.BodyPartEntity;21 import com.sun.jersey.multipart.MultiPart;20 import org.glassfish.jersey.media.multipart.MultiPart; 21 import org.glassfish.jersey.media.multipart.BodyPartEntity; 22 22 import eu.dasish.annotation.backend.BackendConstants; 23 23 import eu.dasish.annotation.backend.ForbiddenException; … … 82 82 Map params = new HashMap(); 83 83 try { 84 Target result = (Target) (new RequestWrappers(this)).wrapRequestResource(params, new GetTarget(), Resource.TARGET, ResourceAction.READ, externalIdentifier);84 Target result = (Target) (new RequestWrappers(this)).wrapRequestResource(params, new TargetResource.GetTarget(), Resource.TARGET, ResourceAction.READ, externalIdentifier); 85 85 if (result != null) { 86 86 return new ObjectFactory().createTarget(result); … … 114 114 Map params = new HashMap(); 115 115 try { 116 ReferenceList result = (ReferenceList) (new RequestWrappers(this)).wrapRequestResource(params, new GetSiblingTargets(), Resource.TARGET, ResourceAction.READ, externalIdentifier);116 ReferenceList result = (ReferenceList) (new RequestWrappers(this)).wrapRequestResource(params, new TargetResource.GetSiblingTargets(), Resource.TARGET, ResourceAction.READ, externalIdentifier); 117 117 if (result != null) { 118 118 return new ObjectFactory().createReferenceList(result); … … 153 153 params.put("fragmentDescriptor", fragmentDescriptor); 154 154 try { 155 CachedRepresentationInfo result = (CachedRepresentationInfo) (new RequestWrappers(this)).wrapRequestResource(params, new PostCached(), Resource.TARGET, ResourceAction.WRITE_W_METAINFO, targetIdentifier);155 CachedRepresentationInfo result = (CachedRepresentationInfo) (new RequestWrappers(this)).wrapRequestResource(params, new TargetResource.PostCached(), Resource.TARGET, ResourceAction.WRITE_W_METAINFO, targetIdentifier); 156 156 if (result != null) { 157 157 return new ObjectFactory().createCachedRepresentationInfo(result); -
DASISH/t5.6/backend/annotator-backend/branches/Jersey-2.12-adaptation/annotator-backend/src/test/java/eu/dasish/annotation/backend/MyResourceTest.java
r4603 r5739 22 22 package eu.dasish.annotation.backend; 23 23 24 import com.sun.jersey.api.client.ClientResponse;25 import com.sun.jersey.test.framework.JerseyTest;26 import com.sun.jersey.test.framework.WebAppDescriptor;27 import com.sun.jersey.test.framework.spi.container.TestContainerException;24 import javax.ws.rs.core.Application; 25 import javax.ws.rs.core.Response; 26 import org.glassfish.jersey.server.ResourceConfig; 27 import org.glassfish.jersey.test.JerseyTest; 28 28 29 30 import static org.junit.Assert.*; 29 31 import org.junit.Test; 30 import static org.junit.Assert.*;31 32 32 33 /** … … 36 37 public class MyResourceTest extends JerseyTest { 37 38 38 public MyResourceTest() throws TestContainerException { 39 super(new WebAppDescriptor.Builder(MyResource.class.getPackage().getName()) 40 // .servletClass(SpringServlet.class) 41 // .contextParam("contextConfigLocation", "classpath:testApplicationContext.xml") 42 // .contextListenerClass(ContextLoaderListener.class) 43 .build()); 39 @Override 40 protected Application configure() { 41 return new ResourceConfig(MyResource.class).property("contextConfigLocation", "classpath:spring-test-config/testApplication.xml"); 44 42 } 45 43 … … 50 48 public void testGetIt() { 51 49 System.out.println("getIt"); 52 ClientResponse response = resource().path("myresource").get(ClientResponse.class);50 Response response = this.target("myresource/test").request().get(); 53 51 assertEquals(200, response.getStatus()); 54 assertEquals("Hi there!", response.getEntity(String.class)); 55 // final String hello = target("hello").request().get(String.class); 56 // assertEquals("Hello World!", hello); 52 assertEquals("Hi there!", target("myresource/test").request().get(String.class)); 57 53 } 58 54 } -
DASISH/t5.6/backend/annotator-backend/branches/Jersey-2.12-adaptation/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationsTest.java
r5385 r5739 18 18 package eu.dasish.annotation.backend.rest; 19 19 20 import com.sun.jersey.api.client.ClientResponse; 21 import com.sun.jersey.api.client.WebResource; 22 import com.sun.jersey.api.client.WebResource.Builder; 23 import com.sun.jersey.core.util.Base64; 24 import com.sun.jersey.spi.spring.container.servlet.SpringServlet; 25 import com.sun.jersey.test.framework.AppDescriptor; 26 import com.sun.jersey.test.framework.JerseyTest; 27 import com.sun.jersey.test.framework.WebAppDescriptor; 28 import eu.dasish.annotation.backend.Helpers; 20 21 import org.glassfish.jersey.oauth1.signature.Base64; 22 import org.glassfish.jersey.test.JerseyTest; 29 23 import eu.dasish.annotation.backend.NotInDataBaseException; 30 import eu.dasish.annotation.backend.TestInstances;31 24 import eu.dasish.annotation.backend.dao.impl.JdbcResourceDaoTest; 32 import eu.dasish.annotation.schema.Access;33 import eu.dasish.annotation.schema.Annotation;34 import eu.dasish.annotation.schema.AnnotationBody;35 import eu.dasish.annotation.schema.AnnotationBody.TextBody;36 import eu.dasish.annotation.schema.AnnotationBody.XmlBody;37 import eu.dasish.annotation.schema.ObjectFactory;38 import eu.dasish.annotation.schema.ResponseBody;39 25 import java.io.FileNotFoundException; 40 26 import java.io.IOException; 41 27 import java.net.URISyntaxException; 28 import javax.ws.rs.core.Application; 42 29 import javax.ws.rs.core.HttpHeaders; 43 30 import javax.ws.rs.core.MediaType; 44 import javax.xml.bind.JAXBElement; 45 import javax.xml.parsers.ParserConfigurationException; 31 import javax.ws.rs.core.Response; 32 import org.glassfish.jersey.server.ResourceConfig; 33 import org.glassfish.jersey.server.spring.SpringLifecycleListener; 34 import org.glassfish.jersey.server.spring.scope.RequestContextFilter; 35 import org.glassfish.jersey.test.TestProperties; 46 36 import org.junit.Test; 47 37 import static org.junit.Assert.*; 48 38 import org.junit.Before; 49 import org.junit.Ignore;50 39 import org.junit.runner.RunWith; 51 40 import org.springframework.beans.factory.annotation.Autowired; 41 import org.springframework.context.ApplicationContext; 52 42 import org.springframework.dao.DataAccessException; 53 43 import org.springframework.jdbc.core.JdbcTemplate; 54 44 import org.springframework.test.context.ContextConfiguration; 55 45 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 56 import org.springframework.web.context.ContextLoaderListener; 57 import org.springframework.web.context.request.RequestContextListener; 58 import org.w3c.dom.Element; 59 import org.xml.sax.SAXException; 46 import org.springframework.context.support.ClassPathXmlApplicationContext; 60 47 61 48 /** … … 64 51 */ 65 52 @RunWith(value = SpringJUnit4ClassRunner.class) 66 @ContextConfiguration( {"/spring-test-config/dataSource.xml"})53 @ContextConfiguration(locations = {"/spring-test-config/dataSource.xml"}) 67 54 public class AnnotationsTest extends JerseyTest { 68 55 … … 70 57 private JdbcTemplate jdbcTemplate; 71 58 72 String _relativePath = "/backend/api";59 //String _relativePath = "/backend/api"; 73 60 74 61 75 62 @Override 76 protected AppDescriptor configure() { 77 return new WebAppDescriptor.Builder(AnnotationResource.class.getPackage().getName()) 78 .servletClass(SpringServlet.class) 79 .contextParam("contextConfigLocation", getApplicationContextFile()) 80 .addFilter(DummySecurityFilter.class, "DummySecurityFilter") 81 .requestListenerClass(RequestContextListener.class) 82 .contextListenerClass(ContextLoaderListener.class) 83 .contextPath("/backend").servletPath("/api") 84 .build(); 63 protected Application configure() { 64 65 enable(TestProperties.LOG_TRAFFIC); 66 enable(TestProperties.DUMP_ENTITY); 67 68 69 70 ApplicationContext ctx = new ClassPathXmlApplicationContext( 71 "/spring-test-config/dataSource.xml", 72 "/spring-config/componentscan.xml", 73 "/spring-config/dbDispatcher.xml", 74 "/spring-config/principalDao.xml", 75 "/spring-config/annotationDao.xml", 76 "/spring-config/cachedRepresentationDao.xml", 77 "/spring-config/targetDao.xml", 78 "/spring-config/notebookDao.xml", 79 "/spring-config/jaxbMarshallerFactory.xml", 80 "/spring-config/jaxbUnmarshallerFactory.xml"); 81 82 return (new ResourceConfig()) 83 .register(AutheticationResource.class) 84 .register(AnnotationResource.class) 85 .register(DummySecurityFilter.class) 86 .register(SpringLifecycleListener.class) 87 .register(RequestContextFilter.class) 88 .property("contextConfig", ctx); 89 // .property("contextPath", "/backend") //?? 90 // .property("servletPath", "/api"); // 91 92 //.servletClass(SpringServlet.class) 93 //.contextParam("contextConfigLocation", getApplicationContextFile()) 94 //.addFilter(DummySecurityFilter.class, "DummySecurityFilter") 95 //.requestListenerClass(RequestContextListener.class) 96 //.contextListenerClass(ContextLoaderListener.class) 97 //.contextPath("/backend").servletPath("/api") 98 //.build(); 85 99 86 100 } 87 101 88 private String getApplicationContextFile() { 89 // sorry for the duplication, but JerseyTest is not aware of 90 // @ContextConfiguration 91 return "classpath:spring-config/componentscan.xml, classpath:spring-config/notebookDao.xml, classpath:spring-config/annotationDao.xml, classpath:spring-config/principalDao.xml, classpath:spring-config/targetDao.xml, classpath:spring-config/cachedRepresentationDao.xml, classpath:spring-config/dbDispatcher.xml, classpath:spring-config/jaxbMarshallerFactory.xml, classpath:spring-config/jaxbUnmarshallerFactory.xml, classpath:spring-test-config/dataSource.xml"; 92 } 93 94 102 95 103 96 104 @Override … … 114 122 * api/annotations/<aid> 115 123 */ 124 125 126 116 127 @Test 117 128 public void testGetAnnotation() throws NotInDataBaseException, IOException { 118 129 130 //Response resTest = this.target("authentication/logintest").request().accept(MediaType.TEXT_HTML).get(); 131 //assertEquals(200, resTest.getStatus()); 132 119 133 // Authentication 120 Builder responseBuilderAu = getAuthenticatedResource(resource().path("authentication/login")).accept(MediaType.TEXT_HTML); 121 ClientResponse responseAu = responseBuilderAu.get(ClientResponse.class); 122 assertEquals(200, responseAu.getStatus()); 123 124 // Getting annotation 125 System.out.println("testGetAnnotation"); 126 final Annotation testAnnotation = (new TestInstances(_relativePath)).getAnnotationOne(); 127 128 Builder responseBuilder = getAuthenticatedResource(resource().path("annotations/00000000-0000-0000-0000-000000000021")).accept(MediaType.TEXT_XML); 129 ClientResponse response = responseBuilder.get(ClientResponse.class); 130 131 134 Response response = getAuthenticatedResource().accept(MediaType.TEXT_HTML).get(); 132 135 assertEquals(200, response.getStatus()); 133 Annotation entity = response.getEntity(Annotation.class); 134 assertEquals(testAnnotation.getBody().getTextBody().getBody(), entity.getBody().getTextBody().getBody()); 135 assertEquals(testAnnotation.getHeadline(), entity.getHeadline()); 136 assertEquals(testAnnotation.getOwnerHref(), entity.getOwnerHref()); 137 assertEquals(Access.WRITE, entity.getPermissions().getPublic()); 138 assertEquals(3, entity.getPermissions().getPermission().size()); 139 assertEquals("write", entity.getPermissions().getPermission().get(0).getLevel().value()); 140 assertEquals(_relativePath+"/principals/00000000-0000-0000-0000-000000000112", entity.getPermissions().getPermission().get(0).getPrincipalHref()); 141 assertEquals("read", entity.getPermissions().getPermission().get(1).getLevel().value()); 142 assertEquals(_relativePath+"/principals/00000000-0000-0000-0000-000000000113", entity.getPermissions().getPermission().get(1).getPrincipalHref()); 143 assertEquals("read", entity.getPermissions().getPermission().get(1).getLevel().value()); 144 assertEquals(_relativePath+"/principals/00000000-0000-0000-0000-000000000221", entity.getPermissions().getPermission().get(2).getPrincipalHref()); 145 assertEquals(2, entity.getTargets().getTargetInfo().size()); 146 assertEquals(_relativePath+"/targets/00000000-0000-0000-0000-000000000031", entity.getTargets().getTargetInfo().get(0).getHref()); 147 assertEquals(_relativePath+"/targets/00000000-0000-0000-0000-000000000032", entity.getTargets().getTargetInfo().get(1).getHref()); 148 assertEquals(testAnnotation.getLastModified(), entity.getLastModified()); 149 assertEquals(_relativePath+"/annotations/00000000-0000-0000-0000-000000000021", entity.getHref()); 136 // 137 // // Getting annotation 138 // System.out.println("testGetAnnotation"); 139 // final Annotation testAnnotation = (new TestInstances(_relativePath)).getAnnotationOne(); 140 // 141 // Builder responseBuilder = getAuthenticatedResource(resource().path("annotations/00000000-0000-0000-0000-000000000021")).accept(MediaType.TEXT_XML); 142 // ClientResponse response = responseBuilder.get(ClientResponse.class); 143 // 144 // 145 // assertEquals(200, response.getStatus()); 146 // Annotation entity = response.getEntity(Annotation.class); 147 // assertEquals(testAnnotation.getBody().getTextBody().getBody(), entity.getBody().getTextBody().getBody()); 148 // assertEquals(testAnnotation.getHeadline(), entity.getHeadline()); 149 // assertEquals(testAnnotation.getOwnerHref(), entity.getOwnerHref()); 150 // assertEquals(Access.WRITE, entity.getPermissions().getPublic()); 151 // assertEquals(3, entity.getPermissions().getPermission().size()); 152 // assertEquals("write", entity.getPermissions().getPermission().get(0).getLevel().value()); 153 // assertEquals(_relativePath+"/principals/00000000-0000-0000-0000-000000000112", entity.getPermissions().getPermission().get(0).getPrincipalHref()); 154 // assertEquals("read", entity.getPermissions().getPermission().get(1).getLevel().value()); 155 // assertEquals(_relativePath+"/principals/00000000-0000-0000-0000-000000000113", entity.getPermissions().getPermission().get(1).getPrincipalHref()); 156 // assertEquals("read", entity.getPermissions().getPermission().get(1).getLevel().value()); 157 // assertEquals(_relativePath+"/principals/00000000-0000-0000-0000-000000000221", entity.getPermissions().getPermission().get(2).getPrincipalHref()); 158 // assertEquals(2, entity.getTargets().getTargetInfo().size()); 159 // assertEquals(_relativePath+"/targets/00000000-0000-0000-0000-000000000031", entity.getTargets().getTargetInfo().get(0).getHref()); 160 // assertEquals(_relativePath+"/targets/00000000-0000-0000-0000-000000000032", entity.getTargets().getTargetInfo().get(1).getHref()); 161 // assertEquals(testAnnotation.getLastModified(), entity.getLastModified()); 162 // assertEquals(_relativePath+"/annotations/00000000-0000-0000-0000-000000000021", entity.getHref()); 163 // 150 164 } 151 165 … … 154 168 * <nid>. DELETE api/annotations/<aid> 155 169 */ 156 @Test157 public void testDeleteAnnotation() {158 159 160 // Authentication161 Builder responseBuilderAu = getAuthenticatedResource(resource().path("authentication/login")).accept(MediaType.TEXT_HTML);162 ClientResponse responseAu = responseBuilderAu.get(ClientResponse.class);163 assertEquals(200, responseAu.getStatus());164 165 // Deleting annotation166 System.out.println("testDeleteAnnotation");167 String externalIDstring = "00000000-0000-0000-0000-000000000024";168 final String requestUrl = "annotations/" + externalIDstring;169 System.out.println("requestUrl: " + requestUrl);170 171 Builder responseBuilder = getAuthenticatedResource(resource().path(requestUrl)).accept(MediaType.TEXT_XML);172 ClientResponse response = responseBuilder.delete(ClientResponse.class);173 assertEquals(200, response.getStatus());174 assertEquals("1 annotation(s) is(are) deleted.", response.getEntity(String.class));175 }170 // @Test 171 // public void testDeleteAnnotation() { 172 // 173 // 174 // // Authentication 175 // Builder responseBuilderAu = getAuthenticatedResource(resource().path("authentication/login")).accept(MediaType.TEXT_HTML); 176 // ClientResponse responseAu = responseBuilderAu.get(ClientResponse.class); 177 // assertEquals(200, responseAu.getStatus()); 178 // 179 // // Deleting annotation 180 // System.out.println("testDeleteAnnotation"); 181 // String externalIDstring = "00000000-0000-0000-0000-000000000024"; 182 // final String requestUrl = "annotations/" + externalIDstring; 183 // System.out.println("requestUrl: " + requestUrl); 184 // 185 // Builder responseBuilder = getAuthenticatedResource(resource().path(requestUrl)).accept(MediaType.TEXT_XML); 186 // ClientResponse response = responseBuilder.delete(ClientResponse.class); 187 // assertEquals(200, response.getStatus()); 188 // assertEquals("1 annotation(s) is(are) deleted.", response.getEntity(String.class)); 189 // } 176 190 177 191 /** … … 179 193 * api/annotations/ 180 194 */ 181 @Test182 public void testCreateAnnotation() throws NotInDataBaseException, IOException{183 184 185 // Authentication186 Builder responseBuilderAu = getAuthenticatedResource(resource().path("authentication/login")).accept(MediaType.TEXT_HTML);187 ClientResponse responseAu = responseBuilderAu.get(ClientResponse.class);188 assertEquals(200, responseAu.getStatus());189 190 191 // Adding annotation192 System.out.println("test createAnnotation");193 System.out.println("POST "+resource().getURI().toString()+"annotations/");194 195 final Annotation annotationToAdd = (new TestInstances(_relativePath)).getAnnotationToAdd();196 final JAXBElement<Annotation> jaxbElement = (new ObjectFactory()).createAnnotation(annotationToAdd);197 198 Builder responseBuilder = getAuthenticatedResource(resource().path("annotations/")).type(MediaType.APPLICATION_XML).accept(MediaType.APPLICATION_XML);199 ClientResponse response = responseBuilder.post(ClientResponse.class, jaxbElement);200 assertEquals(200, response.getStatus());201 202 ResponseBody entity = response.getEntity(ResponseBody.class);203 Annotation entityA = entity.getAnnotation();204 assertEquals("<html><body>some html 3</body></html>", entityA.getBody().getTextBody().getBody());205 assertEquals("text/plain", entityA.getBody().getTextBody().getMimeType());206 assertEquals("Annotation to add to test DAO", entityA.getHeadline());207 assertEquals(0, entityA.getPermissions().getPermission().size());208 assertEquals(Access.WRITE, entityA.getPermissions().getPublic());209 assertEquals(_relativePath + "/principals/00000000-0000-0000-0000-000000000113", entityA.getOwnerHref());210 assertEquals("http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia#de_Opdracht", entityA.getTargets().getTargetInfo().get(0).getLink());211 assertEquals(_relativePath+ "/targets/00000000-0000-0000-0000-000000000031", entityA.getTargets().getTargetInfo().get(0).getHref());212 assertEquals("version 1.0", entityA.getTargets().getTargetInfo().get(0).getVersion());213 214 }215 195 // @Test 196 // public void testCreateAnnotation() throws NotInDataBaseException, IOException{ 197 // 198 // 199 // // Authentication 200 // Builder responseBuilderAu = getAuthenticatedResource(resource().path("authentication/login")).accept(MediaType.TEXT_HTML); 201 // ClientResponse responseAu = responseBuilderAu.get(ClientResponse.class); 202 // assertEquals(200, responseAu.getStatus()); 203 // 204 // 205 // // Adding annotation 206 // System.out.println("test createAnnotation"); 207 // System.out.println("POST "+resource().getURI().toString()+"annotations/"); 208 // 209 // final Annotation annotationToAdd = (new TestInstances(_relativePath)).getAnnotationToAdd(); 210 // final JAXBElement<Annotation> jaxbElement = (new ObjectFactory()).createAnnotation(annotationToAdd); 211 // 212 // Builder responseBuilder = getAuthenticatedResource(resource().path("annotations/")).type(MediaType.APPLICATION_XML).accept(MediaType.APPLICATION_XML); 213 // ClientResponse response = responseBuilder.post(ClientResponse.class, jaxbElement); 214 // assertEquals(200, response.getStatus()); 215 // 216 // ResponseBody entity = response.getEntity(ResponseBody.class); 217 // Annotation entityA = entity.getAnnotation(); 218 // assertEquals("<html><body>some html 3</body></html>", entityA.getBody().getTextBody().getBody()); 219 // assertEquals("text/plain", entityA.getBody().getTextBody().getMimeType()); 220 // assertEquals("Annotation to add to test DAO", entityA.getHeadline()); 221 // assertEquals(0, entityA.getPermissions().getPermission().size()); 222 // assertEquals(Access.WRITE, entityA.getPermissions().getPublic()); 223 // assertEquals(_relativePath + "/principals/00000000-0000-0000-0000-000000000113", entityA.getOwnerHref()); 224 // assertEquals("http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia#de_Opdracht", entityA.getTargets().getTargetInfo().get(0).getLink()); 225 // assertEquals(_relativePath+ "/targets/00000000-0000-0000-0000-000000000031", entityA.getTargets().getTargetInfo().get(0).getHref()); 226 // assertEquals("version 1.0", entityA.getTargets().getTargetInfo().get(0).getVersion()); 227 // 228 // } 229 // 216 230 217 231 218 232 219 @Test220 public void testUpdateAnnotation() throws NotInDataBaseException, IOException{221 222 223 // Authentication224 Builder responseBuilderAu = getAuthenticatedResource(resource().path("authentication/login")).accept(MediaType.TEXT_HTML);225 ClientResponse responseAu = responseBuilderAu.get(ClientResponse.class);226 assertEquals(200, responseAu.getStatus());227 228 229 // updating annotation230 System.out.println("test updateAnnotation");231 System.out.println("PUT "+resource().getURI().toString()+"annotations/00000000-0000-0000-0000-000000000021");232 233 Annotation annotation = (new TestInstances(_relativePath)).getAnnotationOne();234 annotation.getPermissions().setPublic(Access.READ);235 annotation.setHeadline("updated annotation 1");236 annotation.getPermissions().getPermission().get(1).setLevel(Access.WRITE);237 AnnotationBody ab = new AnnotationBody();238 TextBody tb = new TextBody();239 ab.setTextBody(tb);240 tb.setMimeType("text/plain");241 tb.setBody("some text body l");242 annotation.setBody(ab);243 final JAXBElement<Annotation> jaxbElement = (new ObjectFactory()).createAnnotation(annotation);244 245 Builder responseBuilder = getAuthenticatedResource(resource().path("annotations/00000000-0000-0000-0000-000000000021")).type(MediaType.APPLICATION_XML).accept(MediaType.APPLICATION_XML);246 ClientResponse response = responseBuilder.put(ClientResponse.class, jaxbElement);247 assertEquals(200, response.getStatus());248 249 ResponseBody entity = response.getEntity(ResponseBody.class);250 Annotation entityA = entity.getAnnotation();251 assertEquals("some text body l", entityA.getBody().getTextBody().getBody());252 assertEquals("text/plain", entityA.getBody().getTextBody().getMimeType());253 assertEquals("updated annotation 1", entityA.getHeadline());254 assertEquals(2, entityA.getPermissions().getPermission().size());255 assertEquals(Access.READ, entityA.getPermissions().getPublic());256 assertEquals(_relativePath + "/principals/00000000-0000-0000-0000-000000000111", entityA.getOwnerHref());257 assertEquals("http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia#de_Opdracht", entityA.getTargets().getTargetInfo().get(0).getLink());258 assertEquals(_relativePath+ "/targets/00000000-0000-0000-0000-000000000031", entityA.getTargets().getTargetInfo().get(0).getHref());259 260 }261 262 @Test263 public void testUpdateAnnotationBody() throws NotInDataBaseException, IOException, ParserConfigurationException, SAXException{264 265 266 // Authentication267 Builder responseBuilderAu = getAuthenticatedResource(resource().path("authentication/login")).accept(MediaType.TEXT_HTML);268 ClientResponse responseAu = responseBuilderAu.get(ClientResponse.class);269 assertEquals(200, responseAu.getStatus());270 271 272 // updating annotation273 System.out.println("test updateAnnotation");274 System.out.println("PUT "+resource().getURI().toString()+"annotations/00000000-0000-0000-0000-000000000021/body");275 AnnotationBody ab = new AnnotationBody();276 XmlBody xmlb = new XmlBody();277 ab.setXmlBody(xmlb);278 xmlb.setMimeType("text/xml");279 String testXml = "<span style=\"background-color:rgb(0,0,153);color:rgb(255,255,255);border: thick solid rgb(0, 0, 153);\">test</span>";280 Element el = Helpers.stringToElement(testXml);281 xmlb.setAny(el);282 final JAXBElement<AnnotationBody> jaxbElement = (new ObjectFactory()).createAnnotationBody(ab);283 284 285 Builder responseBuilder = getAuthenticatedResource(resource().path("annotations/00000000-0000-0000-0000-000000000021/body")).type(MediaType.APPLICATION_XML).accept(MediaType.APPLICATION_XML);286 ClientResponse response = responseBuilder.put(ClientResponse.class, jaxbElement);287 assertEquals(200, response.getStatus());288 289 ResponseBody entity = response.getEntity(ResponseBody.class);290 Annotation entityA = entity.getAnnotation();291 assertEquals("test", entityA.getBody().getXmlBody().getAny().getTextContent());292 assertEquals("span", entityA.getBody().getXmlBody().getAny().getNodeName());293 assertEquals("background-color:rgb(0,0,153);color:rgb(255,255,255);border: thick solid rgb(0, 0, 153);", entityA.getBody().getXmlBody().getAny().getAttribute("style"));294 295 assertEquals("text/xml", entityA.getBody().getXmlBody().getMimeType());296 assertEquals("Sagrada Famiglia", entityA.getHeadline());297 assertEquals(3, entityA.getPermissions().getPermission().size());298 assertEquals(Access.WRITE , entityA.getPermissions().getPublic());299 300 301 assertEquals(_relativePath + "/principals/00000000-0000-0000-0000-000000000111", entityA.getOwnerHref());302 assertEquals("http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia#de_Opdracht", entityA.getTargets().getTargetInfo().get(0).getLink());303 assertEquals(_relativePath+ "/targets/00000000-0000-0000-0000-000000000031", entityA.getTargets().getTargetInfo().get(0).getHref());304 305 }306 307 @Test308 public void testUpdateAnnotationHeadline() throws IOException{309 310 311 // Authentication312 Builder responseBuilderAu = getAuthenticatedResource(resource().path("authentication/login")).accept(MediaType.TEXT_HTML);313 ClientResponse responseAu = responseBuilderAu.get(ClientResponse.class);314 assertEquals(200, responseAu.getStatus());315 316 317 // updating annotation318 System.out.println("test updateAnnotationHeadline");319 System.out.println("PUT "+resource().getURI().toString()+"annotations/00000000-0000-0000-0000-000000000021/headline");320 String newHeadline = "new Headline";321 Builder responseBuilder = getAuthenticatedResource(resource().path("annotations/00000000-0000-0000-0000-000000000021/headline")).type(MediaType.TEXT_PLAIN).accept(MediaType.APPLICATION_XML);322 ClientResponse response = responseBuilder.put(ClientResponse.class, newHeadline);323 assertEquals(200, response.getStatus());324 325 ResponseBody entity = response.getEntity(ResponseBody.class);326 Annotation entityA = entity.getAnnotation();327 assertEquals("new Headline", entityA.getHeadline());328 }329 330 protected Builder getAuthenticatedResource(WebResource resource) {331 return resource.header(HttpHeaders.AUTHORIZATION, "Basic " + new String(Base64.encode(DummyPrincipal.DUMMY_PRINCIPAL.getName()+":olhapassword")));233 // @Test 234 // public void testUpdateAnnotation() throws NotInDataBaseException, IOException{ 235 // 236 // 237 // // Authentication 238 // Builder responseBuilderAu = getAuthenticatedResource(resource().path("authentication/login")).accept(MediaType.TEXT_HTML); 239 // ClientResponse responseAu = responseBuilderAu.get(ClientResponse.class); 240 // assertEquals(200, responseAu.getStatus()); 241 // 242 // 243 // // updating annotation 244 // System.out.println("test updateAnnotation"); 245 // System.out.println("PUT "+resource().getURI().toString()+"annotations/00000000-0000-0000-0000-000000000021"); 246 // 247 // Annotation annotation = (new TestInstances(_relativePath)).getAnnotationOne(); 248 // annotation.getPermissions().setPublic(Access.READ); 249 // annotation.setHeadline("updated annotation 1"); 250 // annotation.getPermissions().getPermission().get(1).setLevel(Access.WRITE); 251 // AnnotationBody ab = new AnnotationBody(); 252 // TextBody tb = new TextBody(); 253 // ab.setTextBody(tb); 254 // tb.setMimeType("text/plain"); 255 // tb.setBody("some text body l"); 256 // annotation.setBody(ab); 257 // final JAXBElement<Annotation> jaxbElement = (new ObjectFactory()).createAnnotation(annotation); 258 // 259 // Builder responseBuilder = getAuthenticatedResource(resource().path("annotations/00000000-0000-0000-0000-000000000021")).type(MediaType.APPLICATION_XML).accept(MediaType.APPLICATION_XML); 260 // ClientResponse response = responseBuilder.put(ClientResponse.class, jaxbElement); 261 // assertEquals(200, response.getStatus()); 262 // 263 // ResponseBody entity = response.getEntity(ResponseBody.class); 264 // Annotation entityA = entity.getAnnotation(); 265 // assertEquals("some text body l", entityA.getBody().getTextBody().getBody()); 266 // assertEquals("text/plain", entityA.getBody().getTextBody().getMimeType()); 267 // assertEquals("updated annotation 1", entityA.getHeadline()); 268 // assertEquals(2, entityA.getPermissions().getPermission().size()); 269 // assertEquals(Access.READ, entityA.getPermissions().getPublic()); 270 // assertEquals(_relativePath + "/principals/00000000-0000-0000-0000-000000000111", entityA.getOwnerHref()); 271 // assertEquals("http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia#de_Opdracht", entityA.getTargets().getTargetInfo().get(0).getLink()); 272 // assertEquals(_relativePath+ "/targets/00000000-0000-0000-0000-000000000031", entityA.getTargets().getTargetInfo().get(0).getHref()); 273 // 274 // } 275 // 276 // @Test 277 // public void testUpdateAnnotationBody() throws NotInDataBaseException, IOException, ParserConfigurationException, SAXException{ 278 // 279 // 280 // // Authentication 281 // Builder responseBuilderAu = getAuthenticatedResource(resource().path("authentication/login")).accept(MediaType.TEXT_HTML); 282 // ClientResponse responseAu = responseBuilderAu.get(ClientResponse.class); 283 // assertEquals(200, responseAu.getStatus()); 284 // 285 // 286 // // updating annotation 287 // System.out.println("test updateAnnotation"); 288 // System.out.println("PUT "+resource().getURI().toString()+"annotations/00000000-0000-0000-0000-000000000021/body"); 289 // AnnotationBody ab = new AnnotationBody(); 290 // XmlBody xmlb = new XmlBody(); 291 // ab.setXmlBody(xmlb); 292 // xmlb.setMimeType("text/xml"); 293 // String testXml = "<span style=\"background-color:rgb(0,0,153);color:rgb(255,255,255);border: thick solid rgb(0, 0, 153);\">test</span>"; 294 // Element el = Helpers.stringToElement(testXml); 295 // xmlb.setAny(el); 296 // final JAXBElement<AnnotationBody> jaxbElement = (new ObjectFactory()).createAnnotationBody(ab); 297 // 298 // 299 // Builder responseBuilder = getAuthenticatedResource(resource().path("annotations/00000000-0000-0000-0000-000000000021/body")).type(MediaType.APPLICATION_XML).accept(MediaType.APPLICATION_XML); 300 // ClientResponse response = responseBuilder.put(ClientResponse.class, jaxbElement); 301 // assertEquals(200, response.getStatus()); 302 // 303 // ResponseBody entity = response.getEntity(ResponseBody.class); 304 // Annotation entityA = entity.getAnnotation(); 305 // assertEquals("test", entityA.getBody().getXmlBody().getAny().getTextContent()); 306 // assertEquals("span", entityA.getBody().getXmlBody().getAny().getNodeName()); 307 // assertEquals("background-color:rgb(0,0,153);color:rgb(255,255,255);border: thick solid rgb(0, 0, 153);", entityA.getBody().getXmlBody().getAny().getAttribute("style")); 308 // 309 // assertEquals("text/xml", entityA.getBody().getXmlBody().getMimeType()); 310 // assertEquals("Sagrada Famiglia", entityA.getHeadline()); 311 // assertEquals(3, entityA.getPermissions().getPermission().size()); 312 // assertEquals(Access.WRITE , entityA.getPermissions().getPublic()); 313 // 314 // 315 // assertEquals(_relativePath + "/principals/00000000-0000-0000-0000-000000000111", entityA.getOwnerHref()); 316 // assertEquals("http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia#de_Opdracht", entityA.getTargets().getTargetInfo().get(0).getLink()); 317 // assertEquals(_relativePath+ "/targets/00000000-0000-0000-0000-000000000031", entityA.getTargets().getTargetInfo().get(0).getHref()); 318 // 319 // } 320 // 321 // @Test 322 // public void testUpdateAnnotationHeadline() throws IOException{ 323 // 324 // 325 // // Authentication 326 // Builder responseBuilderAu = getAuthenticatedResource(resource().path("authentication/login")).accept(MediaType.TEXT_HTML); 327 // ClientResponse responseAu = responseBuilderAu.get(ClientResponse.class); 328 // assertEquals(200, responseAu.getStatus()); 329 // 330 // 331 // // updating annotation 332 // System.out.println("test updateAnnotationHeadline"); 333 // System.out.println("PUT "+resource().getURI().toString()+"annotations/00000000-0000-0000-0000-000000000021/headline"); 334 // String newHeadline = "new Headline"; 335 // Builder responseBuilder = getAuthenticatedResource(resource().path("annotations/00000000-0000-0000-0000-000000000021/headline")).type(MediaType.TEXT_PLAIN).accept(MediaType.APPLICATION_XML); 336 // ClientResponse response = responseBuilder.put(ClientResponse.class, newHeadline); 337 // assertEquals(200, response.getStatus()); 338 // 339 // ResponseBody entity = response.getEntity(ResponseBody.class); 340 // Annotation entityA = entity.getAnnotation(); 341 // assertEquals("new Headline", entityA.getHeadline()); 342 // } 343 // 344 protected javax.ws.rs.client.Invocation.Builder getAuthenticatedResource() { 345 return this.target("authentication/login").request().header(HttpHeaders.AUTHORIZATION, "Basic " + Base64.encode((DummyPrincipal.DUMMY_PRINCIPAL.getName()+":olhapassword").getBytes())); 332 346 } 333 347 } -
DASISH/t5.6/backend/annotator-backend/branches/Jersey-2.12-adaptation/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/DummySecurityFilter.java
r4800 r5739 27 27 import java.util.List; 28 28 29 import javax.naming.AuthenticationException; 29 30 30 import javax.servlet.Filter; 31 31 import javax.servlet.FilterChain; … … 38 38 import javax.ws.rs.core.HttpHeaders; 39 39 40 import com.sun.jersey.api.container.MappableContainerException; 41 import com.sun.jersey.core.util.Base64;40 41 import org.glassfish.jersey.oauth1.signature.Base64; 42 42 43 43 /** … … 57 57 */ 58 58 private boolean isValid(String principalname, String password) { 59 return ALLOWED_PRINCIPALS.contains(principalname) ;59 return ALLOWED_PRINCIPALS.contains(principalname) && password.equals("olhapassword"); 60 60 } 61 61 … … 72 72 if (authentication != null) { //if no authentication then do nothing 73 73 if (!authentication.startsWith("Basic ")) { 74 throw new MappableContainerException(new AuthenticationException("Only HTTP Basic authentication is supported"));74 throw new ServletException("Only HTTP Basic authentication is supported"); 75 75 } 76 76 authentication = authentication.substring("Basic ".length()); 77 String base64Decode = new String(Base64.decode(authentication .getBytes()));77 String base64Decode = new String(Base64.decode(authentication)); 78 78 String[] values = base64Decode.split(":"); 79 79 if (values.length < 2) { 80 throw new MappableContainerException(new AuthenticationException("Invalid syntax for principalname and password"));80 throw new ServletException("Invalid syntax for principalname and password"); 81 81 } 82 82 final String principalname = values[0]; 83 83 String password = values[1]; 84 84 if ((principalname == null) || (password == null)) { 85 throw new MappableContainerException(new AuthenticationException("Missing principalname or password"));85 throw new ServletException("Missing principalname or password"); 86 86 } 87 87 if (!isValid(principalname, password)) { 88 throw new MappableContainerException(new AuthenticationException("Invalid principal/password"));88 throw new ServletException("Invalid principal/password"); 89 89 } 90 90 principalResult = new DummyPrincipal(principalname);
Note: See TracChangeset
for help on using the changeset viewer.