Search in sources :

Example 21 with URLString

use of com.adaptris.util.URLString in project interlok by adaptris.

the class VersionedHttpsProduceConnection method initialiseClient.

/**
 * @see HttpClientConnection#initialiseClient(java.lang.String)
 */
@Override
public HttpClientTransport initialiseClient(String url) throws HttpException {
    HttpsClient client = new HttpsClient(new URLString(url), protocolVersion);
    try {
        if (getKeystore() != null) {
            KeystoreFactory ksf = KeystoreFactory.getDefault();
            KeystoreLocation ksl = null;
            if (getKeystorePassword() != null) {
                ksl = ksf.create(getKeystore(), Password.decode(getKeystorePassword()).toCharArray());
            } else {
                ksl = ksf.create(getKeystore());
            }
            char[] pkpw = PasswordOverride.discoverPrivateKeyPassword(ksl, getPrivateKeyPasswordProvider());
            if (pkpw != null) {
                client.registerPrivateKeyPassword(pkpw);
            }
            client.registerKeystore(ksf.create(ksl));
        }
    } catch (AdaptrisSecurityException e) {
        throw new HttpException(e);
    }
    client.setAlwaysTrust(getAlwaysTrust());
    return client;
}
Also used : KeystoreLocation(com.adaptris.security.keystore.KeystoreLocation) HttpsClient(com.adaptris.http.HttpsClient) AdaptrisSecurityException(com.adaptris.security.exc.AdaptrisSecurityException) KeystoreFactory(com.adaptris.security.keystore.KeystoreFactory) HttpException(com.adaptris.http.HttpException) URLString(com.adaptris.util.URLString)

Example 22 with URLString

use of com.adaptris.util.URLString in project interlok by adaptris.

the class MarshallingBaseCase method testUnmarshalFromURLString.

@Test
public void testUnmarshalFromURLString() throws Exception {
    AdaptrisMarshaller marshaller = createMarshaller();
    Adapter adapter = createMarshallingObject();
    File f = new File(testOutputDir, new GuidGenerator().getUUID());
    marshaller.marshal(adapter, f);
    assertRoundtripEquality(adapter, marshaller.unmarshal(new URLString(f.toURI().toURL())));
}
Also used : AdaptrisMarshaller(com.adaptris.core.AdaptrisMarshaller) Adapter(com.adaptris.core.Adapter) GuidGenerator(com.adaptris.util.GuidGenerator) File(java.io.File) URLString(com.adaptris.util.URLString) Test(org.junit.Test)

Example 23 with URLString

use of com.adaptris.util.URLString in project interlok by adaptris.

the class MarshallingBaseCase method testUnmarshalFromUrlStringClasspath.

@Test
public void testUnmarshalFromUrlStringClasspath() throws Exception {
    AdaptrisMarshaller marshaller = createMarshaller();
    StandaloneProducer o1 = (StandaloneProducer) marshaller.unmarshal(new URLString(getClasspathXmlFilename()));
    assertEquals("unique-id", o1.getUniqueId());
    String unknownLoc = "zzzz-does-not-exist.xml";
    try {
        o1 = (StandaloneProducer) marshaller.unmarshal(new URLString(unknownLoc));
        fail("Success unmarshal of something that doesn't exist");
    } catch (CoreException e) {
        assertNotNull(e.getCause());
        assertTrue(IOException.class.isAssignableFrom(e.getCause().getClass()));
    }
}
Also used : CoreException(com.adaptris.core.CoreException) AdaptrisMarshaller(com.adaptris.core.AdaptrisMarshaller) URLString(com.adaptris.util.URLString) URLString(com.adaptris.util.URLString) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 24 with URLString

use of com.adaptris.util.URLString in project interlok by adaptris.

the class AdapterRegistryTest method testMultiPreProcessorCalled.

