How to return x509 certificate in Jersey ws
<p>I am able to generate a certificate correctly but I am not able to return back to the client. </p>

<p>I am getting the following error in returning back to the client from my REST resource:</p>

<pre><code>SEVERE: A message body writer for Java class sun.security.x509.X509CertImpl, and Java type class java.security.cert.X509Certificate, and MIME media type application/x-x509-user-cert was not found
</code></pre>

<p>The client code is correct since it works with other services.</p>

<p>REST resource:</p>

<pre><code>@POST
    @XmlElement(name = "data")
    @Path("/,system/newCert")
    @Consumes({ "application/x-www-form-urlencoded" })
    @Produces({ "application/x-x509-user-cert" })
    public X509Certificate newCert(@FormParam("username") String uname,
            @FormParam("name") String CommonName,
            @FormParam("email") String email,
            @FormParam("pictureURL") String pURL,
            @FormParam("spkac") String spkacData) {

        String webId = "https://" + uname + "/profile/card#me";

        BouncyKeygenService keygen = new BouncyKeygenService();

        try {

            keygen.initialize();

        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        Certificate cert = null;

        if (!spkacData.isEmpty()) {
            cert = keygen.createFromSpkac(spkacData);
        }

        cert.setSubjectCommonName(CommonName);
        cert.setSubjectWebID(webId);
        cert.addDurationInDays("36135"); // valid for 99 years
        cert.startEarlier("12"); 

        CertSerialisation certByte = null;
        X509Certificate x509 = null;
        try {
            certByte = cert.getSerialisation();

            ByteArrayOutputStream bout = new ByteArrayOutputStream(
                    certByte.getLength());
            certByte.writeTo(bout);
            CertificateFactory cf = CertificateFactory.getInstance("X.509");
            x509 = (X509Certificate) cf
                    .generateCertificate(new ByteArrayInputStream(bout
                            .toByteArray()));
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        Date notAfter = x509.getNotAfter();

        return x509;
    }
</code></pre>

<p>The thing is that there is no MediaType x509 Certificate in Java, what is suppose to be returned?</p>

<p>Any help would be appreciated.</p>

<p>Thanks.</p>