-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added an example of custom http header
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
example/exam/client/src/main/java/hprose/exam/client/ClientExam11.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package hprose.exam.client; | ||
|
||
import hprose.client.HproseHttpClient; | ||
import hprose.common.HproseContext; | ||
import hprose.common.HproseFilter; | ||
import java.nio.ByteBuffer; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
class LogFilter implements HproseFilter { | ||
private static final Logger logger = Logger.getLogger(LogFilter.class.getName()); | ||
@Override | ||
public ByteBuffer inputFilter(ByteBuffer data, HproseContext context) { | ||
logger.log(Level.INFO, context.get("httpHeader").toString()); | ||
return data; | ||
} | ||
@Override | ||
public ByteBuffer outputFilter(ByteBuffer data, HproseContext context) { | ||
Map<String, List<String>> header = new HashMap<>(); | ||
header.put("Test", Arrays.asList("Hello Hprose")); | ||
context.set("httpHeader", header); | ||
return data; | ||
} | ||
} | ||
|
||
public class ClientExam11 { | ||
public static void main(String[] args) throws Throwable { | ||
HproseHttpClient client = new HproseHttpClient(); | ||
client.useService("http://localhost:8084/examserver/Methods"); | ||
client.addFilter(new LogFilter()); | ||
System.out.println(client.invoke("ex1_getId")); | ||
System.out.println(client.invoke("ex2_getId")); | ||
} | ||
} |