Search in sources :

Example 6 with RsWithStatus

use of com.artipie.http.rs.RsWithStatus in project artipie by artipie.

the class ResponseMetricsSliceTest method shouldReportInternalErrorResponse.

@Test
public void shouldReportInternalErrorResponse() {
    this.send(RqMethod.POST, new RsWithStatus(RsStatus.INTERNAL_ERROR));
    this.send(RqMethod.POST, new RsWithStatus(RsStatus.INTERNAL_ERROR));
    MatcherAssert.assertThat(this.metrics.counter("post.error.internal").value(), new IsEqual<>(2L));
}
Also used : RsWithStatus(com.artipie.http.rs.RsWithStatus) Test(org.junit.jupiter.api.Test)

Example 7 with RsWithStatus

use of com.artipie.http.rs.RsWithStatus in project artipie by artipie.

the class ContentLengthRestrictionTest method shouldNotPassRequestsAboveLimit.

@Test
public void shouldNotPassRequestsAboveLimit() {
    final int limit = 10;
    final Slice slice = new ContentLengthRestriction((line, headers, body) -> new RsWithStatus(RsStatus.OK), limit);
    final Response response = slice.response("", this.headers("11"), Flowable.empty());
    MatcherAssert.assertThat(response, new RsHasStatus(RsStatus.PAYLOAD_TOO_LARGE));
}
Also used : Response(com.artipie.http.Response) RsWithStatus(com.artipie.http.rs.RsWithStatus) RsHasStatus(com.artipie.http.hm.RsHasStatus) Slice(com.artipie.http.Slice) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with RsWithStatus

use of com.artipie.http.rs.RsWithStatus in project maven-adapter by artipie.

the class HeadProxySliceTest method passesStatusAndHeadersFromResponse.

@Test
void passesStatusAndHeadersFromResponse() {
    final RsStatus status = RsStatus.CREATED;
    final Headers.From headers = new Headers.From("abc", "123");
    MatcherAssert.assertThat(new HeadProxySlice(new SliceSimple(new RsWithHeaders(new RsWithStatus(status), headers))), new SliceHasResponse(Matchers.allOf(new RsHasStatus(status), new RsHasHeaders(headers)), new RequestLine(RqMethod.HEAD, "/")));
}
Also used : RequestLine(com.artipie.http.rq.RequestLine) SliceHasResponse(com.artipie.http.hm.SliceHasResponse) RsWithStatus(com.artipie.http.rs.RsWithStatus) RsHasStatus(com.artipie.http.hm.RsHasStatus) RsWithHeaders(com.artipie.http.rs.RsWithHeaders) RsHasHeaders(com.artipie.http.hm.RsHasHeaders) Headers(com.artipie.http.Headers) RsWithHeaders(com.artipie.http.rs.RsWithHeaders) RsStatus(com.artipie.http.rs.RsStatus) RsHasHeaders(com.artipie.http.hm.RsHasHeaders) SliceSimple(com.artipie.http.slice.SliceSimple) Test(org.junit.jupiter.api.Test)

Example 9 with RsWithStatus

use of com.artipie.http.rs.RsWithStatus in project maven-adapter by artipie.

the class PutMetadataSlice method response.

@Override
public Response response(final String line, final Iterable<Map.Entry<String, String>> headers, final Publisher<ByteBuffer> body) {
    final Response res;
    final Matcher matcher = PutMetadataSlice.PTN_META.matcher(new RequestLineFrom(line).uri().getPath());
    if (matcher.matches()) {
        final Key pkg = new KeyFromPath(matcher.group("pkg"));
        res = new AsyncResponse(new PublisherAs(body).asciiString().thenCombine(this.asto.list(new Key.From(UploadSlice.TEMP, pkg)), (xml, list) -> {
            final Optional<String> snapshot = new DeployMetadata(xml).snapshots().stream().filter(item -> list.stream().anyMatch(key -> key.string().contains(item))).findFirst();
            final Key key;
            if (snapshot.isPresent()) {
                key = new Key.From(UploadSlice.TEMP, pkg.string(), snapshot.get(), PutMetadataSlice.SUB_META, PutMetadataSlice.MAVEN_METADATA);
            } else {
                key = new Key.From(UploadSlice.TEMP, pkg.string(), new DeployMetadata(xml).release(), PutMetadataSlice.SUB_META, PutMetadataSlice.MAVEN_METADATA);
            }
            return this.asto.save(key, new Content.From(xml.getBytes(StandardCharsets.US_ASCII)));
        }).thenApply(nothing -> new RsWithStatus(RsStatus.CREATED)));
    } else {
        res = new RsWithStatus(RsStatus.BAD_REQUEST);
    }
    return res;
}
Also used : PublisherAs(com.artipie.asto.ext.PublisherAs) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) RsWithStatus(com.artipie.http.rs.RsWithStatus) KeyFromPath(com.artipie.http.slice.KeyFromPath) DeployMetadata(com.artipie.maven.metadata.DeployMetadata) Slice(com.artipie.http.Slice) Publisher(org.reactivestreams.Publisher) Response(com.artipie.http.Response) RsStatus(com.artipie.http.rs.RsStatus) Content(com.artipie.asto.Content) Key(com.artipie.asto.Key) ByteBuffer(java.nio.ByteBuffer) StandardCharsets(java.nio.charset.StandardCharsets) PublisherAs(com.artipie.asto.ext.PublisherAs) Matcher(java.util.regex.Matcher) Storage(com.artipie.asto.Storage) Map(java.util.Map) AsyncResponse(com.artipie.http.async.AsyncResponse) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) Optional(java.util.Optional) Matcher(java.util.regex.Matcher) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) Response(com.artipie.http.Response) AsyncResponse(com.artipie.http.async.AsyncResponse) DeployMetadata(com.artipie.maven.metadata.DeployMetadata) KeyFromPath(com.artipie.http.slice.KeyFromPath) RsWithStatus(com.artipie.http.rs.RsWithStatus) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) AsyncResponse(com.artipie.http.async.AsyncResponse) Key(com.artipie.asto.Key)

