List of usage examples for java.lang.reflect Method getAnnotation
public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
From source file:core.commonapp.server.security.CommonAppServiceSecurity.java
/** * Get the security annotation from the given method * /* w ww .jav a2s . c o m*/ * @param serviceInterface * @param method * @throws IllegalArgumentException * if no Security annotation exist on method * @return */ private Security getMethodSecurity(Class serviceInterface, Method method) { Security security = method.getAnnotation(Security.class); if (security == null) { throw new IllegalArgumentException( "This service method cannot be authenticated against (serviceInterface=" + serviceInterface.getName() + ",method=" + method.getName() + ")."); } return security; }
From source file:com.wx.spring.interceptor.OAuth2Interceptor.java
/** * ??? false ?afterCompletion(),? /* ww w .j av a 2 s . c om*/ * true , ?Controller ?, * ?postHandle() ???afterCompletion() */ @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { System.out.println("**?: 1?preHandle**"); String url = request.getRequestURL().toString(); HttpSession session = request.getSession(); // ? HandlerMethod handlerMethod = (HandlerMethod) handler; Method method = handlerMethod.getMethod(); OAuthRequired annotation = method.getAnnotation(OAuthRequired.class); if (annotation != null) { System.out.println("OAuthRequired????"); Object objUid = session.getAttribute("UserId"); if (objUid == null) { String resultUrl = request.getRequestURL().toString(); String param = request.getQueryString(); if (param != null) { resultUrl += "?" + param; } System.out.println("resultUrl=" + resultUrl); try { resultUrl = java.net.URLEncoder.encode(resultUrl, "utf-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } // String contextPath = request.getContextPath(); response.sendRedirect(contextPath + "/oauth2.do?resultUrl=" + resultUrl); return false; } } return true; }
From source file:org.os890.ds.addon.remote.impl.server.ServiceConfigUpdateTask.java
private void createCacheEntryFor(Class<?> beanClass) { Path path = beanClass.getAnnotation(Path.class); if (path != null) { ObjectMapper objectMapper = new ObjectMapper(); for (Method method : beanClass.getDeclaredMethods()) { Path methodPath = method.getAnnotation(Path.class); if (methodPath != null) { try { ServiceDescriptor serviceDescriptor = ServiceDescriptorFactory.create(methodPath.value(), path.value()); String serviceDescriptorAsJson = objectMapper.writeValueAsString(serviceDescriptor); Cache<String, String> cache = cacheProvider.getCache(); String cachedValue = cache.get(serviceDescriptor.getKey()); if (!serviceDescriptorAsJson.equals(cachedValue)) { cache.put(serviceDescriptor.getKey(), serviceDescriptorAsJson); }//from w ww . j a va 2s.com LOG.fine("cached endpoint descriptor: " + serviceDescriptor.getKey() + " -> " + serviceDescriptorAsJson); } catch (JsonProcessingException e) { throw ExceptionUtils.throwAsRuntimeException(e); } } } } }
From source file:com.wavemaker.tools.apidocs.tools.spring.parser.SpringMethodParser.java
@Override protected void handleFrameWorkSpecific(final Method methodToParse, final Operation operation) { RequestMapping requestMapping = methodToParse.getAnnotation(RequestMapping.class); operation.setConsumes(Arrays.asList(requestMapping.consumes())); operation.setProduces(Arrays.asList(requestMapping.produces())); // operation.setResponseMessages(new ArrayList<ResponseMessage>()); // TODO // operation.setPolicy(null); // TODO }
From source file:pl.com.bottega.ecommerce.system.infrastructure.events.impl.EventListenerBeanPostProcessor.java
@Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (!(bean instanceof SagaInstance)) { for (Method method : bean.getClass().getMethods()) { EventListener listenerAnnotation = method.getAnnotation(EventListener.class); if (listenerAnnotation == null) { continue; }/*from w w w. j a v a 2 s .c o m*/ Class<?> eventType = method.getParameterTypes()[0]; if (listenerAnnotation.asynchronous()) { //TODO just a temporary fake impl EventHandler handler = new AsynchronousEventHandler(eventType, beanName, method, beanFactory); //TODO add to some queue eventPublisher.registerEventHandler(handler); } else { EventHandler handler = new SpringEventHandler(eventType, beanName, method, beanFactory); eventPublisher.registerEventHandler(handler); } } } return bean; }
From source file:ch.caleb.scaffolding.grid.column.IColumnFactory.java
public Map<String, Object> filterForIgnore(Object source, Map<String, Object> input) throws Exception { Map<String, Object> resultMap = new HashMap<String, Object>(); for (String value : input.keySet()) { Method method = input.getClass().getMethod(value); GridMetaData gmd = method.getAnnotation(GridMetaData.class); if (gmd == null || gmd.mode() != GridMetaData.Mode.IGNORE) { resultMap.put(value, input.get(value)); } else {//from w ww .j a va 2 s.com // is marked ignore } } return resultMap; }
From source file:com.ryantenney.metrics.spring.AbstractMetricMethodInterceptor.java
@Override public void doWith(Method method) throws IllegalAccessException { final A annotation = method.getAnnotation(annotationClass); if (annotation != null) { final MethodKey methodKey = MethodKey.forMethod(method); final String metricName = buildMetricName(targetClass, method, annotation); final M metric = buildMetric(metricRegistry, metricName, annotation); if (metric != null) { metrics.put(methodKey, new AnnotationMetricPair<A, M>(annotation, metric)); if (LOG.isDebugEnabled()) { LOG.debug("Created {} {} for method {}", metric.getClass().getSimpleName(), metricName, methodKey);/*from ww w . ja v a2 s . co m*/ } } } }
From source file:org.socialsignin.spring.data.dynamodb.repository.support.DynamoDBHashAndRangeKeyExtractingEntityMetadataImpl.java
public DynamoDBHashAndRangeKeyExtractingEntityMetadataImpl(final Class<T> domainType) { super(domainType); this.hashAndRangeKeyMethodExtractor = new DynamoDBHashAndRangeKeyMethodExtractorImpl<T>(getJavaType()); ReflectionUtils.doWithMethods(domainType, new MethodCallback() { public void doWith(Method method) { if (method.getAnnotation(DynamoDBHashKey.class) != null) { String setterMethodName = toSetterMethodNameFromAccessorMethod(method); if (setterMethodName != null) { hashKeySetterMethod = ReflectionUtils.findMethod(domainType, setterMethodName, method.getReturnType()); }//from ww w . j av a2 s .c o m } } }); ReflectionUtils.doWithFields(domainType, new FieldCallback() { public void doWith(Field field) { if (field.getAnnotation(DynamoDBHashKey.class) != null) { hashKeyField = ReflectionUtils.findField(domainType, field.getName()); } } }); Assert.isTrue(hashKeySetterMethod != null || hashKeyField != null, "Unable to find hash key field or setter method on " + domainType + "!"); Assert.isTrue(hashKeySetterMethod == null || hashKeyField == null, "Found both hash key field and setter method on " + domainType + "!"); }
From source file:ru.jts_dev.gameserver.handlers.TextHandlerManager.java
/** * Adds all handlers for enumerated handler classes of manager. * Handler commands detected when {link @TextCommand} annotation present on method. * * @param classes List of handler classes. *//*from w ww .ja v a 2s.c o m*/ @SuppressWarnings("unchecked") protected void addHandlers(Class<? extends ICommandHandler>[] classes) { for (Class<? extends ICommandHandler> cls : classes) { try { Class<? extends ICommandHandler<String>> castedClass = (Class<? extends ICommandHandler<String>>) cls; ICommandHandler<String> handler = getHandlerInstance(castedClass); if (handler != null) { for (Method method : getAnnotatedMethods(castedClass, TextCommand.class)) { String command = method.getAnnotation(TextCommand.class).value(); if (command.isEmpty()) { command = method.getName(); } command = command.toLowerCase(); addHandler(command, handler, method); } } } catch (Exception e) { log.error("Cannot register handler for class [" + cls.getName() + "].", e); } } }
From source file:hsa.awp.common.test.AbstractFacadeTest.java
/** * Tests all facade methods for their @Transactional annotations. *///from w ww. jav a2 s . c om @Test public void testTransactionalAnnotations() { for (Method method : facadeToTest.getMethods()) { if (isTransactionalNecessary(method.getName()) && method.getAnnotation(Transactional.class) == null) { fail("Every logic method in a facade must have a @Transactional annotation: " + method.getName()); } } }