aboutsummaryrefslogtreecommitdiffstats
path: root/application/src/test/java/com/yahoo/application/container/processors/Rot13Processor.java
blob: 0a7fe321880964c3389029816f50d0278dd7c1f2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.application.container.processors;

import com.yahoo.processing.Processor;
import com.yahoo.processing.Request;
import com.yahoo.processing.Response;
import com.yahoo.processing.execution.Execution;
import com.yahoo.processing.response.AbstractData;

import static com.yahoo.application.container.docprocs.Rot13DocumentProcessor.rot13;

/**
 * @author Einar M R Rosenvinge
 */
public class Rot13Processor extends Processor {
    public static class StringData extends AbstractData {

        private String string;

        public StringData(Request request, String string) {
            super(request);
            this.string = string;
        }

        public void setString(String string) {
            this.string = string;
        }

        @Override
        public String toString() {
            return string;
        }

    }

    @SuppressWarnings("unchecked")
    @Override
    public Response process(Request request, Execution execution) {
        Object fooObj = request.properties().get("title");

        Response response = new Response(request);
        if (fooObj != null) {
            response.data().add(new StringData(request, rot13(fooObj.toString())));
        }
        return response;
    }

}