本文整理匯總了Java中org.apache.commons.httpclient.HttpMethodBase類的典型用法代碼示例。如果您正苦於以下問題:Java HttpMethodBase類的具體用法?Java HttpMethodBase怎麽用?Java HttpMethodBase使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
HttpMethodBase類屬於org.apache.commons.httpclient包,在下文中一共展示了HttpMethodBase類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createMultiPartRequestContentWithDataTest
import org.apache.commons.httpclient.HttpMethodBase; //導入依賴的package包/類
/**
* Test
*
* @throws Exception
* Any exception
*/
@Test
public void createMultiPartRequestContentWithDataTest() throws Exception
{
String string="FILE_DATA";
File file=File.createTempFile("temp_",".txt");
file.deleteOnExit();
byte[] input=string.getBytes(IOHelper.getDefaultEncoding());
IOHelper.writeFile(input,file);
HTTPRequest httpRequest=new HTTPRequest();
ContentPart<?>[] parts=new ContentPart[5]; //make array bigger to simulate null parts
parts[0]=new ContentPart<String>("string_part","TEST_DATA",ContentPartType.STRING);
parts[1]=new ContentPart<String>("string_part2","TEST_DATA2",ContentPartType.STRING);
parts[2]=new ContentPart<File>("file_part",file,ContentPartType.FILE);
httpRequest.setContent(parts);
HttpMethodBase method=this.client.createMethod("http://fax4j.org",HTTPMethod.POST);
RequestEntity output=this.client.createMultiPartRequestContent(httpRequest,method);
file.delete();
Assert.assertNotNull(output);
Assert.assertEquals(MultipartRequestEntity.class,output.getClass());
}
示例2: setupHTTPRequestHeaderProperties
import org.apache.commons.httpclient.HttpMethodBase; //導入依賴的package包/類
/**
* This function sets the header properties in the HTTP method.
*
* @param httpRequest
* The HTTP request
* @param httpMethodClient
* The apache HTTP method
*/
protected void setupHTTPRequestHeaderProperties(HTTPRequest httpRequest,HttpMethodBase httpMethodClient)
{
//setup header properties
Properties headerProperties=httpRequest.getHeaderProperties();
if(headerProperties!=null)
{
Iterator<Entry<Object,Object>> iterator=headerProperties.entrySet().iterator();
Entry<Object,Object> entry=null;
while(iterator.hasNext())
{
//get next entry
entry=iterator.next();
//set header values
httpMethodClient.addRequestHeader((String)entry.getKey(),(String)entry.getValue());
}
}
}
示例3: setupHTTPRequestHeaderPropertiesWithDataTest
import org.apache.commons.httpclient.HttpMethodBase; //導入依賴的package包/類
/**
* Test
*
* @throws Exception
* Any exception
*/
@Test
public void setupHTTPRequestHeaderPropertiesWithDataTest() throws Exception
{
Properties headerProperties=new Properties();
headerProperties.setProperty("key1","value1");
headerProperties.setProperty("key2","value2");
headerProperties.setProperty("key3","value3");
HTTPRequest httpRequest=new HTTPRequest();
httpRequest.setHeaderProperties(headerProperties);
HttpMethodBase method=this.client.createMethod("http://fax4j.org",HTTPMethod.GET);
this.client.setupHTTPRequestHeaderProperties(httpRequest,method);
Header[] headers=method.getRequestHeaders();
Assert.assertEquals(3,headers.length);
Assert.assertEquals("value1",method.getRequestHeader("key1").getValue());
Assert.assertEquals("value2",method.getRequestHeader("key2").getValue());
Assert.assertEquals("value3",method.getRequestHeader("key3").getValue());
}
示例4: getDownloadWFSMethod
import org.apache.commons.httpclient.HttpMethodBase; //導入依賴的package包/類
/**
* When triggered, the wfs download service will call the Observations and Measurements WFS request,
* get the GeoSciML? output and compress it into a zip file for download. The user will have to
* first make a download request and come back to check the download status. When the download is
* completed, a link will be provided to download the requested Observations and Measurements output
* in zip format.
*
* This method will return a HTML stream
*
* @param serviceUrl The URL of the NVCLDataService
* @param email The user's email address
* @param boreholeId selected borehole id (use as feature id for filtering purpose)
* @param omUrl The valid url for the Observations and Measurements WFS
* @param typeName The url parameter for the wfs request
* @return
*/
public HttpMethodBase getDownloadWFSMethod(String serviceUrl, String email, String boreholeId, String omUrl, String typeName) {
GetMethod method = new GetMethod(urlPathConcat(serviceUrl, "downloadwfs.html"));
ArrayList<NameValuePair> valuePairs = new ArrayList<NameValuePair>();
//set all of the parameters
valuePairs.add(new NameValuePair("email", email));
valuePairs.add(new NameValuePair("boreholeid", boreholeId));
valuePairs.add(new NameValuePair("serviceurl", omUrl));
valuePairs.add(new NameValuePair("typename", typeName));
//attach them to the method
method.setQueryString((NameValuePair[]) valuePairs.toArray(new NameValuePair[valuePairs.size()]));
return method;
}
示例5: getAllBoreholes
import org.apache.commons.httpclient.HttpMethodBase; //導入依賴的package包/類
/**
* Get all boreholes from a given service url and return the response
* @param serviceURL
* @param bbox Set to the bounding box in which to fetch results, otherwise set it to null
* @param restrictToIDList [Optional] A list of gml:id values that the resulting filter should restrict its search space to
* @return
* @throws Exception
*/
public WFSTransformedResponse getAllBoreholes(String serviceURL, String boreholeName, String custodian, String dateOfDrilling, int maxFeatures, FilterBoundingBox bbox, List<String> restrictToIDList) throws Exception {
String filterString;
BoreholeFilter nvclFilter = new BoreholeFilter(boreholeName, custodian, dateOfDrilling, restrictToIDList);
if (bbox == null) {
filterString = nvclFilter.getFilterStringAllRecords();
} else {
filterString = nvclFilter.getFilterStringBoundingBox(bbox);
}
HttpMethodBase method = null;
try {
// Create a GetFeature request with an empty filter - get all
method = this.generateWFSRequest(serviceURL, "gsml:Borehole", null, filterString, maxFeatures, null, ResultType.Results);
String responseGml = this.httpServiceCaller.getMethodResponseAsString(method);
String responseKml = this.wfsToKml.convert(responseGml, serviceURL);
return new WFSTransformedResponse(responseGml, responseKml, method);
} catch (Exception ex) {
throw new PortalServiceException(method, ex);
}
}
示例6: testDoMineFilterAllMines
import org.apache.commons.httpclient.HttpMethodBase; //導入依賴的package包/類
/**
* Test doing a mine filter and getting all mines
* @throws Exception
*/
@Test
public void testDoMineFilterAllMines() throws Exception {
final String serviceURL = "http://localhost?";
final String mineName = ""; //to get all mines
final HttpMethodBase mockMethod = context.mock(HttpMethodBase.class);
final String expectedKML = "<kml/>";
final String expectedGML = "<gml/>";
context.checking(new Expectations() {{
allowing(mockMethod).getURI();will(returnValue(new URI(serviceURL, true)));
oneOf(mineralOccurrenceService).getMinesGml(serviceURL, mineName, null, 0);will(returnValue(new WFSTransformedResponse(expectedGML, expectedKML, mockMethod)));
}});
//call with updateCSWRecords dud url
ModelAndView modelAndView = this.earthResourcesFilterController.doMineFilter(serviceURL, mineName, null, 0);
//Ensure that we get a valid response
testMAVResponse(modelAndView, new Boolean(true), expectedGML, expectedKML);
}
示例7: getAllScalarConcepts
import org.apache.commons.httpclient.HttpMethodBase; //導入依賴的package包/類
/**
* Gets all RDF concepts at the specified repository as a single JENA Model. The results
* will be requested page by page until the entire repository has been traversed.
*
* @return
* @throws PortalServiceException
*/
public Model getAllScalarConcepts() throws PortalServiceException {
Model model = ModelFactory.createDefaultModel();
int pageNumber = 0;
int pageSize = this.getPageSize();
//Request each page in turn - put the results into Model
do {
HttpMethodBase method = ((NvclVocabMethodMaker)sissVocMethodMaker).getAllScalars(getBaseUrl(), getRepository(), Format.Rdf, pageSize, pageNumber);
if (requestPageOfConcepts(method, model)) {
pageNumber++;
} else {
break;
}
} while (true);
return model;
}
示例8: testHyloggerFilterNoDatasets
import org.apache.commons.httpclient.HttpMethodBase; //導入依賴的package包/類
/**
* Tests that hylogger filter uses the correct functions when the underlying hylogger lookup returns no results.
*
* @throws Exception the exception
*/
@Test
public void testHyloggerFilterNoDatasets() throws Exception {
final String serviceUrl = "http://fake.com/wfs";
final String nameFilter = "filterBob";
final String custodianFilter = "filterCustodian";
final String filterDate = "1986-10-09";
final int maxFeatures = 10;
final FilterBoundingBox bbox = new FilterBoundingBox("EPSG:4326", new double[] {1., 2.}, new double[] {3., 4.});
final boolean onlyHylogger = true;
final HttpMethodBase mockHttpMethodBase = context.mock(HttpMethodBase.class);
final URI httpMethodURI = new URI("http://example.com", true);
context.checking(new Expectations() {{
oneOf(mockBoreholeService).discoverHyloggerBoreholeIDs(with(equal(mockCSWService)),with(any(CSWRecordsFilterVisitor.class)));
will(returnValue(new ArrayList<String>()));
allowing(mockHttpMethodBase).getURI();
will(returnValue(httpMethodURI));
}});
ModelAndView response = this.nvclController.doBoreholeFilter(serviceUrl, nameFilter, custodianFilter, filterDate, maxFeatures, bbox, onlyHylogger);
Assert.assertFalse((Boolean) response.getModel().get("success"));
}
示例9: downloadMiningActivityGml
import org.apache.commons.httpclient.HttpMethodBase; //導入依賴的package包/類
/**
* Given a list of parameters, call a service and get the Mineral Activity features as GML/KML
* @param serviceURL
* @param mineName
* @param startDate
* @param endDate
* @param oreProcessed
* @param producedMaterial
* @param cutOffGrade
* @param production
* @param maxFeatures
* @param bbox [Optional] the spatial bounds to constrain the result set
* @return
* @throws Exception
*/
public InputStream downloadMiningActivityGml(String serviceURL,
String mineName,
String startDate,
String endDate,
String oreProcessed,
String producedMaterial,
String cutOffGrade,
String production,
int maxFeatures,
FilterBoundingBox bbox
) throws Exception {
//create the filter
MiningActivityFilter filter = new MiningActivityFilter(mineName, startDate, endDate, oreProcessed, producedMaterial, cutOffGrade, production);
String filterString = generateFilterString(filter, bbox);
HttpMethodBase method = generateWFSRequest(serviceURL, MINING_ACTIVITY_FEATURE_TYPE, null, filterString, maxFeatures, null, ResultType.Results);
try {
return httpServiceCaller.getMethodResponseAsStream(method,client);
} catch (Exception ex) {
throw new PortalServiceException(method, ex);
}
}
示例10: getMinesGml
import org.apache.commons.httpclient.HttpMethodBase; //導入依賴的package包/類
/**
* Gets the GML/KML response for all mines matching the specified parameters
* @param serviceUrl a Web Feature Service URL
* @param mineName [Optional] The mine name to constrain the result set
* @param bbox [Optional] the spatial bounds to constrain the result set
* @param maxFeatures The maximum number of features to request
* @return
* @throws PortalServiceException
*/
public WFSTransformedResponse getMinesGml(String serviceUrl, String mineName, FilterBoundingBox bbox, int maxFeatures) throws PortalServiceException {
MineFilter filter = new MineFilter(mineName);
String filterString = generateFilterString(filter, bbox);
HttpMethodBase method = null;
try {
method = generateWFSRequest(serviceUrl, MINE_FEATURE_TYPE, null, filterString, maxFeatures, null, ResultType.Results);
String responseGml = httpServiceCaller.getMethodResponseAsString(method);
String responseKml = gmlToKml.convert(responseGml, serviceUrl);
return new WFSTransformedResponse(responseGml, responseKml, method);
} catch (Exception ex) {
throw new PortalServiceException(method, "Error when attempting to download Mines GML", ex);
}
}
示例11: testDoMineFilterSingleMine
import org.apache.commons.httpclient.HttpMethodBase; //導入依賴的package包/類
/**
* Test doing a mine filter and getting all mines
* @throws Exception
*/
@Test
public void testDoMineFilterSingleMine() throws Exception {
final String serviceURL = "http://localhost?";
final String mineName = "mineName"; //to get all mines
final HttpMethodBase mockMethod = context.mock(HttpMethodBase.class);
final String expectedKML = "<kml/>";
final String expectedGML = "<gml/>";
context.checking(new Expectations() {{
allowing(mockMethod).getURI();will(returnValue(new URI(serviceURL, true)));
oneOf(mineralOccurrenceService).getMinesGml(serviceURL, mineName, null, 0);will(returnValue(new WFSTransformedResponse(expectedGML, expectedKML, mockMethod)));
}});
//call with updateCSWRecords dud url
ModelAndView modelAndView = this.earthResourcesFilterController.doMineFilter(serviceURL, mineName, null, 0);
//Ensure that we get a valid response
testMAVResponse(modelAndView, new Boolean(true), expectedGML, expectedKML);
}
示例12: getMineralOccurrenceCount
import org.apache.commons.httpclient.HttpMethodBase; //導入依賴的package包/類
/**
* Given a list of parameters, call a service and get the count of Mineral Occurrence GML
* @param serviceURL
* @param commodityName
* @param measureType
* @param minOreAmount
* @param minOreAmountUOM
* @param minCommodityAmount
* @param minCommodityAmountUOM
* @param cutOffGrade
* @param cutOffGradeUOM
* @param bbox [Optional] the spatial bounds to constrain the result set
* @return
*/
public WFSCountResponse getMineralOccurrenceCount(String serviceURL,
String commodityName,
String measureType,
String minOreAmount,
String minOreAmountUOM,
String minCommodityAmount,
String minCommodityAmountUOM,
int maxFeatures,
FilterBoundingBox bbox) throws PortalServiceException {
MineralOccurrenceFilter filter = new MineralOccurrenceFilter(commodityName,
measureType,
minOreAmount,
minOreAmountUOM,
minCommodityAmount,
minCommodityAmountUOM);
String filterString = generateFilterString(filter, bbox);
HttpMethodBase method = generateWFSRequest(serviceURL, MINERAL_OCCURRENCE_FEATURE_TYPE, null, filterString, maxFeatures, null, ResultType.Hits);
return getWfsFeatureCount(method);
}
示例13: getMiningActivityCount
import org.apache.commons.httpclient.HttpMethodBase; //導入依賴的package包/類
/**
* Given a list of parameters, call a service and get the count of Mineral Activity features
* @param serviceURL
* @param mineName
* @param startDate
* @param endDate
* @param oreProcessed
* @param producedMaterial
* @param cutOffGrade
* @param production
* @param maxFeatures
* @param bbox [Optional] the spatial bounds to constrain the result set
* @return
* @throws Exception
*/
public WFSCountResponse getMiningActivityCount(String serviceURL,
String mineName,
String startDate,
String endDate,
String oreProcessed,
String producedMaterial,
String cutOffGrade,
String production,
int maxFeatures,
FilterBoundingBox bbox
) throws Exception {
//create the filter
MiningActivityFilter filter = new MiningActivityFilter(mineName, startDate, endDate, oreProcessed, producedMaterial, cutOffGrade, production);
String filterString = generateFilterString(filter, bbox);
HttpMethodBase method = generateWFSRequest(serviceURL, MINING_ACTIVITY_FEATURE_TYPE, null, filterString, maxFeatures, null, ResultType.Hits);
return getWfsFeatureCount(method);
}
示例14: getAllCommodityConcepts
import org.apache.commons.httpclient.HttpMethodBase; //導入依賴的package包/類
/**
* Gets all RDF concepts at the specified repository as a single JENA Model. The results
* will be requested page by page until the entire repository has been traversed.
*
* @return
* @throws PortalServiceException
*/
public Model getAllCommodityConcepts() throws PortalServiceException {
Model model = ModelFactory.createDefaultModel();
int pageNumber = 0;
int pageSize = this.getPageSize();
//Request each page in turn - put the results into Model
do {
HttpMethodBase method = ((CommodityVocabMethodMaker)sissVocMethodMaker).getAllCommodities(getBaseUrl(), getRepository(), Format.Rdf, pageSize, pageNumber);
if (requestPageOfConcepts(method, model)) {
pageNumber++;
} else {
break;
}
} while (true);
return model;
}
示例15: checkForExceptionResponse
import org.apache.commons.httpclient.HttpMethodBase; //導入依賴的package包/類
/**
* Will attempt to parse an <DataServiceError> element
*
* Will throw an PressureDBException if document does contain an <DataServiceError>, otherwise it will do nothing
* @param doc
* @throws PressureDBException
*/
public static void checkForExceptionResponse(Document doc) throws PortalServiceException {
XPath xPath = XPathFactory.newInstance().newXPath();
try {
//Check for an exception response
NodeList exceptionNodes = (NodeList)xPath.evaluate("/DataServiceError", doc, XPathConstants.NODESET);
if (exceptionNodes.getLength() > 0) {
Node exceptionNode = exceptionNodes.item(0);
throw new PortalServiceException((HttpMethodBase)null, exceptionNode.getTextContent());
}
} catch (XPathExpressionException ex) {
//This should *hopefully* never occur
log.error("Error whilst attempting to check for errors", ex);
}
}