Example 10 with RsWithStatus

use of com.artipie.http.rs.RsWithStatus in project maven-adapter by artipie.

the class PutMetadataChecksumSlice method response.

@Override
public Response response(final String line, final Iterable<Map.Entry<String, String>> headers, final Publisher<ByteBuffer> body) {
    final Matcher matcher = PutMetadataChecksumSlice.PTN.matcher(new RequestLineFrom(line).uri().getPath());
    final Response res;
    if (matcher.matches()) {
        final String alg = matcher.group("alg");
        final String pkg = matcher.group("pkg");
        res = new AsyncResponse(this.findAndSave(body, alg, pkg).thenCompose(key -> {
            final CompletionStage<Response> resp;
            if (key.isPresent() && key.get().parent().isPresent() && key.get().parent().get().parent().isPresent()) {
                final Key location = key.get().parent().get().parent().get();
                // @checkstyle NestedIfDepthCheck (10 lines)
                resp = this.valid.ready(location).thenCompose(ready -> {
                    final CompletionStage<Response> action;
                    if (ready) {
                        action = this.validateAndUpdate(pkg, location);
                    } else {
                        action = CompletableFuture.completedFuture(new RsWithStatus(RsStatus.CREATED));
                    }
                    return action;
                });
            } else {
                resp = CompletableFuture.completedFuture(PutMetadataChecksumSlice.BAD_REQUEST);
            }
            return resp;
        }));
    } else {
        res = new RsWithStatus(RsStatus.BAD_REQUEST);
    }
    return res;
}
Also used : Response(com.artipie.http.Response) AsyncResponse(com.artipie.http.async.AsyncResponse) ContentDigest(com.artipie.asto.ext.ContentDigest) Slice(com.artipie.http.Slice) CompletableFuture(java.util.concurrent.CompletableFuture) Single(io.reactivex.Single) ByteBuffer(java.nio.ByteBuffer) Digests(com.artipie.asto.ext.Digests) Matcher(java.util.regex.Matcher) Storage(com.artipie.asto.Storage) Locale(java.util.Locale) Map(java.util.Map) Observable(io.reactivex.Observable) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) Maven(com.artipie.maven.Maven) RsWithStatus(com.artipie.http.rs.RsWithStatus) Publisher(org.reactivestreams.Publisher) Response(com.artipie.http.Response) RsStatus(com.artipie.http.rs.RsStatus) Content(com.artipie.asto.Content) Key(com.artipie.asto.Key) StandardCharsets(java.nio.charset.StandardCharsets) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) SingleInterop(hu.akarnokd.rxjava2.interop.SingleInterop) ValidUpload(com.artipie.maven.ValidUpload) PublisherAs(com.artipie.asto.ext.PublisherAs) CompletionStage(java.util.concurrent.CompletionStage) RxStorageWrapper(com.artipie.asto.rx.RxStorageWrapper) AsyncResponse(com.artipie.http.async.AsyncResponse) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) RsWithStatus(com.artipie.http.rs.RsWithStatus) Matcher(java.util.regex.Matcher) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) AsyncResponse(com.artipie.http.async.AsyncResponse) Key(com.artipie.asto.Key) CompletionStage(java.util.concurrent.CompletionStage)

Aggregations

RsWithStatus (com.artipie.http.rs.RsWithStatus)16 Test (org.junit.jupiter.api.Test)12 RsHasStatus (com.artipie.http.hm.RsHasStatus)8 RsStatus (com.artipie.http.rs.RsStatus)7 Response (com.artipie.http.Response)6 Slice (com.artipie.http.Slice)5 RequestLine (com.artipie.http.rq.RequestLine)5 SliceSimple (com.artipie.http.slice.SliceSimple)5 Map (java.util.Map)5 BasicAuthSlice (com.artipie.http.auth.BasicAuthSlice)4 Permission (com.artipie.http.auth.Permission)4 Authorization (com.artipie.http.headers.Authorization)4 AsyncResponse (com.artipie.http.async.AsyncResponse)3 ListOf (org.cactoos.list.ListOf)3 Base64Encoded (org.cactoos.text.Base64Encoded)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 Content (com.artipie.asto.Content)2 Key (com.artipie.asto.Key)2 Storage (com.artipie.asto.Storage)2 PublisherAs (com.artipie.asto.ext.PublisherAs)2