use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser in project BIMserver by opensourceBIM.
the class StreamingModel method processDownload.
private void processDownload(Long topicId) throws UserException, ServerException, PublicInterfaceNotFoundException, IfcModelInterfaceException, IOException {
InputStream inputStream = bimServerClient.getDownloadData(topicId);
if (inputStream == null) {
throw new IfcModelInterfaceException("No InputStream to read from for topicId " + topicId);
}
InputStream downloadData = new org.bimserver.utils.CountingInputStream(inputStream) {
};
try {
JsonFactory jsonFactory = new JsonFactory();
JsonParser jp = jsonFactory.createParser(downloadData);
// TODO implement
} catch (Exception e) {
throw new IfcModelInterfaceException(e);
} finally {
if (downloadData != null) {
downloadData.close();
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser in project keycloak by keycloak.
the class JsonSerialization method createObjectNode.
/**
* Creates an {@link ObjectNode} based on the given {@code pojo}, copying all its properties to the resulting {@link ObjectNode}.
*
* @param pojo a pojo which properties will be populates into the resulting a {@link ObjectNode}
* @return a {@link ObjectNode} with all the properties from the given pojo
* @throws IOException if the resulting a {@link ObjectNode} can not be created
*/
public static ObjectNode createObjectNode(Object pojo) throws IOException {
if (pojo == null) {
throw new IllegalArgumentException("Pojo can not be null.");
}
ObjectNode objectNode = createObjectNode();
JsonParser jsonParser = mapper.getFactory().createParser(writeValueAsBytes(pojo));
JsonNode jsonNode = jsonParser.readValueAsTree();
if (!jsonNode.isObject()) {
throw new RuntimeException("JsonNode [" + jsonNode + "] is not a object.");
}
objectNode.setAll((ObjectNode) jsonNode);
return objectNode;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser in project keycloak by keycloak.
the class ImportUtils method importFederatedUsersFromStream.
// Assuming that it's invoked inside transaction
public static void importFederatedUsersFromStream(KeycloakSession session, String realmName, ObjectMapper mapper, InputStream is) throws IOException {
RealmProvider model = session.realms();
JsonFactory factory = mapper.getJsonFactory();
JsonParser parser = factory.createJsonParser(is);
try {
parser.nextToken();
while (parser.nextToken() == JsonToken.FIELD_NAME) {
if ("realm".equals(parser.getText())) {
parser.nextToken();
String currRealmName = parser.getText();
if (!currRealmName.equals(realmName)) {
throw new IllegalStateException("Trying to import users into invalid realm. Realm name: " + realmName + ", Expected realm name: " + currRealmName);
}
} else if ("federatedUsers".equals(parser.getText())) {
parser.nextToken();
if (parser.getCurrentToken() == JsonToken.START_ARRAY) {
parser.nextToken();
}
// TODO: support for more transactions per single users file (if needed)
List<UserRepresentation> userReps = new ArrayList<UserRepresentation>();
while (parser.getCurrentToken() == JsonToken.START_OBJECT) {
UserRepresentation user = parser.readValueAs(UserRepresentation.class);
userReps.add(user);
parser.nextToken();
}
importFederatedUsers(session, model, realmName, userReps);
if (parser.getCurrentToken() == JsonToken.END_ARRAY) {
parser.nextToken();
}
}
}
} finally {
parser.close();
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser in project keycloak by keycloak.
the class ImportUtils method getRealmsFromStream.
public static Map<String, RealmRepresentation> getRealmsFromStream(ObjectMapper mapper, InputStream is) throws IOException {
Map<String, RealmRepresentation> result = new HashMap<String, RealmRepresentation>();
JsonFactory factory = mapper.getFactory();
JsonParser parser = factory.createParser(is);
try {
parser.nextToken();
if (parser.getCurrentToken() == JsonToken.START_ARRAY) {
// Case with more realms in stream
parser.nextToken();
List<RealmRepresentation> realmReps = new ArrayList<RealmRepresentation>();
while (parser.getCurrentToken() == JsonToken.START_OBJECT) {
RealmRepresentation realmRep = parser.readValueAs(RealmRepresentation.class);
parser.nextToken();
// Ensure that master realm is imported first
if (Config.getAdminRealm().equals(realmRep.getRealm())) {
realmReps.add(0, realmRep);
} else {
realmReps.add(realmRep);
}
}
for (RealmRepresentation realmRep : realmReps) {
result.put(realmRep.getRealm(), realmRep);
}
} else if (parser.getCurrentToken() == JsonToken.START_OBJECT) {
// Case with single realm in stream
RealmRepresentation realmRep = parser.readValueAs(RealmRepresentation.class);
result.put(realmRep.getRealm(), realmRep);
}
} finally {
parser.close();
}
return result;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser in project keycloak by keycloak.
the class ClaimInformationPointProviderTest method onBeforeClass.
@BeforeClass
public static void onBeforeClass() {
httpService = Undertow.builder().addHttpListener(8989, "localhost").setHandler(exchange -> {
if (exchange.isInIoThread()) {
try {
if (exchange.getRelativePath().equals("/post-claim-information-provider")) {
FormParserFactory parserFactory = FormParserFactory.builder().build();
FormDataParser parser = parserFactory.createParser(exchange);
FormData formData = parser.parseBlocking();
if (!"Bearer tokenString".equals(exchange.getRequestHeaders().getFirst("Authorization")) || !"post".equalsIgnoreCase(exchange.getRequestMethod().toString()) || !"application/x-www-form-urlencoded".equals(exchange.getRequestHeaders().getFirst("Content-Type")) || !exchange.getRequestHeaders().get("header-b").contains("header-b-value1") || !exchange.getRequestHeaders().get("header-b").contains("header-b-value2") || !formData.get("param-a").getFirst().getValue().equals("param-a-value1") || !formData.get("param-a").getLast().getValue().equals("param-a-value2") || !formData.get("param-subject").getFirst().getValue().equals("sub") || !formData.get("param-user-name").getFirst().getValue().equals("username") || !formData.get("param-other-claims").getFirst().getValue().equals("param-other-claims-value1") || !formData.get("param-other-claims").getLast().getValue().equals("param-other-claims-value2")) {
exchange.setStatusCode(400);
return;
}
exchange.setStatusCode(200);
} else if (exchange.getRelativePath().equals("/get-claim-information-provider")) {
if (!"Bearer idTokenString".equals(exchange.getRequestHeaders().getFirst("Authorization")) || !"get".equalsIgnoreCase(exchange.getRequestMethod().toString()) || !exchange.getRequestHeaders().get("header-b").contains("header-b-value1") || !exchange.getRequestHeaders().get("header-b").contains("header-b-value2") || !exchange.getQueryParameters().get("param-a").contains("param-a-value1") || !exchange.getQueryParameters().get("param-a").contains("param-a-value2") || !exchange.getQueryParameters().get("param-subject").contains("sub") || !exchange.getQueryParameters().get("param-user-name").contains("username")) {
exchange.setStatusCode(400);
return;
}
exchange.setStatusCode(200);
} else {
exchange.setStatusCode(404);
}
} finally {
if (exchange.getStatusCode() == 200) {
try {
ObjectMapper mapper = JsonSerialization.mapper;
JsonParser jsonParser = mapper.getFactory().createParser("{\"a\": \"a-value1\", \"b\": \"b-value1\", \"d\": [\"d-value1\", \"d-value2\"]}");
TreeNode treeNode = mapper.readTree(jsonParser);
exchange.getResponseSender().send(treeNode.toString());
} catch (Exception ignore) {
ignore.printStackTrace();
}
}
exchange.endExchange();
}
}
}).build();
httpService.start();
}
Aggregations