use of com.liferay.apio.architect.writer.FormWriter in project com-liferay-apio-architect by liferay.
the class FormMessageBodyWriter method writeTo.
@Override
public void writeTo(Success<Form> success, 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);
Form form = success.getValue();
Optional<FormMessageMapper> optional = _formMessageMapperManager.getFormMessageMapperOptional(_request);
FormMessageMapper formMessageMapper = 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());
FormWriter formWriter = FormWriter.create(builder -> builder.form(form).formMessageMapper(formMessageMapper).requestInfo(requestInfo).build());
httpHeaders.put(CONTENT_TYPE, Collections.singletonList(formMessageMapper.getMediaType()));
printWriter.println(formWriter.write());
printWriter.close();
}
use of com.liferay.apio.architect.writer.FormWriter in project com-liferay-apio-architect by liferay.
the class MockFormWriter method write.
/**
* Writes a {@link com.liferay.apio.architect.form.Form} object.
*
* @param httpHeaders the request's HTTP headers
* @param formMessageMapper the {@code FormMessageMapper} to use for writing
* the JSON object
*/
public static JsonObject write(HttpHeaders httpHeaders, FormMessageMapper formMessageMapper) {
RequestInfo requestInfo = getRequestInfo(httpHeaders);
FormWriter formWriter = FormWriter.create(builder -> builder.form(MockFormCreator.createForm("f", "s")).formMessageMapper(formMessageMapper).requestInfo(requestInfo).build());
return new Gson().fromJson(formWriter.write(), JsonObject.class);
}
Aggregations