0

ZK with Jersey

asked 2018-02-09 19:08:14 +0800

sustav86 gravatar image sustav86
1

My ZK project doesn't see Jersey MessageBodyWriter when I do request to the server.

Client client = ClientBuilder.newClient();

WebTarget baseTarget = client.target("target");

Response postResponse = baseTarget.request().post(Entity.text(transaction));

add to web.xml:

    <servlet>
    <servlet-name>Jersey Web Application</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <param-value>ua.sustavov.payment.service, org.codehaus.jackson.jaxrs</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Jersey Web Application</servlet-name>
    <url-pattern>/api/*</url-pattern>
</servlet-mapping>

MessageBodyWriter:

@Provider
@Produces(MediaType.TEXT_PLAIN)
public class TransactionMessageBodyWriter implements MessageBodyWriter<Transaction> {

    @Override
    public boolean isWriteable(Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType) {
        return Transaction.class.isAssignableFrom(aClass);
    }

    @Override
    public void writeTo(Transaction transaction, Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> multivaluedMap, OutputStream outputStream) throws IOException, WebApplicationException {

        outputStream.write(transaction.toString().getBytes());
    }

    @Override
    public long getSize(Transaction transaction, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
        return -1;
    }

When I whant to send request? my App doesn't see MessageBodyWriter Thanks!

delete flag offensive retag edit
Be the first one to answer this question!
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2018-02-09 19:08:14 +0800

Seen: 6 times

Last updated: Feb 09

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More