Search in sources :

Example 26 with HttpHeaders

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));
}
Also used : ThreadLocalHttpHeaders(org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpHeaders) HttpHeaders(javax.ws.rs.core.HttpHeaders) ThreadLocalHttpHeaders(org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpHeaders) Function(java.util.function.Function) Collection(java.util.Collection) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 27 with HttpHeaders

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);
}
Also used : FileInputDetails(uk.gov.justice.services.adapter.rest.multipart.FileInputDetails) Optional.empty(java.util.Optional.empty) JsonObject(javax.json.JsonObject) Parameter(uk.gov.justice.services.adapter.rest.parameter.Parameter) Logger(org.slf4j.Logger) Collection(java.util.Collection) Function(java.util.function.Function) String.format(java.lang.String.format) InterceptorContext.interceptorContextWithInput(uk.gov.justice.services.core.interceptor.InterceptorContext.interceptorContextWithInput) RestEnvelopeBuilderFactory(uk.gov.justice.services.adapter.rest.envelope.RestEnvelopeBuilderFactory) HttpTraceLoggerHelper(uk.gov.justice.services.messaging.logging.HttpTraceLoggerHelper) Inject(javax.inject.Inject) FileBasedInterceptorContextFactory(uk.gov.justice.services.adapter.rest.multipart.FileBasedInterceptorContextFactory) List(java.util.List) HttpHeaders(javax.ws.rs.core.HttpHeaders) Response(javax.ws.rs.core.Response) InterceptorContext(uk.gov.justice.services.core.interceptor.InterceptorContext) TraceLogger(uk.gov.justice.services.messaging.logging.TraceLogger) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) InterceptorContext(uk.gov.justice.services.core.interceptor.InterceptorContext) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope)

Example 28 with HttpHeaders

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]));
    }
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders) ArrayList(java.util.ArrayList)

Example 29 with HttpHeaders

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);
}
Also used : MessageBundle(org.ovirt.engine.api.restapi.logging.MessageBundle) Locale(java.util.Locale) HttpHeaders(javax.ws.rs.core.HttpHeaders) BackendLocal(org.ovirt.engine.core.common.interfaces.BackendLocal) ArrayList(java.util.ArrayList) Current(org.ovirt.engine.api.restapi.invocation.Current) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser) Before(org.junit.Before)

Example 30 with 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();
}
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

HttpHeaders (javax.ws.rs.core.HttpHeaders)95 Test (org.junit.Test)57 Message (org.apache.cxf.message.Message)31 Optional (java.util.Optional)13 HttpServletRequest (javax.servlet.http.HttpServletRequest)13 UriInfo (javax.ws.rs.core.UriInfo)12 CatalogFramework (ddf.catalog.CatalogFramework)10 Locale (java.util.Locale)10 Response (javax.ws.rs.core.Response)10 MultipartBody (org.apache.cxf.jaxrs.ext.multipart.MultipartBody)10 JsonObject (com.google.gson.JsonObject)9 MediaType (javax.ws.rs.core.MediaType)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 Map (java.util.Map)8 Cookie (javax.ws.rs.core.Cookie)8 IOException (java.io.IOException)7 Collections (java.util.Collections)7 WebApplicationException (javax.ws.rs.WebApplicationException)7 URI (java.net.URI)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6