org.springframework.core.ResolvableType Java Examples

The following examples show how to use org.springframework.core.ResolvableType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultListableBeanFactory.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public String[] getBeanNamesForType(@Nullable Class<?> type, boolean includeNonSingletons, boolean allowEagerInit) {
	if (!isConfigurationFrozen() || type == null || !allowEagerInit) {
		return doGetBeanNamesForType(ResolvableType.forRawClass(type), includeNonSingletons, allowEagerInit);
	}
	Map<Class<?>, String[]> cache =
			(includeNonSingletons ? this.allBeanNamesByType : this.singletonBeanNamesByType);
	String[] resolvedBeanNames = cache.get(type);
	if (resolvedBeanNames != null) {
		return resolvedBeanNames;
	}
	resolvedBeanNames = doGetBeanNamesForType(ResolvableType.forRawClass(type), includeNonSingletons, true);
	if (ClassUtils.isCacheSafe(type, getBeanClassLoader())) {
		cache.put(type, resolvedBeanNames);
	}
	return resolvedBeanNames;
}
 
Example #2
Source File: FastJsonHttpMessageConverter.java    From uavstack with Apache License 2.0 6 votes vote down vote up
private static ResolvableType resolveVariable(TypeVariable<?> typeVariable, ResolvableType contextType) {
    ResolvableType resolvedType;
    if (contextType.hasGenerics()) {
        resolvedType = ResolvableType.forType(typeVariable, contextType);
        if (resolvedType.resolve() != null) {
            return resolvedType;
        }
    }

    ResolvableType superType = contextType.getSuperType();
    if (superType != ResolvableType.NONE) {
        resolvedType = resolveVariable(typeVariable, superType);
        if (resolvedType.resolve() != null) {
            return resolvedType;
        }
    }
    for (ResolvableType ifc : contextType.getInterfaces()) {
        resolvedType = resolveVariable(typeVariable, ifc);
        if (resolvedType.resolve() != null) {
            return resolvedType;
        }
    }
    return ResolvableType.NONE;
}
 
Example #3
Source File: ApplicationListenerMethodAdapter.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Nullable
private ResolvableType getResolvableType(ApplicationEvent event) {
	ResolvableType payloadType = null;
	if (event instanceof PayloadApplicationEvent) {
		PayloadApplicationEvent<?> payloadEvent = (PayloadApplicationEvent<?>) event;
		ResolvableType eventType = payloadEvent.getResolvableType();
		if (eventType != null) {
			payloadType = eventType.as(PayloadApplicationEvent.class).getGeneric();
		}
	}
	for (ResolvableType declaredEventType : this.declaredEventTypes) {
		Class<?> eventClass = declaredEventType.toClass();
		if (!ApplicationEvent.class.isAssignableFrom(eventClass) &&
				payloadType != null && declaredEventType.isAssignableFrom(payloadType)) {
			return declaredEventType;
		}
		if (eventClass.isInstance(event)) {
			return declaredEventType;
		}
	}
	return null;
}
 
Example #4
Source File: ConfigurationClassPostProcessorTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void genericsBasedInjectionWithLateGenericsMatchingOnJdkProxyAndRawFactoryMethod() {
	beanFactory.registerBeanDefinition("configClass", new RootBeanDefinition(RawFactoryMethodRepositoryConfiguration.class));
	new ConfigurationClassPostProcessor().postProcessBeanFactory(beanFactory);
	DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();
	autoProxyCreator.setBeanFactory(beanFactory);
	beanFactory.addBeanPostProcessor(autoProxyCreator);
	beanFactory.registerSingleton("traceInterceptor", new DefaultPointcutAdvisor(new SimpleTraceInterceptor()));
	beanFactory.preInstantiateSingletons();

	String[] beanNames = beanFactory.getBeanNamesForType(RepositoryInterface.class);
	assertTrue(ObjectUtils.containsElement(beanNames, "stringRepo"));

	beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(RepositoryInterface.class, String.class));
	assertEquals(1, beanNames.length);
	assertEquals("stringRepo", beanNames[0]);

	beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(RepositoryInterface.class, String.class));
	assertEquals(1, beanNames.length);
	assertEquals("stringRepo", beanNames[0]);

	assertTrue(AopUtils.isJdkDynamicProxy(beanFactory.getBean("stringRepo")));
}
 
