Search in sources :

Example 61 with HttpHeaders

use of javax.ws.rs.core.HttpHeaders in project candlepin by candlepin.

the class AuthUtil method getHeader.

/**
 * Retrieve a header, or the empty string if it is not there.
 *
 * @return the header or a blank string (no nils)
 */
public static String getHeader(HttpRequest request, String name) {
    String headerValue = "";
    if (request != null && name != null) {
        List<String> header = null;
        HttpHeaders headers = request.getHttpHeaders();
        for (String key : headers.getRequestHeaders().keySet()) {
            if (key.equalsIgnoreCase(name)) {
                header = headers.getRequestHeader(key);
                break;
            }
        }
        if (null != header && header.size() > 0) {
            headerValue = header.get(0);
        }
    }
    return headerValue;
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders)

Example 62 with HttpHeaders

use of javax.ws.rs.core.HttpHeaders in project microservice_framework by CJSCommonPlatform.

the class RestEnvelopeBuilder method mergeHeadersIntoMetadata.

private MetadataBuilder mergeHeadersIntoMetadata(final Optional<Metadata> metadata, final MetadataBuilder metadataBuilder) {
    final Optional<String> correlationId;
    final Optional<String> sessionId;
    final Optional<String> userId;
    final List<UUID> causation;
    if (metadata.isPresent()) {
        final Metadata metadataValue = metadata.get();
        correlationId = metadataValue.clientCorrelationId();
        sessionId = metadataValue.sessionId();
        userId = metadataValue.userId();
        causation = metadataValue.causation();
    } else {
        correlationId = Optional.empty();
        sessionId = Optional.empty();
        userId = Optional.empty();
        causation = emptyList();
    }
    final boolean requestHeadersArePresent = headers.isPresent() && headers.get().getRequestHeaders() != null;
    if (requestHeadersArePresent) {
        final HttpHeaders httpHeaders = this.headers.get();
        setMetaDataIfNotSet(correlationId, httpHeaders.getHeaderString(CLIENT_CORRELATION_ID), metadataBuilder::withClientCorrelationId, "Client Correlation Id");
        setMetaDataIfNotSet(userId, httpHeaders.getHeaderString(USER_ID), metadataBuilder::withUserId, "User Id");
        setMetaDataIfNotSet(sessionId, httpHeaders.getHeaderString(SESSION_ID), metadataBuilder::withSessionId, "Session Id");
        setCausationMetaDataIfNotSet(causation, httpHeaders.getHeaderString(CAUSATION), metadataBuilder::withCausation);
    }
    return metadataBuilder;
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders) Metadata(uk.gov.justice.services.messaging.Metadata) UUID(java.util.UUID)

Example 63 with HttpHeaders

use of javax.ws.rs.core.HttpHeaders in project kafka by apache.

the class InternalRequestSignatureTest method internalRequestHeaders.

private static HttpHeaders internalRequestHeaders(String signature, String signatureAlgorithm) {
    HttpHeaders result = mock(HttpHeaders.class);
    when(result.getHeaderString(eq(InternalRequestSignature.SIGNATURE_HEADER))).thenReturn(signature);
    when(result.getHeaderString(eq(InternalRequestSignature.SIGNATURE_ALGORITHM_HEADER))).thenReturn(signatureAlgorithm);
    return result;
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders)

Example 64 with HttpHeaders

use of javax.ws.rs.core.HttpHeaders in project neo4j by neo4j.

the class AbstractCypherResource method executeStatementsInNewTransaction.

