Search in sources :

Example 1 with DocumentationMessageMapper

use of com.liferay.apio.architect.message.json.DocumentationMessageMapper in project com-liferay-apio-architect by liferay.

the class DocumentationMessageBodyWriter method writeTo.

@Override
public void writeTo(Documentation documentation, Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream outputStream) throws IOException, WebApplicationException {
    OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8);
    PrintWriter printWriter = new PrintWriter(outputStreamWriter, true);
    Optional<DocumentationMessageMapper> optional = _documentationMessageMapperManager.getDocumentationMessageMapperOptional(_request);
    DocumentationMessageMapper documentationMessageMapper = optional.orElseThrow(NotSupportedException::new);
    RequestInfo requestInfo = RequestInfo.create(builder -> builder.httpHeaders(_httpHeaders).httpServletRequest(_httpServletRequest).serverURL(_providerManager.provideMandatory(_httpServletRequest, ServerURL.class)).embedded(_providerManager.provideOptional(_httpServletRequest, Embedded.class).orElse(__ -> false)).fields(_providerManager.provideOptional(_httpServletRequest, Fields.class).orElse(__ -> string -> true)).language(_providerManager.provideOptional(_httpServletRequest, Language.class).orElse(Locale::getDefault)).build());
    DocumentationWriter documentationWriter = DocumentationWriter.create(builder -> builder.documentation(documentation).documentationMessageMapper(documentationMessageMapper).requestInfo(requestInfo).build());
    httpHeaders.put(CONTENT_TYPE, Collections.singletonList(documentationMessageMapper.getMediaType()));
    printWriter.println(documentationWriter.write());
    printWriter.close();
}
Also used : CONTENT_TYPE(javax.ws.rs.core.HttpHeaders.CONTENT_TYPE) Provider(javax.ws.rs.ext.Provider) RequestInfo(com.liferay.apio.architect.request.RequestInfo) Embedded(com.liferay.apio.architect.response.control.Embedded) DocumentationMessageMapperManager(com.liferay.apio.architect.wiring.osgi.manager.message.json.DocumentationMessageMapperManager) MessageBodyWriter(javax.ws.rs.ext.MessageBodyWriter) HttpServletRequest(javax.servlet.http.HttpServletRequest) MediaType(javax.ws.rs.core.MediaType) Component(org.osgi.service.component.annotations.Component) Locale(java.util.Locale) Documentation(com.liferay.apio.architect.documentation.Documentation) Fields(com.liferay.apio.architect.response.control.Fields) OutputStreamWriter(java.io.OutputStreamWriter) ProviderManager(com.liferay.apio.architect.wiring.osgi.manager.ProviderManager) NotSupportedException(javax.ws.rs.NotSupportedException) OutputStream(java.io.OutputStream) PrintWriter(java.io.PrintWriter) Context(javax.ws.rs.core.Context) DocumentationMessageMapper(com.liferay.apio.architect.message.json.DocumentationMessageMapper) ServerURL(com.liferay.apio.architect.url.ServerURL) IOException(java.io.IOException) StandardCharsets(java.nio.charset.StandardCharsets) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) Language(com.liferay.apio.architect.language.Language) HttpHeaders(javax.ws.rs.core.HttpHeaders) Type(java.lang.reflect.Type) Annotation(java.lang.annotation.Annotation) Optional(java.util.Optional) WebApplicationException(javax.ws.rs.WebApplicationException) DocumentationWriter(com.liferay.apio.architect.writer.DocumentationWriter) Request(javax.ws.rs.core.Request) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) Fields(com.liferay.apio.architect.response.control.Fields) DocumentationWriter(com.liferay.apio.architect.writer.DocumentationWriter) OutputStreamWriter(java.io.OutputStreamWriter) NotSupportedException(javax.ws.rs.NotSupportedException) RequestInfo(com.liferay.apio.architect.request.RequestInfo) PrintWriter(java.io.PrintWriter) DocumentationMessageMapper(com.liferay.apio.architect.message.json.DocumentationMessageMapper)

Aggregations

Documentation (com.liferay.apio.architect.documentation.Documentation)1 Language (com.liferay.apio.architect.language.Language)1 DocumentationMessageMapper (com.liferay.apio.architect.message.json.DocumentationMessageMapper)1 RequestInfo (com.liferay.apio.architect.request.RequestInfo)1 Embedded (com.liferay.apio.architect.response.control.Embedded)1 Fields (com.liferay.apio.architect.response.control.Fields)1 ServerURL (com.liferay.apio.architect.url.ServerURL)1 ProviderManager (com.liferay.apio.architect.wiring.osgi.manager.ProviderManager)1 DocumentationMessageMapperManager (com.liferay.apio.architect.wiring.osgi.manager.message.json.DocumentationMessageMapperManager)1 DocumentationWriter (com.liferay.apio.architect.writer.DocumentationWriter)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1 Annotation (java.lang.annotation.Annotation)1 Type (java.lang.reflect.Type)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Collections (java.util.Collections)1 Locale (java.util.Locale)1 Optional (java.util.Optional)1