use of jakarta.ws.rs.ext.Providers in project resteasy by resteasy.
the class PKCS7SignatureReader method readFrom.
@SuppressWarnings(value = "unchecked")
public PKCS7SignatureInput readFrom(Class<PKCS7SignatureInput> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> headers, InputStream entityStream) throws IOException, WebApplicationException {
Class<?> baseType = null;
Type baseGenericType = null;
if (genericType != null && genericType instanceof ParameterizedType) {
ParameterizedType param = (ParameterizedType) genericType;
baseGenericType = param.getActualTypeArguments()[0];
baseType = Types.getRawType(baseGenericType);
}
try {
CMSSignedData data = new CMSSignedData(entityStream);
PKCS7SignatureInput input = new PKCS7SignatureInput();
input.setType(baseType);
input.setGenericType(baseGenericType);
input.setAnnotations(annotations);
input.setData(data);
Providers providers = ResteasyContext.getContextData(Providers.class);
input.setProviders(providers);
return input;
} catch (Exception e) {
throw new ReaderException(e);
}
}
use of jakarta.ws.rs.ext.Providers in project resteasy by resteasy.
the class JsonSerialization method fromBytes.
public static <T> T fromBytes(Class<T> type, byte[] bytes, ResteasyProviderFactory factory) throws IOException {
MessageBodyReader<T> reader = factory.getMessageBodyReader(type, type, null, MediaType.APPLICATION_JSON_TYPE);
if (reader == null)
throw new NullPointerException(Messages.MESSAGES.couldNotFindMessageBodyReaderForJSON());
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
Providers old = ResteasyContext.getContextData(Providers.class);
ResteasyContext.pushContext(Providers.class, factory);
try {
return reader.readFrom(type, type, null, MediaType.APPLICATION_JSON_TYPE, new MultivaluedHashMap<String, String>(), bais);
} finally {
ResteasyContext.popContextData(Providers.class);
if (old != null)
ResteasyContext.pushContext(Providers.class, old);
}
}
Aggregations