use of io.s4.message.Request in project core by s4.
the class ObjectBuilder method main.
public static void main(String[] argv) throws Exception {
ObjectBuilder b = new ObjectBuilder();
String s = "{a:5, b:100}";
Object out = b.fromJson(s, TEST.class);
System.out.println(out.toString());
TEST t = new TEST(1, 2);
System.out.println(b.toJson(t));
String[] query = { "name", "count", "freq" };
String[] target = { "ACDW", "11" };
io.s4.message.Request.ClientRInfo rinfo = new io.s4.message.Request.ClientRInfo();
rinfo.setRequesterUUID(UUID.randomUUID());
Request req = new io.s4.message.SinglePERequest(Arrays.asList(target), Arrays.asList(query), rinfo);
System.out.println(req.toString());
InstanceCreator<io.s4.message.Request.RInfo> infoCreator = new InstanceCreator<io.s4.message.Request.RInfo>() {
public io.s4.message.Request.RInfo createInstance(Type type) {
return new io.s4.message.Request.ClientRInfo();
}
};
Gson gson = (new GsonBuilder()).registerTypeAdapter(io.s4.message.Request.RInfo.class, infoCreator).registerTypeAdapter(Object.class, new ObjectTypeAdapter()).create();
System.out.println("gson: " + gson.toJson(req));
System.out.println("gson reversed: " + gson.fromJson(gson.toJson(req), SinglePERequest.class));
System.out.println(b.toJson(req));
System.out.println(b.toJson(Arrays.asList(query)));
System.out.println("----------------------------------------------");
ArrayList<SSTest> list = new ArrayList<SSTest>();
SSTest ss1 = new SSTest();
ss1.str = "list-element-1";
SSTest ss2 = new SSTest();
ss2.str = "list-element-2";
list.add(ss1);
list.add(ss2);
Map<String, Object> listmap = new HashMap<String, Object>();
listmap.put("ll", list);
MapTest mt = new MapTest();
mt.map = listmap;
Object listmapobj = listmap;
System.out.println("list: " + gson.toJson(list));
System.out.println("listmap: " + gson.toJson(listmap));
System.out.println("listmapobj: " + gson.toJson(listmapobj));
System.out.println("mapobject: " + gson.toJson(mt));
}
use of io.s4.message.Request in project core by s4.
the class Response method partition.
public List<CompoundKeyInfo> partition(int partCount) {
// partition id is available from the request info object
int p = this.getRInfo().getPartition();
List<CompoundKeyInfo> partitionInfoList = null;
if (p >= 0 && p < partCount) {
CompoundKeyInfo partitionInfo = new CompoundKeyInfo();
partitionInfo.setPartitionId(p);
partitionInfoList = new ArrayList<CompoundKeyInfo>();
partitionInfoList.add(partitionInfo);
}
return partitionInfoList;
}
use of io.s4.message.Request in project rest.li by linkedin.
the class SslRequestHandler method write.
/**
* Override this method to set the handlers for SSL connection the first time this channel
* is used to make a request. Once used, the scheme of the request on this channel cannot be changed.
*/
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
if (msg instanceof Request) {
Request request = (Request) msg;
URI uri = request.getURI();
String scheme = uri.getScheme();
if (_firstTimeScheme == null) {
// handler to the channel pipeline
if (scheme.equalsIgnoreCase(HTTPS_SCHEME)) {
if (_sslHandler == null) {
throw new IllegalStateException("The client hasn't been configured with SSLContext " + "- cannot make an https request to " + uri);
}
/** Note: {@link SslHandler} will initiate a handshake upon being added to the pipeline. */
ctx.pipeline().addFirst(SSL_HANDLER, _sslHandler);
}
_firstTimeScheme = scheme;
} else if (!scheme.equalsIgnoreCase(_firstTimeScheme)) {
throw new IllegalStateException(String.format("Cannot switch scheme from %s to %s for %s", _firstTimeScheme, scheme, ctx.channel().remoteAddress()));
}
}
ctx.write(msg, promise);
}
use of io.s4.message.Request in project rest.li by linkedin.
the class Http2InitializerHandler method write.
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
if (!(msg instanceof RequestWithCallback)) {
ctx.write(msg, promise);
return;
}
if (_setupComplete) {
ctx.write(msg);
} else {
Request request = ((RequestWithCallback) msg).request();
URI uri = request.getURI();
String scheme = uri.getScheme();
if (scheme.equalsIgnoreCase(HttpScheme.HTTPS.toString())) {
configureHttpsPipeline(ctx);
} else if (scheme.equalsIgnoreCase(HttpScheme.HTTP.toString())) {
configureHttpPipeline(ctx, request);
} else {
throw new IllegalArgumentException("Invalid scheme " + scheme + ", expected either http or https");
}
ctx.write(msg);
}
}
use of io.s4.message.Request in project rest.li by linkedin.
the class Http2SchemeHandler method write.
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
if (!(msg instanceof RequestWithCallback)) {
ctx.write(msg, promise);
return;
}
Request request = ((RequestWithCallback) msg).request();
URI uri = request.getURI();
String scheme = uri.getScheme();
if (!scheme.equalsIgnoreCase(_scheme)) {
// Specified scheme does not match the existing scheme for the pipeline. Returns channel back to the pool
// and throws exception to the caller.
((RequestWithCallback) msg).handle().release();
throw new IllegalStateException(String.format("Cannot switch scheme from %s to %s for %s", _scheme, scheme, ctx.channel().remoteAddress()));
}
ctx.write(msg, promise);
}
Aggregations