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);
}
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;
}
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);
}
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));
}
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;
}
Aggregations