List of usage examples for org.apache.commons.httpclient HttpMethodBase HttpMethodBase
public HttpMethodBase()
From source file:com.cyberway.issue.crawler.extractor.ExtractorTool.java
protected CrawlURI getCrawlURI(final ARCRecord record, final HttpRecorder hr) throws URIException { CrawlURI curi = new CrawlURI(UURIFactory.getInstance(record.getMetaData().getUrl())); curi.setContentSize(record.getMetaData().getLength()); curi.setContentType(record.getMetaData().getMimetype()); curi.setHttpRecorder(hr);//w ww . ja v a 2 s . c om // Fake out the extractor that this is a legit HTTP transaction. if (!curi.getUURI().getScheme().equals("filedesc")) { curi.putObject(CoreAttributeConstants.A_HTTP_TRANSACTION, new HttpMethodBase() { public String getName() { return this.getClass().getName() + "_method"; } public Header getResponseHeader(String headerName) { String value = (String) record.getMetaData().getHeaderValue(headerName); return (value == null || value.length() == 0) ? null : new Header(headerName, value); } }); String statusCode = record.getMetaData().getStatusCode(); curi.setFetchStatus(statusCode == null ? 200 : Integer.parseInt(statusCode)); } return curi; }
From source file:org.geoserver.security.iride.IrideRoleServiceTest.java
/** * @param createRoleService//from w ww.j ava 2 s . c o m * @return * @throws UnsupportedEncodingException */ private IrideRoleService wrapRoleService(final IrideRoleService roleService, final String roleName) throws UnsupportedEncodingException { IrideRoleService wrapped = spy(roleService); when(wrapped.createHttpMethod(anyString())).thenAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); final String requestXml = args[0].toString(); IrideRoleService mock = (IrideRoleService) invocation.getMock(); mock.getHttpClient().setState(new HttpState() { @Override public synchronized String toString() { return requestXml; } }); return new HttpMethodBase() { @Override public String getName() { return "FileMethod"; } @Override public String getResponseBodyAsString() throws IOException { InputStream in = getClass().getResource("/" + roleName + ".xml").openStream(); try { return IOUtils.toString(in); } finally { IOUtils.closeQuietly(in); } } }; } }); return wrapped; }