Package org.microproxy.contentviews
Class ContentViews
java.lang.Object
org.microproxy.contentviews.ContentViews
A set of
ContentViews, and the choice among them. In auto mode the view with the
highest ContentView.priority(byte[], org.microproxy.contentviews.ContentView.Metadata) renders a body; if it cannot, the next one tries, and when
none can, there is no rendering (callers show the body as they would without views).
ContentViews views = ContentViews.defaults().withSchema(ProtoSchema.load(Path.of("api.desc")));
views.render(body, ContentView.Metadata.forResponse(request, response))
.ifPresent(r -> System.out.println(r.view() + ":\n" + r.text()));
The default views: protobuf, grpc, json, graphql,
msgpack, urlencoded, multipart, query, socketio, dns
(application/dns-message), and hex (only when named). Instances are immutable
and safe to share; with(org.microproxy.contentviews.ContentView) and withSchema(org.microproxy.contentviews.ProtoSchema) return new ones.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA body rendered by a view. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic ContentViewsdefaults()Returns the default views, decoding protobuf without a schema.describeHeader(String name, String value) What a header or trailer field means, for the fields gRPC defines: the name of agrpc-statuscode, the text of a percent-encodedgrpc-message, and the message in a binary (-bin) field,grpc-status-details-binas agoogle.rpc.Status.The view namedname.names()Returns "auto" and the views' names, sorted.render(byte[] data, ContentView.Metadata metadata) Renders a body with the best view that can.render(String view, byte[] data, ContentView.Metadata metadata) Renders a body with the view namedview, or the best one for "auto".schema()Returns the schema the protobuf and gRPC views decode with.select(byte[] data, ContentView.Metadata metadata) The viewautomode would try first.toString()with(ContentView view) These views withviewadded, replacing a view of the same name.withSchema(ProtoSchema schema) These views with the protobuf and gRPC views decoding withschema.
-
Field Details
-
AUTO
The name that picks the best view for each body.- See Also:
-
-
Method Details
-
defaults
Returns the default views, decoding protobuf without a schema.- Returns:
- the default views, decoding protobuf without a schema
-
with
These views withviewadded, replacing a view of the same name.- Parameters:
view- the view- Returns:
- the new set
-
withSchema
These views with the protobuf and gRPC views decoding withschema.- Parameters:
schema- the schema- Returns:
- the new set
-
schema
Returns the schema the protobuf and gRPC views decode with.- Returns:
- the schema the protobuf and gRPC views decode with
-
names
Returns "auto" and the views' names, sorted.- Returns:
- "auto" and the views' names, sorted
-
get
The view namedname.- Parameters:
name- a view's name (any case)- Returns:
- the view, or empty if there is none
-
select
The viewautomode would try first.- Parameters:
data- the body, decodedmetadata- what is known about the message- Returns:
- the view with the highest positive priority, or empty if none applies
-
render
Renders a body with the best view that can.- Parameters:
data- the body, decodedmetadata- what is known about the message- Returns:
- the rendering, or empty if no view applies or none could render the body
-
render
public Optional<ContentViews.Rendered> render(String view, byte[] data, ContentView.Metadata metadata) Renders a body with the view namedview, or the best one for "auto".- Parameters:
view- a view's name, or "auto"data- the body, decodedmetadata- what is known about the message- Returns:
- the rendering, or empty if the view could not render the body
- Throws:
IllegalArgumentException- if there is no view namedview
-
describeHeader
What a header or trailer field means, for the fields gRPC defines: the name of agrpc-statuscode, the text of a percent-encodedgrpc-message, and the message in a binary (-bin) field,grpc-status-details-binas agoogle.rpc.Status.- Parameters:
name- the field's namevalue- the field's value- Returns:
- a line (or YAML lines) explaining the value, or
nullfor other fields
-
toString
-