private WebServiceContext createWebServiceContextMock(String expectedIP, String expectedUser) { requestMock = mock(HttpServletRequest.class); when(requestMock.getRemoteAddr()).thenReturn(expectedIP); Principal principalMock = mock(Principal.class); when(principalMock.getName()).thenReturn(expectedUser); MessageContext msgContextMock = mock(MessageContext.class); when(msgContextMock.get(anyString())).thenReturn(requestMock); WebServiceContext wsContextMock = mock(WebServiceContext.class); when(wsContextMock.getUserPrincipal()).thenReturn(principalMock); when(wsContextMock.getMessageContext()).thenReturn(msgContextMock); return wsContextMock; }
public UddiEntityPublisher identify(String authInfo, String authorizedName, WebServiceContext ctx) throws AuthenticationException { EntityManager em = PersistenceManager.getEntityManager(); EntityTransaction tx = em.getTransaction(); try { tx.begin(); Publisher publisher = em.find(Publisher.class, authorizedName); if (publisher == null) { throw new UnknownUserException(new ErrorMessage("errors.auth.NoPublisher", authorizedName)); } return publisher; } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } }
@Override public UddiEntityPublisher identify(String authInfo, String authorizedName, WebServiceContext ctx) throws AuthenticationException { EntityManager em = PersistenceManager.getEntityManager(); EntityTransaction tx = em.getTransaction(); try { tx.begin(); Publisher publisher = em.find(Publisher.class, authorizedName); if (publisher == null) { throw new UnknownUserException(new ErrorMessage("errors.auth.NoPublisher", authorizedName)); } return publisher; } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } }
public UddiEntityPublisher identify(String authInfo, String authorizedName, WebServiceContext ctx) throws AuthenticationException, FatalErrorException { EntityManager em = PersistenceManager.getEntityManager(); EntityTransaction tx = em.getTransaction(); try { tx.begin(); Publisher publisher = em.find(Publisher.class, authorizedName); if (publisher == null) throw new UnknownUserException(new ErrorMessage("errors.auth.NoPublisher", authorizedName)); return publisher; } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } }
private boolean isWebServiceContextResource(Resource atResource, Field field) { Class type = atResource.type(); if (type == java.lang.Object.class) { if (field != null && field.getType() == WebServiceContext.class) { return true; } } else if (type == WebServiceContext.class) { //TODO: Should I check if the field declared type is assignable from WebServiceContext. Spec is not clear about this. return true; } if (log.isDebugEnabled()) { log.debug( "Invalid Field type or Resource Type found, cannot inject WebServiceContext on this field"); } return false; }
private boolean isWebServiceContextResource(Resource atResource, Method method) { //As per JSR-250 the method injection is nothing but setter based injection, //Such a injection can happen if method name starts with "set" returns a void and //only has one parameter and the type of this parameter must be compatible with //resource. Class type = atResource.type(); Class[] paramTypes = method.getParameterTypes(); for (Class paramType : paramTypes) if (type == java.lang.Object.class) { if (paramType == WebServiceContext.class || paramType.isAssignableFrom(WebServiceContext.class)) { return true; } } else if (type == WebServiceContext.class) { //TODO: Should I check if the field declared type is assignable from WebServiceContext. Spec is not clear about this. return true; } if (log.isDebugEnabled()) { log.debug( "Invalid Field type or Resource Type found, cannot inject WebServiceContext on this method"); } return false; }
public void testInjectionOnField(){ Object serviceInstance = new ResourceInjectionTestImpl1(); TestLogger.logger.debug("------------------------------"); TestLogger.logger.debug("Test : " + getName()); try{ ResourceInjector injector = ResourceInjectionFactory.createResourceInjector(WebServiceContext.class); injector.inject(resource, serviceInstance); ResourceInjectionTestImpl1 serviceImpl =(ResourceInjectionTestImpl1)serviceInstance; assertNotNull(serviceImpl.ctx); TestLogger.logger.debug("Resource Injected on Field"); TestLogger.logger.debug("------------------------------"); }catch(Exception e){ e.printStackTrace(); fail(); } }
public void testInjectionOnMethod(){ Object serviceInstance = new ResourceInjectionTestImpl2(); TestLogger.logger.debug("------------------------------"); TestLogger.logger.debug("Test : " + getName()); try{ ResourceInjector injector = ResourceInjectionFactory.createResourceInjector(WebServiceContext.class); injector.inject(resource, serviceInstance); ResourceInjectionTestImpl2 serviceImpl =(ResourceInjectionTestImpl2)serviceInstance; assertNotNull(serviceImpl.ctx); TestLogger.logger.debug("Resource Injected on Method"); TestLogger.logger.debug("------------------------------"); }catch(Exception e){ e.printStackTrace(); fail(); } }