org.apache.http.client.fluent.Request Java Examples

The following examples show how to use org.apache.http.client.fluent.Request. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FinderServiceImpl.java    From AthenaServing with Apache License 2.0 6 votes vote down vote up
@Override
public JsonResult serviceDiscovery(ServiceValue serviceValue) {
    JsonResult jsonResult = new JsonResult();
    String url = Program.CONFIG_VALUE.getWebsiteUrl() + Constants.DISCOVERY_SERVICE_SITE_URI;
    String reqJson = JacksonUtils.toJson(serviceValue);
    try {
        StringEntity entity = new StringEntity(reqJson);
        String result;
        if (url.startsWith("https")) {
            result = HttpsClientUtil.doPostByStringEntity(url, entity, Constants.DEFAULT_CHARSET);
        } else {
            result = Request.Post(url).setHeader("Content-type", "application/json")
                    .body(entity).socketTimeout(5000).connectTimeout(5000)
                    .execute().returnContent().asString();
        }
        WebsitResult response = JacksonUtils.toObject(result, WebsitResult.class);
        if (!Constants.SUCCESS.equals(response.getCode())) {
            logger.error("request:" + reqJson + ",result:" + result);
        }
        jsonResult.setRet(Integer.parseInt(response.getCode()));
        jsonResult.setMsg(response.getMessage());
    } catch (Exception e) {
        logger.error(e);
    }
    return jsonResult;
}
 
Example #2
Source File: AbstractStreamingAnalyticsConnection.java    From streamsx.topology with Apache License 2.0 6 votes vote down vote up
protected boolean delete(String deleteJobUrl) throws IOException {
    boolean rc = false;
    String sReturn = "";

    Request request = Request
            .Delete(deleteJobUrl)
            .addHeader(AUTH.WWW_AUTH_RESP, getAuthorization())
            .useExpectContinue();

    Response response = executor.execute(request);
    HttpResponse hResponse = response.returnResponse();
    int rcResponse = hResponse.getStatusLine().getStatusCode();

    if (HttpStatus.SC_OK == rcResponse) {
        sReturn = EntityUtils.toString(hResponse.getEntity());
        rc = true;
    } else {
        rc = false;
    }
    traceLog.finest("Request: [" + deleteJobUrl + "]");
    traceLog.finest(rcResponse + ": " + sReturn);
    return rc;
}
 
Example #3
Source File: SSLJKSTrustStoreTest.java    From gravitee-gateway with Apache License 2.0 6 votes vote down vote up
@Test
public void simple_request_ssl() throws Exception {
    wireMockRule.stubFor(get("/team/my_team").willReturn(ok()));

    // First call is calling an endpoint where trustAll is defined to true, no need for truststore => 200
    HttpResponse response = Request.Get("http://localhost:8082/test/my_team").execute().returnResponse();
    assertEquals("trustAll is defined to true, no need for truststore => 200", HttpStatus.SC_OK, response.getStatusLine().getStatusCode());

    // Second call is calling an endpoint where trustAll is defined to false, without truststore => 502
    response = Request.Get("http://localhost:8082/test/my_team").execute().returnResponse();
    assertEquals("trustAll is defined to false, without truststore => 502", HttpStatus.SC_BAD_GATEWAY, response.getStatusLine().getStatusCode());

    // Third call is calling an endpoint where trustAll is defined to false, with truststore => 200
    response = Request.Get("http://localhost:8082/test/my_team").execute().returnResponse();
    assertEquals("trustAll is defined to false, with truststore => 200", HttpStatus.SC_OK, response.getStatusLine().getStatusCode());

    // Check that the stub has been successfully invoked by the gateway
    wireMockRule.verify(2, getRequestedFor(urlPathEqualTo("/team/my_team")));
}
 
