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;
}
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;
}
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;
}
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()));
}
}
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));
}
Aggregations