Java Code Examples for org.springframework.util.Assert#isInstanceOf()

The following examples show how to use org.springframework.util.Assert#isInstanceOf() . These examples are extracted from open source projects. 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: haven-platform   File: KvMap.java    License: Apache License 2.0 6 votes vote down vote up
void flush() {
    Object obj;
    synchronized (this) {
        if(this.value == null) {
            // no value set, nothing to flush
            return;
        }
        this.dirty = false;
        obj = adapter.get(this.key, this.value);
    }
    // Note that message will be concatenated with type of object by `Assert.isInstanceOf`
    Assert.isInstanceOf(mapper.getType(), obj, "Adapter " + adapter + " return object of inappropriate");
    Assert.notNull(obj, "Adapter " + adapter + " return null from " + this.value + " that is not allowed");
    mapper.save(key, obj, (name, res) -> {
        synchronized (this) {
            index.put(toIndexKey(name), res.getIndex());
        }
    });
}
 
Example 2
@Override
public DeferredResult<?> adaptToDeferredResult(Object returnValue) {
	Assert.isInstanceOf(ListenableFuture.class, returnValue, "ListenableFuture expected");
	final DeferredResult<Object> result = new DeferredResult<Object>();
	((ListenableFuture<?>) returnValue).addCallback(new ListenableFutureCallback<Object>() {
		@Override
		public void onSuccess(Object value) {
			result.setResult(value);
		}
		@Override
		public void onFailure(Throwable ex) {
			result.setErrorResult(ex);
		}
	});
	return result;
}
 
Example 3
private static ReactiveFirestoreTransactionObject extractFirestoreTransaction(Object transaction) {

		Assert.isInstanceOf(ReactiveFirestoreTransactionObject.class, transaction,
				() -> String.format("Expected to find a %s but it turned out to be %s.",
						ReactiveFirestoreTransactionObject.class,
						transaction.getClass()));

		return (ReactiveFirestoreTransactionObject) transaction;
	}
 
Example 4
Source Project: cas4.0.x-server-wechat   File: WebUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static HttpServletResponse getHttpServletResponse(
    final RequestContext context) {
    Assert.isInstanceOf(ServletExternalContext.class, context
        .getExternalContext(),
        "Cannot obtain HttpServletResponse from event of type: "
            + context.getExternalContext().getClass().getName());
    return (HttpServletResponse) context.getExternalContext()
        .getNativeResponse();
}
 
Example 5
/**
 * Construct a new {@code MappingJackson2XmlHttpMessageConverter} with a custom {@link ObjectMapper}
 * (must be a {@link XmlMapper} instance).
 * You can use {@link Jackson2ObjectMapperBuilder} to build it easily.
 * @see Jackson2ObjectMapperBuilder#xml()
 */
public MappingJackson2XmlHttpMessageConverter(ObjectMapper objectMapper) {
	super(objectMapper, new MediaType("application", "xml"),
			new MediaType("text", "xml"),
			new MediaType("application", "*+xml"));
	Assert.isInstanceOf(XmlMapper.class, objectMapper, "XmlMapper required");
}
 
Example 6
protected ParameterizedTypeReference() {
	Class<?> parameterizedTypeReferenceSubclass = findParameterizedTypeReferenceSubclass(getClass());
	Type type = parameterizedTypeReferenceSubclass.getGenericSuperclass();
	Assert.isInstanceOf(ParameterizedType.class, type, "Type must be a parameterized type");
	ParameterizedType parameterizedType = (ParameterizedType) type;
	Assert.isTrue(parameterizedType.getActualTypeArguments().length == 1, "Number of type arguments must be 1");
	this.type = parameterizedType.getActualTypeArguments()[0];
}
 
Example 7
/**
 * Construct a new {@code MappingJackson2XmlHttpMessageConverter} with a custom {@link ObjectMapper}
 * (must be a {@link XmlMapper} instance).
 * You can use {@link Jackson2ObjectMapperBuilder} to build it easily.
 * @see Jackson2ObjectMapperBuilder#xml()
 */
public MappingJackson2XmlHttpMessageConverter(ObjectMapper objectMapper) {
	super(objectMapper, new MediaType("application", "xml"),
			new MediaType("text", "xml"),
			new MediaType("application", "*+xml"));
	Assert.isInstanceOf(XmlMapper.class, objectMapper, "XmlMapper required");
}
 