Example #4
Source File: PushbulletNotifier.java    From yfiton with Apache License 2.0 6 votes vote down vote up
@Override
protected AccessTokenData requestAccessTokenData(AuthorizationData authorizationData) throws NotificationException {
    try {
        String authorizationCode = authorizationData.getAuthorizationCode();

        String response =
                Request.Post(getAccessTokenUrl(authorizationCode).get()).bodyForm(
                        Form.form()
                                .add("client_id", getClientId())
                                .add("client_secret", getClientSecret())
                                .add("code", authorizationCode)
                                .add("grant_type", "authorization_code").build())
                        .execute().returnContent().asString();

        JsonObject json = new JsonParser().parse(response).getAsJsonObject();

        String accessToken = json.get("access_token").getAsString();
        String tokenType = json.get("token_type").getAsString();

        return new AccessTokenData(accessToken, ImmutableMap.of("tokenType", tokenType));
    } catch (IOException e) {
        throw new NotificationException(e);
    }
}
 
Example #5
Source File: JavaxJsonbTest.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Test
@RunAsClient
public void testJavaxJsonb() throws IOException {
    Dog dog = new Dog();
    dog.name = "Falco";
    dog.age = 4;
    dog.bitable = false;

    Jsonb jsonb = JsonbBuilder.create();
    String json = jsonb.toJson(dog);

    String response = Request.Post("http://localhost:8080/").body(new StringEntity(json))
        .execute().returnContent().asString().trim();
    Dog dog2 = jsonb.fromJson(response, Dog.class);
    assertThat(dog2.name).isEqualTo(dog.name);
    assertThat(dog2.age).isEqualTo(dog.age);
    assertThat(dog2.bitable).isTrue();
}
 
Example #6
Source File: HttpsTest.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Test
@RunAsClient
public void hello() throws IOException, GeneralSecurityException {
    SSLContext sslContext = SSLContexts.custom()
            .loadTrustMaterial((TrustStrategy) (chain, authType) -> true)
            .build();
    try (CloseableHttpClient httpClient = HttpClients.custom()
            .setSSLContext(sslContext)
            .build()) {

        String response = Executor.newInstance(httpClient)
                .execute(Request.Get("https://localhost:8443/"))
                .returnContent().asString();
        assertThat(response).contains("Hello on port 8443, secure: true");
    }
}
 
Example #7
Source File: StreamsRestActions.java    From streamsx.topology with Apache License 2.0 6 votes vote down vote up
static Result<Job, JsonObject> submitJob(ApplicationBundle bundle, JsonObject jco) throws IOException {
	UploadedApplicationBundle uab = (UploadedApplicationBundle) bundle;
	
	JsonObject body = new JsonObject();
	body.addProperty("application", uab.getBundleId());
	body.addProperty("preview", false);		
	body.add("jobConfigurationOverlay", jco);
	
	final AbstractStreamsConnection conn = bundle.instance().connection();
	
	Request postBundle = Request.Post(bundle.instance().self() + "/jobs");
	postBundle.addHeader(AUTH.WWW_AUTH_RESP, conn.getAuthorization());
	postBundle.body(new StringEntity(body.toString(), ContentType.APPLICATION_JSON));		
	
	JsonObject response = requestGsonResponse(conn.executor, postBundle);
	
	Job job = Job.create(bundle.instance(), response.toString());
	
	if (!response.has(SubmissionResultsKeys.JOB_ID))
		response.addProperty(SubmissionResultsKeys.JOB_ID, job.getId());

	return new ResultImpl<Job, JsonObject>(true, job.getId(),
			() -> job, response);
}
 
Example #8
Source File: TikaHttpClientImpl.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Override
public Optional<InputStream> recursiveMetaDataAsJson(InputStream inputStream, org.apache.james.mailbox.model.ContentType contentType) {
    try {
        ContentType httpContentType = ContentType.create(contentType.mimeType().asString(),
            contentType.charset()
                .map(Charset::name)
                .orElse(null));
        return Optional.ofNullable(
                Request.Put(recursiveMetaData)
                    .socketTimeout(tikaConfiguration.getTimeoutInMillis())
                    .bodyStream(inputStream, httpContentType)
                    .execute()
                    .returnContent()
                    .asStream());
    } catch (IOException e) {
        LOGGER.warn("Failing to call Tika for content type {}", contentType, e);
        return Optional.empty();
    }
}
 
