use of javax.ws.rs.core.HttpHeaders in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_GETMethodBodyTest method shouldPassHttpHeadersToRestProcessor.
@SuppressWarnings("unchecked")
@Test
public void shouldPassHttpHeadersToRestProcessor() throws Exception {
generator.run(restRamlWithQueryApiDefaults().with(resource("/path").with(httpActionWithDefaultMapping(GET).withDefaultResponseType())).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
final Class<?> resourceClass = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultQueryApiPathResource");
final Object resourceObject = getInstanceOf(resourceClass);
final HttpHeaders headers = new ThreadLocalHttpHeaders();
setField(resourceObject, "headers", headers);
final Method method = firstMethodOf(resourceClass).get();
method.invoke(resourceObject);
verify(restProcessor).process(anyString(), any(Function.class), anyString(), eq(headers), any(Collection.class));
}
use of javax.ws.rs.core.HttpHeaders in project microservice_framework by CJSCommonPlatform.
the class DefaultRestProcessor method process.
private Response process(final String responseStrategyName, final Function<InterceptorContext, Optional<JsonEnvelope>> interceptorChain, final String action, final Optional<JsonObject> initialPayload, final HttpHeaders headers, final Collection<Parameter> params, final Optional<List<FileInputDetails>> fileInputDetails) {
traceLogger.trace(logger, () -> format("Processing REST message: %s", httpTraceLoggerHelper.toHttpHeaderTrace(headers)));
final JsonEnvelope envelope = envelopeBuilderFactory.builder().withInitialPayload(initialPayload).withAction(action).withHeaders(headers).withParams(params).build();
traceLogger.trace(logger, () -> format("REST message converted to envelope: %s", envelope));
final InterceptorContext interceptorContext = fileInputDetails.map(value -> fileBasedInterceptorContextFactory.create(value, envelope)).orElseGet(() -> interceptorContextWithInput(envelope));
final Optional<JsonEnvelope> result = interceptorChain.apply(interceptorContext);
traceLogger.trace(logger, () -> format("REST message processed: %s", envelope));
return responseStrategyCache.responseStrategyOf(responseStrategyName).responseFor(action, result);
}
use of javax.ws.rs.core.HttpHeaders in project ovirt-engine by oVirt.
the class DetailHelperTest method doTestIncludes.
private void doTestIncludes(String spec, String[] rels, boolean[] expected) throws Exception {
HttpHeaders httpheaders = mock(HttpHeaders.class);
List<String> requestHeaders = new ArrayList<>();
when(httpheaders.getRequestHeader("Accept")).thenReturn(requestHeaders);
requestHeaders.add(ACCEPTABLE + spec);
for (int i = 0; i < rels.length; i++) {
Set<String> details = DetailHelper.getDetails(httpheaders, null);
assertEquals(expected[i], details.contains(rels[i]));
}
}
use of javax.ws.rs.core.HttpHeaders in project ovirt-engine by oVirt.
the class BackendApiResourceTest method setUp.
@Before
public void setUp() {
backend = mock(BackendLocal.class);
currentUser = new DbUser();
currentUser.setLoginName(USER);
currentUser.setDomain(DOMAIN);
current = new Current();
current.setUser(currentUser);
current.setSessionId(SESSION_ID);
current.setRoot(URI_ROOT);
current.setPrefix(BASE_PATH);
current.setPath("");
current.setVersion("4");
current.setVersionSource(VersionSource.DEFAULT);
current.setBackend(backend);
CurrentManager.put(current);
MessageBundle messageBundle = new MessageBundle();
messageBundle.setPath(BUNDLE_PATH);
messageBundle.populate();
resource.setMessageBundle(messageBundle);
httpHeaders = mock(HttpHeaders.class);
List<Locale> locales = new ArrayList<>();
when(httpHeaders.getAcceptableLanguages()).thenReturn(locales);
List<String> filterValue = new ArrayList<>();
filterValue.add("false");
when(httpHeaders.getRequestHeader(USER_FILTER_HEADER)).thenReturn(filterValue);
resource.setHttpHeaders(httpHeaders);
}
use of javax.ws.rs.core.HttpHeaders 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();
}
Aggregations