Example #5
Source File: AutowiredAnnotationBeanPostProcessorTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
@SuppressWarnings("rawtypes")
public void testGenericsBasedInjectionIntoTypeVariableSelectingBestMatch() {
	RootBeanDefinition bd = new RootBeanDefinition(GenericInterface1Impl.class);
	bd.setFactoryMethodName("create");
	bf.registerBeanDefinition("bean1", bd);
	bf.registerBeanDefinition("bean2", new RootBeanDefinition(GenericInterface2Impl.class));
	bf.registerBeanDefinition("bean2a", new RootBeanDefinition(ReallyGenericInterface2Impl.class));
	bf.registerBeanDefinition("bean2b", new RootBeanDefinition(PlainGenericInterface2Impl.class));

	GenericInterface1Impl bean1 = (GenericInterface1Impl) bf.getBean("bean1");
	GenericInterface2Impl bean2 = (GenericInterface2Impl) bf.getBean("bean2");
	assertSame(bean2, bean1.gi2);
	assertArrayEquals(new String[] {"bean1"}, bf.getBeanNamesForType(ResolvableType.forClassWithGenerics(GenericInterface1.class, String.class)));
	assertArrayEquals(new String[] {"bean2"}, bf.getBeanNamesForType(ResolvableType.forClassWithGenerics(GenericInterface2.class, String.class)));
}
 
Example #6
Source File: InvocableHandlerMethod.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public Class<?> getParameterType() {
	if (this.returnValue != null) {
		return this.returnValue.getClass();
	}
	if (!ResolvableType.NONE.equals(this.returnType)) {
		return this.returnType.toClass();
	}
	return super.getParameterType();
}
 
Example #7
Source File: ServerSentEventHttpMessageReaderTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void readError() {
	Flux<DataBuffer> body =
			Flux.just(stringBuffer("data:foo\ndata:bar\n\ndata:baz\n\n"))
					.concatWith(Flux.error(new RuntimeException()));

	MockServerHttpRequest request = MockServerHttpRequest.post("/")
			.body(body);

	Flux<String> data = messageReader.read(ResolvableType.forClass(String.class),
			request, Collections.emptyMap()).cast(String.class);

	StepVerifier.create(data)
			.expectNextMatches(elem -> elem.equals("foo\nbar"))
			.expectNextMatches(elem -> elem.equals("baz"))
			.expectError()
			.verify();
}
 
Example #8
Source File: ApplicationListenerMethodAdapter.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Resolve the method arguments to use for the specified {@link ApplicationEvent}.
 * <p>These arguments will be used to invoke the method handled by this instance.
 * Can return {@code null} to indicate that no suitable arguments could be resolved
 * and therefore the method should not be invoked at all for the specified event.
 */
@Nullable
protected Object[] resolveArguments(ApplicationEvent event) {
	ResolvableType declaredEventType = getResolvableType(event);
	if (declaredEventType == null) {
		return null;
	}
	if (this.method.getParameterCount() == 0) {
		return new Object[0];
	}
	Class<?> declaredEventClass = declaredEventType.toClass();
	if (!ApplicationEvent.class.isAssignableFrom(declaredEventClass) &&
			event instanceof PayloadApplicationEvent) {
		Object payload = ((PayloadApplicationEvent<?>) event).getPayload();
		if (declaredEventClass.isInstance(payload)) {
			return new Object[] {payload};
		}
	}
	return new Object[] {event};
}
 
Example #9
Source File: ApplicationListenerMethodAdapter.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private ResolvableType getResolvableType(ApplicationEvent event) {
	ResolvableType payloadType = null;
	if (event instanceof PayloadApplicationEvent) {
		PayloadApplicationEvent<?> payloadEvent = (PayloadApplicationEvent<?>) event;
		payloadType = payloadEvent.getResolvableType().as(PayloadApplicationEvent.class).getGeneric();
	}
	for (ResolvableType declaredEventType : this.declaredEventTypes) {
		if (!ApplicationEvent.class.isAssignableFrom(declaredEventType.getRawClass()) && payloadType != null) {
			if (declaredEventType.isAssignableFrom(payloadType)) {
				return declaredEventType;
			}
		}
		if (declaredEventType.getRawClass().isInstance(event)) {
			return declaredEventType;
		}
	}
	return null;
}
 
