You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by sm...@apache.org on 2015/10/31 16:45:45 UTC
[1/2] directory-fortress-core git commit: FC-122 - Use latest
httpclient from apache httpcomponents since common-httpclient is not
maintained anymore
Repository: directory-fortress-core
Updated Branches:
refs/heads/master c8b9db889 -> c4ec02a0a
FC-122 - Use latest httpclient from apache httpcomponents since common-httpclient is not maintained anymore
Project: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/commit/ca53b1e3
Tree: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/tree/ca53b1e3
Diff: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/diff/ca53b1e3
Branch: refs/heads/master
Commit: ca53b1e331939d780742ddae0d03f472b33d41db
Parents: c8b9db8
Author: brainmaster <br...@localhost.localdomain>
Authored: Fri Oct 30 11:14:29 2015 +0700
Committer: brainmaster <br...@localhost.localdomain>
Committed: Fri Oct 30 11:14:29 2015 +0700
----------------------------------------------------------------------
.gitignore | 2 +
pom.xml | 7 +
.../directory/fortress/core/rest/RestUtils.java | 164 ++++++++-----------
3 files changed, 80 insertions(+), 93 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/ca53b1e3/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index 7fe757e..9f8023f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,4 +14,6 @@ dist
apache-ant-1.9.1
ldap/setup/refreshLDAPData.xml
maven-eclipse.xml
+.idea
+config
http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/ca53b1e3/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index aea6e70..07e7419 100644
--- a/pom.xml
+++ b/pom.xml
@@ -93,6 +93,7 @@
<version.commons.configuration>1.10</version.commons.configuration>
<version.commons.digester>1.8</version.commons.digester>
<version.commons.httpclient>3.1</version.commons.httpclient>
+ <version.httpcomponent.httpclient>4.5.1</version.httpcomponent.httpclient>
<version.commons.io>2.4</version.commons.io>
<version.commons.lang>2.6</version.commons.lang>
<version.commons.logging>1.1.1</version.commons.logging>
@@ -176,6 +177,12 @@
</dependency>
<dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ <version>${version.httpcomponent.httpclient}</version>
+ </dependency>
+
+ <dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<version>${version.ehcache.core}</version>
http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/ca53b1e3/src/main/java/org/apache/directory/fortress/core/rest/RestUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/rest/RestUtils.java b/src/main/java/org/apache/directory/fortress/core/rest/RestUtils.java
index 95ce399..b0f41ff 100644
--- a/src/main/java/org/apache/directory/fortress/core/rest/RestUtils.java
+++ b/src/main/java/org/apache/directory/fortress/core/rest/RestUtils.java
@@ -23,6 +23,7 @@ package org.apache.directory.fortress.core.rest;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
+import java.nio.charset.Charset;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;
@@ -41,10 +42,23 @@ import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.PutMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.methods.StringRequestEntity;
+
+
import org.apache.cxf.common.util.Base64Utility;
import org.apache.cxf.helpers.IOUtils;
import org.apache.directory.fortress.core.model.FortRequest;
import org.apache.directory.fortress.core.model.FortResponse;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.client.CredentialsProvider;
+import org.apache.http.client.methods.*;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.BasicCredentialsProvider;
+import org.apache.http.impl.client.HttpClientBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -192,9 +206,10 @@ public class RestUtils
url += "/" + id3;
}
LOG.debug( "get function1:{}, id1:{}, id2:{}, id3:{}, url:{}", function, id, id2, id3, url );
- GetMethod get = new GetMethod( url );
- setMethodHeaders( get, userId, password );
- return handleHttpMethod( get );
+ HttpGet get = new HttpGet(url);
+ setMethodHeaders( get );
+ return handleHttpMethod( get ,HttpClientBuilder.create()
+ .setDefaultCredentialsProvider(getCredentialProvider(userId, password)).build() );
}
@@ -210,19 +225,7 @@ public class RestUtils
*/
public static String get( String id, String id2, String id3, String function ) throws RestException
{
- String url = URI + function + "/" + id;
- if ( id2 != null )
- {
- url += "/" + id2;
- }
- if ( id3 != null )
- {
- url += "/" + id3;
- }
- LOG.debug( "get function2:{}, id1:{}, id2:{}, id3:{}, url:{}", function, id, id2, id3, url );
- GetMethod get = new GetMethod( url );
- setMethodHeaders( get, HTTP_UID, HTTP_PW );
- return handleHttpMethod( get );
+ return get( null, null, id, id2, id3, function );
}
@@ -238,79 +241,35 @@ public class RestUtils
*/
public static String post( String userId, String password, String szInput, String function ) throws RestException
{
- LOG.debug( "post URI=[{}], function=[{}], request={}", URI, function, szInput );
- String szResponse = null;
- PostMethod post = new PostMethod( URI + function );
- post.addRequestHeader( "Accept", "text/xml" );
- setMethodHeaders( post, userId, password );
- try
- {
- RequestEntity entity = new StringRequestEntity( szInput, "text/xml; charset=ISO-8859-1", null );
- post.setRequestEntity( entity );
- HttpClient httpclient = new HttpClient();
- int result = httpclient.executeMethod( post );
- szResponse = IOUtils.toString( post.getResponseBodyAsStream(), "UTF-8" );
- LOG.debug( "post URI=[{}], function=[{}], response=[{}], result=[{}]", URI, function, szResponse, result );
- }
- catch ( IOException ioe )
- {
- String error = "post URI=[" + URI + "], [" + function + "] caught IOException=" + ioe;
- LOG.error( error );
- throw new RestException( GlobalErrIds.REST_IO_ERR, error, ioe );
- }
- catch ( WebApplicationException we )
- {
- String error = "post URI=[" + URI + "], function=[" + function
- + "] caught WebApplicationException=" + we;
- LOG.error( error );
- throw new RestException( GlobalErrIds.REST_WEB_ERR, error, we );
- }
- finally
- {
- // Release current connection to the connection pool.
- post.releaseConnection();
- }
- return szResponse;
- }
-
-
- /**
- * Perform an HTTP Post REST operation.
- *
- * @param szInput
- * @param function
- * @return String containing response
- * @throws RestException
- */
- public static String post( String szInput, String function ) throws RestException
- {
LOG.debug( "post URI=[{}], function=[{}], request=[{}]", URI, function, szInput );
String szResponse = null;
- PostMethod post = new PostMethod( URI + function );
- post.addRequestHeader( "Accept", "text/xml" );
- setMethodHeaders( post, HTTP_UID, HTTP_PW );
+// PostMethod post = new PostMethod( URI + function );
+ HttpPost post = new HttpPost(URI + function);
+ post.addHeader("Accept", "text/xml");
+ setMethodHeaders( post );
try
{
- RequestEntity entity = new StringRequestEntity( szInput, "text/xml; charset=ISO-8859-1", null );
- post.setRequestEntity( entity );
- HttpClient httpclient = new HttpClient();
- int result = httpclient.executeMethod( post );
+ HttpEntity entity = new StringEntity( szInput, ContentType.TEXT_XML );
+ post.setEntity(entity);
+ org.apache.http.client.HttpClient httpclient = HttpClientBuilder.create()
+ .setDefaultCredentialsProvider(getCredentialProvider(userId, password)).build();
+ HttpResponse response = httpclient.execute(post);
String error;
- switch ( result )
+ switch ( response.getStatusLine().getStatusCode() )
{
case HTTP_OK :
- szResponse = IOUtils.toString( post.getResponseBodyAsStream(), "UTF-8" );
+ szResponse = IOUtils.toString( response.getEntity().getContent(), "UTF-8" );
LOG.debug( "post URI=[{}], function=[{}], response=[{}]", URI, function, szResponse );
break;
case HTTP_401_UNAUTHORIZED :
error = "post URI=[" + URI + "], function=[" + function
- + "], 401 function unauthorized on host";
+ + "], 401 function unauthorized on host";
LOG.error( error );
throw new RestException( GlobalErrIds.REST_UNAUTHORIZED_ERR, error );
case HTTP_403_FORBIDDEN :
error = "post URI=[" + URI + "], function=[" + function
- + "], 403 function forbidden on host";
+ + "], 403 function forbidden on host";
LOG.error( error );
throw new RestException( GlobalErrIds.REST_FORBIDDEN_ERR, error );
case HTTP_404_NOT_FOUND :
@@ -319,7 +278,7 @@ public class RestUtils
throw new RestException( GlobalErrIds.REST_NOT_FOUND_ERR, error );
default :
error = "post URI=[" + URI + "], function=[" + function
- + "], error received from host: " + result;
+ + "], error received from host: " + response.getStatusLine().getStatusCode();
LOG.error( error );
throw new RestException( GlobalErrIds.REST_UNKNOWN_ERR, error );
}
@@ -333,7 +292,7 @@ public class RestUtils
catch ( WebApplicationException we )
{
String error = "post URI=[" + URI + "], function=[" + function
- + "] caught WebApplicationException=" + we;
+ + "] caught WebApplicationException=" + we;
LOG.error( error );
throw new RestException( GlobalErrIds.REST_WEB_ERR, error, we );
}
@@ -347,23 +306,43 @@ public class RestUtils
/**
+ * Perform an HTTP Post REST operation.
+ *
+ * @param szInput
+ * @param function
+ * @return String containing response
+ * @throws RestException
+ */
+ public static String post( String szInput, String function ) throws RestException
+ {
+ return post(null,null,szInput, function);
+ }
+
+ private static CredentialsProvider getCredentialProvider(String uid, String password) {
+ BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
+ credentialsProvider.setCredentials( new AuthScope(HTTP_HOST,Integer.valueOf(HTTP_PORT)),
+ new UsernamePasswordCredentials(uid==null?HTTP_UID:uid,password==null?HTTP_PW:password) );
+ return credentialsProvider;
+ }
+
+ /**
* Set these params into their associated HTTP header vars.
*
- * @param httpMethod
- * @param name
- * @param password
+ * @param httpRequest
*/
- private static void setMethodHeaders( HttpMethod httpMethod, String name, String password )
+ private static void setMethodHeaders( HttpRequest httpRequest )
{
- if ( httpMethod instanceof PostMethod || httpMethod instanceof PutMethod )
+ if ( httpRequest instanceof HttpPost || httpRequest instanceof HttpPut)
{
- httpMethod.setRequestHeader( "Content-Type", "application/xml" );
- httpMethod.setRequestHeader( "Accept", "application/xml" );
+ httpRequest.addHeader("Content-Type", "application/xml");
+ httpRequest.addHeader("Accept", "application/xml");
}
//httpMethod.setDoAuthentication(false);
- httpMethod.setDoAuthentication( true );
- httpMethod.setRequestHeader( "Authorization",
- "Basic " + base64Encode( name + ":" + password ) );
+// httpRequest.setDoAuthentication(true);
+// httpRequest.addHeader("Authorization",
+// "Basic " + base64Encode(name + ":" + password));
+
+
}
@@ -382,24 +361,23 @@ public class RestUtils
/**
* Process the HTTP method request.
*
- * @param httpMethod
+ * @param httpGetRequest
* @return String containing response
* @throws Exception
*/
- private static String handleHttpMethod( HttpMethod httpMethod ) throws RestException
+ private static String handleHttpMethod( HttpRequestBase httpGetRequest ,org.apache.http.client.HttpClient client ) throws RestException
{
- HttpClient client = new HttpClient();
String szResponse = null;
try
{
- int statusCode = client.executeMethod( httpMethod );
- LOG.debug( "handleHttpMethod Response status : {}", statusCode );
+ HttpResponse response = client.execute( httpGetRequest );
+ LOG.debug( "handleHttpMethod Response status : {}", response.getStatusLine().getStatusCode() );
- Response.Status status = Response.Status.fromStatusCode( statusCode );
+ Response.Status status = Response.Status.fromStatusCode( response.getStatusLine().getStatusCode() );
if ( status == Response.Status.OK )
{
- szResponse = httpMethod.getResponseBodyAsString();
+ szResponse = IOUtils.toString( response.getEntity().getContent() );
LOG.debug( szResponse );
}
else if ( status == Response.Status.FORBIDDEN )
@@ -424,7 +402,7 @@ public class RestUtils
finally
{
// Release current connection to the connection pool.
- httpMethod.releaseConnection();
+ httpGetRequest.releaseConnection();
}
return szResponse;
}
[2/2] directory-fortress-core git commit: FC-122 - Use latest
httpclient from apache httpcomponents
Posted by sm...@apache.org.
FC-122 - Use latest httpclient from apache httpcomponents
Project: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/commit/c4ec02a0
Tree: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/tree/c4ec02a0
Diff: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/diff/c4ec02a0
Branch: refs/heads/master
Commit: c4ec02a0afd9af1d4b3e6ec086e9a4261b0e7d76
Parents: ca53b1e
Author: Shawn McKinney <sm...@apache.org>
Authored: Sat Oct 31 10:45:29 2015 -0500
Committer: Shawn McKinney <sm...@apache.org>
Committed: Sat Oct 31 10:45:29 2015 -0500
----------------------------------------------------------------------
build.xml | 15 ++++---
ivy.xml | 9 ++--
pom.xml | 47 ++++++++++++--------
.../directory/fortress/core/rest/RestUtils.java | 35 ++++++---------
4 files changed, 57 insertions(+), 49 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/c4ec02a0/build.xml
----------------------------------------------------------------------
diff --git a/build.xml b/build.xml
index 8fdba44..07c5bfb 100644
--- a/build.xml
+++ b/build.xml
@@ -154,8 +154,11 @@
<property name="commons-collections.jar" value="${lib.dir}/commons-collections-3.2.1.jar"/>
<property name="commons-logging.jar" value="${lib.dir}/commons-logging-1.1.1.jar"/>
<property name="commons-io.jar" value="${lib.dir}/commons-io-2.4.jar"/>
- <property name="cxf-common-utilities.jar" value="${lib.dir}/cxf-common-utilities-2.5.11.jar"/>
- <property name="commons-codec.jar" value="${lib.dir}/commons-codec-1.2.jar"/>
+ <property name="httpclient.jar" value="${lib.dir}/httpclient-4.5.1.jar"/>
+ <property name="httpcore.jar" value="${lib.dir}/httpcore-4.4.3.jar"/>
+ <property name="cxf-common-utilities.jar" value="${lib.dir}/cxf-api-2.7.17.jar"/>
+ <property name="javax.ws.rs-api.jar" value="${lib.dir}/javax.ws.rs-api-2.0.1.jar"/>
+ <property name="commons-codec.jar" value="${lib.dir}/commons-codec-1.10.jar"/>
<property name="jgraph.jar" value="${lib.dir}/jgrapht-core-0.9.1.jar"/>
<property name="log4j.jar" value="${lib.dir}/log4j-1.2.17.jar"/>
<property name="junit.jar" value="${lib.dir}/junit-4.12.jar"/>
@@ -165,7 +168,6 @@
<property name="jaxb-impl.jar" value="${lib.dir}/jaxb-impl-2.2.4-1.jar"/>
<property name="jaxb-xjc.jar" value="${lib.dir}/jaxb-xjc-2.2.4-1.jar"/>
<property name="jackson-jaxrs.jar" value="${lib.dir}/jackson-jaxrs-1.9.0.jar"/>
- <property name="commons-httpclient.jar" value="${lib.dir}/commons-httpclient-3.1.jar"/>
<property name="javaee-api.jar" value="${lib.dir}/javaee-api-7.0.jar"/>
<property name="ehcache-core.jar" value="${lib.dir}/ehcache-core-2.6.10.jar"/>
<property name="slf4j-api.jar" value="${lib.dir}/slf4j-api-1.7.12.jar"/>
@@ -186,12 +188,13 @@
<pathelement location="${commons-config.jar}"/>
<pathelement location="${commons-lang.jar}"/>
<pathelement location="${commons-io.jar}"/>
+ <pathelement location="${httpclient.jar}"/>
+ <pathelement location="${httpcore.jar}"/>
<pathelement location="${jasypt.jar}"/>
<pathelement location="${jaxb-api.jar}"/>
<pathelement location="${jaxb-impl.jar}"/>
<pathelement location="${jaxb-xjc.jar}"/>
<pathelement location="${jackson-jaxrs.jar}"/>
- <pathelement location="${commons-httpclient.jar}"/>
<pathelement location="${javaee-api.jar}"/>
<pathelement location="${cxf-common-utilities.jar}"/>
<pathelement location="${ehcache-core.jar}"/>
@@ -223,11 +226,13 @@
<pathelement location="${commons-collections.jar}"/>
<pathelement location="${commons-codec.jar}"/>
<pathelement location="${commons-io.jar}"/>
+ <pathelement location="${httpclient.jar}"/>
+ <pathelement location="${httpcore.jar}"/>
<pathelement location="${jasypt.jar}"/>
<pathelement location="${jackson-jaxrs.jar}"/>
- <pathelement location="${commons-httpclient.jar}"/>
<pathelement location="${javaee-api.jar}"/>
<pathelement location="${cxf-common-utilities.jar}"/>
+ <pathelement location="${javax.ws.rs-api.jar}"/>
<pathelement location="${jaxb-api.jar}"/>
<pathelement location="${jaxb-impl.jar}"/>
<pathelement location="${jaxb-xjc.jar}"/>
http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/c4ec02a0/ivy.xml
----------------------------------------------------------------------
diff --git a/ivy.xml b/ivy.xml
index a1ff094..3430e1b 100755
--- a/ivy.xml
+++ b/ivy.xml
@@ -30,7 +30,7 @@
<dependency org="commons-lang" name="commons-lang" rev="2.6" conf="default->master"/>
<dependency org="commons-collections" name="commons-collections" rev="3.2.1" conf="default->master"/>
<dependency org="commons-logging" name="commons-logging" rev="1.1.1" conf="default->master"/>
- <dependency org="commons-codec" name="commons-codec" rev="1.2" conf="default->master"/>
+ <dependency org="commons-codec" name="commons-codec" rev="1.10" conf="default->master"/>
<dependency org="commons-io" name="commons-io" rev="2.4" conf="default->master"/>
<dependency org="junit" name="junit" rev="4.12" conf="default->master"/>
<dependency org="org.hamcrest" name="hamcrest-core" rev="1.3" conf="default->master"/>
@@ -40,11 +40,12 @@
<dependency org="com.sun.xml.bind" name="jaxb-xjc" rev="2.2.4-1" conf="default->master"/>
<dependency org="com.sun.xml.bind" name="jaxb-impl" rev="2.2.4-1" conf="default->master"/>
<dependency org="javax.xml.bind" name="jaxb-api" rev="2.2.6" conf="default->master"/>
- <dependency org="commons-httpclient" name="commons-httpclient" rev="3.1" conf="default->master"/>
+ <dependency org="org.apache.httpcomponents" name="httpclient" rev="4.5.1" conf="default->master"/>
+ <dependency org="org.apache.httpcomponents" name="httpcore" rev="4.4.3" conf="default->master"/>
<dependency org="org.codehaus.jackson" name="jackson-jaxrs" rev="1.9.0" conf="default->master"/>
-<!-- <dependency org="javax.ws.rs" name="jsr311-api" rev="1.1.1" conf="default->master" />-->
<dependency org="javax" name="javaee-api" rev="7.0" conf="default->master"/>
- <dependency org="org.apache.cxf" name="cxf-common-utilities" rev="2.5.11" conf="default->master"/>
+ <dependency org="org.apache.cxf" name="cxf-api" rev="2.7.17" conf="default->master"/>
+ <dependency org="javax.ws.rs" name="javax.ws.rs-api" rev="2.0.1" conf="default->master"/>
<dependency org="net.sf.ehcache" name="ehcache-core" rev="2.6.10" conf="default->master"/>
<dependency org="org.slf4j" name="slf4j-api" rev="1.7.12" conf="default->master"/>
<dependency org="org.slf4j" name="slf4j-log4j12" rev="1.7.12" conf="default->master"/>
http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/c4ec02a0/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 07e7419..2dd1669 100644
--- a/pom.xml
+++ b/pom.xml
@@ -88,17 +88,19 @@
<version.api.all>1.0.0-M31</version.api.all>
<version.commons.beanutils>1.7.0</version.commons.beanutils>
<version.commons.beanutils-core>1.8.0</version.commons.beanutils-core>
- <version.commons.codec>1.2</version.commons.codec>
+ <version.commons.codec>1.10</version.commons.codec>
<version.commons.collections>3.2.1</version.commons.collections>
<version.commons.configuration>1.10</version.commons.configuration>
<version.commons.digester>1.8</version.commons.digester>
<version.commons.httpclient>3.1</version.commons.httpclient>
<version.httpcomponent.httpclient>4.5.1</version.httpcomponent.httpclient>
+ <version.httpcomponent.httpcore>4.4.3</version.httpcomponent.httpcore>
<version.commons.io>2.4</version.commons.io>
<version.commons.lang>2.6</version.commons.lang>
<version.commons.logging>1.1.1</version.commons.logging>
<version.commons.pool>1.6</version.commons.pool>
- <version.cxf.common.utilities>2.5.11</version.cxf.common.utilities>
+ <version.cxf.common.utilities>2.7.17</version.cxf.common.utilities>
+ <version.javax.ws.rs-api>2.0.1</version.javax.ws.rs-api>
<version.dom4j>1.6.1</version.dom4j>
<version.ehcache.core>2.6.10</version.ehcache.core>
<version.hamcrest.core>1.3</version.hamcrest.core>
@@ -120,7 +122,6 @@
<version.xpp3>1.1.4c</version.xpp3>
<version.xml.apis>1.0b2</version.xml.apis>
<version.jaxb>2.2.4-1</version.jaxb>
- <version.commons.codec>1.2</version.commons.codec>
<!-- ===================================================== -->
<!-- This is a hack to allow someone to release -->
@@ -171,15 +172,15 @@
</dependency>
<dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- <version>${version.commons.httpclient}</version>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ <version>${version.httpcomponent.httpclient}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpclient</artifactId>
- <version>${version.httpcomponent.httpclient}</version>
+ <artifactId>httpcore</artifactId>
+ <version>${version.httpcomponent.httpcore}</version>
</dependency>
<dependency>
@@ -196,11 +197,17 @@
<dependency>
<groupId>org.apache.cxf</groupId>
- <artifactId>cxf-common-utilities</artifactId>
+ <artifactId>cxf-api</artifactId>
<version>${version.cxf.common.utilities}</version>
</dependency>
<dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ <version>${version.javax.ws.rs-api}</version>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.directory.api</groupId>
<artifactId>api-all</artifactId>
<version>${version.api.all}</version>
@@ -662,9 +669,10 @@
<pathelement location="${org.slf4j:slf4j-api:jar}" />
<pathelement location="${org.slf4j:slf4j-log4j12:jar}" />
<pathelement location="${antlr:antlr:jar}" />
- <pathelement location="${org.apache.cxf:cxf-common-utilities:jar}" />
- <pathelement location="${javax.ws.rs:jsr311-api:jar}" />
- <pathelement location="${commons-httpclient:commons-httpclient:jar}" />
+ <pathelement location="${org.apache.cxf:cxf-api:jar}" />
+ <pathelement location="${javax.ws.rs:javax.ws.rs-api:jar}" />
+ <pathelement location="${org.apache.httpcomponents:httpclient:jar}" />
+ <pathelement location="${org.apache.httpcomponents:httpcore:jar}" />
<pathelement location="${com.sun.xml.bind:jaxb-impl:jar}" />
<pathelement location="${commons-codec:commons-codec:jar}" />
</classpath>
@@ -730,9 +738,11 @@
<pathelement location="${org.slf4j:slf4j-log4j12:jar}" />
<pathelement location="${antlr:antlr:jar}" />
<pathelement location="${junit:junit:jar}" />
- <pathelement location="${org.apache.cxf:cxf-common-utilities:jar}" />
- <pathelement location="${javax.ws.rs:jsr311-api:jar}" />
- <pathelement location="${commons-httpclient:commons-httpclient:jar}" />
+ <pathelement location="${org.apache.cxf:cxf-api:jar}" />
+ <pathelement location="${javax.ws.rs:javax.ws.rs-api:jar}" />
+ <pathelement location="${javax.ws.rs:javax.ws.rs-api:jar}" />
+ <pathelement location="${org.apache.httpcomponents:httpclient:jar}" />
+ <pathelement location="${org.apache.httpcomponents:httpcore:jar}" />
<pathelement location="${com.sun.xml.bind:jaxb-impl:jar}" />
<pathelement location="${commons-codec:commons-codec:jar}" />
</classpath>
@@ -790,9 +800,10 @@
<pathelement location="${org.slf4j:slf4j-log4j12:jar}" />
<pathelement location="${antlr:antlr:jar}" />
<pathelement location="${junit:junit:jar}" />
- <pathelement location="${org.apache.cxf:cxf-common-utilities:jar}" />
- <pathelement location="${javax.ws.rs:jsr311-api:jar}" />
- <pathelement location="${commons-httpclient:commons-httpclient:jar}" />
+ <pathelement location="${org.apache.cxf:cxf-api:jar}" />
+ <pathelement location="${javax.ws.rs:javax.ws.rs-api:jar}" />
+ <pathelement location="${org.apache.httpcomponents:httpclient:jar}" />
+ <pathelement location="${org.apache.httpcomponents:httpcore:jar}" />
<pathelement location="${com.sun.xml.bind:jaxb-impl:jar}" />
<pathelement location="${commons-codec:commons-codec:jar}" />
</classpath>
http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/c4ec02a0/src/main/java/org/apache/directory/fortress/core/rest/RestUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/rest/RestUtils.java b/src/main/java/org/apache/directory/fortress/core/rest/RestUtils.java
index b0f41ff..3886f20 100644
--- a/src/main/java/org/apache/directory/fortress/core/rest/RestUtils.java
+++ b/src/main/java/org/apache/directory/fortress/core/rest/RestUtils.java
@@ -23,7 +23,6 @@ package org.apache.directory.fortress.core.rest;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
-import java.nio.charset.Charset;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;
@@ -35,15 +34,6 @@ import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpMethod;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.methods.PostMethod;
-import org.apache.commons.httpclient.methods.PutMethod;
-import org.apache.commons.httpclient.methods.RequestEntity;
-import org.apache.commons.httpclient.methods.StringRequestEntity;
-
-
import org.apache.cxf.common.util.Base64Utility;
import org.apache.cxf.helpers.IOUtils;
import org.apache.directory.fortress.core.model.FortRequest;
@@ -243,17 +233,16 @@ public class RestUtils
{
LOG.debug( "post URI=[{}], function=[{}], request=[{}]", URI, function, szInput );
String szResponse = null;
-// PostMethod post = new PostMethod( URI + function );
HttpPost post = new HttpPost(URI + function);
- post.addHeader("Accept", "text/xml");
+ post.addHeader( "Accept", "text/xml" );
setMethodHeaders( post );
try
{
HttpEntity entity = new StringEntity( szInput, ContentType.TEXT_XML );
- post.setEntity(entity);
+ post.setEntity( entity );
org.apache.http.client.HttpClient httpclient = HttpClientBuilder.create()
.setDefaultCredentialsProvider(getCredentialProvider(userId, password)).build();
- HttpResponse response = httpclient.execute(post);
+ HttpResponse response = httpclient.execute( post );
String error;
switch ( response.getStatusLine().getStatusCode() )
@@ -296,6 +285,14 @@ public class RestUtils
LOG.error( error );
throw new RestException( GlobalErrIds.REST_WEB_ERR, error, we );
}
+ catch ( java.lang.NoSuchMethodError e )
+ {
+ String error = "post URI=[" + URI + "], function=[" + function
+ + "] caught Exception=" + e;
+ LOG.error( error );
+ e.printStackTrace();
+ throw new RestException( GlobalErrIds.REST_UNKNOWN_ERR, error );
+ }
finally
{
// Release current connection to the connection pool.
@@ -334,15 +331,9 @@ public class RestUtils
{
if ( httpRequest instanceof HttpPost || httpRequest instanceof HttpPut)
{
- httpRequest.addHeader("Content-Type", "application/xml");
- httpRequest.addHeader("Accept", "application/xml");
+ httpRequest.addHeader( "Content-Type", "application/xml" );
+ httpRequest.addHeader( "Accept", "application/xml" );
}
- //httpMethod.setDoAuthentication(false);
-// httpRequest.setDoAuthentication(true);
-// httpRequest.addHeader("Authorization",
-// "Basic " + base64Encode(name + ":" + password));
-
-
}