protected String getUri(String... paths) { String uri = client.getHostConfiguration().getHostURL(); for (String path : paths) { uri += '/' + path; } return uri; }
private String executeGetMethod(GetMethod get) { LOGGER.debug("Making HTTP request to fetch OpenMRS Atom Feed: " + httpClient.getHostConfiguration().getHostURL() + get.getPath() + get.getQueryString()); try { int responseCode = httpClient.executeMethod(get); if (responseCode == HttpStatus.SC_OK) { LOGGER.debug("Successfully made HTTP request to OpenMRS"); return get.getResponseBodyAsString(); } else { LOGGER.warn("OpenMRS Atom Feed module returned non 200 status: " + get.getStatusCode()); return ""; } } catch (IOException e) { LOGGER.error("Motech OpenMRS Atom Feed module could not communicate with the OpenMRS"); throw new MotechException(e.getMessage(), e); } }
public class MyHTTPConnectionManager extends SimpleHttpConnectionManager { @Override public HttpConnection getConnectionWithTimeout( HostConfiguration hostConfiguration, long timeout) { HttpConnection hc = super.getConnectionWithTimeout(hostConfiguration, timeout); try { URI uri = new URI( hostConfiguration.getHostURL()); List<Proxy> hostProxies = ProxySelector.getDefault().select(uri); Proxy Proxy = hostProxies.get(0); InetSocketAddress sa = (InetSocketAddress) Proxy.address(); hc.setProxyHost(sa.getHostName()); hc.setProxyPort(sa.getPort()); } catch (URISyntaxException e) { return hc; } return hc; } }
protected String getEscapedUrlFromPath(String escapedPath) throws URIException { URI uri = new URI(httpClient.getHostConfiguration().getHostURL(), true); uri.setEscapedPath(escapedPath); return uri.getEscapedURI(); }
/** Simple means to return the search result as an InputStream */ public java.io.InputStream searchAsInputStream(DiscoverQuery query) throws SearchServiceException, java.io.IOException { try { org.apache.commons.httpclient.methods.GetMethod method = new org.apache.commons.httpclient.methods.GetMethod(getSolr().getHttpClient().getHostConfiguration().getHostURL() + ""); method.setQueryString(query.toString()); getSolr().getHttpClient().executeMethod(method); return method.getResponseBodyAsStream(); } catch (org.apache.solr.client.solrj.SolrServerException e) { throw new SearchServiceException(e.getMessage(), e); } }
String solrurl = httpClient.getHostConfiguration().getHostURL() + httpClientAndBaseUrl.getSecond(); url.append(solrurl);
@Before public void setUp() throws Exception { initMocks(this); // Set up the mock HTTP call method on the class under test. doReturn(mockResultSet).when(solrSQLHttpClient).postSolrQuery(any(HttpClient.class), anyString(), bodyCaptor.capture(), // Capture the supplied HTTP request body. any(SolrJsonProcessor.class)); // Set up the store configuration. when(mockSearchParameters.getStores()).thenReturn(new ArrayList(asList(STORE_REF))); HashMap<StoreRef, SolrStoreMappingWrapper> mappingLookup = new HashMap<>(); mappingLookup.put(STORE_REF, mockSolrStoreMappingWrapper); // Set up the HTTP configuration. solrSQLHttpClient.setMappingLookup(mappingLookup); when(mockHttpClient.getHostConfiguration()).thenReturn(mockHostConfiguration); when(mockHostConfiguration.getHostURL()).thenReturn("hostURL"); Pair<HttpClient, String> httpClientAndBaseUrl = new Pair<>(mockHttpClient, "baseURL"); when(mockSolrStoreMappingWrapper.getHttpClientAndBaseUrl()).thenReturn(httpClientAndBaseUrl); // Set up the other services. when(mockPermissionService.getAuthorisations()).thenReturn(emptySet()); when(mockTenantService.getCurrentUserDomain()).thenReturn("currentUserDomain"); when(mockSearchParameters.getQuery()).thenReturn("statement"); }
String solrurl = httpClient.getHostConfiguration().getHostURL() + httpClientAndBaseUrl.getSecond(); url.append(solrurl);
protected void checkPublicFolder() { synchronized (httpClient.getState()) { Cookie[] currentCookies = httpClient.getState().getCookies(); // check public folder access try { publicFolderUrl = httpClient.getHostConfiguration().getHostURL() + PUBLIC_ROOT; DavPropertyNameSet davPropertyNameSet = new DavPropertyNameSet(); davPropertyNameSet.add(Field.getPropertyName("displayname")); PropFindMethod propFindMethod = new PropFindMethod(publicFolderUrl, davPropertyNameSet, 0); try { DavGatewayHttpClientFacade.executeMethod(httpClient, propFindMethod); } catch (IOException e) { // workaround for NTLM authentication only on /public if (!DavGatewayHttpClientFacade.hasNTLMorNegotiate(httpClient)) { DavGatewayHttpClientFacade.addNTLM(httpClient); DavGatewayHttpClientFacade.executeMethod(httpClient, propFindMethod); } } // update public folder URI publicFolderUrl = propFindMethod.getURI().getURI(); } catch (IOException e) { // restore cookies on error httpClient.getState().addCookies(currentCookies); LOGGER.warn("Public folders not available: " + (e.getMessage() == null ? e : e.getMessage())); // default public folder path publicFolderUrl = PUBLIC_ROOT; } } }