Example #10
Source File: CodecConfigurerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void defaultsOffCustomReaders() {
	Decoder<?> customDecoder1 = mock(Decoder.class);
	Decoder<?> customDecoder2 = mock(Decoder.class);

	when(customDecoder1.canDecode(ResolvableType.forClass(Object.class), null)).thenReturn(false);
	when(customDecoder2.canDecode(ResolvableType.forClass(Object.class), null)).thenReturn(true);

	HttpMessageReader<?> customReader1 = mock(HttpMessageReader.class);
	HttpMessageReader<?> customReader2 = mock(HttpMessageReader.class);

	when(customReader1.canRead(ResolvableType.forClass(Object.class), null)).thenReturn(false);
	when(customReader2.canRead(ResolvableType.forClass(Object.class), null)).thenReturn(true);

	this.configurer.customCodecs().decoder(customDecoder1);
	this.configurer.customCodecs().decoder(customDecoder2);

	this.configurer.customCodecs().reader(customReader1);
	this.configurer.customCodecs().reader(customReader2);

	this.configurer.registerDefaults(false);

	List<HttpMessageReader<?>> readers = this.configurer.getReaders();

	assertEquals(4, readers.size());
	assertSame(customDecoder1, getNextDecoder(readers));
	assertSame(customReader1, readers.get(this.index.getAndIncrement()));
	assertSame(customDecoder2, getNextDecoder(readers));
	assertSame(customReader2, readers.get(this.index.getAndIncrement()));
}
 
Example #11
Source File: RequestProcessor.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
public Mono<ResponseEntity<?>> post(FunctionWrapper wrapper, String body,
		boolean stream) {
	Object function = wrapper.handler();
	Class<?> inputType = this.inspector.getInputType(function);
	Type itemType = getItemType(function);

	Object input = body == null && inputType.isAssignableFrom(String.class) ? "" : body;

	if ((isInputMultiple(this.getTargetIfRouting(wrapper, function))  || !(function instanceof RoutingFunction))
			&& input != null) { // TODO rework. . . pretty ugly
		if (this.shouldUseJsonConversion((String) input, wrapper.headers.getContentType())) {
			Type jsonType = body.startsWith("[")
					&& Collection.class.isAssignableFrom(inputType)
					|| body.startsWith("{") ? inputType : Collection.class;
			if (body.startsWith("[") && itemType instanceof Class) {
				jsonType = ResolvableType.forClassWithGenerics((Class<?>) jsonType,
						(Class<?>) itemType).getType();
			}
			input = this.mapper.fromJson((String) input, jsonType);
		}
		else {
			input = this.converter.convert(function, (String) input);
		}
	}

	return response(wrapper, input, stream);
}
 
Example #12
Source File: IndexedElementsBinder.java    From spring-cloud-gray with Apache License 2.0 5 votes vote down vote up
/**
 * Bind indexed elements to the supplied collection.
 *
 * @param name          the name of the property to bind
 * @param target        the target bindable
 * @param elementBinder the binder to use for elements
 * @param aggregateType the aggregate type, may be a collection or an array
 * @param elementType   the element type
 * @param result        the destination for results
 */
protected final void bindIndexed(ConfigurationPropertyName name, Bindable<?> target,
                                 AggregateElementBinder elementBinder, ResolvableType aggregateType,
                                 ResolvableType elementType, IndexedCollectionSupplier result) {
    for (ConfigurationPropertySource source : getContext().getSources()) {
        bindIndexed(source, name, target, elementBinder, result, aggregateType,
                elementType);
        if (result.wasSupplied() && result.get() != null) {
            return;
        }
    }
}
 
Example #13
Source File: Forwarding.java    From spring-cloud-rsocket with Apache License 2.0 5 votes vote down vote up
@Override
public DataBuffer encodeValue(Forwarding value, DataBufferFactory bufferFactory,
		ResolvableType valueType, MimeType mimeType, Map<String, Object> hints) {
	NettyDataBufferFactory factory = (NettyDataBufferFactory) bufferFactory;
	ByteBuf encoded = Forwarding.encode(factory.getByteBufAllocator(), value);
	return factory.wrap(encoded);
}
 
