org.eclipse.microprofile.rest.client.ext.ResponseExceptionMapper Java Examples
The following examples show how to use
org.eclipse.microprofile.rest.client.ext.ResponseExceptionMapper.
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: AdditionalRegistrationTest.java From microprofile-rest-client with Apache License 2.0 | 6 votes |
@Test public void shouldRegisterAMultiTypedProviderInstanceWithPriorities() { MultiTypedProvider provider = new MultiTypedProvider(); Map<Class<?>, Integer> priorities = new HashMap<>(); priorities.put(ClientRequestFilter.class, 500); priorities.put(ClientResponseFilter.class, 501); priorities.put(MessageBodyReader.class, 502); priorities.put(MessageBodyWriter.class, 503); priorities.put(ReaderInterceptor.class, 504); priorities.put(WriterInterceptor.class, 505); priorities.put(ResponseExceptionMapper.class, 506); priorities.put(ParamConverterProvider.class, 507); RestClientBuilder builder = RestClientBuilder.newBuilder().register(provider, priorities); Configuration configuration = builder.getConfiguration(); assertTrue(configuration.isRegistered(MultiTypedProvider.class), MultiTypedProvider.class + " should be registered"); assertTrue(configuration.isRegistered(provider), MultiTypedProvider.class + " should be registered"); Map<Class<?>, Integer> contracts = configuration.getContracts(MultiTypedProvider.class); assertEquals(contracts.size(), priorities.size(), "There should be "+priorities.size()+" provider types registered"); for(Map.Entry<Class<?>, Integer> priority : priorities.entrySet()) { Integer contractPriority = contracts.get(priority.getKey()); assertEquals(contractPriority, priority.getValue(), "The priority for "+priority.getKey()+" should be "+priority.getValue()); } }
Example #2
Source File: AdditionalRegistrationTest.java From microprofile-rest-client with Apache License 2.0 | 6 votes |
@Test public void shouldRegisterAMultiTypedProviderClassWithPriorities() { Map<Class<?>, Integer> priorities = new HashMap<>(); priorities.put(ClientRequestFilter.class, 500); priorities.put(ClientResponseFilter.class, 501); priorities.put(MessageBodyReader.class, 502); priorities.put(MessageBodyWriter.class, 503); priorities.put(ReaderInterceptor.class, 504); priorities.put(WriterInterceptor.class, 505); priorities.put(ResponseExceptionMapper.class, 506); priorities.put(ParamConverterProvider.class, 507); RestClientBuilder builder = RestClientBuilder.newBuilder().register(MultiTypedProvider.class, priorities); Configuration configuration = builder.getConfiguration(); assertTrue(configuration.isRegistered(MultiTypedProvider.class), MultiTypedProvider.class + " should be registered"); Map<Class<?>, Integer> contracts = configuration.getContracts(MultiTypedProvider.class); assertEquals(contracts.size(), priorities.size(), "There should be "+priorities.size()+" provider types registered"); for(Map.Entry<Class<?>, Integer> priority : priorities.entrySet()) { Integer contractPriority = contracts.get(priority.getKey()); assertEquals(contractPriority, priority.getValue(), "The priority for "+priority.getKey()+" should be "+priority.getValue()); } }
Example #3
Source File: MicroProfileClientProxyImpl.java From cxf with Apache License 2.0 | 6 votes |
@Override protected void checkResponse(Method m, Response r, Message inMessage) throws Throwable { MicroProfileClientProviderFactory factory = MicroProfileClientProviderFactory.getInstance(inMessage); List<ResponseExceptionMapper<?>> mappers = factory.createResponseExceptionMapper(inMessage, Throwable.class); for (ResponseExceptionMapper<?> mapper : mappers) { if (mapper.handles(r.getStatus(), r.getHeaders())) { Throwable t = mapper.toThrowable(r); if (t instanceof RuntimeException) { throw t; } else if (t != null && m.getExceptionTypes() != null) { // its a checked exception, make sure its declared for (Class<?> c : m.getExceptionTypes()) { if (c.isAssignableFrom(t.getClass())) { throw t; } } // TODO Log the unhandled declarable } } } }
Example #4
Source File: AdditionalRegistrationTest.java From microprofile-rest-client with Apache License 2.0 | 5 votes |
@Test public void shouldRegisterAMultiTypedProviderInstance() { MultiTypedProvider provider = new MultiTypedProvider(); Class<?>[] providerTypes = {ClientRequestFilter.class, ClientResponseFilter.class, MessageBodyReader.class, MessageBodyWriter.class, ReaderInterceptor.class, WriterInterceptor.class, ResponseExceptionMapper.class, ParamConverterProvider.class}; RestClientBuilder builder = RestClientBuilder.newBuilder().register(provider, providerTypes); Configuration configuration = builder.getConfiguration(); assertTrue(configuration.isRegistered(MultiTypedProvider.class), MultiTypedProvider.class + " should be registered"); assertTrue(configuration.isRegistered(provider), MultiTypedProvider.class + " should be registered"); assertEquals(configuration.getContracts(MultiTypedProvider.class).size(), providerTypes.length, "There should be "+providerTypes.length+" provider types registered"); }
Example #5
Source File: AdditionalRegistrationTest.java From microprofile-rest-client with Apache License 2.0 | 5 votes |
@Test public void shouldRegisterAMultiTypedProviderClass() { Class<?>[] providerTypes = {ClientRequestFilter.class, ClientResponseFilter.class, MessageBodyReader.class, MessageBodyWriter.class, ReaderInterceptor.class, WriterInterceptor.class, ResponseExceptionMapper.class, ParamConverterProvider.class}; RestClientBuilder builder = RestClientBuilder.newBuilder().register(MultiTypedProvider.class, providerTypes); Configuration configuration = builder.getConfiguration(); assertTrue(configuration.isRegistered(MultiTypedProvider.class), MultiTypedProvider.class + " should be registered"); assertEquals(configuration.getContracts(MultiTypedProvider.class).size(), providerTypes.length, "There should be "+providerTypes.length+" provider types registered"); }
Example #6
Source File: MicroProfileClientProviderFactory.java From cxf with Apache License 2.0 | 5 votes |
@Override protected void setProviders(boolean custom, boolean busGlobal, Object... providers) { List<ProviderInfo<?>> theProviders = prepareProviders(custom, busGlobal, providers, null); super.setCommonProviders(theProviders); for (ProviderInfo<?> provider : theProviders) { Class<?> providerCls = ClassHelper.getRealClass(getBus(), provider.getProvider()); if (ResponseExceptionMapper.class.isAssignableFrom(providerCls)) { addProviderToList(responseExceptionMappers, provider); } String className = "org.eclipse.microprofile.rest.client.ext.AsyncInvocationInterceptorFactory"; try { Class<?> asyncIIFactoryClass = ClassLoaderUtils.loadClass(className, MicroProfileClientProviderFactory.class); if (asyncIIFactoryClass.isAssignableFrom(providerCls)) { addProviderToList(asyncInvocationInterceptorFactories, provider); } } catch (ClassNotFoundException ex) { // expected if using the MP Rest Client 1.0 APIs LOG.log(Level.FINEST, ex, () -> { return "Caught ClassNotFoundException - expected if using MP Rest Client 1.0 APIs"; }); } } responseExceptionMappers.sort(comparator); asyncInvocationInterceptorFactories.sort(comparator); injectContextProxies(responseExceptionMappers); injectContextProxies(asyncInvocationInterceptorFactories); }
Example #7
Source File: MicroProfileClientProviderFactory.java From cxf with Apache License 2.0 | 5 votes |
public List<ResponseExceptionMapper<?>> createResponseExceptionMapper(Message m, Class<?> paramType) { if (responseExceptionMappers.isEmpty()) { return Collections.emptyList(); } return Collections.unmodifiableList(responseExceptionMappers .stream() .map(ProviderInfo::getProvider) .sorted(new ResponseExceptionMapperComparator()) .collect(Collectors.toList())); }
Example #8
Source File: MicroProfileClientProviderFactory.java From cxf with Apache License 2.0 | 4 votes |
@Override public int compare(ResponseExceptionMapper<?> oLeft, ResponseExceptionMapper<?> oRight) { return oLeft.getPriority() - oRight.getPriority(); }