Search in sources :

Example 11 with Providers

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);
    }
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) MediaType(jakarta.ws.rs.core.MediaType) Type(java.lang.reflect.Type) Providers(jakarta.ws.rs.ext.Providers) CMSSignedData(org.bouncycastle.cms.CMSSignedData) IOException(java.io.IOException) WebApplicationException(jakarta.ws.rs.WebApplicationException) ReaderException(org.jboss.resteasy.spi.ReaderException) ReaderException(org.jboss.resteasy.spi.ReaderException)

Example 12 with Providers

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);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Providers(jakarta.ws.rs.ext.Providers)

Aggregations

Providers (jakarta.ws.rs.ext.Providers)12 IOException (java.io.IOException)6 MediaType (jakarta.ws.rs.core.MediaType)5 ParameterizedType (java.lang.reflect.ParameterizedType)4 Type (java.lang.reflect.Type)4 MessagingException (jakarta.mail.MessagingException)3 Client (jakarta.ws.rs.client.Client)3 ClientRequestContext (jakarta.ws.rs.client.ClientRequestContext)3 ClientRequestFilter (jakarta.ws.rs.client.ClientRequestFilter)3 WebTarget (jakarta.ws.rs.client.WebTarget)3 Context (jakarta.ws.rs.core.Context)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Test (org.junit.Test)3 ClientResponseContext (jakarta.ws.rs.client.ClientResponseContext)2 ReaderInterceptorContext (jakarta.ws.rs.ext.ReaderInterceptorContext)2 WriterInterceptorContext (jakarta.ws.rs.ext.WriterInterceptorContext)2 InputStream (java.io.InputStream)2 ReaderException (org.jboss.resteasy.spi.ReaderException)2 Header (jakarta.mail.Header)1 MimeBodyPart (jakarta.mail.internet.MimeBodyPart)1