List of usage examples for com.fasterxml.jackson.databind.node JsonNodeType STRING
JsonNodeType STRING
To view the source code for com.fasterxml.jackson.databind.node JsonNodeType STRING.
Click Source Link
From source file:de.thingweb.typesystem.TypeSystemChecker.java
public static boolean isXmlSchemaType(JsonNode type) { boolean isXsd = false; if (type != null && type.getNodeType() == JsonNodeType.STRING) { // very naive and simple for now isXsd = type.asText().trim().startsWith("xsd:"); }/*from www. j a v a 2s. c o m*/ return isXsd; }
From source file:com.spotify.hamcrest.jackson.IsJsonText.java
private IsJsonText(final Matcher<? super String> textMatcher) { super(JsonNodeType.STRING); this.textMatcher = Objects.requireNonNull(textMatcher); }
From source file:de.thingweb.thing.Thing.java
public URI getUri(int index) { JsonNode uris = getMetadata().get("uris"); if (uris != null) { try {/*from w ww . j a v a 2s. c om*/ if (uris.getNodeType() == JsonNodeType.STRING) { return new URI(uris.asText()); } else if (uris.getNodeType() == JsonNodeType.ARRAY) { ArrayNode an = (ArrayNode) uris; return new URI(an.get(index).asText()); } } catch (URISyntaxException e) { throw new RuntimeException("TD with malformed base uris"); } } else { throw new RuntimeException("TD without base uris field"); } // should never be reached throw new RuntimeException("Unexpected error while retrieving uri at index " + index); }
From source file:org.tomitribe.tribestream.registryng.security.oauth2.AccessTokenService.java
private String tryExtractingTheUser(final String accessToken) { try {/* ww w . j av a 2 s . c o m*/ final String[] segments = accessToken.split("\\."); if (segments.length != 3) { return null; } JsonNode node = mapper.readTree(Base64.getUrlDecoder().decode(segments[1])); for (final String part : configuration.getJwtUsernameAttribute().split("\\/")) { node = node.get(part); if (node == null) { return null; } } return ofNullable(node).filter(n -> n.getNodeType() == JsonNodeType.STRING).map(JsonNode::textValue) .orElse(null); } catch (final RuntimeException | IOException re) { return null; } }
From source file:de.thingweb.client.ClientFactory.java
protected Client pickClient() throws UnsupportedException, URISyntaxException { // check for right protocol&encoding List<Client> clients = new ArrayList<>(); // it is assumed URIs are ordered by priority JsonNode uris = thing.getMetadata().get("uris"); if (uris != null) { if (uris.getNodeType() == JsonNodeType.STRING) { checkUri(uris.asText(), clients); } else if (uris.getNodeType() == JsonNodeType.ARRAY) { ArrayNode an = (ArrayNode) uris; for (int i = 0; i < an.size(); i++) { checkUri(an.get(i).asText(), i, clients); }// www .j a va 2 s . co m } // int prio = 1; // for (JsonNode juri : uris) { // String suri = juri.asText(); // URI uri = new URI(suri); // if(isCoapScheme(uri.getScheme())) { // clients.add(new CoapClientImpl(suri, thing)); // log.info("Found matching client '" + CoapClientImpl.class.getName() + "' with priority " + prio++); // } else if(isHttpScheme(uri.getScheme())) { // clients.add(new HttpClientImpl(suri, thing)); // log.info("Found matching client '" + HttpClientImpl.class.getName() + "' with priority " + prio++); // } // } } // take priority into account if (clients.isEmpty()) { log.warn("No fitting client implementation found!"); throw new UnsupportedException("No fitting client implementation found!"); // return null; } else { // pick first one with highest priority Client c = clients.get(0); log.info("Use '" + c.getClass().getName() + "' according to priority"); return c; } }
From source file:de.thingweb.client.security.Security4NicePlugfest.java
public Registration requestRegistrationAM() throws IOException { Registration registration = null;/*from w w w . jav a 2 s . c o m*/ String clientName = CLIENT_NAME_PREFIX + System.currentTimeMillis(); String clientCredentials = "client_credentials"; String requestBodyRegistration = "{\"client_name\": \"" + clientName + "\",\"grant_types\": [\"" + clientCredentials + "\"]}"; // Registration URL urlRegistration = new URL(HTTPS_PREFIX + HOST + REQUEST_REGISTRATION_AM); HttpsURLConnection httpConRegistration = (HttpsURLConnection) urlRegistration.openConnection(); httpConRegistration.setDoOutput(true); httpConRegistration.setRequestProperty("Host", REQUEST_HEADER_HOST); httpConRegistration.setRequestProperty("Content-Type", "application/json"); httpConRegistration.setRequestProperty("Accept", "application/json"); httpConRegistration.setRequestMethod("POST"); OutputStream outRegistration = httpConRegistration.getOutputStream(); outRegistration.write(requestBodyRegistration.getBytes()); outRegistration.close(); int responseCodeRegistration = httpConRegistration.getResponseCode(); log.info("responseCode Registration for " + urlRegistration + ": " + responseCodeRegistration); if (responseCodeRegistration == 201) { // everything ok InputStream isR = httpConRegistration.getInputStream(); byte[] bisR = getBytesFromInputStream(isR); String jsonResponseRegistration = new String(bisR); log.info(jsonResponseRegistration); // extract the value of client_id (this value is called <c_id>in // the following) and the value of client_secret (called // <c_secret> in the following) from the JSON response ObjectMapper mapper = new ObjectMapper(); JsonFactory factory = mapper.getFactory(); JsonParser jp = factory.createParser(bisR); JsonNode actualObj = mapper.readTree(jp); JsonNode c_id = actualObj.get("client_id"); JsonNode c_secret = actualObj.get("client_secret"); if (c_id == null || c_id.getNodeType() != JsonNodeType.STRING || c_secret == null || c_secret.getNodeType() != JsonNodeType.STRING) { log.error("client_id: " + c_id); log.error("client_secret: " + c_secret); } else { // ok so far // Store <c_id> and <c_secret> for use during the token // acquisition log.info("client_id: " + c_id); log.info("client_secret: " + c_secret); registration = new Registration(c_id.textValue(), c_secret.textValue()); } } else { // error InputStream error = httpConRegistration.getErrorStream(); byte[] berror = getBytesFromInputStream(error); log.error(new String(berror)); } httpConRegistration.disconnect(); return registration; }
From source file:de.thingweb.typesystem.jsonschema.JsonSchemaType.java
public static JsonType getJsonType(JsonNode jsonSchemaNode) throws JsonSchemaException { JsonType jtype = null;/*from ww w. jav a 2 s. c om*/ if (jsonSchemaNode != null) { JsonNode typeNode = jsonSchemaNode.findValue("type"); if (typeNode != null) { switch (typeNode.asText()) { case "boolean": jtype = new JsonBoolean(); break; case "integer": case "number": boolean exclusiveMinimum = false; JsonNode exclusiveMinimumNode = jsonSchemaNode.findValue("exclusiveMinimum"); if (exclusiveMinimumNode != null && exclusiveMinimumNode.getNodeType() == JsonNodeType.BOOLEAN) { exclusiveMinimum = exclusiveMinimumNode.asBoolean(); } boolean exclusiveMaximum = false; JsonNode exclusiveMaximumNode = jsonSchemaNode.findValue("exclusiveMaximum"); if (exclusiveMaximumNode != null && exclusiveMaximumNode.getNodeType() == JsonNodeType.BOOLEAN) { exclusiveMaximum = exclusiveMaximumNode.asBoolean(); } if ("integer".equals(typeNode.asText())) { jtype = new JsonInteger(); JsonNode minimumNode = jsonSchemaNode.findValue("minimum"); if (minimumNode != null && minimumNode.getNodeType() == JsonNodeType.NUMBER) { ((JsonInteger) jtype).setMinimum(minimumNode.asLong()); } JsonNode maximumNode = jsonSchemaNode.findValue("maximum"); if (maximumNode != null && maximumNode.getNodeType() == JsonNodeType.NUMBER) { ((JsonInteger) jtype).setMaximum(maximumNode.asLong()); } } else { assert ("number".equals(typeNode.asText())); jtype = new JsonNumber(); JsonNode minimumNode = jsonSchemaNode.findValue("minimum"); if (minimumNode != null && minimumNode.getNodeType() == JsonNodeType.NUMBER) { ((JsonNumber) jtype).setMinimum(minimumNode.asDouble()); } JsonNode maximumNode = jsonSchemaNode.findValue("maximum"); if (maximumNode != null && maximumNode.getNodeType() == JsonNodeType.NUMBER) { ((JsonNumber) jtype).setMaximum(maximumNode.asDouble()); } } ((AbstractJsonNumeric) jtype).setExclusiveMinimum(exclusiveMinimum); ((AbstractJsonNumeric) jtype).setExclusiveMaximum(exclusiveMaximum); break; case "null": jtype = new JsonNull(); break; case "string": jtype = new JsonString(); break; case "array": JsonNode itemsNode = jsonSchemaNode.findValue("items"); if (itemsNode != null && JsonNodeType.OBJECT == itemsNode.getNodeType()) { jtype = new JsonArray(getJsonType(itemsNode)); } else { throw new JsonSchemaException("items not object"); } break; case "object": JsonNode propertiesNode = jsonSchemaNode.findValue("properties"); if (propertiesNode != null && JsonNodeType.OBJECT == propertiesNode.getNodeType()) { Iterator<Entry<String, JsonNode>> iter = propertiesNode.fields(); Map<String, JsonType> properties = new HashMap<String, JsonType>(); while (iter.hasNext()) { Entry<String, JsonNode> e = iter.next(); JsonNode nodeProp = e.getValue(); properties.put(e.getKey(), getJsonType(nodeProp)); } jtype = new JsonObject(properties); } else { throw new JsonSchemaException("Properties not object"); } // required JsonNode requiredNode = jsonSchemaNode.findValue("required"); if (requiredNode != null && JsonNodeType.ARRAY == requiredNode.getNodeType()) { ArrayNode an = (ArrayNode) requiredNode; Iterator<JsonNode> iterReq = an.elements(); while (iterReq.hasNext()) { JsonNode nreq = iterReq.next(); if (JsonNodeType.STRING == nreq.getNodeType()) { ((JsonObject) jtype).addRequired(nreq.asText()); } else { throw new JsonSchemaException("Unexpected required node: " + nreq); } } } break; } } } return jtype; }
From source file:org.agatom.springatom.cmp.action.DefaultActionsModelReader.java
private ActionRole resolveSecurityRoles(final JsonNode roles, final ActionRoleMap.Connector[] connectors) { if (JsonNodeType.STRING.equals(roles.getNodeType())) { return new DefaultActionRole().appendRole(roles.asText()); }//from ww w. j a v a 2s .c o m final Iterator<JsonNode> iterator = roles.iterator(); ActionRole actionRole = null; while (iterator.hasNext()) { final JsonNode node = iterator.next(); final JsonNodeType type = node.getNodeType(); if (JsonNodeType.STRING.equals(type)) { actionRole = new DefaultActionRole().appendRole(node.asText()); } else if (JsonNodeType.ARRAY.equals(type)) { final ArrayNode arrayNode = (ArrayNode) node; final DefaultActionRole role = new DefaultActionRole(); for (JsonNode textRoleNode : arrayNode) { role.appendRole(textRoleNode.asText()); } actionRole = role; } else if (JsonNodeType.OBJECT.equals(type)) { final ActionRoleMap actionRoleMap = new ActionRoleMap(); final Map<ActionRoleMap.Connector, DefaultActionRole> map = Maps .newHashMapWithExpectedSize(node.size()); String strConnector; for (final ActionRoleMap.Connector connector : connectors) { strConnector = connector.toString().toLowerCase(); if (node.has(strConnector)) { final DefaultActionRole role = new DefaultActionRole(); for (JsonNode textRoleNode : node.get(strConnector)) { role.appendRole(textRoleNode.asText()); } map.put(connector, role); } } actionRoleMap.setRoles(map); actionRole = actionRoleMap; } } return actionRole; }
From source file:de.thingweb.client.security.Security4NicePlugfest.java
public Registration requestRegistrationAS() throws IOException { String clientName = "opPostmanTestRS"; // CLIENT_NAME_PREFIX + // System.currentTimeMillis(); String clientCredentials = "client_credentials"; String requestBodyRegistration = "{\"client_name\": \"" + clientName + "\",\"grant_types\": [\"" + clientCredentials + "\"], \"id_token_signed_response_alg\":\"" + "HS256" + "\"}"; // Registration URL urlRegistration = new URL(HTTPS_PREFIX + HOST + REQUEST_REGISTRATION_AS); HttpsURLConnection httpConRegistration = (HttpsURLConnection) urlRegistration.openConnection(); httpConRegistration.setDoOutput(true); httpConRegistration.setRequestProperty("Host", REQUEST_HEADER_HOST); httpConRegistration.setRequestProperty("Content-Type", "application/json"); httpConRegistration.setRequestProperty("Accept", "application/json"); httpConRegistration.setRequestMethod("POST"); OutputStream outRegistration = httpConRegistration.getOutputStream(); outRegistration.write(requestBodyRegistration.getBytes()); outRegistration.close();/* w ww . ja v a 2 s . c o m*/ int responseCodeRegistration = httpConRegistration.getResponseCode(); log.info("responseCode Registration for " + urlRegistration + ": " + responseCodeRegistration); if (responseCodeRegistration == 201) { // everything ok InputStream isR = httpConRegistration.getInputStream(); byte[] bisR = getBytesFromInputStream(isR); String jsonResponseRegistration = new String(bisR); log.info(jsonResponseRegistration); // extract the value of client_id (this value is called <c_id>in // the following) and the value of client_secret (called // <c_secret> in the following) from the JSON response ObjectMapper mapper = new ObjectMapper(); JsonFactory factory = mapper.getFactory(); JsonParser jp = factory.createParser(bisR); JsonNode actualObj = mapper.readTree(jp); JsonNode c_id = actualObj.get("client_id"); JsonNode c_secret = actualObj.get("client_secret"); if (c_id == null || c_id.getNodeType() != JsonNodeType.STRING || c_secret == null || c_secret.getNodeType() != JsonNodeType.STRING) { log.error("client_id: " + c_id); log.error("client_secret: " + c_secret); } else { // ok so far // Store <c_id> and <c_secret> for use during the token // acquisition log.info("client_id: " + c_id); log.info("client_secret: " + c_secret); return new Registration(c_id.textValue(), c_secret.textValue()); } } else { // error InputStream error = httpConRegistration.getErrorStream(); byte[] berror = getBytesFromInputStream(error); log.error(new String(berror)); } httpConRegistration.disconnect(); return null; }
From source file:io.swagger.parser.util.SwaggerDeserializer.java
public Path path(ObjectNode obj, String location, ParseResult result) { boolean hasRef = false; Path output = null;// www . ja va2 s . co m if (obj.get("$ref") != null) { JsonNode ref = obj.get("$ref"); if (ref.getNodeType().equals(JsonNodeType.STRING)) { return pathRef((TextNode) ref, location, result); } else if (ref.getNodeType().equals(JsonNodeType.OBJECT)) { ObjectNode on = (ObjectNode) ref; // extra keys Set<String> keys = getKeys(on); for (String key : keys) { result.extra(location, key, on.get(key)); } } return null; } Path path = new Path(); ArrayNode parameters = getArray("parameters", obj, false, location, result); path.setParameters(parameters(parameters, location, result)); ObjectNode on = getObject("get", obj, false, location, result); if (on != null) { Operation op = operation(on, location + "(get)", result); if (op != null) { path.setGet(op); } } on = getObject("put", obj, false, location, result); if (on != null) { Operation op = operation(on, location + "(put)", result); if (op != null) { path.setPut(op); } } on = getObject("post", obj, false, location, result); if (on != null) { Operation op = operation(on, location + "(post)", result); if (op != null) { path.setPost(op); } } on = getObject("head", obj, false, location, result); if (on != null) { Operation op = operation(on, location + "(head)", result); if (op != null) { path.setHead(op); } } on = getObject("delete", obj, false, location, result); if (on != null) { Operation op = operation(on, location + "(delete)", result); if (op != null) { path.setDelete(op); } } on = getObject("patch", obj, false, location, result); if (on != null) { Operation op = operation(on, location + "(patch)", result); if (op != null) { path.setPatch(op); } } on = getObject("options", obj, false, location, result); if (on != null) { Operation op = operation(on, location + "(options)", result); if (op != null) { path.setOptions(op); } } // extra keys Set<String> keys = getKeys(obj); for (String key : keys) { if (key.startsWith("x-")) { path.setVendorExtension(key, extension(obj.get(key))); } else if (!PATH_KEYS.contains(key)) { result.extra(location, key, obj.get(key)); } } return path; }