Example #14
Source File: ByteArrayDecoder.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
protected byte[] decodeDataBuffer(DataBuffer dataBuffer, ResolvableType elementType,
		@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {

	byte[] result = new byte[dataBuffer.readableByteCount()];
	dataBuffer.read(result);
	DataBufferUtils.release(dataBuffer);
	if (logger.isDebugEnabled()) {
		logger.debug(Hints.getLogPrefix(hints) + "Read " + result.length + " bytes");
	}
	return result;
}
 
Example #15
Source File: GenericApplicationListenerAdapter.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Nullable
private static ResolvableType resolveDeclaredEventType(ApplicationListener<ApplicationEvent> listener) {
	ResolvableType declaredEventType = resolveDeclaredEventType(listener.getClass());
	if (declaredEventType == null || declaredEventType.isAssignableFrom(ApplicationEvent.class)) {
		Class<?> targetClass = AopUtils.getTargetClass(listener);
		if (targetClass != listener.getClass()) {
			declaredEventType = resolveDeclaredEventType(targetClass);
		}
	}
	return declaredEventType;
}
 
Example #16
Source File: GenericConversionService.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void addConverterFactory(ConverterFactory<?, ?> factory) {
	ResolvableType[] typeInfo = getRequiredTypeInfo(factory.getClass(), ConverterFactory.class);
	if (typeInfo == null && factory instanceof DecoratingProxy) {
		typeInfo = getRequiredTypeInfo(((DecoratingProxy) factory).getDecoratedClass(), ConverterFactory.class);
	}
	if (typeInfo == null) {
		throw new IllegalArgumentException("Unable to determine source type <S> and target type <T> for your " +
				"ConverterFactory [" + factory.getClass().getName() + "]; does the class parameterize those types?");
	}
	addConverter(new ConverterFactoryAdapter(factory,
			new ConvertiblePair(typeInfo[0].toClass(), typeInfo[1].toClass())));
}
 
Example #17
Source File: AbstractMessageConverterMethodProcessor.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Return the generic type of the {@code returnType} (or of the nested type
 * if it is an {@link HttpEntity}).
 */
private Type getGenericType(MethodParameter returnType) {
	if (HttpEntity.class.isAssignableFrom(returnType.getParameterType())) {
		return ResolvableType.forType(returnType.getGenericParameterType()).getGeneric().getType();
	}
	else {
		return returnType.getGenericParameterType();
	}
}
 
Example #18
Source File: StaticListableBeanFactory.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public String[] getBeanNamesForType(@Nullable ResolvableType type) {
	boolean isFactoryType = false;
	if (type != null) {
		Class<?> resolved = type.resolve();
		if (resolved != null && FactoryBean.class.isAssignableFrom(resolved)) {
			isFactoryType = true;
		}
	}
	List<String> matches = new ArrayList<>();
	for (Map.Entry<String, Object> entry : this.beans.entrySet()) {
		String name = entry.getKey();
		Object beanInstance = entry.getValue();
		if (beanInstance instanceof FactoryBean && !isFactoryType) {
			Class<?> objectType = ((FactoryBean<?>) beanInstance).getObjectType();
			if (objectType != null && (type == null || type.isAssignableFrom(objectType))) {
				matches.add(name);
			}
		}
		else {
			if (type == null || type.isInstance(beanInstance)) {
				matches.add(name);
			}
		}
	}
	return StringUtils.toStringArray(matches);
}
 
Example #19
Source File: SolaceJmsAutoCloudConfigurationTest.java    From solace-jms-spring-boot with Apache License 2.0 5 votes vote down vote up
@Parameters(name = "{0}")
public static Collection<Object[]> parameterData() {
    Set<ResolvableType> classes = new HashSet<>();
    classes.add(ResolvableType.forClass(SpringSolJmsConnectionFactoryCloudFactory.class));
    classes.add(ResolvableType.forClass(SolConnectionFactory.class));
    classes.add(ResolvableType.forClass(SolaceServiceCredentials.class));
    classes.add(ResolvableType.forClass(SolaceMessagingInfo.class));
    return getTestParameters(classes);
}
 
Example #20
Source File: DefaultListableBeanFactoryTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testSingletonFactoryBeanIgnoredByNonEagerTypeMatching() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	Properties p = new Properties();
	p.setProperty("x1.(class)", DummyFactory.class.getName());
	// Reset static state
	DummyFactory.reset();
	p.setProperty("x1.(singleton)", "false");
	p.setProperty("x1.singleton", "true");
	(new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);

	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
	String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
	assertEquals(0, beanNames.length);
	beanNames = lbf.getBeanNamesForAnnotation(SuppressWarnings.class);
	assertEquals(0, beanNames.length);

	assertFalse(lbf.containsSingleton("x1"));
	assertTrue(lbf.containsBean("x1"));
	assertTrue(lbf.containsBean("&x1"));
	assertFalse(lbf.isSingleton("x1"));
	assertFalse(lbf.isSingleton("&x1"));
	assertTrue(lbf.isPrototype("x1"));
	assertTrue(lbf.isPrototype("&x1"));
	assertTrue(lbf.isTypeMatch("x1", TestBean.class));
	assertFalse(lbf.isTypeMatch("&x1", TestBean.class));
	assertTrue(lbf.isTypeMatch("&x1", DummyFactory.class));
	assertTrue(lbf.isTypeMatch("&x1", ResolvableType.forClass(DummyFactory.class)));
	assertTrue(lbf.isTypeMatch("&x1", ResolvableType.forClassWithGenerics(FactoryBean.class, Object.class)));
	assertFalse(lbf.isTypeMatch("&x1", ResolvableType.forClassWithGenerics(FactoryBean.class, String.class)));
	assertEquals(TestBean.class, lbf.getType("x1"));
	assertEquals(DummyFactory.class, lbf.getType("&x1"));
	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
}
 
