Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binary render type with byte array #407

Open
ucin opened this issue Nov 19, 2017 · 4 comments
Open

Binary render type with byte array #407

ucin opened this issue Nov 19, 2017 · 4 comments

Comments

@ucin
Copy link

ucin commented Nov 19, 2017

It would be good if Pippo can render binary type using byte[]. I'm intend to use for rendering Protobuf. Currently is impossible because ContentTypeEngine.toString(Object object) only allow String type.

public interface ContentTypeEngine {

    void init(Application application);

    String getContentType();

    String toString(Object object);

    <T> T fromString(String content, Class<T> classOfT);

}
@decebals
Copy link
Member

I will investigate your request. If you have some ideas please let me know.

@decebals
Copy link
Member

I started to work on this feature.
The new signature of ContentTypeEngine is:

public interface ContentTypeEngine {

    void init(Application application);

    String getContentType();

    <T> T readObject(Class<T> classOfT, Request request);

    void writeObject(Object object, Response response);

}

So, the old toString method becomes writeObject and the old fromString method becomes readObject.
The modifications are trivial. For example instead of send(contentTypeEngine.toString(object)) (https://github.com/decebals/pippo/blob/master/pippo-core/src/main/java/ro/pippo/core/Response.java#L923) we have contentTypeEngine.writeObject(object, this).

You should remark that in readObject and writeObject you have full access to Request and Response (maybe some implementations want to deal with headers).
The actual implementations of ContentTypeEngines are text based. In this case the implementations of readObject and writeObject are trivial, based on request.getBody() and response.send(object.toString()).

I see a single problem for now. PippoRule uses the actual toString and fromString for RestAssured's ObjectMapper (https://github.com/decebals/pippo/blob/master/pippo-test/src/main/java/ro/pippo/test/PippoRule.java#L100) and I don't know for the moment how to resolve this mismatch (I don't have a Request, Response).

Any idea, any advice or feedback is welcome.

@midn1
Copy link

midn1 commented Apr 21, 2018

Any news on this, so far?
Just realized Jetty doesn't support partial requests, so I was left with implementing that myself

EDIT: It's currently possible to avoid the issue by registering a custom content type || outputting to the HttpServletOutput directly

@decebals
Copy link
Member

@lvivtotoro
I didn't finish my work on this feature because I didn't find a solution for the problem with PippoRule. I think that I can push my work on GitHub, maybe someone will find a solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants