Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.github.joschi.jersey.security.smime;
 
 

Author(s):
Bill Burke
Version:
$Revision: 1 $
@Produces("*/*")
public class SignedWriter implements MessageBodyWriter<SignedOutput> {
    static {
        BouncyIntegration.init();
    }
    @Context
    protected Providers providers;
    @Override
    public boolean isWriteable(Class<?> typeType genericTypeAnnotation[] annotationsMediaType mediaType) {
        return SignedOutput.class.isAssignableFrom(type);
    }
    @Override
    public long getSize(SignedOutput smimeOutputClass<?> typeType genericTypeAnnotation[] annotationsMediaType mediaType) {
        return -1;
    }
    @Override
    public void writeTo(SignedOutput outClass<?> typeType genericTypeAnnotation[] annotationsMediaType mediaTypeMultivaluedMap<StringObjectheadersOutputStream osthrows IOExceptionWebApplicationException {
        try {
            SMIMESignedGenerator gen = new SMIMESignedGenerator();
            SignerInfoGenerator signer = new JcaSimpleSignerInfoGeneratorBuilder().setProvider("BC").build("SHA1WITHRSA"out.getPrivateKey(), out.getCertificate());
            gen.addSignerInfoGenerator(signer);
            MimeMultipart mp = gen.generate(EnvelopedWriter.createBodyPart(out));
            String contentType = mp.getContentType();
            contentType = contentType.replace("\r\n""").replace("\t"" ");
            headers.putSingle("Content-Type"contentType);
            mp.writeTo(os);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
New to GrepCode? Check out our FAQ X