Search in sources :

Example 46 with ByteArrayResource

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();
}
Also used : MockWebServer(org.apereo.cas.util.MockWebServer) SamlMetadataDocument(org.apereo.cas.support.saml.services.idp.metadata.SamlMetadataDocument) ByteArrayResource(org.springframework.core.io.ByteArrayResource) ClassPathResource(org.springframework.core.io.ClassPathResource) Before(org.junit.Before) SneakyThrows(lombok.SneakyThrows)

Example 47 with ByteArrayResource

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());
}
Also used : InputStream(java.io.InputStream) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Resource(org.springframework.core.io.Resource) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.Test)

Example 48 with ByteArrayResource

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;
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ArrayList(java.util.ArrayList) ByteArrayResource(org.springframework.core.io.ByteArrayResource) FileItem(org.apache.commons.fileupload.FileItem) FormArtifactTransferObj(org.akaza.openclinica.service.crfdata.FormArtifactTransferObj) RestTemplate(org.springframework.web.client.RestTemplate) ExecuteIndividualCrfObject(org.akaza.openclinica.service.crfdata.ExecuteIndividualCrfObject)

Example 49 with ByteArrayResource

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());
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) ByteArrayResource(org.springframework.core.io.ByteArrayResource)

Example 50 with ByteArrayResource

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());
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) ByteArrayResource(org.springframework.core.io.ByteArrayResource)

Aggregations

ByteArrayResource (org.springframework.core.io.ByteArrayResource)95 Test (org.junit.Test)67 Resource (org.springframework.core.io.Resource)32 Properties (java.util.Properties)26 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 JmsNorthbounderConfig (org.opennms.netmgt.alarmd.northbounder.jms.JmsNorthbounderConfig)6 JmsNorthbounderConfigDao (org.opennms.netmgt.alarmd.northbounder.jms.JmsNorthbounderConfigDao)6 InetAddress (java.net.InetAddress)5 ArrayList (java.util.ArrayList)5 LinkedList (java.util.LinkedList)5 Before (org.junit.Before)5 NorthboundAlarm (org.opennms.netmgt.alarmd.api.NorthboundAlarm)5 JmsDestination (org.opennms.netmgt.alarmd.northbounder.jms.JmsDestination)5 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)5 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)5 OnmsNode (org.opennms.netmgt.model.OnmsNode)5 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 MutablePropertySources (org.springframework.core.env.MutablePropertySources)4