Example #9
Source File: GogsConfigHandler.java    From gogs-webhook-plugin with MIT License 6 votes vote down vote up
/**
 * Get Access token of the user.
 *
 * @return an access token of the user
 */
public String getGogsAccessToken() {
    String resp;
    String sha1 = null;
    Executor executor = getExecutor();
    try {
        resp = executor.execute(
                Request.Get(this.getGogsUrl() + "/api/v1/users/" + this.gogsServer_user + "/tokens")
        ).returnContent().toString();
        JSONArray jsonArray = JSONArray.fromObject(resp);
        if (!jsonArray.isEmpty()) {
            sha1 = ((JSONObject) jsonArray.get(0)).getString("sha1");
        }
    } catch (IOException e) { }
    return sha1;
}
 
Example #10
Source File: YarnUtil.java    From yanagishima with Apache License 2.0 6 votes vote down vote up
public static List<Map> getJobList(String resourceManagerUrl, Optional<String> beginTime) {
    try {
        String json;
        if (beginTime.isPresent()) {
            long currentTimeMillis = System.currentTimeMillis();
            long startedTimeBegin = currentTimeMillis - Long.valueOf(beginTime.get());
            json = Request.Get(resourceManagerUrl + "/ws/v1/cluster/apps?startedTimeBegin=" + startedTimeBegin)
                          .execute().returnContent().asString(UTF_8);
        } else {
            json = Request.Get(resourceManagerUrl + "/ws/v1/cluster/apps")
                          .execute().returnContent().asString(UTF_8);
        }
        return jsonToMaps(json);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example #11
Source File: Test.java    From trident with MIT License 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        // URL白名单组件测试
        CheckURL urlCheck = new CheckURL();
        String[] urlWList = {"joychou.com", "joychou.me"};
        Boolean ret = urlCheck.checkUrlWlist("http://test.joychou.org", urlWList);
        System.out.println(ret);

        // SSRF组件测试
        SSRF check = new SSRF();
        String url = "http://127.0.0.1.xip.io";
        ret = check.checkSSRF(url);
        if (ret){
            String con = Request.Get(url).execute().returnContent().toString();
            System.out.println(con);
        }
        else {
            System.out.println("Bad boy. The url is illegal");
        }

        // 获取客户端IP测试


    }
 
Example #12
Source File: InvalidHttpMethodGatewayTest.java    From gravitee-gateway with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldRespondWithNotImplemented() throws Exception {
    wireMockRule.stubFor(any(urlEqualTo("/team/my_team"))
            .willReturn(aResponse().withStatus(HttpStatus.SC_NOT_IMPLEMENTED)));


    Request request = Request.Get("http://localhost:8082/test/my_team");

    // A little bit of reflection to set an unknown HTTP method since the fluent API does not allow it.
    Field requestField = request.getClass().getDeclaredField("request");
    requestField.setAccessible(true);
    Field methodField = requestField.get(request).getClass().getDeclaredField("method");
    methodField.setAccessible(true);
    methodField.set(requestField.get(request), "unkown-method");

    Response response = request.execute();
    HttpResponse returnResponse = response.returnResponse();

    assertEquals(HttpStatus.SC_NOT_IMPLEMENTED, returnResponse.getStatusLine().getStatusCode());

    wireMockRule.verify(anyRequestedFor(urlPathEqualTo("/team/my_team")));
}
 
Example #13
Source File: GenericBlockingRestKiqrClientImpl.java    From kiqr with Apache License 2.0 6 votes vote down vote up
private <U> U execute(URISupplier<URI> uriSupplier, MappingFunction<byte[], U> responseMapper, Supplier<U> notFoundMapper) {
    try {
        URI uri = uriSupplier.get();
        Request request = Request.Get(uri);
        HttpResponse response = request.execute().returnResponse();

        if (response.getStatusLine().getStatusCode() == 200) {
            byte[] returnJson = EntityUtils.toByteArray(response.getEntity());

            return responseMapper.apply(returnJson);


        } else if (response.getStatusLine().getStatusCode() == 404) {
            return notFoundMapper.get();
        } else if (response.getStatusLine().getStatusCode() == 400) {
            throw new IllegalArgumentException("Bad Request");
        } else {
            throw new QueryExecutionException("Something went wrong, status code: " + response.getStatusLine().getStatusCode());
        }


    } catch (URISyntaxException | IOException e) {
        throw new ConnectionException("Error creating connection", e);
    }

}
 
Example #14
Source File: RoundRobinLoadBalancingMultipleTest.java    From gravitee-gateway with Apache License 2.0 6 votes vote down vote up
@Test
public void call_round_robin_lb_multiple_endpoints() throws Exception {
    wireMockRule.stubFor(get("/api1").willReturn(ok()));
    wireMockRule.stubFor(get("/api2").willReturn(ok()));

    Request request = Request.Get("http://localhost:8082/api");

    int calls = 20;

    for(int i = 0 ; i < calls ; i++) {
        HttpResponse response = request.execute().returnResponse();

        assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
        wireMockRule.verify((i / 2) + 1, getRequestedFor(urlEqualTo("/api" + (i%2 + 1))));
    }

    wireMockRule.verify(calls / 2, getRequestedFor(urlPathEqualTo("/api1")));
    wireMockRule.verify(calls / 2, getRequestedFor(urlPathEqualTo("/api2")));
}
 
Example #15
Source File: GogsConfigHandler.java    From gogs-webhook-plugin with MIT License 6 votes vote down vote up
/**
 * A method to wait for the availability of the Gogs server
 *
 * @param retries    the number of times we should try to connect
 * @param retryDelay the number of seconds to wait between tentatives
 * @throws TimeoutException     thrown when number of retries was exhausted
 * @throws InterruptedException thrown when the wait has been interrupted
 */
void waitForServer(int retries, int retryDelay) throws TimeoutException, InterruptedException {
    String testUrl = this.getGogsUrl() + "/";

    for (int i = 0; i < retries; i++) {
        int status;
        try {
            status = Request.Get(testUrl)
                            .execute().returnResponse().getStatusLine().getStatusCode();
        } catch (IOException e) {
            TimeUnit.SECONDS.sleep(retryDelay);
            continue;
        }
        if (status == 200) {
            return;
        } else {
            TimeUnit.SECONDS.sleep(retryDelay);
        }
    }
    throw new TimeoutException("Timeout waiting for availability of " + testUrl);
}
 
Example #16
Source File: QueryParametersTest.java    From gravitee-gateway with Apache License 2.0 6 votes vote down vote up
@Test
public void call_get_query_accent() throws Exception {
    wireMockRule.stubFor(
            get(urlPathEqualTo("/team/my_team"))
                    .willReturn(
                            ok()
                                    .withBody("{{request.query.q}}")
                                    .withTransformers("response-template")));

    String query = "poupée";

    URI target = new URIBuilder("http://localhost:8082/test/my_team")
            .addParameter("q", query)
            .build();

    HttpResponse response = Request.Get(target).execute().returnResponse();

    assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());

    String responseContent = StringUtils.copy(response.getEntity().getContent());
    assertEquals(query, responseContent);

    wireMockRule.verify(1, getRequestedFor(urlPathEqualTo("/team/my_team")));
}
 
