List of usage examples for com.google.gson JsonObject addProperty
public void addProperty(String property, Character value)
From source file:co.cask.cdap.proto.codec.BasicThrowableCodec.java
License:Apache License
@Override public JsonElement serialize(BasicThrowable src, Type typeOfSrc, JsonSerializationContext context) { JsonObject json = new JsonObject(); json.addProperty("className", src.getClassName()); json.addProperty("message", src.getMessage()); json.add("stackTraces", context.serialize(src.getStackTraces(), StackTraceElement[].class)); json.add("cause", context.serialize(src.getCause(), BasicThrowable.class)); return json;/* w ww . ja v a 2s . c om*/ }
From source file:co.cask.cdap.proto.codec.HttpServiceSpecificationCodec.java
License:Apache License
@Override public JsonElement serialize(HttpServiceHandlerSpecification src, Type typeOfSrc, JsonSerializationContext context) { JsonObject json = new JsonObject(); json.addProperty("className", src.getClassName()); json.addProperty("name", src.getName()); json.addProperty("description", src.getDescription()); json.add("properties", serializeMap(src.getProperties(), context, String.class)); json.add("datasets", serializeSet(src.getDatasets(), context, String.class)); json.add("endpoints", serializeList(src.getEndpoints(), context, ServiceHttpEndpoint.class)); return json;/*from w w w .jav a2 s. co m*/ }
From source file:co.cask.cdap.proto.codec.MapReduceSpecificationCodec.java
License:Apache License
@Override public JsonElement serialize(MapReduceSpecification src, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObj = new JsonObject(); jsonObj.addProperty("className", src.getClassName()); jsonObj.addProperty("name", src.getName()); jsonObj.addProperty("description", src.getDescription()); if (src.getDriverResources() != null) { jsonObj.add("driverResources", context.serialize(src.getDriverResources())); }//from w ww. j a va2s . com if (src.getMapperResources() != null) { jsonObj.add("mapperResources", context.serialize(src.getMapperResources())); } if (src.getReducerResources() != null) { jsonObj.add("reducerResources", context.serialize(src.getReducerResources())); } if (src.getInputDataSet() != null) { jsonObj.addProperty("inputDataSet", src.getInputDataSet()); } if (src.getOutputDataSet() != null) { jsonObj.addProperty("outputDataSet", src.getOutputDataSet()); } jsonObj.add("datasets", serializeSet(src.getDataSets(), context, String.class)); jsonObj.add("properties", serializeMap(src.getProperties(), context, String.class)); return jsonObj; }
From source file:co.cask.cdap.proto.codec.WorkerSpecificationCodec.java
License:Apache License
@Override public JsonElement serialize(WorkerSpecification spec, Type typeOfSrc, JsonSerializationContext context) { JsonObject object = new JsonObject(); object.addProperty("className", spec.getClassName()); object.addProperty("name", spec.getName()); object.addProperty("description", spec.getDescription()); object.add("properties", serializeMap(spec.getProperties(), context, String.class)); object.add("resources", context.serialize(spec.getResources(), Resources.class)); object.add("datasets", serializeSet(spec.getDatasets(), context, String.class)); object.addProperty("instances", spec.getInstances()); return object; }
From source file:co.cask.cdap.proto.codec.WorkflowNodeThrowableCodec.java
License:Apache License
@Override public JsonElement serialize(WorkflowNodeThrowable src, Type typeOfSrc, JsonSerializationContext context) { JsonObject json = new JsonObject(); json.addProperty("className", src.getClassName()); json.addProperty("message", src.getMessage()); json.add("stackTraces", context.serialize(src.getStackTraces(), StackTraceElement[].class)); json.add("cause", context.serialize(src.getCause(), WorkflowNodeThrowable.class)); return json;/*www. j a v a 2 s .c om*/ }
From source file:co.cask.cdap.security.server.GrantAccessToken.java
License:Apache License
private void grantToken(HttpServletRequest request, HttpServletResponse response, long tokenValidity) throws IOException, ServletException { String username = request.getUserPrincipal().getName(); List<String> userGroups = Collections.emptyList(); long issueTime = System.currentTimeMillis(); long expireTime = issueTime + tokenValidity; // Create and sign a new AccessTokenIdentifier to generate the AccessToken. AccessTokenIdentifier tokenIdentifier = new AccessTokenIdentifier(username, userGroups, issueTime, expireTime);/*from www . j ava 2 s .c o m*/ AccessToken token = tokenManager.signIdentifier(tokenIdentifier); LOG.debug("Issued token for user {}", username); // Set response headers response.setContentType("application/json;charset=UTF-8"); response.addHeader(HttpHeaders.Names.CACHE_CONTROL, "no-store"); response.addHeader(HttpHeaders.Names.PRAGMA, "no-cache"); // Set response body JsonObject json = new JsonObject(); byte[] encodedIdentifier = Base64.encodeBase64(tokenCodec.encode(token)); json.addProperty(ExternalAuthenticationServer.ResponseFields.ACCESS_TOKEN, new String(encodedIdentifier, Charsets.UTF_8)); json.addProperty(ExternalAuthenticationServer.ResponseFields.TOKEN_TYPE, ExternalAuthenticationServer.ResponseFields.TOKEN_TYPE_BODY); json.addProperty(ExternalAuthenticationServer.ResponseFields.EXPIRES_IN, TimeUnit.SECONDS.convert(tokenValidity, TimeUnit.MILLISECONDS)); response.getOutputStream().print(json.toString()); response.setStatus(HttpServletResponse.SC_OK); }
From source file:co.cask.cdap.test.internal.AppFabricClient.java
License:Apache License
public void setRunnableInstances(String applicationId, String serviceName, String runnableName, int instances) { MockResponder responder = new MockResponder(); String uri = String.format("/v2/apps/%s/services/%s/runnables/%s/instances", applicationId, serviceName, runnableName);/*from w w w .j a va2 s . c o m*/ HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, uri); JsonObject json = new JsonObject(); json.addProperty("instances", instances); request.setContent(ChannelBuffers.wrappedBuffer(json.toString().getBytes())); serviceHttpHandler.setInstances(request, responder, applicationId, serviceName, runnableName); Preconditions.checkArgument(responder.getStatus().getCode() == 200, "set runnable instances failed"); }
From source file:co.cask.cdap.test.internal.AppFabricClient.java
License:Apache License
public void setFlowletInstances(String applicationId, String flowId, String flowletName, int instances) { MockResponder responder = new MockResponder(); String uri = String.format("/v2/apps/%s/flows/%s/flowlets/%s/instances/%s", applicationId, flowId, flowletName, instances);//from w w w.j a v a 2s .co m HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, uri); JsonObject json = new JsonObject(); json.addProperty("instances", instances); request.setContent(ChannelBuffers.wrappedBuffer(json.toString().getBytes())); httpHandler.setFlowletInstances(request, responder, applicationId, flowId, flowletName); Preconditions.checkArgument(responder.getStatus().getCode() == 200, "set flowlet instances failed"); }
From source file:co.cask.common.security.server.GrantAccessToken.java
License:Apache License
private void grantToken(HttpServletRequest request, HttpServletResponse response, long tokenValidity) throws IOException, ServletException { String username = request.getUserPrincipal().getName(); List<String> userGroups = Collections.emptyList(); long issueTime = System.currentTimeMillis(); long expireTime = issueTime + tokenValidity; // Create and sign a new AccessTokenIdentifier to generate the AccessToken. AccessTokenIdentifier tokenIdentifier = new AccessTokenIdentifier(username, userGroups, issueTime, expireTime);/*from ww w. jav a2s.c o m*/ AccessToken token = tokenManager.signIdentifier(tokenIdentifier); LOG.debug("Issued token for user {}", username); // Set response headers response.setContentType("application/json;charset=UTF-8"); response.addHeader("Cache-Control", "no-store"); response.addHeader("Pragma", "no-cache"); // Set response body JsonObject json = new JsonObject(); byte[] encodedIdentifier = Base64.encodeBase64(tokenCodec.encode(token)); json.addProperty(ExternalAuthenticationServer.ResponseFields.ACCESS_TOKEN, new String(encodedIdentifier, Charsets.UTF_8)); json.addProperty(ExternalAuthenticationServer.ResponseFields.TOKEN_TYPE, ExternalAuthenticationServer.ResponseFields.TOKEN_TYPE_BODY); json.addProperty(ExternalAuthenticationServer.ResponseFields.EXPIRES_IN, TimeUnit.SECONDS.convert(tokenValidity, TimeUnit.MILLISECONDS)); response.getOutputStream().print(json.toString()); response.setStatus(HttpServletResponse.SC_OK); }
From source file:co.cask.tigon.sql.manager.HubHttpHandler.java
License:Apache License
private JsonObject createResponse(String ip, int port) { JsonObject res = new JsonObject(); res.addProperty("ip", ip); res.addProperty("port", port); return res;// w w w . j ava2 s .com }