use of org.springframework.core.io.ByteArrayResource in project cas by apereo.
the class RestSamlRegisteredServiceMetadataResolverTests method setup.
@Before
@SneakyThrows
public void setup() {
final SamlMetadataDocument doc = new SamlMetadataDocument();
doc.setId(1);
doc.setName("SAML Document");
doc.setSignature(null);
doc.setValue(IOUtils.toString(new ClassPathResource("sp-metadata.xml").getInputStream(), StandardCharsets.UTF_8));
final String data = MAPPER.writeValueAsString(doc);
this.webServer = new MockWebServer(8078, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_XML_VALUE);
this.webServer.start();
}
use of org.springframework.core.io.ByteArrayResource in project leopard by tanhaichao.
the class LeopardSqlSessionFactoryIntegrationTest method replaceResource.
@Test
public void replaceResource() throws IOException {
String content = "ok";
Resource resource = new ByteArrayResource(content.getBytes());
InputStream is = resource.getInputStream();
String str = IOUtils.toString(is);
System.err.println("str:" + str + " resource:" + resource.toString());
}
use of org.springframework.core.io.ByteArrayResource in project OpenClinica by OpenClinica.
the class CreateXformCRFVersionServlet method getFormArtifactsFromFM.
private FormArtifactTransferObj getFormArtifactsFromFM(List<FileItem> files, String studyOid, String crfName) {
LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
ArrayList<ByteArrayResource> byteArrayResources = new ArrayList<>();
RestTemplate restTemplate = new RestTemplate();
String uploadFilesUrl = FM_BASEURL + studyOid + "/forms/" + crfName + "/artifacts";
map.add("file", byteArrayResources);
for (FileItem file : files) {
String filename = file.getName();
if (!file.isFormField()) {
ByteArrayResource contentsAsResource = new ByteArrayResource(file.get()) {
@Override
public String getFilename() {
return filename;
}
};
map.get("file").add(contentsAsResource);
}
}
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
HttpEntity<LinkedMultiValueMap<String, Object>> requestEntity = new HttpEntity<>(map, headers);
// TODO: replace with Crf object instead of String object
FormArtifactTransferObj response = restTemplate.postForObject(uploadFilesUrl, requestEntity, FormArtifactTransferObj.class);
return response;
}
use of org.springframework.core.io.ByteArrayResource in project opennms by OpenNMS.
the class SnmpPeerFactoryTest method testSnmpv3WithNoAuthNoPriv.
public void testSnmpv3WithNoAuthNoPriv() throws Exception {
SnmpPeerFactory.setInstance(new SnmpPeerFactory(new ByteArrayResource(getSnmpConfig().getBytes())));
SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr("10.11.12.13"));
assertEquals("opennmsuser1", agentConfig.getSecurityName());
assertEquals("VF:2", agentConfig.getContextName());
assertNull(agentConfig.getAuthProtocol());
assertNull(agentConfig.getPrivProtocol());
assertNull(agentConfig.getAuthPassPhrase());
assertNull(agentConfig.getPrivPassPhrase());
assertEquals(1, agentConfig.getSecurityLevel());
agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr("10.11.12.14"));
assertEquals("opennmsuser2", agentConfig.getSecurityName());
assertEquals("VF:3", agentConfig.getContextName());
assertEquals("", agentConfig.getAuthProtocol());
assertEquals("", agentConfig.getPrivProtocol());
assertEquals("", agentConfig.getAuthPassPhrase());
assertEquals("", agentConfig.getPrivPassPhrase());
assertEquals(1, agentConfig.getSecurityLevel());
agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr(myLocalHost()));
assertEquals(3, agentConfig.getSecurityLevel());
}
use of org.springframework.core.io.ByteArrayResource in project opennms by OpenNMS.
the class SnmpPeerFactoryTest method testReversedRange.
/**
* This tests for ranges configured for a v2 node and community string
*
* @throws UnknownHostException
*/
public void testReversedRange() throws UnknownHostException {
SnmpPeerFactory.setInstance(new SnmpPeerFactory(new ByteArrayResource(getBadRangeSnmpConfig().getBytes())));
SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr("10.7.23.100"));
assertNotNull(agentConfig);
assertEquals(SnmpAgentConfig.VERSION2C, agentConfig.getVersion());
assertEquals("rangev2c", agentConfig.getReadCommunity());
}
Aggregations