Example #21
Source File: ServerSentEventHttpMessageWriterTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void canWrite() {
	assertTrue(this.messageWriter.canWrite(forClass(Object.class), null));
	assertFalse(this.messageWriter.canWrite(forClass(Object.class), new MediaType("foo", "bar")));

	assertTrue(this.messageWriter.canWrite(null, MediaType.TEXT_EVENT_STREAM));
	assertTrue(this.messageWriter.canWrite(forClass(ServerSentEvent.class), new MediaType("foo", "bar")));

	// SPR-15464
	assertTrue(this.messageWriter.canWrite(ResolvableType.NONE, MediaType.TEXT_EVENT_STREAM));
	assertFalse(this.messageWriter.canWrite(ResolvableType.NONE, new MediaType("foo", "bar")));
}
 
Example #22
Source File: HttpEntityMethodProcessor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
protected Class<?> getReturnValueType(@Nullable Object returnValue, MethodParameter returnType) {
	if (returnValue != null) {
		return returnValue.getClass();
	}
	else {
		Type type = getHttpEntityType(returnType);
		type = (type != null ? type : Object.class);
		return ResolvableType.forMethodParameter(returnType, type).toClass();
	}
}
 
Example #23
Source File: ByteBufferEncoderTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
@Test
public void canEncode() {
	assertTrue(this.encoder.canEncode(ResolvableType.forClass(ByteBuffer.class),
			MimeTypeUtils.TEXT_PLAIN));
	assertFalse(this.encoder.canEncode(ResolvableType.forClass(Integer.class),
			MimeTypeUtils.TEXT_PLAIN));
	assertTrue(this.encoder.canEncode(ResolvableType.forClass(ByteBuffer.class),
			MimeTypeUtils.APPLICATION_JSON));

	// SPR-15464
	assertFalse(this.encoder.canEncode(ResolvableType.NONE, null));
}
 
Example #24
Source File: FunctionTypeUtils.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
static Type fromFunctionMethod(Method functionalMethod) {
	Type[] parameterTypes = functionalMethod.getGenericParameterTypes();

	Type functionType = null;
	switch (parameterTypes.length) {
	case 0:
		functionType =  ResolvableType.forClassWithGenerics(Supplier.class,
				ResolvableType.forMethodReturnType(functionalMethod)).getType();
		break;
	case 1:
		if (Void.class.isAssignableFrom(functionalMethod.getReturnType())) {
			functionType =  ResolvableType.forClassWithGenerics(Consumer.class,
					ResolvableType.forMethodParameter(functionalMethod, 0)).getType();
		}
		else {
			functionType =  ResolvableType.forClassWithGenerics(Function.class,
					ResolvableType.forMethodParameter(functionalMethod, 0),
					ResolvableType.forMethodReturnType(functionalMethod)).getType();
		}
		break;
	case 2:
		ResolvableType canonicalParametersWrapper = fromTwoArityFunction(functionalMethod);
		functionType =  ResolvableType.forClassWithGenerics(Function.class,
				canonicalParametersWrapper,
				ResolvableType.forMethodReturnType(functionalMethod)).getType();
		break;
	default:
		throw new UnsupportedOperationException("Functional method: " + functionalMethod + " is not supported");
	}
	return functionType;
}
 
