public RegisterDs3TargetSpectraS3Request(
      final String adminAuthId,
      final String adminSecretKey,
      final String dataPathEndPoint,
      final String name) {
    this.adminAuthId = adminAuthId;
    this.adminSecretKey = adminSecretKey;
    this.dataPathEndPoint = dataPathEndPoint;
    this.name = name;

    this.getQueryParams()
        .put(
            "admin_auth_id",
            UrlEscapers.urlFragmentEscaper().escape(adminAuthId).replace("+", "%2B"));
    this.getQueryParams()
        .put(
            "admin_secret_key",
            UrlEscapers.urlFragmentEscaper().escape(adminSecretKey).replace("+", "%2B"));
    this.getQueryParams()
        .put(
            "data_path_end_point",
            UrlEscapers.urlFragmentEscaper().escape(dataPathEndPoint).replace("+", "%2B"));
    this.getQueryParams()
        .put("name", UrlEscapers.urlFragmentEscaper().escape(name).replace("+", "%2B"));
  }
Exemplo n.º 2
0
 private void writeData(HttpURLConnection conn) throws IOException {
   conn.setRequestProperty("Content-Type", contentType);
   try (OutputStream os = conn.getOutputStream()) {
     switch (contentType) {
       case "application/json":
         Jackson.defaultMapper().writeValue(os, data);
         break;
       case "application/x-www-form-urlencoded":
         {
           Escaper escaper = UrlEscapers.urlFormParameterEscaper();
           StringBuilder content = new StringBuilder();
           Iterator<Map.Entry<String, JsonNode>> fields = data.fields();
           while (fields.hasNext()) {
             Map.Entry<String, JsonNode> field = fields.next();
             content.append(escaper.escape(field.getKey()));
             content.append("=");
             content.append(escaper.escape(field.getValue().asText()));
             if (fields.hasNext()) {
               content.append("&");
             }
           }
           String contentString = content.toString();
           log.info(
               "First {} characters of POST body are {}",
               LOG_TRUNCATE_CHARS,
               LessStrings.trunc(contentString, LOG_TRUNCATE_CHARS));
           os.write(contentString.getBytes());
           break;
         }
       default:
         throw new IllegalStateException("Unknown content type " + contentType);
     }
     os.flush();
   }
 }
  public PutDataReplicationRuleSpectraS3Request(
      final String dataPolicyId, final String ds3TargetId, final DataReplicationRuleType type) {
    this.dataPolicyId = dataPolicyId;
    this.ds3TargetId = ds3TargetId;
    this.type = type;

    this.getQueryParams()
        .put(
            "data_policy_id",
            UrlEscapers.urlFragmentEscaper().escape(dataPolicyId).replace("+", "%2B"));
    this.getQueryParams()
        .put(
            "ds3_target_id",
            UrlEscapers.urlFragmentEscaper().escape(ds3TargetId).replace("+", "%2B"));
    this.getQueryParams().put("type", type.toString());
  }
Exemplo n.º 4
0
 public static String getQRBarcodeURL(String user, String host, String secret) {
   String format =
       "https://www.google.com/chart?chs=130x130&chld=M%%7C0&cht=qr&chl="
           + "otpauth://totp/"
           + "%s@%s%%3Fsecret%%3D%s";
   Escaper urlEscaper = UrlEscapers.urlFragmentEscaper();
   return String.format(format, urlEscaper.escape(user), urlEscaper.escape(host), secret);
 }
Exemplo n.º 5
0
 @Description("escape a string for use in URL query parameter names and values")
 @ScalarFunction
 @LiteralParameters({"x", "y"})
 @Constraint(variable = "y", expression = "min(2147483647, x * 12)")
 @SqlType("varchar(y)")
 public static Slice urlEncode(@SqlType("varchar(x)") Slice value) {
   Escaper escaper = UrlEscapers.urlFormParameterEscaper();
   return slice(escaper.escape(value.toStringUtf8()));
 }
Exemplo n.º 6
0
 private String path(final String resource, final Object... params) {
   final String path;
   final Escaper escaper = UrlEscapers.urlPathSegmentEscaper();
   if (params.length == 0) {
     path = resource;
   } else {
     final List<String> encodedParams = Lists.newArrayList();
     for (final Object param : params) {
       encodedParams.add(escaper.escape(param.toString()));
     }
     path = format(resource, encodedParams.toArray());
   }
   return path;
 }
  @Test
  public void testSearchWithTokenParameter() throws Exception {
    String token =
        UrlEscapers.urlFragmentEscaper().asFunction().apply("http://www.dmix.gov/vista/2957|301");
    HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?tokenParam=" + token);
    HttpResponse status = ourClient.execute(httpGet);
    String responseContent = IOUtils.toString(status.getEntity().getContent());
    IOUtils.closeQuietly(status.getEntity().getContent());
    assertEquals(200, status.getStatusLine().getStatusCode());
    Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
    assertEquals(1, bundle.getEntries().size());

    Patient p = bundle.getResources(Patient.class).get(0);
    assertEquals("http://www.dmix.gov/vista/2957", p.getNameFirstRep().getFamilyAsSingleString());
    assertEquals("301", p.getNameFirstRep().getGivenAsSingleString());
  }
 @RequestMapping(
     value = "/channel/{channelId}/artifacts/{artifactId}/generate",
     method = RequestMethod.GET)
 @HttpConstraint(PERMIT)
 public ModelAndView generate(
     @PathVariable("channelId") final String channelId,
     @PathVariable("artifactId") final String artifactId) {
   return Channels.withArtifact(
       this.service,
       channelId,
       artifactId,
       ModifiableChannel.class,
       (channel, artifact) -> {
         channel.getContext().regenerate(artifact.getId());
         return new ModelAndView(
             "redirect:/channel/"
                 + UrlEscapers.urlPathSegmentEscaper().escape(artifact.getChannelId().getId())
                 + "/view");
       });
 }
Exemplo n.º 9
0
 @Override
 public void init() {
   HttpURLConnection conn = null;
   try {
     StringBuilder urlMaker = new StringBuilder(url);
     if (!params.isEmpty()) {
       Escaper escaper = UrlEscapers.urlPathSegmentEscaper();
       urlMaker.append('?');
       for (Map.Entry<String, String> entry : params.entrySet()) {
         urlMaker.append(escaper.escape(entry.getKey()));
         urlMaker.append('=');
         urlMaker.append(escaper.escape(entry.getValue()));
         urlMaker.append('&');
       }
     }
     URL javaUrl = new URL(urlMaker.toString());
     conn = (HttpURLConnection) javaUrl.openConnection();
     conn.setDoOutput(true);
     conn.setRequestMethod("POST");
     if (!data.isNull()) {
       writeData(conn);
     }
     underlyingInputStream = conn.getInputStream();
     bundleizer = format.createBundleizer(underlyingInputStream, new ListBundle());
   } catch (Exception outer) {
     if (conn != null && conn.getErrorStream() != null) {
       try {
         log.error(
             "URL connection was unsuccessful. Response is {}",
             new String(ByteStreams.toByteArray(conn.getErrorStream())));
       } catch (IOException inner) {
         log.error("During connection error failure to read error stream: ", inner);
       }
     }
     throw Throwables.propagate(outer);
   }
 }