List of usage examples for org.apache.commons.httpclient.methods StringRequestEntity StringRequestEntity
public StringRequestEntity(String paramString)
From source file:de.mpg.escidoc.http.UserGroup.java
@SuppressWarnings("deprecation") public Boolean activateUserGroup() { String userGroupID = Util.input("Enter UserGroupID which you want to activate:"); // String userGroupID = "escidoc:27004"; Document userGroupXML = this.getUserGroupXML(userGroupID); if (userGroupXML == null) { return false; }/*from w w w . j a v a2s . co m*/ Element rootElement = userGroupXML.getRootElement(); String lastModificationDate = rootElement.getAttributeValue("last-modification-date"); if (this.USER_HANDLE != null) { PostMethod post = new PostMethod(this.FRAMEWORK_URL + "/aa/user-group/" + userGroupID + "/activate"); post.setRequestHeader("Cookie", "escidocCookie=" + this.USER_HANDLE); try { System.out.println("Request body sent to Server: "); post.setRequestEntity(new StringRequestEntity( Util.getParamXml(Util.OPTION_REMOVE_SELECTOR, lastModificationDate, ""))); this.client.executeMethod(post); if (post.getStatusCode() != 200) { System.out.println("Server StatusCode: " + post.getStatusCode()); return false; } System.out.println("Usergroup " + userGroupID + " activated"); } catch (IOException e) { e.printStackTrace(); } } else { System.out.println("Error in activateUserGroup: No userHandle available"); } this.getUserGroupXML(userGroupID); return true; }
From source file:cz.vsb.gis.ruz76.gt.Examples.java
private void addWorkspace(String name) { String strURL = "http://localhost:8080/geoserver/rest/workspaces"; PostMethod post = new PostMethod(strURL); post.setRequestHeader("Content-type", "text/xml"); post.setRequestEntity(//w w w.jav a 2s. com new StringRequestEntity("<?xml version=\"1.0\"?><workspace><name>" + name + "</name></workspace>")); post.setDoAuthentication(true); HttpClient httpclient = new HttpClient(); Credentials defaultcreds = new UsernamePasswordCredentials("admin", "geoserver"); httpclient.getState().setCredentials(new AuthScope("localhost", 8080, AuthScope.ANY_REALM), defaultcreds); try { int response = httpclient.executeMethod(post); } catch (IOException ex) { Logger.getLogger(Examples.class.getName()).log(Level.SEVERE, null, ex); } finally { post.releaseConnection(); } }
From source file:de.mpg.escidoc.http.UserGroup.java
@SuppressWarnings("deprecation") public Boolean deactivateUserGroup() { String userGroupID = Util.input("Enter UserGroupID which you want to deactivate:"); // String userGroupID = "escidoc:27004"; Document userGroupXML = this.getUserGroupXML(userGroupID); if (userGroupXML == null) { return false; }/*from w w w .j av a 2s.co m*/ Element rootElement = userGroupXML.getRootElement(); String lastModificationDate = rootElement.getAttributeValue("last-modification-date"); if (this.USER_HANDLE != null) { PostMethod post = new PostMethod(this.FRAMEWORK_URL + "/aa/user-group/" + userGroupID + "/deactivate"); post.setRequestHeader("Cookie", "escidocCookie=" + this.USER_HANDLE); try { System.out.println("Request body sent to Server: "); post.setRequestEntity(new StringRequestEntity( Util.getParamXml(Util.OPTION_REMOVE_SELECTOR, lastModificationDate, ""))); this.client.executeMethod(post); if (post.getStatusCode() != 200) { System.out.println("Server StatusCode: " + post.getStatusCode()); return false; } System.out.println("Usergroup " + userGroupID + " deactivated"); } catch (IOException e) { e.printStackTrace(); } } else { System.out.println("Error in deactivateUserGroup: No userHandle available"); } this.getUserGroupXML(userGroupID); return true; }
From source file:cz.vsb.gis.ruz76.gt.Examples.java
private void publishShapefile(String workspace, String datastore, String shp) { String strURL = "http://localhost:8080/geoserver/rest/workspaces/" + workspace + "/datastores/" + datastore + "/external.shp"; PutMethod put = new PutMethod(strURL); put.setRequestHeader("Content-type", "text/plain"); put.setRequestEntity(new StringRequestEntity(shp)); put.setDoAuthentication(true);/*from w ww .ja v a 2 s. c om*/ HttpClient httpclient = new HttpClient(); Credentials defaultcreds = new UsernamePasswordCredentials("admin", "geoserver"); httpclient.getState().setCredentials(new AuthScope("localhost", 8080, AuthScope.ANY_REALM), defaultcreds); try { int response = httpclient.executeMethod(put); } catch (IOException ex) { Logger.getLogger(Examples.class.getName()).log(Level.SEVERE, null, ex); } finally { put.releaseConnection(); } }
From source file:com.funambol.json.dao.JsonDAOImpl.java
public JsonResponse getItemKeysFromTwin(String token, String jsonContent) throws HttpException, IOException { String request = Utility.getUrl(jsonServerUrl, resourceType, GET_ITEM_FROM_TWIN_URL); PostMethod post = new PostMethod(request); post.setRequestHeader(Utility.TOKEN_HEADER_NAME, token); post.setRequestEntity(new StringRequestEntity(jsonContent)); if (log.isTraceEnabled()) { log.trace("Getting item keys from twin.."); }// ww w . java 2 s . c o m if (Configuration.getConfiguration().isDebugMode()) { if (log.isTraceEnabled()) { log.trace("Getting item keys from twin of '" + jsonContent + "'"); } } int statusCode = 0; String responseBody = null; try { statusCode = httpClient.executeMethod(post); responseBody = post.getResponseBodyAsString(); } finally { post.releaseConnection(); } if (log.isTraceEnabled()) { log.trace("Found item keys from twin '" + responseBody + "'"); } JsonResponse response = new JsonResponse(statusCode, responseBody); return response; }
From source file:cz.vsb.gis.ruz76.gt.Examples.java
public String testREST_POST_WorkSpace() { String strURL = "http://localhost:8080/geoserver/rest/workspaces"; PostMethod post = new PostMethod(strURL); post.setRequestHeader("Content-type", "text/xml"); post.setRequestEntity(// w w w .j ava2 s. c o m new StringRequestEntity("<?xml version=\"1.0\"?><workspace><name>acme2</name></workspace>")); post.setDoAuthentication(true); HttpClient httpclient = new HttpClient(); Credentials defaultcreds = new UsernamePasswordCredentials("admin", "geoserver"); httpclient.getState().setCredentials(new AuthScope("localhost", 8080, AuthScope.ANY_REALM), defaultcreds); try { int response = httpclient.executeMethod(post); System.out.println("Response: "); BufferedReader br = new BufferedReader(new InputStreamReader(post.getResponseBodyAsStream())); String line; while ((line = br.readLine()) != null) { System.out.println(line); } //System.out.println(post.getResponseBodyAsStream()); } catch (IOException ex) { Logger.getLogger(Examples.class.getName()).log(Level.SEVERE, null, ex); } finally { post.releaseConnection(); } return "testREST_POST_WorkSpace"; }
From source file:cz.vsb.gis.ruz76.gt.Examples.java
public String testREST_PUT_Local() { String strURL = "http://localhost:8080/geoserver/rest/workspaces/acme/datastores/zeleznice/external.shp"; PutMethod put = new PutMethod(strURL); put.setRequestHeader("Content-type", "text/plain"); put.setRequestEntity(new StringRequestEntity("file:///data/shpdata/cr-shp-wgs84/linie/zeleznice.shp")); put.setDoAuthentication(true);/*from w w w .j av a2 s. c om*/ HttpClient httpclient = new HttpClient(); Credentials defaultcreds = new UsernamePasswordCredentials("admin", "geoserver"); httpclient.getState().setCredentials(new AuthScope("localhost", 8080, AuthScope.ANY_REALM), defaultcreds); try { int response = httpclient.executeMethod(put); System.out.println("Response: "); BufferedReader br = new BufferedReader(new InputStreamReader(put.getResponseBodyAsStream())); String line; while ((line = br.readLine()) != null) { System.out.println(line); } //System.out.println(post.getResponseBodyAsStream()); } catch (IOException ex) { Logger.getLogger(Examples.class.getName()).log(Level.SEVERE, null, ex); } finally { put.releaseConnection(); } return "http://localhost:8080/geoserver/acme/wms?service=WMS&version=1.3.0&request=GetCapabilities"; }
From source file:cz.vsb.gis.ruz76.gt.Examples.java
private void publishPostGISTable(String name) { String strURL = "http://localhost:8080/geoserver/rest/workspaces/crwgs84/datastores/public/featuretypes"; PostMethod post = new PostMethod(strURL); post.setRequestHeader("Content-type", "text/xml"); post.setRequestEntity(new StringRequestEntity( "<?xml version=\"1.0\"?><featureType><name>" + name + "</name></featureType>")); post.setDoAuthentication(true);// ww w .j a va2s . c o m HttpClient httpclient = new HttpClient(); Credentials defaultcreds = new UsernamePasswordCredentials("admin", "geoserver"); httpclient.getState().setCredentials(new AuthScope("localhost", 8080, AuthScope.ANY_REALM), defaultcreds); try { int response = httpclient.executeMethod(post); } catch (IOException ex) { Logger.getLogger(Examples.class.getName()).log(Level.SEVERE, null, ex); } finally { post.releaseConnection(); } }
From source file:nl.b3p.viewer.image.PrePostImageCollector.java
@Override protected BufferedImage loadImage(String url, String user, String pass) throws IOException, Exception { String theUrl = url;/* ww w. j a v a2 s . co m*/ if (this.getBody() != null) { PostMethod method = null; try { method = new PostMethod(url); method.setRequestEntity(new StringRequestEntity(this.getBody())); int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { throw new Exception("Error connecting to server. HTTP status code: " + statusCode); } String returnXML = method.getResponseBodyAsString(); theUrl = getUrlFromXML(returnXML); if (theUrl == null && returnXML != null) { throw new Exception("Error getting the correct url. Server returned: \n" + returnXML); } } finally { if (method != null) { method.releaseConnection(); } } } return super.loadImage(theUrl, user, pass); }
From source file:org.apache.asterix.test.aql.TestsUtils.java
public static InputStream executeQuery(String str, OutputFormat fmt) throws Exception { final String url = "http://localhost:19002/query"; HttpMethodBase method = null;/*from ww w. j ava2 s . c om*/ if (str.length() + url.length() < MAX_URL_LENGTH) { //Use GET for small-ish queries method = new GetMethod(url); method.setQueryString(new NameValuePair[] { new NameValuePair("query", str) }); } else { //Use POST for bigger ones to avoid 413 FULL_HEAD method = new PostMethod(url); ((PostMethod) method).setRequestEntity(new StringRequestEntity(str)); } //Set accepted output response type method.setRequestHeader("Accept", fmt.mimeType()); // Provide custom retry handler is necessary method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); executeHttpMethod(method); return method.getResponseBodyAsStream(); }