SHOW:
|
|
- or go back to the newest paste.
| 1 | package org.opendaylight.ovsdb.internal; | |
| 2 | ||
| 3 | import com.fasterxml.jackson.core.JsonParser; | |
| 4 | import com.fasterxml.jackson.databind.JsonNode; | |
| 5 | import com.fasterxml.jackson.databind.ObjectMapper; | |
| 6 | import org.opendaylight.ovsdb.table.*; | |
| 7 | ||
| 8 | import io.netty.channel.*; | |
| 9 | import org.slf4j.Logger; | |
| 10 | import org.slf4j.LoggerFactory; | |
| 11 | ||
| 12 | ||
| 13 | import java.io.IOException; | |
| 14 | ||
| 15 | public class MessageHandler extends SimpleChannelInboundHandler<String> {
| |
| 16 | protected static final Logger logger = LoggerFactory | |
| 17 | .getLogger(ConnectionService.class); | |
| 18 | ||
| 19 | private Object response; | |
| 20 | ||
| 21 | public Object getResponse(){
| |
| 22 | return this.response; | |
| 23 | } | |
| 24 | ||
| 25 | @Override | |
| 26 | public void channelRead0(ChannelHandlerContext ctx, String msg){
| |
| 27 | ||
| 28 | JsonNode jsonNode; | |
| 29 | ObjectMapper mapper = new ObjectMapper(); | |
| 30 | ||
| 31 | try{
| |
| 32 | jsonNode = mapper.readTree(msg); | |
| 33 | }catch(IOException e){
| |
| 34 | e.printStackTrace(); | |
| 35 | return; | |
| 36 | } | |
| 37 | ||
| 38 | if(jsonNode.has("method")){
| |
| 39 | String method = jsonNode.get("method").toString();
| |
| 40 | if(method.contains("echo")){
| |
| 41 | EchoReply echoreply = new EchoReply(); | |
| 42 | JsonNode echoReplyJnode = mapper.valueToTree(echoreply); | |
| 43 | System.out.println(echoReplyJnode.toString()); | |
| 44 | ctx.writeAndFlush(echoReplyJnode.toString()); | |
| 45 | } | |
| 46 | } | |
| 47 | else if(jsonNode.has("result")){
| |
| 48 | Long requestId = jsonNode.get("id").asLong();
| |
| 49 | JsonParser parser = mapper.treeAsTokens(jsonNode.get("result"));
| |
| 50 | try{
| |
| 51 | this.response = mapper.readValue(parser, MessageIDMapper.getMapper().pop(requestId)); | |
| 52 | System.out.println(this.response.toString()); | |
| 53 | ||
| 54 | }catch(Exception e){
| |
| 55 | - | Data baseCopy = mapper.readValue(parser, Data.class); |
| 55 | + | |
| 56 | - | System.out.println(baseCopy); |
| 56 | + | |
| 57 | } | |
| 58 | ||
| 59 | ||
| 60 | } | |
| 61 | @Override | |
| 62 | public void channelReadComplete(ChannelHandlerContext ctx) throws Exception{
| |
| 63 | ctx.flush(); | |
| 64 | } | |
| 65 | } |