Example 8
/**
 * {@inheritDoc}
 * <p>This implementation uses Netty's {@link CompositeByteBuf}.
 */
@Override
public DataBuffer join(List<? extends DataBuffer> dataBuffers) {
	Assert.notEmpty(dataBuffers, "DataBuffer List must not be empty");
	int bufferCount = dataBuffers.size();
	if (bufferCount == 1) {
		return dataBuffers.get(0);
	}
	CompositeByteBuf composite = this.byteBufAllocator.compositeBuffer(bufferCount);
	for (DataBuffer dataBuffer : dataBuffers) {
		Assert.isInstanceOf(NettyDataBuffer.class, dataBuffer);
		composite.addComponent(true, ((NettyDataBuffer) dataBuffer).getNativeBuffer());
	}
	return new NettyDataBuffer(composite, this);
}
 
Example 9
@Nullable
@Override
public Object resolveArgumentValue(
		MethodParameter parameter, BindingContext bindingContext, ServerWebExchange exchange) {

	Assert.isInstanceOf(InitBinderBindingContext.class, bindingContext);
	return ((InitBinderBindingContext) bindingContext).getSessionStatus();
}
 
Example 10
@PostMapping(path = "genericMapListUser")
public Generic<Map<String, List<User>>> genericMapListUser(
    @RequestBody Generic<Map<String, List<User>>> mapListUserGeneric) {
  Assert.isInstanceOf(Generic.class, mapListUserGeneric);
  Assert.isInstanceOf(Map.class, mapListUserGeneric.value);
  return mapListUserGeneric;
}
 
Example 11
/**
 * {@inheritDoc}
 * <p>This implementation uses Netty's {@link CompositeByteBuf}.
 */
@Override
public DataBuffer join(List<? extends DataBuffer> dataBuffers) {
	Assert.notEmpty(dataBuffers, "DataBuffer List must not be empty");
	int bufferCount = dataBuffers.size();
	if (bufferCount == 1) {
		return dataBuffers.get(0);
	}
	CompositeByteBuf composite = this.byteBufAllocator.compositeBuffer(bufferCount);
	for (DataBuffer dataBuffer : dataBuffers) {
		Assert.isInstanceOf(NettyDataBuffer.class, dataBuffer);
		composite.addComponent(true, ((NettyDataBuffer) dataBuffer).getNativeBuffer());
	}
	return new NettyDataBuffer(composite, this);
}
 
Example 12
Source Project: springboot-shiro-cas-mybatis   File: WebUtils.java    License: MIT License 5 votes vote down vote up
/**
 * Gets the http servlet response.
 *
 * @param context the context
 * @return the http servlet response
 */
public static HttpServletResponse getHttpServletResponse(
    final RequestContext context) {
    Assert.isInstanceOf(ServletExternalContext.class, context
        .getExternalContext(),
        "Cannot obtain HttpServletResponse from event of type: "
            + context.getExternalContext().getClass().getName());
    return (HttpServletResponse) context.getExternalContext()
        .getNativeResponse();
}
 
Example 13
Source Project: skywalking   File: DubboInterceptorTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testServiceOverrideFromPlugin() {
    ContextManagerExtendService service = ServiceManager.INSTANCE.findService(ContextManagerExtendService.class);

    Assert.isInstanceOf(ContextManagerExtendOverrideService.class, service);
}
 
Example 14
private static PropertySources getSources(Environment environment) {
    Assert.notNull(environment, "Environment must not be null");
    Assert.isInstanceOf(ConfigurableEnvironment.class, environment,
            "Environment must be a ConfigurableEnvironment");
    return ((ConfigurableEnvironment) environment).getPropertySources();
}
 
Example 15
private HttpServletRequest getHttpServletRequest(ServerHttpRequest request) {
	Assert.isInstanceOf(AbstractServerHttpRequest.class, request);
	return ((AbstractServerHttpRequest) request).getNativeRequest();
}
 
Example 16
/**
 * {@inheritDoc}
 * The {@code ObjectMapper} must be configured with a {@code SmileFactory} instance.
 */