Example #17
Source File: SlackNotifier.java    From yfiton with Apache License 2.0 6 votes vote down vote up
@Override
protected AccessTokenData requestAccessTokenData(AuthorizationData authorizationData) throws NotificationException {
    try {
        String accessTokenUrl = getAccessTokenUrl(authorizationData.getAuthorizationCode()).get();

        log.trace("Access token URL is {}", accessTokenUrl);

        String response = Request.Get(accessTokenUrl).execute().returnContent().asString();

        JsonParser jsonParser = new JsonParser();
        JsonObject json = jsonParser.parse(response).getAsJsonObject();

        ImmutableMap.Builder<String, String> result = ImmutableMap.builder();

        if (!json.get("ok").getAsBoolean()) {
            throw new NotificationException(json.get("error").getAsString());
        }

        result.put("teamId", json.get("team_id").getAsString());
        result.put("teamName", json.get("team_name").getAsString());

        return new AccessTokenData(json.get("access_token").getAsString(), result.build());
    } catch (IOException e) {
        throw new NotificationException(e.getMessage(), e);
    }
}
 
Example #18
Source File: HttpProxyUtils.java    From android-uiconductor with Apache License 2.0 6 votes vote down vote up
public static String postRequestAsString(String url, String request)
    throws UicdDeviceHttpConnectionResetException {
  logger.info("post request to xmldumper:" + url);
  String ret = "";
  Response response = null;
  try {
    response = Request.Post(url)
        .body(new StringEntity(request))
        .execute();
    ret = response.returnContent().asString(Consts.UTF_8);
  } catch (IOException e) {
    logger.severe(e.getMessage());
    // See comments in getRequestAsString
    if (CONNECTION_RESET_KEYWORDS_LIST.stream().parallel().anyMatch(e.getMessage()::contains)) {
      throw new UicdDeviceHttpConnectionResetException(e.getMessage());
    }
  }
  logger.info("return from xmldumper:" + ret);
  return ret;
}
 
