本文整理汇总了Java中org.sonatype.nexus.repository.view.Request类的典型用法代码示例。如果您正苦于以下问题:Java Request类的具体用法?Java Request怎么用?Java Request使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Request类属于org.sonatype.nexus.repository.view包,在下文中一共展示了Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doService
import org.sonatype.nexus.repository.view.Request; //导入依赖的package包/类
protected void doService(final HttpServletRequest httpRequest, final HttpServletResponse httpResponse)
throws Exception
{
// resolve repository for request
RepositoryPath path = RepositoryPath.parse(httpRequest.getPathInfo());
log.debug("Parsed path: {}", path);
Repository repo = repository(path.getRepositoryName());
if (repo == null) {
send(null, HttpResponses.notFound(REPOSITORY_NOT_FOUND_MESSAGE), httpResponse);
return;
}
log.debug("Repository: {}", repo);
if (!repo.getConfiguration().isOnline()) {
send(null, HttpResponses.serviceUnavailable("Repository offline"), httpResponse);
return;
}
ViewFacet facet = repo.facet(ViewFacet.class);
log.debug("Dispatching to view facet: {}", facet);
// Dispatch the request
Request request = buildRequest(httpRequest, path.getRemainingPath());
dispatchAndSend(request, facet, httpResponseSenderSelector.sender(repo), httpResponse);
}
示例2: buildRequest
import org.sonatype.nexus.repository.view.Request; //导入依赖的package包/类
/**
* Build view request from {@link HttpServletRequest}.
*/
private Request buildRequest(final HttpServletRequest httpRequest, final String path) {
Request.Builder builder = new Request.Builder()
.headers(new HttpHeadersAdapter(httpRequest))
.action(httpRequest.getMethod())
.path(path)
.parameters(new HttpParametersAdapter(httpRequest))
.payload(new HttpRequestPayloadAdapter(httpRequest));
if (HttpPartIteratorAdapter.isMultipart(httpRequest)) {
builder.multiparts(new HttpPartIteratorAdapter(httpRequest));
}
// copy http-servlet-request attributes
Enumeration<String> attributes = httpRequest.getAttributeNames();
while (attributes.hasMoreElements()) {
String name = attributes.nextElement();
builder.attribute(name, httpRequest.getAttribute(name));
}
return builder.build();
}
示例3: describeRequest
import org.sonatype.nexus.repository.view.Request; //导入依赖的package包/类
public void describeRequest(final Description desc, final Request request) {
desc.topic("Request");
desc.addTable("Details", ImmutableMap.<String, Object>builder()
.put("Action", request.getAction())
.put("path", request.getPath()).build()
);
desc.addTable("Parameters", toMap(request.getParameters()));
desc.addTable("Headers", toMap(request.getHeaders()));
desc.addTable("Attributes", toMap(request.getAttributes()));
if (request.isMultipart()) {
Iterable<PartPayload> parts = request.getMultiparts();
checkState(parts != null);
for (Payload payload : parts) {
desc.addTable("Payload", toMap(payload));
}
}
else {
if (request.getPayload() != null) {
desc.addTable("Payload", toMap(request.getPayload()));
}
}
}
示例4: normalRequestReturnsFacetResponse
import org.sonatype.nexus.repository.view.Request; //导入依赖的package包/类
@Test
@Ignore("disabled, due to unknown heap issue with defaultResponseSender spy")
public void normalRequestReturnsFacetResponse() throws Exception {
descriptionRequested(null);
facetThrowsException(false);
underTest.dispatchAndSend(request, facet, defaultResponseSender, servletResponse);
verify(underTest, never()).describe(
any(Request.class),
any(Response.class),
any(Exception.class),
any(String.class)
);
verify(defaultResponseSender).send(eq(request), any(Response.class), eq(servletResponse));
}
示例5: action
import org.sonatype.nexus.repository.view.Request; //导入依赖的package包/类
/**
* Returns BREAD action for request action.
*/
protected String action(final Request request) {
switch (request.getAction()) {
case HttpMethods.OPTIONS:
case HttpMethods.GET:
case HttpMethods.HEAD:
case HttpMethods.TRACE:
return BreadActions.READ;
case HttpMethods.POST:
case HttpMethods.MKCOL:
case HttpMethods.PATCH:
return BreadActions.ADD;
case HttpMethods.PUT:
return BreadActions.EDIT;
case HttpMethods.DELETE:
return BreadActions.DELETE;
}
throw new RuntimeException("Unsupported action: " + request.getAction());
}
示例6: getFirst
import org.sonatype.nexus.repository.view.Request; //导入依赖的package包/类
/**
* Returns the first OK response from member repositories or {@link HttpResponses#notFound()} if none of the members
* responded with OK.
*/
protected Response getFirst(@Nonnull final Context context,
@Nonnull final List<Repository> members,
@Nonnull final DispatchedRepositories dispatched)
throws Exception
{
final Request request = context.getRequest();
for (Repository member : members) {
log.trace("Trying member: {}", member);
// track repositories we have dispatched to, prevent circular dispatch for nested groups
if (dispatched.contains(member)) {
log.trace("Skipping already dispatched member: {}", member);
continue;
}
dispatched.add(member);
final ViewFacet view = member.facet(ViewFacet.class);
final Response response = view.dispatch(request, context);
log.trace("Member {} response {}", member, response.getStatus());
if (response.getStatus().isSuccessful()) {
return response;
}
}
return notFoundResponse(context);
}
示例7: getAll
import org.sonatype.nexus.repository.view.Request; //导入依赖的package包/类
/**
* Returns all responses from all members as a linked map, where order is group member order.
*/
protected LinkedHashMap<Repository, Response> getAll(@Nonnull final Context context,
@Nonnull final Iterable<Repository> members,
@Nonnull final DispatchedRepositories dispatched)
throws Exception
{
final Request request = context.getRequest();
final LinkedHashMap<Repository, Response> responses = Maps.newLinkedHashMap();
for (Repository member : members) {
log.trace("Trying member: {}", member);
// track repositories we have dispatched to, prevent circular dispatch for nested groups
if (dispatched.contains(member)) {
log.trace("Skipping already dispatched member: {}", member);
continue;
}
dispatched.add(member);
final ViewFacet view = member.facet(ViewFacet.class);
final Response response = view.dispatch(request, context);
log.trace("Member {} response {}", member, response.getStatus());
responses.put(member, response);
}
return responses;
}
示例8: ifModifiedSince
import org.sonatype.nexus.repository.view.Request; //导入依赖的package包/类
@Nullable
private static Predicate<Response> ifModifiedSince(final Request request) {
final DateTime date = parseDateHeader(request.getHeaders().get(HttpHeaders.IF_MODIFIED_SINCE));
if (date != null) {
return new Predicate<Response>()
{
@Override
public boolean apply(final Response response) {
final DateTime lastModified = parseDateHeader(response.getHeaders().get(HttpHeaders.LAST_MODIFIED));
if (lastModified != null) {
return lastModified.isAfter(date);
}
return true;
}
@Override
public String toString() {
return HttpConditions.class.getSimpleName() + ".ifModifiedSince(" + date + ")";
}
};
}
return null;
}
示例9: ifUnmodifiedSince
import org.sonatype.nexus.repository.view.Request; //导入依赖的package包/类
@Nullable
private static Predicate<Response> ifUnmodifiedSince(final Request request) {
final DateTime date = parseDateHeader(request.getHeaders().get(HttpHeaders.IF_UNMODIFIED_SINCE));
if (date != null) {
return new Predicate<Response>()
{
@Override
public boolean apply(final Response response) {
final DateTime lastModified = parseDateHeader(response.getHeaders().get(HttpHeaders.LAST_MODIFIED));
if (lastModified != null) {
return !lastModified.isAfter(date);
}
return true;
}
@Override
public String toString() {
return HttpConditions.class.getSimpleName() + ".ifUnmodifiedSince(" + date + ")";
}
};
}
return null;
}
示例10: ifMatch
import org.sonatype.nexus.repository.view.Request; //导入依赖的package包/类
@Nullable
private static Predicate<Response> ifMatch(final Request request) {
final String match = request.getHeaders().get(HttpHeaders.IF_MATCH);
if (match != null && !"*".equals(match)) {
return new Predicate<Response>()
{
@Override
public boolean apply(final Response response) {
final String etag = response.getHeaders().get(HttpHeaders.ETAG);
if (etag != null) {
return match.contains(etag);
}
return true;
}
@Override
public String toString() {
return HttpConditions.class.getSimpleName() + ".ifMatch(" + match + ")";
}
};
}
return null;
}
示例11: ifNoneMatch
import org.sonatype.nexus.repository.view.Request; //导入依赖的package包/类
@Nullable
private static Predicate<Response> ifNoneMatch(final Request request) {
final String match = request.getHeaders().get(HttpHeaders.IF_NONE_MATCH);
if (match != null && !"*".equals(match)) {
return new Predicate<Response>()
{
@Override
public boolean apply(final Response response) {
final String etag = response.getHeaders().get(HttpHeaders.ETAG);
if (etag != null) {
return !match.contains(etag);
}
return true;
}
@Override
public String toString() {
return HttpConditions.class.getSimpleName() + ".ifNoneMatch(" + match + ")";
}
};
}
return null;
}
示例12: addContributedHandlers
import org.sonatype.nexus.repository.view.Request; //导入依赖的package包/类
@Test
public void addContributedHandlers() throws Exception {
final AttributesMap attributes = new AttributesMap();
final Request request = mock(Request.class);
final Context context = mock(Context.class);
when(context.getRequest()).thenReturn(request);
when(context.getAttributes()).thenReturn(attributes);
when(context.proceed()).thenReturn(HttpResponses.ok(new Content(new StringPayload("test", "text/plain"))));
final ContributedHandler handlerA = mock(ContributedHandler.class);
final ContributedHandler handlerB = mock(ContributedHandler.class);
final HandlerContributor underTest = new HandlerContributor(asList(handlerA, handlerB));
final Response response = underTest.handle(context);
assertThat(response.getStatus().isSuccessful(), is(true));
assertThat(attributes.get(HandlerContributor.EXTENDED_MARKER), is(Boolean.TRUE));
// Handle a second time to ensure the contributed handlers aren't injected twice
underTest.handle(context);
ArgumentCaptor<ContributedHandler> handlerCaptor = ArgumentCaptor.forClass(ContributedHandler.class);
verify(context, times(2)).insertHandler(handlerCaptor.capture());
assertThat(handlerCaptor.getAllValues(), is(asList(handlerB, handlerA))); // Intentionally added in "reverse" order
}
示例13: limitCooperatingThreads
import org.sonatype.nexus.repository.view.Request; //导入依赖的package包/类
@Test
public void limitCooperatingThreads() throws Exception {
int threadLimit = 10;
underTest.configureCooperation(true, Time.seconds(60), Time.seconds(1), threadLimit);
Request request = new Request.Builder().action(GET).path("some/fixed/path").build();
ConcurrentRunner runner = new ConcurrentRunner(1, 60);
runner.addTask(NUM_CLIENTS, () -> verifyThreadLimit(request));
runner.go();
assertThat(runner.getRunInvocations(), is(runner.getTaskCount() * runner.getIterations()));
// only one request should have made it upstream
assertThat(upstreamRequests.count(ASSET_PREFIX + "some/fixed/path"), is(1));
// majority of requests should have been cancelled to maintain thread limit
assertThat(cooperationExceptionCount.get(), is(NUM_CLIENTS - threadLimit));
}
示例14: dispatchAndSend
import org.sonatype.nexus.repository.view.Request; //导入依赖的package包/类
@VisibleForTesting
void dispatchAndSend(final Request request,
final ViewFacet facet,
final HttpResponseSender sender,
final HttpServletResponse httpResponse)
throws Exception
{
Response response = null;
Exception failure = null;
try {
response = facet.dispatch(request);
}
catch (Exception e) {
failure = e;
}
String describeFlags = request.getParameters().get(P_DESCRIBE);
log.trace("Describe flags: {}", describeFlags);
if (describeFlags != null) {
send(request, describe(request, response, failure, describeFlags), httpResponse);
}
else {
if (failure != null) {
throw failure;
}
log.debug("Request: {}", request);
sender.send(request, response, httpResponse);
}
}
示例15: describe
import org.sonatype.nexus.repository.view.Request; //导入依赖的package包/类
@VisibleForTesting
Response describe(final Request request, final Response response, final Exception exception, final String flags) {
final Description description = new Description(ImmutableMap.<String, Object>of(
"path", request.getPath(),
"nexusUrl", BaseUrlHolder.get()
));
if (exception != null) {
descriptionHelper.describeException(description, exception);
}
descriptionHelper.describeRequest(description, request);
if (response != null) {
descriptionHelper.describeResponse(description, response);
}
DescribeType type = DescribeType.parse(flags);
log.trace("Describe type: {}", type);
switch (type) {
case HTML: {
String html = descriptionRenderer.renderHtml(description);
return HttpResponses.ok(new StringPayload(html, ContentTypes.TEXT_HTML));
}
case JSON: {
String json = descriptionRenderer.renderJson(description);
return HttpResponses.ok(new StringPayload(json, ContentTypes.APPLICATION_JSON));
}
default:
throw new RuntimeException("Invalid describe-type: " + type);
}
}