Search in sources :

Example 11 with URLString

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

the class HttpClientTransport method handleRedirection.

/**
 * Handle a redirected input.
 * <p>
 *
 * @param input The input stream to be resent.
 * @return InputStream the resulting data from the Http server
 */
private HttpSession handleRedirection(HttpSession session, HttpMessage input, int timeout) throws IOException, HttpException {
    URLString newUrl = null;
    HttpHeaders receiveHeader = session.getResponseMessage().getHeaders();
    // 301 / 302 gives us a Location: <newlocation>
    if (!receiveHeader.containsHeader(Http.LOCATION)) {
        throw (new IOException("Re-direction, but to nowhere!"));
    }
    if ((++redirectCount) > MAX_REDIRECTS) {
        throw (new IOException("Maxiumum number of redirects has been reached :" + MAX_REDIRECTS));
    }
    logR.debug("Redirection enabled, and attempting to handle");
    // Get the new URL
    String newUrlString = (String) receiveHeader.get(Http.LOCATION);
    newUrl = mergeUrl(currentUrl, newUrlString);
    if (urlList.contains(newUrl.toString())) {
        throw (new IOException("Possible recursive redirection, location " + newUrl + " already visited"));
    }
    // The new Location could be a
    // http://localhost:8888/NasApp/ICOE/B2BTest?datatype=CIDX201
    // or a /NasApp/ICOE/B2BTest?datatype=CIDX201
    logR.trace("Current uri " + currentUrl + " is being redirected to " + newUrl);
    setUrl(newUrl.toString());
    if (!newUrl.getHost().equals(currentUrl.getHost())) {
        input.getHeaders().put(Http.HOST, currentUrl.getHost());
    }
    session.close();
    return this.send(input, timeout, true);
}
Also used : IOException(java.io.IOException) URLString(com.adaptris.util.URLString) URLString(com.adaptris.util.URLString)

Example 12 with URLString

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

the class HttpClientTransport method mergeUrl.

/**
 * Merge a URLString object with an arbitary string. if original is
 * http://localhost:8888/FRED/FRED?datatype=CIDX201 and newurl =
 * /NasApp/ICOE/B2BTest?datatype=CIDX201 then the merged url should be
 * http://localhost:8888/NasApp/ICOE/B2BTest?datatype=CIDX201
 */
private static URLString mergeUrl(URLString orig, String newurl) {
    URLString temp = null;
    do {
        temp = new URLString(newurl);
        if (orig == null) {
            break;
        }
        StringBuffer sb = new StringBuffer();
        sb.append((temp.getProtocol() != null) ? temp.getProtocol() : orig.getProtocol());
        sb.append("://");
        sb.append((temp.getHost() != null) ? temp.getHost() : orig.getHost());
        sb.append(":");
        sb.append((temp.getPort() != -1) ? temp.getPort() : orig.getPort());
        sb.append("/");
        sb.append((temp.getFile() != null) ? temp.getFile() : orig.getFile());
        temp = new URLString(sb.toString());
    } while (false);
    return temp;
}
Also used : URLString(com.adaptris.util.URLString)

Example 13 with URLString

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

the class MarshallingBaseCase method testUnmarshalFromUrlStringLocalFile.

@Test
public void testUnmarshalFromUrlStringLocalFile() throws Exception {
    AdaptrisMarshaller marshaller = createMarshaller();
    Adapter adapter = createMarshallingObject();
    File f = new File(testOutputDir, new GuidGenerator().getUUID());
    String fname = f.getCanonicalPath();
    if (Os.isFamily(Os.WINDOWS_FAMILY)) {
        // THis is juist to remove c: and leave us with \blah.
        fname = f.getCanonicalPath().substring(2).replaceAll("\\\\", "/");
    }
    marshaller.marshal(adapter, f);
    Adapter o2 = (Adapter) marshaller.unmarshal(new URLString(fname));
    assertRoundtripEquality(adapter, o2);
}
Also used : AdaptrisMarshaller(com.adaptris.core.AdaptrisMarshaller) Adapter(com.adaptris.core.Adapter) GuidGenerator(com.adaptris.util.GuidGenerator) URLString(com.adaptris.util.URLString) File(java.io.File) URLString(com.adaptris.util.URLString) Test(org.junit.Test)

Example 14 with URLString

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

the class AdapterRegistry method persistAdapter.

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

Example 15 with URLString

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

the class BootstrapProperties method findAdapterResource.

public String findAdapterResource() {
    String[] urls = getConfigurationUrls();
    String adapterXml = null;
    for (int i = 0; i < urls.length; i++) {
        if (DBG) {
            log.trace("trying [{}]", urls[i]);
        }
        if (i == 0) {
            primaryUrl = new URLString(urls[i]);
            if (checkExists(primaryUrl)) {
                adapterXml = urls[i];
                break;
            } else {
                primaryUrl = null;
            }
        } else {
            if (checkExists(new URLString(urls[i]))) {
                adapterXml = urls[i];
                break;
            }
        }
    }
    return adapterXml;
}
Also used : URLString(com.adaptris.util.URLString) 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