Example #19
Source File: ClientAuthenticationJKSTest.java    From gravitee-gateway with Apache License 2.0 6 votes vote down vote up
@Test
public void simple_request_client_auth() throws Exception {
    wireMockRule.stubFor(get("/team/my_team").willReturn(ok()));

    // First call is calling an HTTPS endpoint without ssl configuration => 502
    HttpResponse response = Request.Get("http://localhost:8082/test/my_team").execute().returnResponse();
    assertEquals("without ssl configuration => 502", HttpStatus.SC_BAD_GATEWAY, response.getStatusLine().getStatusCode());

    // Second call is calling an endpoint where trustAll = false, without truststore => 502
    response = Request.Get("http://localhost:8082/test/my_team").execute().returnResponse();
    assertEquals("trustAll = false, without truststore => 502", HttpStatus.SC_BAD_GATEWAY, response.getStatusLine().getStatusCode());

    // Third call is calling an endpoint where trustAll = false, with truststore => 200
    response = Request.Get("http://localhost:8082/test/my_team").execute().returnResponse();
    assertEquals("trustAll = false, with truststore => 200", HttpStatus.SC_OK, response.getStatusLine().getStatusCode());

    // Fourth call is calling an endpoint where trustAll = true, without truststore => 200
    response = Request.Get("http://localhost:8082/test/my_team").execute().returnResponse();
    assertEquals("trustAll = true, with keystore => 200", HttpStatus.SC_OK, response.getStatusLine().getStatusCode());

    // Check that the stub has been successfully invoked by the gateway
    wireMockRule.verify(2, getRequestedFor(urlPathEqualTo("/team/my_team")));
}
 
Example #20
Source File: ProvidersMergingTest.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@RunAsClient
@Test
public void shouldOverrideGetResponseWithUsersProvider() throws Exception {
    String response = Request.Get("http://localhost:8080/mpjwt/providers")
            .setHeader("Authorization", "Bearer " + createToken("MappedRole"))
            .setHeader("Accept", MediaType.TEXT_PLAIN)
            .execute().returnContent().asString();
    Assert.assertEquals("overriden get response", response);
}
 
Example #21
Source File: ParametrizedPathsTest.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@RunAsClient
@Test
public void shouldNotGetPlainForForbiddenUser() throws Exception {
    int statusCode = Request.Get("http://localhost:8080/mpjwt/parameterized-paths/my/hello/view")
            .setHeader("Authorization", "Bearer " + createToken("MappedRole"))
            .setHeader("Accept", MediaType.TEXT_PLAIN)
            .execute().returnResponse().getStatusLine().getStatusCode();
    Assert.assertEquals(403, statusCode);
}
 
Example #22
Source File: OpenApiTest.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Test
@RunAsClient
public void acceptJson() throws Exception {
    HttpResponse response = Request.Get("http://localhost:8080/openapi")
            .addHeader("Accept", "application/json")
            .execute()
            .returnResponse();
    assertTrue(response.getFirstHeader("Content-Type").getValue().contains("application/json"));
}
 
