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 Project: spring-analysis-note   Author: Vip-Augus   File: ServerSentEventHttpMessageReaderTests.java    License: 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 #2
Source Project: java-technology-stack   Author: codeEngraver   File: AutowiredAnnotationBeanPostProcessorTests.java    License: 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 #3
Source Project: java-technology-stack   Author: codeEngraver   File: ConfigurationClassPostProcessorTests.java    License: 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 #4
Source Project: lams   Author: lamsfoundation   File: ApplicationListenerMethodAdapter.java    License: 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 #5
Source Project: spring-analysis-note   Author: Vip-Augus   File: ApplicationListenerMethodAdapter.java    License: 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 #6
Source Project: spring-analysis-note   Author: Vip-Augus   File: DefaultListableBeanFactory.java    License: 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 #7
Source Project: java-technology-stack   Author: codeEngraver   File: InvocableHandlerMethod.java    License: 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 #8
Source Project: java-technology-stack   Author: codeEngraver   File: ApplicationListenerMethodAdapter.java    License: 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 #9
Source Project: uavstack   Author: uavorg   File: FastJsonHttpMessageConverter.java    License: 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 #10
Source Project: spring-cloud-function   Author: spring-cloud   File: JsonMapperTests.java    License: Apache License 2.0 5 votes vote down vote up
@ParameterizedTest
@MethodSource("params")
public void vanillaArray(JsonMapper mapper) {
	String json = "[{\"value\":\"foo\"},{\"value\":\"foo\"}]";
	List<Foo> list = mapper.fromJson(json,
			ResolvableType.forClassWithGenerics(List.class, Foo.class).getType());
	assertThat(list).hasSize(2);
	assertThat(list.get(0).getValue()).isEqualTo("foo");
	assertThat(mapper.toString(list)).isEqualTo(json);
}
 
Example #11
Source Project: spring-analysis-note   Author: Vip-Augus   File: Jackson2JsonDecoderTests.java    License: MIT License 5 votes vote down vote up
@Test // gh-22042
public void decodeWithNullLiteral() {
	Flux<Object> result = this.decoder.decode(Flux.concat(stringBuffer("null")),
			ResolvableType.forType(Pojo.class), MediaType.APPLICATION_JSON, Collections.emptyMap());

	StepVerifier.create(result).expectComplete().verify();
}
 
Example #12
Source Project: spring-cloud-gray   Author: SpringCloud   File: IndexedElementsBinder.java    License: 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 Project: java-technology-stack   Author: codeEngraver   File: ByteArrayDecoder.java    License: 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 #14
Source Project: java-technology-stack   Author: codeEngraver   File: AbstractMessageConverterMethodProcessor.java    License: 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 #15
Source Project: java-technology-stack   Author: codeEngraver   File: HandlerResult.java    License: MIT License 5 votes vote down vote up
/**
 * Create a new {@code HandlerResult}.
 * @param handler the handler that handled the request
 * @param returnValue the return value from the handler possibly {@code null}
 * @param returnType the return value type
 * @param context the binding context used for request handling
 */
public HandlerResult(Object handler, @Nullable Object returnValue, MethodParameter returnType,
		@Nullable BindingContext context) {

	Assert.notNull(handler, "'handler' is required");
	Assert.notNull(returnType, "'returnType' is required");
	this.handler = handler;
	this.returnValue = returnValue;
	this.returnType = ResolvableType.forMethodParameter(returnType);
	this.bindingContext = (context != null ? context : new BindingContext());
}
 
Example #16
Source Project: java-technology-stack   Author: codeEngraver   File: CodecConfigurerTests.java    License: 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 #17
Source Project: solace-jms-spring-boot   Author: SolaceProducts   File: SolaceJmsAutoCloudConfigurationTest.java    License: 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 #18
Source Project: java-technology-stack   Author: codeEngraver   File: AbstractDecoderTestCase.java    License: MIT License 5 votes vote down vote up
/**
 * Test a {@link Decoder#decode decode} scenario where the input stream is empty.
 * The output is expected to be empty as well.
 *
 * @param outputType the desired output type
 * @param mimeType the mime type to use for decoding. May be {@code null}.
 * @param hints the hints used for decoding. May be {@code null}.
 */
protected void testDecodeEmpty(ResolvableType outputType, @Nullable MimeType mimeType,
		@Nullable Map<String, Object> hints) {

	Flux<DataBuffer> input = Flux.empty();
	Flux<?> result = this.decoder.decode(input, outputType, mimeType, hints);

	StepVerifier.create(result)
			.verifyComplete();
}
 
Example #19
Source Project: spring-cloud-rsocket   Author: spring-cloud-incubator   File: Forwarding.java    License: 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 #20
Source Project: java-technology-stack   Author: codeEngraver   File: GenericConversionService.java    License: 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 #21
Source Project: java-technology-stack   Author: codeEngraver   File: DefaultListableBeanFactoryTests.java    License: 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 #22
Source Project: java-technology-stack   Author: codeEngraver   File: ServerSentEventHttpMessageWriterTests.java    License: 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 #23
Source Project: spring-analysis-note   Author: Vip-Augus   File: ByteBufferEncoderTests.java    License: 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 Project: spring-cloud-function   Author: spring-cloud   File: FunctionTypeUtils.java    License: 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 Project: spring-analysis-note   Author: Vip-Augus   File: DefaultListableBeanFactoryTests.java    License: 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 Project: gravitee-gateway   Author: gravitee-io   File: ApiDeployerStatement.java    License: 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 #27
Source Project: spring-analysis-note   Author: Vip-Augus   File: CharSequenceEncoder.java    License: 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));
}
 
Example #28
Source Project: alibaba-rsocket-broker   Author: alibaba   File: HessianEncoder.java    License: 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 #29
Source Project: spring-analysis-note   Author: Vip-Augus   File: CancelWithoutDemandCodecTests.java    License: 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 #30
Source Project: java-technology-stack   Author: codeEngraver   File: ProtobufDecoder.java    License: 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));
}