List of usage examples for org.springframework.util Base64Utils encodeToString
public static String encodeToString(byte[] src)
From source file:com.linecorp.bot.client.LineSignatureValidatorTest.java
@Test public void generateSignature() throws Exception { LineSignatureValidator lineSignatureValidator = new LineSignatureValidator( channelSecret.getBytes(StandardCharsets.UTF_8)); String httpRequestBody = "{}"; byte[] headerSignature = lineSignatureValidator .generateSignature(httpRequestBody.getBytes(StandardCharsets.UTF_8)); assertThat(Base64Utils.encodeToString(headerSignature)) .isEqualTo("3q8QXTAGaey18yL8FWTqdVlbMr6hcuNvM4tefa0o9nA="); }
From source file:org.grails.datastore.bson.json.JsonWriter.java
@Override protected void doWriteBinaryData(BsonBinary value) { try {//from www .j a v a2 s. c om writeNameHelper(getName()); byte[] data = value.getData(); writer.write(Base64Utils.encodeToString(data)); setState(getNextState()); } catch (IOException e) { throwBsonException(e); } }
From source file:com.example.ProxyAuthorizationServerTokenServices.java
private HttpHeaders createHeaders() { HttpHeaders headers = new HttpHeaders(); headers.set("Authorization", "Basic " + Base64Utils.encodeToString("cf:".getBytes())); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); return headers; }
From source file:com.github.wnameless.spring.bulkapi.test.BulkApiTest.java
@Test public void bulkRequestCanNotContainBulkPathAsUrl() throws Exception { BulkRequest req = new BulkRequest(); BulkOperation op = new BulkOperation(); op.setUrl(bulkPath);/*w w w . ja v a2 s .c o m*/ op.setMethod("GET"); op.getHeaders().put("Authorization", "Basic " + Base64Utils.encodeToString("user:password".getBytes())); req.getOperations().add(op); HttpEntity entity = new ByteArrayEntity(mapper.writeValueAsString(req).getBytes("UTF-8")); post.setEntity(entity); HttpResponse response = client.execute(post); assertTrue(422 == response.getStatusLine().getStatusCode()); }
From source file:com.github.wnameless.spring.bulkapi.test.BulkApiTest.java
@Test public void bulkRequestToComplexMapping() throws Exception { BulkRequest req = new BulkRequest(); BulkOperation op = new BulkOperation(); op.setUrl("/home2/AAA/ccc"); op.setMethod("PUT"); op.getHeaders().put("Authorization", "Basic " + Base64Utils.encodeToString("user:password".getBytes())); req.getOperations().add(op);/*w w w . j a va2 s . c o m*/ HttpEntity entity = new ByteArrayEntity(mapper.writeValueAsString(req).getBytes("UTF-8")); post.setEntity(entity); HttpResponse response = client.execute(post); assertTrue(200 == response.getStatusLine().getStatusCode()); }
From source file:com.github.wnameless.spring.bulkapi.test.BulkApiTest.java
@Test public void bulkRequestToWrongMapping() throws Exception { BulkRequest req = new BulkRequest(); BulkOperation op = new BulkOperation(); op.setUrl("/home2/BBB/ccc"); op.setMethod("PUT"); op.getHeaders().put("Authorization", "Basic " + Base64Utils.encodeToString("user:password".getBytes())); req.getOperations().add(op);//from ww w . j av a2 s. com HttpEntity entity = new ByteArrayEntity(mapper.writeValueAsString(req).getBytes("UTF-8")); post.setEntity(entity); HttpResponse response = client.execute(post); assertTrue(422 == response.getStatusLine().getStatusCode()); }
From source file:com.github.wnameless.spring.bulkapi.test.BulkApiTest.java
@Test public void bulkRequestToNonBulkableMapping() throws Exception { BulkRequest req = new BulkRequest(); BulkOperation op = new BulkOperation(); op.setUrl("home3"); op.setMethod("PUT"); op.getHeaders().put("Authorization", "Basic " + Base64Utils.encodeToString("user:password".getBytes())); req.getOperations().add(op);/* w w w . j a va2 s . co m*/ HttpEntity entity = new ByteArrayEntity(mapper.writeValueAsString(req).getBytes("UTF-8")); post.setEntity(entity); HttpResponse response = client.execute(post); assertTrue(422 == response.getStatusLine().getStatusCode()); }
From source file:com.github.wnameless.spring.bulkapi.test.BulkApiTest.java
@Test public void bulkRequestWithParam() throws Exception { BulkRequest req = new BulkRequest(); BulkOperation op = new BulkOperation(); op.setUrl("/home4"); op.setMethod("POST"); op.getHeaders().put("Authorization", "Basic " + Base64Utils.encodeToString("user:password".getBytes())); op.getParams().put("abc", "abc"); req.getOperations().add(op);// w w w . ja va2 s. c o m HttpEntity entity = new ByteArrayEntity(mapper.writeValueAsString(req).getBytes("UTF-8")); post.setEntity(entity); HttpResponse response = client.execute(post); assertTrue(200 == response.getStatusLine().getStatusCode()); }
From source file:org.kaaproject.kaa.server.common.admin.AdminClient.java
/** * Provides security credentials, allowing an endpoint that uses them to * interact with the specified application. * * @param applicationToken the application token to allow interaction with * @param credentialsBody the security credentials to save *//*from w ww. j av a2s . c om*/ public CredentialsDto provisionCredentials(String applicationToken, byte[] credentialsBody) { MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<>(); parameters.add("applicationToken", applicationToken); parameters.add("credentialsBody", Base64Utils.encodeToString(credentialsBody)); return this.restTemplate.postForObject(restTemplate.getUrl() + "provisionCredentials", parameters, CredentialsDto.class); }
From source file:org.kaaproject.kaa.server.common.dao.service.InternalCredentialsService.java
@Override public CredentialsDto provideCredentials(String applicationId, CredentialsDto credentials) throws CredentialsServiceException { Validate.notBlank(applicationId, "Invalid application ID provided!"); Validate.notNull(credentials, "Invalid credentials provided!"); try {// w w w. j a v a2 s .co m byte[] credentialsBody = credentials.getCredentialsBody(); credentials.setId(Base64Utils.encodeToString(Sha1HashUtils.hashToBytes(credentialsBody))); return this.credentialsDao.save(applicationId, credentials).toDto(); } catch (Exception cause) { String message = MessageFormat .format("[{0}] An unexpected exception occured while saving " + "credentials!", applicationId); LOG.error(message, cause); throw new CredentialsServiceException(cause); } }