Example #23
Source File: TransformerIT.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Test
@Category(CommunityOnly.class)
public void verifyTransformerFactoryName_Community() throws Exception {
    String result = Request.Get("http://localhost:8080/transformer").execute().returnContent().asString();
    Assert.assertTrue("Expected transformer factory class to be org.apache.xalan.xsltc.trax.TransformerFactoryImpl but was " + result,
                      result.startsWith("org.apache.xalan.xsltc.trax.TransformerFactoryImpl"));
}
 
Example #24
Source File: ConfigTest.java    From json-view with GNU General Public License v3.0 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testResponseEntitySupport() throws Exception {
  HttpResponse response = Request.Get("http://localhost:" + port + "/responseEntity").execute().returnResponse();
  Map<String, Object> map = new ObjectMapper().readValue(response.getEntity().getContent(), HashMap.class);

  assertEquals(202, response.getStatusLine().getStatusCode());
  assertEquals("asdfasdf", response.getFirstHeader("TEST").getValue());
  assertEquals("qwerqwer", map.get("str2"));
  assertEquals("ignored", map.get("ignoredDirect"));
  assertNull(map.get("int1"));
}
 
Example #25
Source File: JwtTokenCookieTest.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@RunAsClient
@Test
public void tokenInCookieHeader() throws Exception {
    String response = Request.Get("http://localhost:8080/mpjwt/default-group/secured")
            .setHeader("Cookie", "a=b;jwt=" + createToken("User"))
            .execute().returnContent().asString();
    assertThat(response).isEqualTo("User");
}
 
Example #26
Source File: AweSomeApi.java    From javabase with Apache License 2.0 5 votes vote down vote up
private static void get() {
    try {
        String result = Request.Get("https://www.baidu.com/").execute().returnContent().asString(Charset.forName("utf-8"));
        log.info(result);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example #27
Source File: AutotranslationServiceImpl.java    From beakerx with Apache License 2.0 5 votes vote down vote up
@Override
public String get(String name) {
  String valueString = "";
  try {
    valueString = Request
            .Get(LOCALHOST + this.context.getPort() + AUTOTRANSLTION + this.context.getContextId() + "/" + name)
            .addHeader(AUTHORIZATION, auth())
            .execute()
            .returnContent()
            .asString();
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
  return valueString;
}
 
Example #28
Source File: EsvGovernmentBodyOperationOutcomeReaderImpl.java    From cia with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized List<GovernmentBodyAnnualOutcomeSummary> readOutgoingCsv() throws IOException {
	if (outGoingCsvValues == null) {
		outGoingCsvValues = readUsingZipInputStream(Request.Get(
			"https://www.esv.se/psidata/manadsutfall/GetFile/?documentType=Utgift&fileType=Zip&fileName=M%C3%A5nadsutfall%20utgifter%20januari%202006%20-%20mars%202020,%20definitivt.zip&year=2020&month=3&status=Definitiv")
			.execute().returnContent().asStream(),SPECIFIC_INCOMING_FIELDS);
	}
	return Collections.unmodifiableList(outGoingCsvValues);
}
 
Example #29
Source File: RolesMapPropertiesTest.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@RunAsClient
@Test
public void testRolesAllowed() throws Exception {
    String response = Request.Get("http://localhost:8080/mpjwt/rolesMap/echoer2")
        .setHeader("Authorization", "Bearer " + createToken("Echoer"))
        .execute().returnContent().asString();
    Assert.assertEquals(response, "Hello [email protected]");
}
 
Example #30
Source File: Configuration.java    From zest-writer with GNU General Public License v3.0 5 votes vote down vote up
public static String getLastRelease() throws IOException {
    String projectUrlRelease = "https://api.github.com/repos/firm1/zest-writer/releases/latest";

    String json = Request.Get(projectUrlRelease).execute().returnContent().asString();
    ObjectMapper mapper = new ObjectMapper(); // can reuse, share globally
    Map map = mapper.readValue(json, Map.class);
    if(map.containsKey("tag_name")) {
        return (String) map.get("tag_name");
    }
    return null;
}