|
| 1 | +package hprose.exam.client; |
| 2 | + |
| 3 | +import hprose.client.HproseHttpClient; |
| 4 | +import hprose.common.HproseContext; |
| 5 | +import hprose.common.HproseFilter; |
| 6 | +import java.nio.ByteBuffer; |
| 7 | +import java.util.Arrays; |
| 8 | +import java.util.HashMap; |
| 9 | +import java.util.List; |
| 10 | +import java.util.Map; |
| 11 | +import java.util.logging.Level; |
| 12 | +import java.util.logging.Logger; |
| 13 | + |
| 14 | +class LogFilter implements HproseFilter { |
| 15 | + private static final Logger logger = Logger.getLogger(LogFilter.class.getName()); |
| 16 | + @Override |
| 17 | + public ByteBuffer inputFilter(ByteBuffer data, HproseContext context) { |
| 18 | + logger.log(Level.INFO, context.get("httpHeader").toString()); |
| 19 | + return data; |
| 20 | + } |
| 21 | + @Override |
| 22 | + public ByteBuffer outputFilter(ByteBuffer data, HproseContext context) { |
| 23 | + Map<String, List<String>> header = new HashMap<>(); |
| 24 | + header.put("Test", Arrays.asList("Hello Hprose")); |
| 25 | + context.set("httpHeader", header); |
| 26 | + return data; |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +public class ClientExam11 { |
| 31 | + public static void main(String[] args) throws Throwable { |
| 32 | + HproseHttpClient client = new HproseHttpClient(); |
| 33 | + client.useService("http://localhost:8084/examserver/Methods"); |
| 34 | + client.addFilter(new LogFilter()); |
| 35 | + System.out.println(client.invoke("ex1_getId")); |
| 36 | + System.out.println(client.invoke("ex2_getId")); |
| 37 | + } |
| 38 | +} |
0 commit comments