@POST
public Response executeStatementsInNewTransaction(InputEventStream inputEventStream, @Context HttpServletRequest request, @Context HttpHeaders headers) {
    try (var memoryTracker = createMemoryTracker()) {
        InputEventStream inputStream = ensureNotNull(inputEventStream);
        var graphDatabaseAPI = httpTransactionManager.getGraphDatabaseAPI(databaseName);
        return graphDatabaseAPI.map(databaseAPI -> {
            if (isDatabaseNotAvailable(databaseAPI)) {
                return createNonAvailableDatabaseResponse(inputStream.getParameters());
            }
            memoryTracker.allocateHeap(Invocation.SHALLOW_SIZE);
            final TransactionFacade transactionFacade = httpTransactionManager.createTransactionFacade(databaseAPI, memoryTracker);
            TransactionHandle transactionHandle = createNewTransactionHandle(transactionFacade, request, headers, memoryTracker, false);
            Invocation invocation = new Invocation(log, transactionHandle, uriScheme.txCommitUri(transactionHandle.getId()), memoryPool, inputStream, false);
            OutputEventStreamImpl outputStream = new OutputEventStreamImpl(inputStream.getParameters(), transactionHandle, uriScheme, invocation::execute);
            return Response.created(transactionHandle.uri()).entity(outputStream).build();
        }).orElse(createNonExistentDatabaseResponse(inputStream.getParameters()));
    }
}
Also used : PathParam(javax.ws.rs.PathParam) Neo4jError(org.neo4j.server.rest.Neo4jError) Log(org.neo4j.logging.Log) TransactionUriScheme(org.neo4j.server.http.cypher.format.api.TransactionUriScheme) Status(org.neo4j.kernel.api.exceptions.Status) Path(javax.ws.rs.Path) LoginContext(org.neo4j.internal.kernel.api.security.LoginContext) LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) Objects.requireNonNullElse(java.util.Objects.requireNonNullElse) HttpServletRequest(javax.servlet.http.HttpServletRequest) Map(java.util.Map) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) MemoryTracker(org.neo4j.memory.MemoryTracker) DELETE(javax.ws.rs.DELETE) HttpHeaderUtils.getTransactionTimeout(org.neo4j.server.web.HttpHeaderUtils.getTransactionTimeout) Collections.emptyMap(java.util.Collections.emptyMap) POST(javax.ws.rs.POST) Context(javax.ws.rs.core.Context) InputEventStream(org.neo4j.server.http.cypher.format.api.InputEventStream) MemoryPool(org.neo4j.memory.MemoryPool) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) AuthorizedRequestWrapper(org.neo4j.server.rest.dbms.AuthorizedRequestWrapper) HttpHeaders(javax.ws.rs.core.HttpHeaders) Response(javax.ws.rs.core.Response) Optional(java.util.Optional) UriInfo(javax.ws.rs.core.UriInfo) InputEventStream(org.neo4j.server.http.cypher.format.api.InputEventStream) POST(javax.ws.rs.POST)

Example 65 with HttpHeaders

use of javax.ws.rs.core.HttpHeaders in project ddf by codice.

the class CatalogServiceImplTest method testAddDocumentPositiveCase.

@Test
public void testAddDocumentPositiveCase() throws Exception {
    CatalogFramework framework = givenCatalogFramework();
    HttpHeaders headers = createHeaders(Collections.singletonList(MediaType.APPLICATION_JSON));
    CatalogServiceImpl catalogService = new CatalogServiceImpl(framework, attachmentParser, attributeRegistry);
    addMatchingService(catalogService, Collections.singletonList(getSimpleTransformer()));
    String response = catalogService.addDocument(headers.getRequestHeader(HttpHeaders.CONTENT_TYPE), mock(MultipartBody.class), null, new ByteArrayInputStream("".getBytes()));
    LOGGER.debug(ToStringBuilder.reflectionToString(response));
    assertThat(response, equalTo(SAMPLE_ID));
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders) ByteArrayInputStream(java.io.ByteArrayInputStream) MultipartBody(org.apache.cxf.jaxrs.ext.multipart.MultipartBody) CatalogFramework(ddf.catalog.CatalogFramework) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

HttpHeaders (javax.ws.rs.core.HttpHeaders)87 Test (org.junit.Test)57 Message (org.apache.cxf.message.Message)31 HttpServletRequest (javax.servlet.http.HttpServletRequest)13 Optional (java.util.Optional)11 CatalogFramework (ddf.catalog.CatalogFramework)10 MultipartBody (org.apache.cxf.jaxrs.ext.multipart.MultipartBody)10 JsonObject (com.google.gson.JsonObject)9 Locale (java.util.Locale)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 Response (javax.ws.rs.core.Response)8 UriInfo (javax.ws.rs.core.UriInfo)8 IOException (java.io.IOException)7 WebApplicationException (javax.ws.rs.WebApplicationException)7 MediaType (javax.ws.rs.core.MediaType)7 RequestInfo (com.liferay.apio.architect.request.RequestInfo)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 Conditions (com.liferay.apio.architect.test.util.json.Conditions)5 OutputStream (java.io.OutputStream)5 Annotation (java.lang.annotation.Annotation)5