@Test
public void testMultiPreProcessorCalled() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName, 2, 2);
    File filename = deleteLater(adapter);
    DefaultMarshaller.getDefaultMarshaller().marshal(adapter, filename);
    AdapterRegistry myAdapterRegistry = (AdapterRegistry) AdapterRegistry.findInstance(new JunitBootstrapProperties(new Properties()));
    AdapterBuilder builder = new ArrayList<AdapterBuilder>(myAdapterRegistry.builders()).get(0);
    builder.setConfigurationPreProcessorLoader(mockPreProcessorLoader);
    ConfigPreProcessors preProcessorsList = new ConfigPreProcessors();
    preProcessorsList.add(mockPreProcessor);
    preProcessorsList.add(mockPreProcessor);
    preProcessorsList.add(mockPreProcessor);
    when(mockPreProcessorLoader.load(any(BootstrapProperties.class))).thenReturn(preProcessorsList);
    when(mockPreProcessor.process(any(String.class))).thenReturn(FileUtils.readFileToString(filename));
    myAdapterRegistry.createAdapter(new URLString(filename));
    // Make sure our pre-processors are called - even though our pre-processors do nothing!
    verify(mockPreProcessor, times(3)).process(any(String.class));
}
Also used : ConfigPreProcessors(com.adaptris.core.config.ConfigPreProcessors) BootstrapProperties(com.adaptris.core.management.BootstrapProperties) JunitBootstrapProperties(com.adaptris.core.stubs.JunitBootstrapProperties) JunitBootstrapProperties(com.adaptris.core.stubs.JunitBootstrapProperties) Adapter(com.adaptris.core.Adapter) URLString(com.adaptris.util.URLString) BootstrapProperties(com.adaptris.core.management.BootstrapProperties) JunitBootstrapProperties(com.adaptris.core.stubs.JunitBootstrapProperties) Properties(java.util.Properties) File(java.io.File) URLString(com.adaptris.util.URLString) Test(org.junit.Test)

Example 25 with URLString

use of com.adaptris.util.URLString in project interlok by adaptris.

the class AdapterRegistryTest method testGetConfigurationURL.

@Test
public void testGetConfigurationURL() throws Exception {
    AdapterRegistry adapterRegistry = (AdapterRegistry) AdapterRegistry.findInstance(new JunitBootstrapProperties(new Properties()));
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName, 2, 2);
    File filename = deleteLater(adapter);
    DefaultMarshaller.getDefaultMarshaller().marshal(adapter, filename);
    URLString expectedURL = new URLString(filename);
    ObjectName objName = adapterRegistry.createAdapter(expectedURL);
    assertNotNull(objName);
    assertTrue(mBeanServer.isRegistered(objName));
    assertEquals(expectedURL, adapterRegistry.getConfigurationURL(objName));
}
Also used : JunitBootstrapProperties(com.adaptris.core.stubs.JunitBootstrapProperties) Adapter(com.adaptris.core.Adapter) URLString(com.adaptris.util.URLString) BootstrapProperties(com.adaptris.core.management.BootstrapProperties) JunitBootstrapProperties(com.adaptris.core.stubs.JunitBootstrapProperties) Properties(java.util.Properties) File(java.io.File) URLString(com.adaptris.util.URLString) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Aggregations

URLString (com.adaptris.util.URLString)32 Test (org.junit.Test)21 Adapter (com.adaptris.core.Adapter)19 File (java.io.File)19 BootstrapProperties (com.adaptris.core.management.BootstrapProperties)18 JunitBootstrapProperties (com.adaptris.core.stubs.JunitBootstrapProperties)18 Properties (java.util.Properties)18 ObjectName (javax.management.ObjectName)14 AdaptrisMarshaller (com.adaptris.core.AdaptrisMarshaller)3 ConfigPreProcessors (com.adaptris.core.config.ConfigPreProcessors)2 GuidGenerator (com.adaptris.util.GuidGenerator)2 InputStream (java.io.InputStream)2 TransformerException (javax.xml.transform.TransformerException)2 SAXException (org.xml.sax.SAXException)2 CoreException (com.adaptris.core.CoreException)1 StandaloneProducer (com.adaptris.core.StandaloneProducer)1 DummyConfigurationPreProcessor (com.adaptris.core.config.DummyConfigurationPreProcessor)1 HttpException (com.adaptris.http.HttpException)1 HttpsClient (com.adaptris.http.HttpsClient)1 AdaptrisSecurityException (com.adaptris.security.exc.AdaptrisSecurityException)1