Search in sources :

Example 16 with URLString

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

the class MappedResolver method retrieveAndCache.

@Override
protected InputStream retrieveAndCache(URLString url) throws Exception {
    String key = url.toString();
    String candidate = getMappings().getValueIgnoringKeyCase(key);
    if (!isEmpty(candidate)) {
        debugLog("[{}] mapped to [{}]", key, candidate);
        return super.retrieveAndCache(new URLString(candidate));
    }
    debugLog("No mapping for [{}]; using as-is", key);
    return super.retrieveAndCache(url);
}
Also used : URLString(com.adaptris.util.URLString) URLString(com.adaptris.util.URLString)

Example 17 with URLString

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

the class Resolver method resolveEntity.

/**
 * @see EntityResolver#resolveEntity(String, String)
 */
@Override
public InputSource resolveEntity(String publicId, String systemId) throws SAXException {
    debugLog("Resolving [{}][{}]", publicId, systemId);
    InputSource result = null;
    try {
        InputSource ret = new InputSource(retrieveAndCache(new URLString(systemId)));
        ret.setPublicId(publicId);
        ret.setSystemId(systemId);
        result = ret;
    } catch (Exception e) {
        debugLog("Couldn't handle [{}][{}], fallback to default parser behaviour", publicId, systemId);
        result = null;
    }
    return result;
}
Also used : InputSource(org.xml.sax.InputSource) URLString(com.adaptris.util.URLString) TransformerException(javax.xml.transform.TransformerException) SAXException(org.xml.sax.SAXException)

Example 18 with URLString

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

the class Resolver method resolve.

/**
 * @see URIResolver#resolve(java.lang.String, java.lang.String)
 */
@Override
public Source resolve(String href, String base) throws TransformerException {
    debugLog("Resolving [{}][{}]", href, base);
    StreamSource result = null;
    try {
        URL myUrl = null;
        try {
            myUrl = new URL(href);
        } catch (Exception ex) {
            // Indicates that the URL was probably relative and therefore Malformed
            int end = base.lastIndexOf('/');
            String url = base.substring(0, end + 1);
            myUrl = new URL(url + href);
        }
        result = new StreamSource(retrieveAndCache(new URLString(myUrl)), myUrl.toExternalForm());
    } catch (Exception e) {
        debugLog("Couldn't handle [{}][{}], fallback to default parser behaviour", href, base);
        result = null;
    }
    return result;
}
Also used : StreamSource(javax.xml.transform.stream.StreamSource) URLString(com.adaptris.util.URLString) URLString(com.adaptris.util.URLString) URL(java.net.URL) TransformerException(javax.xml.transform.TransformerException) SAXException(org.xml.sax.SAXException)

Example 19 with URLString

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

the class Resolver method retrieveAndCache.

protected InputStream retrieveAndCache(URLString url) throws Exception {
    String key = url.toString();
    InputStream result = null;
    if (!hm.containsKey(key)) {
        debugLog("Nothing in cache for [{}]", key);
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        StreamUtil.copyAndClose(URLHelper.connect(url), output);
        hm.put(key, output);
        result = new ByteArrayInputStream(output.toByteArray());
    } else {
        debugLog("Resolved from cache [{}]", key);
        result = new ByteArrayInputStream(hm.get(key).toByteArray());
    }
    return result;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) URLString(com.adaptris.util.URLString) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 20 with URLString

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

the class AdapterRegistry method persistAdapter.

@Override
public void persistAdapter(ObjectName adapter, String url) throws CoreException, IOException {
    assertNotNull(url, EXCEPTION_MSG_URL_NULL);
    persistAdapter(adapter, new URLString(url));
}
Also used : URLString(com.adaptris.util.URLString)

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