Merge remote-tracking branch 'origin/master' into olingo263

This commit is contained in:
Francesco Chicchiriccò 2014-05-05 12:22:37 +02:00
commit 7c079a1a78
4 changed files with 63 additions and 12 deletions

View File

@ -16,6 +16,8 @@
package org.apache.olingo.client.core.communication.request;
import java.io.IOException;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpUriRequest;
@ -68,15 +70,13 @@ public abstract class AbstractRequest {
protected void checkResponse(
final CommonODataClient<?> odataClient, final HttpResponse response, final String accept) {
if (response.getStatusLine().getStatusCode() >= 500) {
throw new ODataServerErrorException(response.getStatusLine());
} else if (response.getStatusLine().getStatusCode() >= 400) {
if (response.getStatusLine().getStatusCode() >= 400) {
try {
final HttpEntity httpEntity = response.getEntity();
if (httpEntity == null) {
throw new ODataClientErrorException(response.getStatusLine());
} else {
final boolean isXML = accept.contains("json");
final boolean isXML = !accept.contains("json");
ODataError error;
try {
error = odataClient.getReader().readError(httpEntity.getContent(), isXML);
@ -87,8 +87,12 @@ public abstract class AbstractRequest {
response.getStatusLine().getReasonPhrase(),
isXML);
}
throw new ODataClientErrorException(response.getStatusLine(), error);
if (response.getStatusLine().getStatusCode() >= 500) {
throw new ODataServerErrorException(response.getStatusLine());
} else {
throw new ODataClientErrorException(response.getStatusLine(), error);
}
}
} catch (IOException e) {
throw new HttpClientException(

View File

@ -62,6 +62,10 @@ public class ProxyWrapperHttpClientFactory implements HttpClientFactory {
this.proxyPassword = proxyPassword;
this.wrapped = wrapped;
}
public DefaultHttpClientFactory getWrappedHttpClientFactory(){
return this.wrapped;
}
@Override
public HttpClient createHttpClient(final HttpMethod method, final URI uri) {

View File

@ -18,7 +18,6 @@
*/
package org.apache.olingo.client.core.uri;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
@ -32,13 +31,20 @@ import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
import java.util.regex.Pattern;
import javax.xml.datatype.Duration;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.entity.AbstractHttpEntity;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.InputStreamEntity;
import org.apache.olingo.client.api.CommonODataClient;
import org.apache.olingo.client.api.http.HttpClientFactory;
import org.apache.olingo.client.core.http.BasicAuthHttpClientFactory;
import org.apache.olingo.client.core.http.ProxyWrapperHttpClientFactory;
import org.apache.olingo.commons.api.Constants;
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
@ -383,9 +389,26 @@ public final class URIUtils {
return value;
}
public static InputStreamEntity buildInputStreamEntity(final CommonODataClient<?> client, final InputStream input) {
InputStreamEntity entity;
if (client.getConfiguration().isUseChuncked()) {
private static boolean shouldUseRepeatableHttpBodyEntry(final CommonODataClient<?> client)
{
// returns true for authentication request in case of http401 which needs retry so requires being repeatable.
HttpClientFactory httpclientFactory = client.getConfiguration().getHttpClientFactory();
if(httpclientFactory instanceof BasicAuthHttpClientFactory){
return true;
} else if (httpclientFactory instanceof ProxyWrapperHttpClientFactory){
ProxyWrapperHttpClientFactory tmp = (ProxyWrapperHttpClientFactory)httpclientFactory;
if(tmp.getWrappedHttpClientFactory() instanceof BasicAuthHttpClientFactory){
return true;
}
}
return false;
}
public static AbstractHttpEntity buildInputStreamEntity(final CommonODataClient<?> client, final InputStream input) {
AbstractHttpEntity entity = null;
boolean repeatableRequired= shouldUseRepeatableHttpBodyEntry(client);
if (!repeatableRequired) {
entity = new InputStreamEntity(input, -1);
} else {
byte[] bytes = new byte[0];
@ -395,10 +418,11 @@ public final class URIUtils {
LOG.error("While reading input for not chunked encoding", e);
}
entity = new InputStreamEntity(new ByteArrayInputStream(bytes), bytes.length);
entity = new ByteArrayEntity(bytes);
}
// both entities can be sent in chunked way or not
entity.setChunked(client.getConfiguration().isUseChuncked());
return entity;
}
}

View File

@ -20,6 +20,25 @@ package org.apache.olingo.commons.core.data;
import org.apache.olingo.commons.api.domain.ODataError;
// TODO p2 supports V4:
// {
// "error": {
// "code": "501",
// "message": "Unsupported functionality",
// "target": "query",
// "details": [
// {
// "code": "301",
// "target": "$search"
// "message": "$search query option not supported",
// }
// ]
// "innererror": {
// "trace": [...],
// "context": {...}
// }
// }
// }
public abstract class AbstractODataError implements ODataError {
private String code;