@Override
public void setObjectMapper(ObjectMapper objectMapper) {
	Assert.isInstanceOf(SmileFactory.class, objectMapper.getFactory(), "SmileFactory required");
	super.setObjectMapper(objectMapper);
}
 
Example 17
protected final HttpServletResponse getHttpServletResponse(ServerHttpResponse response) {
	Assert.isInstanceOf(ServletServerHttpResponse.class, response, "ServletServerHttpResponse required");
	return ((ServletServerHttpResponse) response).getServletResponse();
}
 
Example 18
private HttpServletResponse getHttpServletResponse(ServerHttpResponse response) {
	Assert.isInstanceOf(AbstractServerHttpResponse.class, response, "ServletServerHttpResponse required");
	return ((AbstractServerHttpResponse) response).getNativeResponse();
}
 
Example 19
/**
 * An alternative to {@link #fromMethodCall(Object)} that accepts a
 * {@code UriComponentsBuilder} representing the base URL. This is useful
 * when using MvcUriComponentsBuilder outside the context of processing a
 * request or to apply a custom baseUrl not matching the current request.
 * <p><strong>Note:</strong> This method extracts values from "Forwarded"
 * and "X-Forwarded-*" headers if found. See class-level docs.
 * @param builder the builder for the base URL; the builder will be cloned
 * and therefore not modified and may be re-used for further calls.
 * @param info either the value returned from a "mock" controller
 * invocation or the "mock" controller itself after an invocation
 * @return a UriComponents instance
 */
public static UriComponentsBuilder fromMethodCall(UriComponentsBuilder builder, Object info) {
	Assert.isInstanceOf(MethodInvocationInfo.class, info, "MethodInvocationInfo required");
	MethodInvocationInfo invocationInfo = (MethodInvocationInfo) info;
	Class<?> controllerType = invocationInfo.getControllerType();
	Method method = invocationInfo.getControllerMethod();
	Object[] arguments = invocationInfo.getArgumentValues();
	return fromMethodInternal(builder, controllerType, method, arguments);
}
 
Example 20
/**
 * Create a {@link UriComponentsBuilder} by invoking a "mock" controller method.
 * The controller method and the supplied argument values are then used to
 * delegate to {@link #fromMethod(Class, Method, Object...)}.
 * <p>For example, given this controller:
 * <pre class="code">
 * &#064;RequestMapping("/people/{id}/addresses")
 * class AddressController {
 *
 *   &#064;RequestMapping("/{country}")
 *   public HttpEntity&lt;Void&gt; getAddressesForCountry(&#064;PathVariable String country) { ... }
 *
 *   &#064;RequestMapping(value="/", method=RequestMethod.POST)
 *   public void addAddress(Address address) { ... }
 * }
 * </pre>
 * A UriComponentsBuilder can be created:
 * <pre class="code">
 * // Inline style with static import of "MvcUriComponentsBuilder.on"
 *
 * MvcUriComponentsBuilder.fromMethodCall(
 * 		on(AddressController.class).getAddressesForCountry("US")).buildAndExpand(1);
 *
 * // Longer form useful for repeated invocation (and void controller methods)
 *
 * AddressController controller = MvcUriComponentsBuilder.on(AddressController.class);
 * controller.addAddress(null);
 * builder = MvcUriComponentsBuilder.fromMethodCall(controller);
 * controller.getAddressesForCountry("US")
 * builder = MvcUriComponentsBuilder.fromMethodCall(controller);
 * </pre>
 * <p><strong>Note:</strong> This method extracts values from "Forwarded"
 * and "X-Forwarded-*" headers if found. See class-level docs.
 * @param info either the value returned from a "mock" controller
 * invocation or the "mock" controller itself after an invocation
 * @return a UriComponents instance
 * @see #on(Class)
 * @see #controller(Class)
 */
public static UriComponentsBuilder fromMethodCall(Object info) {
	Assert.isInstanceOf(MethodInvocationInfo.class, info, "MethodInvocationInfo required");
	MethodInvocationInfo invocationInfo = (MethodInvocationInfo) info;
	Class<?> controllerType = invocationInfo.getControllerType();
	Method method = invocationInfo.getControllerMethod();
	Object[] arguments = invocationInfo.getArgumentValues();
	return fromMethodInternal(null, controllerType, method, arguments);
}