Example #25
Source File: DefaultListableBeanFactoryTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testPrototypeFactoryBeanIgnoredByNonEagerTypeMatching() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	Properties p = new Properties();
	p.setProperty("x1.(class)", DummyFactory.class.getName());
	// Reset static state
	DummyFactory.reset();
	p.setProperty("x1.(singleton)", "false");
	p.setProperty("x1.singleton", "false");
	(new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);

	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
	String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
	assertEquals(0, beanNames.length);
	beanNames = lbf.getBeanNamesForAnnotation(SuppressWarnings.class);
	assertEquals(0, beanNames.length);

	assertFalse(lbf.containsSingleton("x1"));
	assertTrue(lbf.containsBean("x1"));
	assertTrue(lbf.containsBean("&x1"));
	assertFalse(lbf.isSingleton("x1"));
	assertFalse(lbf.isSingleton("&x1"));
	assertTrue(lbf.isPrototype("x1"));
	assertTrue(lbf.isPrototype("&x1"));
	assertTrue(lbf.isTypeMatch("x1", TestBean.class));
	assertFalse(lbf.isTypeMatch("&x1", TestBean.class));
	assertTrue(lbf.isTypeMatch("&x1", DummyFactory.class));
	assertTrue(lbf.isTypeMatch("&x1", ResolvableType.forClass(DummyFactory.class)));
	assertTrue(lbf.isTypeMatch("&x1", ResolvableType.forClassWithGenerics(FactoryBean.class, Object.class)));
	assertFalse(lbf.isTypeMatch("&x1", ResolvableType.forClassWithGenerics(FactoryBean.class, String.class)));
	assertEquals(TestBean.class, lbf.getType("x1"));
	assertEquals(DummyFactory.class, lbf.getType("&x1"));
	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
}
 
Example #26
Source File: ProtobufDecoder.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public Flux<Message> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType,
		@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {

	return Flux.from(inputStream)
			.flatMapIterable(new MessageDecoderFunction(elementType, this.maxMessageSize));
}
 
Example #27
Source File: ApiDeployerStatement.java    From gravitee-gateway with Apache License 2.0 5 votes vote down vote up
@Override
public void evaluate() throws Throwable {
    URL home = ApiDeployerStatement.class.getResource("/gravitee-01/");
    System.setProperty("gravitee.home", URLDecoder.decode(home.getPath(), "UTF-8"));

    GatewayContainer container = new GatewayContainer();

    if (target instanceof PolicyRegister) {
        String[] beanNamesForType = container.applicationContext().getBeanNamesForType(
                ResolvableType.forClassWithGenerics(ConfigurablePluginManager.class, PolicyPlugin.class));

        ConfigurablePluginManager<PolicyPlugin> ppm = (ConfigurablePluginManager<PolicyPlugin>)
                container.applicationContext().getBean(beanNamesForType[0]);

        ((PolicyRegister) target).register(ppm);
    }

    container.start();
    Thread.sleep(1000);
    
    ApiManager apiManager = container.applicationContext().getBean(ApiManager.class);
    Api api = loadApi(target.getClass().getAnnotation(ApiDescriptor.class).value());

    try {
        apiManager.deploy(api);
        base.evaluate();
    } finally {
        apiManager.undeploy(api.getId());
        container.stop();
    }
}
 
Example #28
Source File: CancelWithoutDemandCodecTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test // gh-22107
public void cancelWithJackson() {
	Jackson2JsonEncoder encoder = new Jackson2JsonEncoder();

	Flux<DataBuffer> flux = encoder.encode(Flux.just(new Pojo("foofoo", "barbar"), new Pojo("bar", "baz")),
			this.bufferFactory, ResolvableType.forClass(Pojo.class),
			MediaType.APPLICATION_JSON, Collections.emptyMap());

	BaseSubscriber<DataBuffer> subscriber = new ZeroDemandSubscriber();
	flux.subscribe(subscriber); // Assume sync execution (e.g. encoding with Flux.just)..
	subscriber.cancel();
}
 
Example #29
Source File: HessianEncoder.java    From alibaba-rsocket-broker with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public DataBuffer encodeValue(Object value, DataBufferFactory bufferFactory, ResolvableType valueType, MimeType mimeType, Map<String, Object> hints) {
    if (value == null) {
        return bufferFactory.allocateBuffer(0);
    }
    try {
        return encode(value, bufferFactory);
    } catch (Exception e) {
        return bufferFactory.allocateBuffer(0);
    }
}
 
Example #30
Source File: CharSequenceEncoder.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public Flux<DataBuffer> encode(Publisher<? extends CharSequence> inputStream,
		DataBufferFactory bufferFactory, ResolvableType elementType,
		@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {

	return Flux.from(inputStream).map(charSequence ->
			encodeValue(charSequence, bufferFactory, elementType, mimeType, hints));
}