List of usage examples for io.netty.util.internal StringUtil EMPTY_STRING
String EMPTY_STRING
To view the source code for io.netty.util.internal StringUtil EMPTY_STRING.
Click Source Link
From source file:com.vmware.xenon.common.serialization.RequestRouteConverter.java
License:Open Source License
/** * Deserialize the Route instance. During deserialization, the condition field value is * decomposed into Parameter of the Route. * * For RequestUriMatcher ex: Parameter name is 'action' & ParamDef is Query * For RequestBodyMatcher ex: Parameter name is 'kind' & ParamDef is Body *//*from w w w . ja v a2 s .c om*/ @Override public Route deserialize(JsonElement json, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { if (!json.isJsonObject()) { throw new JsonParseException("The json element is not valid"); } JsonObject jsonObject = json.getAsJsonObject(); Route route = new Route(); String action = checkAndGetFromJson(jsonObject, FIELD_ACTION); route.action = action == null ? null : Action.valueOf(action); route.path = checkAndGetFromJson(jsonObject, FIELD_PATH); route.description = checkAndGetFromJson(jsonObject, FIELD_DESCRIPTION); try { String requestType = checkAndGetFromJson(jsonObject, FIELD_REQUEST_TYPE); route.requestType = requestType == null ? null : Class.forName(requestType); // If null, try to fill in if the condition field is filled in. This will be the case // when Operation processing chain is used String condition = checkAndGetFromJson(jsonObject, FIELD_CONDITION); if (!isNullOrEmpty(condition)) { // If condition starts with ? then it is RequestUriMatcher, so construct // QueryParam, else it will be RequestBodyMatcher, so fill in the if (condition.startsWith("?")) { Map<String, String> queryParams = UriUtils.parseUriQueryParams(UriUtils.buildUri(condition)); route.parameters = new ArrayList<>(queryParams.size()); for (Map.Entry<String, String> paramPair : queryParams.entrySet()) { route.parameters.add(new RequestRouter.Parameter(paramPair.getKey(), StringUtil.EMPTY_STRING, TypeName.STRING.name(), true, paramPair.getValue(), RequestRouter.ParamDef.QUERY)); } } else if (condition.equals("#")) { // a default matcher - only decode parameters if present if (jsonObject.has(FIELD_PARAMETERS)) { JsonArray parameters = jsonObject.getAsJsonArray(FIELD_PARAMETERS); Type gsonType = new TypeToken<List<RequestRouter.Parameter>>() { }.getType(); route.parameters = Utils.fromJson(parameters, gsonType); } } else { String[] conditionParts = condition.split(BODY_MATCHER_CLASS_NAME_SPLITTER); if (route.requestType == null) { route.requestType = Class.forName(conditionParts[0]); } String[] bodyParts = conditionParts[1].split(String.valueOf(URI_QUERY_PARAM_KV_CHAR)); RequestRouter.Parameter parameter = new RequestRouter.Parameter(bodyParts[0], StringUtil.EMPTY_STRING, TypeName.STRING.name(), true, bodyParts[1], RequestRouter.ParamDef.BODY); route.parameters = Arrays.asList(parameter); } } else { // This will be the case when getDocumentTemplate() is manually overridden. For a // single route it is either / or only and not both options. if (jsonObject.has(FIELD_PARAMETERS)) { JsonArray parameters = jsonObject.getAsJsonArray(FIELD_PARAMETERS); Type gsonType = new TypeToken<List<RequestRouter.Parameter>>() { }.getType(); route.parameters = Utils.fromJson(parameters, gsonType); } } String responseType = checkAndGetFromJson(jsonObject, FIELD_RESPONSE_TYPE); route.responseType = responseType == null ? null : Class.forName(responseType); } catch (ClassNotFoundException e) { throw new IllegalStateException(e); } return route; }
From source file:io.moquette.spi.impl.subscriptions.DumpTreeVisitor.java
License:Open Source License
private String prettySubscriptions(CNode node) { if (node instanceof TNode) { return "TNode"; }/* w ww . java 2s . c o m*/ if (node.subscriptions.isEmpty()) { return StringUtil.EMPTY_STRING; } StringBuilder subScriptionsStr = new StringBuilder(" ~~["); int counter = 0; for (Subscription couple : node.subscriptions) { subScriptionsStr.append("{filter=").append(couple.topicFilter).append(", ").append("client='") .append(couple.clientId).append("'}"); counter++; if (counter < node.subscriptions.size()) { subScriptionsStr.append(";"); } } return subScriptionsStr.append("]").toString(); }
From source file:io.vertx.core.dns.impl.fix.DnsQueryContext.java
License:Apache License
DnsQueryContext(DnsNameResolver parent, InetSocketAddress nameServerAddr, DnsQuestion question, Iterable<DnsRecord> additional, Promise<AddressedEnvelope<DnsResponse, InetSocketAddress>> promise) { this.parent = checkNotNull(parent, "parent"); this.nameServerAddr = checkNotNull(nameServerAddr, "nameServerAddr"); this.question = checkNotNull(question, "question"); this.additional = checkNotNull(additional, "additional"); this.promise = checkNotNull(promise, "promise"); recursionDesired = parent.isRecursionDesired(); id = parent.queryContextManager.add(this); if (parent.isOptResourceEnabled()) { optResource = new DefaultDnsRawRecord(StringUtil.EMPTY_STRING, DnsRecordType.OPT, parent.maxPayloadSize(), 0, Unpooled.EMPTY_BUFFER); } else {/* www .jav a 2 s. c om*/ optResource = null; } }