[OLINGO-659] Fix code analysis issues

This commit is contained in:
Christian Amend 2015-08-17 15:42:42 +02:00
parent 75b5523080
commit 33478d8ccc
28 changed files with 272 additions and 204 deletions

View File

@ -45,7 +45,9 @@ public class SerializerException extends ODataLibraryException {
/** parameters: primitive-type name, value */
WRONG_PRIMITIVE_VALUE,
UNKNOWN_TYPE,
WRONG_BASE_TYPE;
WRONG_BASE_TYPE,
/** parameter: encoding-name */
UNSUPPORTED_ENCODING;
@Override
public String getKey() {

View File

@ -73,12 +73,11 @@ import org.apache.olingo.server.core.etag.PreconditionsValidator;
public class ODataDispatcher {
private final HttpMethod method;
private static final String NOT_IMPLEMENTED_MESSAGE = "not implemented";
private final UriInfo uriInfo;
private final ODataHandler handler;
public ODataDispatcher(HttpMethod method, UriInfo uriInfo, ODataHandler handler) {
this.method = method;
public ODataDispatcher(UriInfo uriInfo, ODataHandler handler) {
this.uriInfo = uriInfo;
this.handler = handler;
}
@ -87,7 +86,7 @@ public class ODataDispatcher {
ODataLibraryException {
switch (uriInfo.getKind()) {
case metadata:
checkMethod(method, HttpMethod.GET);
checkMethod(request.getMethod(), HttpMethod.GET);
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, handler.getCustomContentTypeSupport(), RepresentationType.METADATA);
handler.selectProcessor(MetadataProcessor.class)
@ -95,7 +94,7 @@ public class ODataDispatcher {
break;
case service:
checkMethod(method, HttpMethod.GET);
checkMethod(request.getMethod(), HttpMethod.GET);
if ("".equals(request.getRawODataPath())) {
handler.selectProcessor(RedirectProcessor.class)
.redirect(request, response);
@ -112,13 +111,13 @@ public class ODataDispatcher {
break;
case batch:
checkMethod(method, HttpMethod.POST);
checkMethod(request.getMethod(), HttpMethod.POST);
new BatchHandler(handler, handler.selectProcessor(BatchProcessor.class))
.process(request, response, true);
break;
default:
throw new ODataHandlerException("not implemented",
throw new ODataHandlerException(NOT_IMPLEMENTED_MESSAGE,
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
}
}
@ -170,7 +169,7 @@ public class ODataDispatcher {
break;
default:
throw new ODataHandlerException("not implemented",
throw new ODataHandlerException(NOT_IMPLEMENTED_MESSAGE,
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
}
}
@ -195,7 +194,7 @@ public class ODataDispatcher {
handleComplexDispatching(request, response, returnType.isCollection());
break;
default:
throw new ODataHandlerException("not implemented",
throw new ODataHandlerException(NOT_IMPLEMENTED_MESSAGE,
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
}
}
@ -258,7 +257,7 @@ public class ODataDispatcher {
break;
default:
throw new ODataHandlerException("not implemented",
throw new ODataHandlerException(NOT_IMPLEMENTED_MESSAGE,
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
}
}
@ -266,44 +265,48 @@ public class ODataDispatcher {
private void handleReferenceDispatching(final ODataRequest request, final ODataResponse response,
final int lastPathSegmentIndex) throws ODataApplicationException, ODataLibraryException {
final HttpMethod method = request.getMethod();
final HttpMethod httpMethod = request.getMethod();
final boolean isCollection = ((UriResourcePartTyped) uriInfo.getUriResourceParts()
.get(lastPathSegmentIndex - 1))
.isCollection();
if (isCollection && method == HttpMethod.GET) {
if (isCollection && httpMethod == HttpMethod.GET) {
final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, handler.getCustomContentTypeSupport(), RepresentationType.COLLECTION_REFERENCE);
handler.selectProcessor(ReferenceCollectionProcessor.class)
.readReferenceCollection(request, response, uriInfo, responseFormat);
} else if (isCollection && method == HttpMethod.POST) {
} else if (isCollection && httpMethod == HttpMethod.POST) {
final ContentType requestFormat = ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
checkContentTypeSupport(requestFormat, RepresentationType.REFERENCE);
handler.selectProcessor(ReferenceProcessor.class)
.createReference(request, response, uriInfo, requestFormat);
} else if (!isCollection && method == HttpMethod.GET) {
} else if (!isCollection && httpMethod == HttpMethod.GET) {
final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, handler.getCustomContentTypeSupport(), RepresentationType.REFERENCE);
handler.selectProcessor(ReferenceProcessor.class).readReference(request, response, uriInfo, responseFormat);
} else if (!isCollection && (method == HttpMethod.PUT || method == HttpMethod.PATCH)) {
} else if (!isCollection && (httpMethod == HttpMethod.PUT || httpMethod == HttpMethod.PATCH)) {
final ContentType requestFormat = ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
checkContentTypeSupport(requestFormat, RepresentationType.REFERENCE);
handler.selectProcessor(ReferenceProcessor.class)
.updateReference(request, response, uriInfo, requestFormat);
} else if (method == HttpMethod.DELETE) {
} else if (httpMethod == HttpMethod.DELETE) {
handler.selectProcessor(ReferenceProcessor.class)
.deleteReference(request, response, uriInfo);
} else {
throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
throw new ODataHandlerException(getMethodNotAllowedStringMessage(httpMethod),
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, httpMethod.toString());
}
}
private String getMethodNotAllowedStringMessage(final HttpMethod httpMethod) {
return "HTTP method " + httpMethod + " is not allowed.";
}
private void handleValueDispatching(final ODataRequest request, final ODataResponse response,
final int lastPathSegmentIndex) throws ODataApplicationException, ODataLibraryException {
final HttpMethod method = request.getMethod();
@ -335,7 +338,7 @@ public class ODataDispatcher {
handler.selectProcessor(PrimitiveValueProcessor.class)
.deletePrimitiveValue(request, response, uriInfo);
} else {
throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
throw new ODataHandlerException(getMethodNotAllowedStringMessage(method),
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
}
} else {
@ -356,7 +359,7 @@ public class ODataDispatcher {
handler.selectProcessor(MediaEntityProcessor.class)
.deleteMediaEntity(request, response, uriInfo);
} else {
throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
throw new ODataHandlerException(getMethodNotAllowedStringMessage(method),
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
}
}
@ -400,7 +403,7 @@ public class ODataDispatcher {
.deleteComplex(request, response, uriInfo);
}
} else {
throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
throw new ODataHandlerException(getMethodNotAllowedStringMessage(method),
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
}
}
@ -443,7 +446,7 @@ public class ODataDispatcher {
.deletePrimitive(request, response, uriInfo);
}
} else {
throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
throw new ODataHandlerException(getMethodNotAllowedStringMessage(method),
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
}
}
@ -490,7 +493,7 @@ public class ODataDispatcher {
.createEntity(request, response, uriInfo, requestFormat, responseFormat);
}
} else {
throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
throw new ODataHandlerException(getMethodNotAllowedStringMessage(method),
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
}
} else {
@ -512,7 +515,7 @@ public class ODataDispatcher {
handler.selectProcessor(isMedia ? MediaEntityProcessor.class : EntityProcessor.class)
.deleteEntity(request, response, uriInfo);
} else {
throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
throw new ODataHandlerException(getMethodNotAllowedStringMessage(method),
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
}
}
@ -534,7 +537,7 @@ public class ODataDispatcher {
private void checkMethod(final HttpMethod requestMethod, final HttpMethod allowedMethod)
throws ODataHandlerException {
if (requestMethod != allowedMethod) {
throw new ODataHandlerException("HTTP method " + requestMethod + " is not allowed.",
throw new ODataHandlerException(getMethodNotAllowedStringMessage(requestMethod),
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, requestMethod.toString());
}
}

View File

@ -35,6 +35,10 @@ import org.apache.olingo.server.core.uri.validator.UriValidationException;
public class ODataExceptionHelper {
private ODataExceptionHelper() {
//Private Constructor
}
public static ODataServerError createServerErrorObject(final UriValidationException e,
final Locale requestedLocale) {
ODataServerError serverError = basicTranslatedError(e, requestedLocale);

View File

@ -132,7 +132,7 @@ public class ODataHandler {
debugger.stopRuntimeMeasurement(measurementUriValidator);
int measurementDispatcher = debugger.startRuntimeMeasurement("Dispatcher", "dispatch");
new ODataDispatcher(method, uriInfo, this).dispatch(request, response);
new ODataDispatcher(uriInfo, this).dispatch(request, response);
debugger.stopRuntimeMeasurement(measurementDispatcher);
}
@ -162,13 +162,11 @@ public class ODataHandler {
private void validateODataVersion(final ODataRequest request)
throws ODataHandlerException {
final String maxVersion = request.getHeader(HttpHeader.ODATA_MAX_VERSION);
if (maxVersion != null) {
if (ODataServiceVersion.isBiggerThan(ODataServiceVersion.V40.toString(), maxVersion)) {
if (maxVersion != null && ODataServiceVersion.isBiggerThan(ODataServiceVersion.V40.toString(), maxVersion)) {
throw new ODataHandlerException("ODataVersion not supported: " + maxVersion,
ODataHandlerException.MessageKeys.ODATA_VERSION_NOT_SUPPORTED, maxVersion);
}
}
}
<T extends Processor> T selectProcessor(final Class<T> cls) throws ODataHandlerException {
for (final Processor processor : processors) {

View File

@ -51,6 +51,11 @@ public class ODataHandlerException extends ODataLibraryException {
super(developmentMessage, messageKey, parameters);
}
public ODataHandlerException(final String developmentMessage, final Throwable cause, final MessageKey messageKey,
final String... parameters) {
super(developmentMessage, cause, messageKey, parameters);
}
@Override
protected String getBundleName() {
return DEFAULT_SERVER_BUNDLE_NAME;

View File

@ -229,7 +229,7 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler {
return httpRequestMethod;
}
} catch (IllegalArgumentException e) {
throw new ODataHandlerException("Invalid HTTP method" + httpRequest.getMethod(),
throw new ODataHandlerException("Invalid HTTP method" + httpRequest.getMethod(), e,
ODataHandlerException.MessageKeys.INVALID_HTTP_METHOD, httpRequest.getMethod());
}
}

View File

@ -29,6 +29,7 @@ import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.olingo.commons.api.ODataRuntimeException;
import org.apache.olingo.commons.api.format.ContentType;
@ -127,7 +128,7 @@ public class DebugResponseHelperImpl implements DebugResponseHelper {
// exceptions
if (debugInfo.getException() != null) {
parts.add(new DebugTabException(debugInfo.getException()));
parts.add(new DebugTabStacktrace(debugInfo.getException()));
}
return parts;
@ -165,8 +166,6 @@ public class DebugResponseHelperImpl implements DebugResponseHelper {
outputStream.close();
return csb.getInputStream();
} catch (IOException e) {
throw e;
} finally {
if (outputStream != null) {
try {
@ -284,12 +283,11 @@ public class DebugResponseHelperImpl implements DebugResponseHelper {
writer.append("<table>\n<thead>\n")
.append("<tr><th class=\"name\">Name</th><th class=\"value\">Value</th></tr>\n")
.append("</thead>\n<tbody>\n");
for (final String name : entries.keySet()) {
final String value = entries.get(name);
writer.append("<tr><td class=\"name\">").append(name).append("</td>")
for (final Entry<String, String> entry : entries.entrySet()) {
writer.append("<tr><td class=\"name\">").append(entry.getKey()).append("</td>")
.append("<td class=\"value\">");
if (value != null) {
writer.append(escapeHtml(value));
if (entry.getValue() != null) {
writer.append(escapeHtml(entry.getValue()));
} else {
writer.append("null");
}

View File

@ -33,18 +33,18 @@ public interface DebugTab {
* Gets the name of this debug information part, useful as title.
* @return the name
*/
public String getName();
String getName();
/**
* Appends the content of this debug information part
* to the given JSON stream writer.
* @param jsonGenerator a JSON generator
*/
public void appendJson(JsonGenerator jsonGenerator) throws IOException;
void appendJson(JsonGenerator jsonGenerator) throws IOException;
/**
* Appends the content of this debug information part to the given writer.
* @param writer a {@link Writer}
*/
public void appendHtml(Writer writer) throws IOException;
void appendHtml(Writer writer) throws IOException;
}

View File

@ -87,7 +87,7 @@ public class DebugTabBody implements DebugTab {
String contentString;
switch (responseContent) {
case IMAGE:
contentString = Base64.encodeBase64String(IOUtils.toString(response.getContent()).getBytes());
contentString = Base64.encodeBase64String(IOUtils.toString(response.getContent()).getBytes("UTF-8"));
break;
case JSON:
case XML:

View File

@ -33,6 +33,7 @@ import com.fasterxml.jackson.core.JsonGenerator;
*/
public class DebugTabRequest implements DebugTab {
private static final String UNKOWN_MSG = "unkown";
private final String method;
private final String uri;
private final String protocol;
@ -40,14 +41,14 @@ public class DebugTabRequest implements DebugTab {
public DebugTabRequest(ODataRequest request) {
if (request != null) {
method = request.getMethod() == null ? "unkown" : request.getMethod().toString();
uri = request.getRawRequestUri() == null ? "unkown" : request.getRawRequestUri();
protocol = request.getProtocol() == null ? "unkown" : request.getProtocol();
method = request.getMethod() == null ? UNKOWN_MSG : request.getMethod().toString();
uri = request.getRawRequestUri() == null ? UNKOWN_MSG : request.getRawRequestUri();
protocol = request.getProtocol() == null ? UNKOWN_MSG : request.getProtocol();
headers = request.getAllHeaders();
} else {
method = "unkown";
uri = "unkown";
protocol = "unkown";
method = UNKOWN_MSG;
uri = UNKOWN_MSG;
protocol = UNKOWN_MSG;
headers = Collections.emptyMap();
}
}

View File

@ -119,11 +119,11 @@ public class DebugTabRuntime implements DebugTab {
private class RuntimeNode {
protected String className;
protected String methodName;
protected long timeStarted;
protected long timeStopped;
protected List<RuntimeNode> children = new ArrayList<RuntimeNode>();
private String className;
private String methodName;
private long timeStarted;
private long timeStopped;
private List<RuntimeNode> children = new ArrayList<RuntimeNode>();
protected RuntimeNode() {
timeStarted = 0;

View File

@ -29,11 +29,11 @@ import com.fasterxml.jackson.core.JsonGenerator;
/**
* Exception debug information.
*/
public class DebugTabException implements DebugTab {
public class DebugTabStacktrace implements DebugTab {
private final Exception exception;
public DebugTabException(final Exception exception) {
public DebugTabStacktrace(final Exception exception) {
this.exception = exception;
}

View File

@ -43,19 +43,49 @@ import org.apache.olingo.server.api.uri.queryoption.expression.UnaryOperatorKind
*/
public class ExpressionJsonVisitor implements ExpressionVisitor<String> {
private static final String ANY_NAME = "ANY";
private static final String ALL_NAME = "ALL";
private static final String STRING_NAME = "String";
private static final String UNKNOWN_NAME = "unknown";
private static final String BOOLEAN_NAME = "Boolean";
private static final String NUMBER_NAME = "Number";
private static final String ENUM_NAME = "enum";
private static final String VALUES_NAME = "values";
private static final String NAME_NAME = "name";
private static final String LAMBDA_REFERENCE_NAME = "lambdaReference";
private static final String ALIAS_NAME = "alias";
private static final String RESOURCE_SEGMENTS_NAME = "resourceSegments";
private static final String MEMBER_NAME = "member";
private static final String VALUE_NAME = "value";
private static final String LITERAL_NAME = "literal";
private static final String EXPRESSION_NAME = "expression";
private static final String LAMBDA_VARIABLE_NAME = "lambdaVariable";
private static final String LAMBDA_FUNCTION_NAME = "lambdaFunction";
private static final String UNARY_NAME = "unary";
private static final String BINARY_NAME = "binary";
private static final String LEFT_NODE_NAME = "left";
private static final String RIGHT_NODE_NAME = "right";
private static final String IO_EXCEPTION_OCCOURED_MESSAGE = "IOException occoured";
private static final String PARAMETERS_NAME = "parameters";
private static final String METHOD_NAME = "method";
private static final String OPERAND_NAME = "operand";
private static final String TYPE_NAME = "type";
private static final String OPERATOR_NAME = "operator";
private static final String NODE_TYPE_NAME = "nodeType";
@Override
public String visitBinaryOperator(BinaryOperatorKind operator, String left, String right)
throws ExpressionVisitException, ODataApplicationException {
try {
StringWriter writer = new StringWriter();
JsonStreamWriter jsonStreamWriter = new JsonStreamWriter(writer);
jsonStreamWriter.beginObject().namedStringValue("nodeType", "binary").separator().namedStringValue("operator",
operator.toString()).separator().namedStringValueRaw("type", getType(operator)).separator().name("left")
.unquotedValue(left).separator().name("right").unquotedValue(right).endObject();
jsonStreamWriter.beginObject().namedStringValue(NODE_TYPE_NAME, BINARY_NAME).separator().namedStringValue(
OPERATOR_NAME, operator.toString()).separator().namedStringValueRaw(TYPE_NAME, getType(operator)).separator()
.name(LEFT_NODE_NAME).unquotedValue(left).separator().name(RIGHT_NODE_NAME).unquotedValue(right).endObject();
writer.flush();
return writer.toString();
} catch (final IOException e) {
throw new ExpressionVisitException("IOException occoured", e);
throw new ExpressionVisitException(IO_EXCEPTION_OCCOURED_MESSAGE, e);
}
}
@ -65,13 +95,13 @@ public class ExpressionJsonVisitor implements ExpressionVisitor<String> {
try {
StringWriter writer = new StringWriter();
JsonStreamWriter jsonStreamWriter = new JsonStreamWriter(writer);
jsonStreamWriter.beginObject().namedStringValue("nodeType", "unary").separator()
.namedStringValueRaw("operator", operator.toString()).separator().namedStringValueRaw("type",
getType(operator)).separator().name("operand").unquotedValue(operand).endObject();
jsonStreamWriter.beginObject().namedStringValue(NODE_TYPE_NAME, UNARY_NAME).separator()
.namedStringValueRaw(OPERATOR_NAME, operator.toString()).separator().namedStringValueRaw(TYPE_NAME,
getType(operator)).separator().name(OPERAND_NAME).unquotedValue(operand).endObject();
writer.flush();
return writer.toString();
} catch (final IOException e) {
throw new ExpressionVisitException("IOException occoured", e);
throw new ExpressionVisitException(IO_EXCEPTION_OCCOURED_MESSAGE, e);
}
}
@ -81,9 +111,9 @@ public class ExpressionJsonVisitor implements ExpressionVisitor<String> {
try {
StringWriter writer = new StringWriter();
JsonStreamWriter jsonStreamWriter = new JsonStreamWriter(writer);
jsonStreamWriter.beginObject().namedStringValueRaw("nodeType", "method").separator()
.namedStringValueRaw("operator", methodCall.toString()).separator().namedStringValueRaw("type",
getType(methodCall)).separator().name("parameters").beginArray();
jsonStreamWriter.beginObject().namedStringValueRaw(NODE_TYPE_NAME, METHOD_NAME).separator()
.namedStringValueRaw(OPERATOR_NAME, methodCall.toString()).separator().namedStringValueRaw(TYPE_NAME,
getType(methodCall)).separator().name(PARAMETERS_NAME).beginArray();
boolean first = true;
for (String parameter : parameters) {
if (first) {
@ -97,7 +127,7 @@ public class ExpressionJsonVisitor implements ExpressionVisitor<String> {
writer.flush();
return writer.toString();
} catch (final IOException e) {
throw new ExpressionVisitException("IOException occoured", e);
throw new ExpressionVisitException(IO_EXCEPTION_OCCOURED_MESSAGE, e);
}
}
@ -107,8 +137,8 @@ public class ExpressionJsonVisitor implements ExpressionVisitor<String> {
try {
StringWriter writer = new StringWriter();
JsonStreamWriter jsonStreamWriter = new JsonStreamWriter(writer);
jsonStreamWriter.beginObject().namedStringValue("nodeType", "lambdaFunction").separator()
.namedStringValue("lambdaVariable", lambdaVariable).separator().name("expression");
jsonStreamWriter.beginObject().namedStringValue(NODE_TYPE_NAME, LAMBDA_FUNCTION_NAME).separator()
.namedStringValue(LAMBDA_VARIABLE_NAME, lambdaVariable).separator().name(EXPRESSION_NAME);
// Write expression string object
String expressionJsonTree = expression.accept(this);
@ -116,7 +146,7 @@ public class ExpressionJsonVisitor implements ExpressionVisitor<String> {
writer.flush();
return writer.toString();
} catch (final IOException e) {
throw new ExpressionVisitException("IOException occoured", e);
throw new ExpressionVisitException(IO_EXCEPTION_OCCOURED_MESSAGE, e);
}
}
@ -125,12 +155,13 @@ public class ExpressionJsonVisitor implements ExpressionVisitor<String> {
try {
StringWriter writer = new StringWriter();
JsonStreamWriter jsonStreamWriter = new JsonStreamWriter(writer);
jsonStreamWriter.beginObject().namedStringValueRaw("nodeType", "literal").separator().namedStringValueRaw("type",
getTypeString(literal.getType())).separator().namedStringValue("value", literal.getText()).endObject();
jsonStreamWriter.beginObject().namedStringValueRaw(NODE_TYPE_NAME, LITERAL_NAME).separator().namedStringValueRaw(
TYPE_NAME, getTypeString(literal.getType())).separator().namedStringValue(VALUE_NAME, literal.getText())
.endObject();
writer.flush();
return writer.toString();
} catch (final IOException e) {
throw new ExpressionVisitException("IOException occoured");
throw new ExpressionVisitException(IO_EXCEPTION_OCCOURED_MESSAGE);
}
}
@ -140,11 +171,11 @@ public class ExpressionJsonVisitor implements ExpressionVisitor<String> {
StringWriter writer = new StringWriter();
JsonStreamWriter jsonStreamWriter = new JsonStreamWriter(writer);
List<UriResource> uriResourceParts = member.getUriResourceParts();
jsonStreamWriter.beginObject().namedStringValue("nodeType", "member").separator()
.namedStringValueRaw("type", getType(uriResourceParts)).separator();
jsonStreamWriter.beginObject().namedStringValue(NODE_TYPE_NAME, MEMBER_NAME).separator()
.namedStringValueRaw(TYPE_NAME, getType(uriResourceParts)).separator();
// write all member properties in an array
jsonStreamWriter.name("resourceSegments").beginArray();
jsonStreamWriter.name(RESOURCE_SEGMENTS_NAME).beginArray();
if (uriResourceParts != null) {
boolean first = true;
for (UriResource segment : uriResourceParts) {
@ -162,7 +193,7 @@ public class ExpressionJsonVisitor implements ExpressionVisitor<String> {
writer.flush();
return writer.toString();
} catch (final IOException e) {
throw new ExpressionVisitException("IOException occoured", e);
throw new ExpressionVisitException(IO_EXCEPTION_OCCOURED_MESSAGE, e);
}
}
@ -171,12 +202,12 @@ public class ExpressionJsonVisitor implements ExpressionVisitor<String> {
try {
StringWriter writer = new StringWriter();
JsonStreamWriter jsonStreamWriter = new JsonStreamWriter(writer);
jsonStreamWriter.beginObject().namedStringValueRaw("nodeType", "alias").separator()
.namedStringValue("alias", aliasName).endObject();
jsonStreamWriter.beginObject().namedStringValueRaw(NODE_TYPE_NAME, ALIAS_NAME).separator()
.namedStringValue(ALIAS_NAME, aliasName).endObject();
writer.flush();
return writer.toString();
} catch (final IOException e) {
throw new ExpressionVisitException("IOException occoured", e);
throw new ExpressionVisitException(IO_EXCEPTION_OCCOURED_MESSAGE, e);
}
}
@ -185,12 +216,12 @@ public class ExpressionJsonVisitor implements ExpressionVisitor<String> {
try {
StringWriter writer = new StringWriter();
JsonStreamWriter jsonStreamWriter = new JsonStreamWriter(writer);
jsonStreamWriter.beginObject().namedStringValueRaw("nodeType", "type").separator()
.namedStringValueRaw("type", getTypeString(type)).endObject();
jsonStreamWriter.beginObject().namedStringValueRaw(NODE_TYPE_NAME, TYPE_NAME).separator()
.namedStringValueRaw(TYPE_NAME, getTypeString(type)).endObject();
writer.flush();
return writer.toString();
} catch (final IOException e) {
throw new ExpressionVisitException("IOException occoured", e);
throw new ExpressionVisitException(IO_EXCEPTION_OCCOURED_MESSAGE, e);
}
}
@ -199,12 +230,12 @@ public class ExpressionJsonVisitor implements ExpressionVisitor<String> {
try {
StringWriter writer = new StringWriter();
JsonStreamWriter jsonStreamWriter = new JsonStreamWriter(writer);
jsonStreamWriter.beginObject().namedStringValueRaw("nodeType", "lambdaReference").separator()
.namedStringValueRaw("name", variableName).endObject();
jsonStreamWriter.beginObject().namedStringValueRaw(NODE_TYPE_NAME, LAMBDA_REFERENCE_NAME).separator()
.namedStringValueRaw(NAME_NAME, variableName).endObject();
writer.flush();
return writer.toString();
} catch (final IOException e) {
throw new ExpressionVisitException("IOException occoured", e);
throw new ExpressionVisitException(IO_EXCEPTION_OCCOURED_MESSAGE, e);
}
}
@ -214,9 +245,9 @@ public class ExpressionJsonVisitor implements ExpressionVisitor<String> {
try {
StringWriter writer = new StringWriter();
JsonStreamWriter jsonStreamWriter = new JsonStreamWriter(writer);
jsonStreamWriter.beginObject().namedStringValueRaw("nodeType", "enum").separator()
.namedStringValueRaw("type", getTypeString(type)).separator();
jsonStreamWriter.name("values").beginArray();
jsonStreamWriter.beginObject().namedStringValueRaw(NODE_TYPE_NAME, ENUM_NAME).separator()
.namedStringValueRaw(TYPE_NAME, getTypeString(type)).separator();
jsonStreamWriter.name(VALUES_NAME).beginArray();
if (enumValues != null) {
boolean first = true;
for (String value : enumValues) {
@ -234,18 +265,18 @@ public class ExpressionJsonVisitor implements ExpressionVisitor<String> {
writer.flush();
return writer.toString();
} catch (final IOException e) {
throw new ExpressionVisitException("IOException occoured", e);
throw new ExpressionVisitException(IO_EXCEPTION_OCCOURED_MESSAGE, e);
}
}
private String getType(UnaryOperatorKind operator) {
switch (operator) {
case MINUS:
return "Number";
return NUMBER_NAME;
case NOT:
return "Boolean";
return BOOLEAN_NAME;
default:
return "unknown";
return UNKNOWN_NAME;
}
}
@ -255,7 +286,7 @@ public class ExpressionJsonVisitor implements ExpressionVisitor<String> {
case CONTAINS:
case ENDSWITH:
case ISOF:
return "Boolean";
return BOOLEAN_NAME;
case INDEXOF:
case LENGTH:
case ROUND:
@ -267,7 +298,7 @@ public class ExpressionJsonVisitor implements ExpressionVisitor<String> {
case MONTH:
case SECOND:
case FRACTIONALSECONDS:
return "Number";
return NUMBER_NAME;
case CAST:
case CONCAT:
case DATE:
@ -285,9 +316,9 @@ public class ExpressionJsonVisitor implements ExpressionVisitor<String> {
case TOUPPER:
case TRIM:
case YEAR:
return "String";
return STRING_NAME;
default:
return "unkown";
return UNKNOWN_NAME;
}
}
@ -295,22 +326,23 @@ public class ExpressionJsonVisitor implements ExpressionVisitor<String> {
ExpressionVisitException, ODataApplicationException {
if (segment instanceof UriResourceLambdaAll) {
UriResourceLambdaAll all = (UriResourceLambdaAll) segment;
String lambdaJsonObjectString = visitLambdaExpression("ALL", all.getLambdaVariable(), all.getExpression());
String lambdaJsonObjectString = visitLambdaExpression(ALL_NAME, all.getLambdaVariable(), all.getExpression());
jsonStreamWriter.unquotedValue(lambdaJsonObjectString);
return;
} else if (segment instanceof UriResourceLambdaAny) {
UriResourceLambdaAny any = (UriResourceLambdaAny) segment;
String lambdaJsonObjectString = visitLambdaExpression("ANY", any.getLambdaVariable(), any.getExpression());
String lambdaJsonObjectString = visitLambdaExpression(ANY_NAME, any.getLambdaVariable(), any.getExpression());
jsonStreamWriter.unquotedValue(lambdaJsonObjectString);
return;
} else if (segment instanceof UriResourcePartTyped) {
String typeName =
((UriResourcePartTyped) segment).getType().getFullQualifiedName().getFullQualifiedNameAsString();
jsonStreamWriter.beginObject().namedStringValue("nodeType", segment.getKind().toString()).separator()
.namedStringValue("name", segment.toString()).separator().namedStringValueRaw("type", typeName).endObject();
jsonStreamWriter.beginObject().namedStringValue(NODE_TYPE_NAME, segment.getKind().toString()).separator()
.namedStringValue(NAME_NAME, segment.toString()).separator().namedStringValueRaw(TYPE_NAME, typeName)
.endObject();
} else {
jsonStreamWriter.beginObject().namedStringValue("nodeType", segment.getKind().toString()).separator()
.namedStringValue("name", segment.toString()).separator().namedStringValueRaw("type", null).endObject();
jsonStreamWriter.beginObject().namedStringValue(NODE_TYPE_NAME, segment.getKind().toString()).separator()
.namedStringValue(NAME_NAME, segment.toString()).separator().namedStringValueRaw(TYPE_NAME, null).endObject();
}
}
@ -321,7 +353,7 @@ public class ExpressionJsonVisitor implements ExpressionVisitor<String> {
case MOD:
case ADD:
case SUB:
return "Number";
return NUMBER_NAME;
case HAS:
case GT:
@ -332,10 +364,10 @@ public class ExpressionJsonVisitor implements ExpressionVisitor<String> {
case NE:
case AND:
case OR:
return "Boolean";
return BOOLEAN_NAME;
default:
return "unkown";
return UNKNOWN_NAME;
}
}
@ -355,7 +387,7 @@ public class ExpressionJsonVisitor implements ExpressionVisitor<String> {
if (lastSegment instanceof UriResourcePartTyped) {
type = ((UriResourcePartTyped) lastSegment).getType();
}
return type == null ? "unknown" : type.getFullQualifiedName().getFullQualifiedNameAsString();
return type == null ? UNKNOWN_NAME : type.getFullQualifiedName().getFullQualifiedNameAsString();
}
}

View File

@ -19,7 +19,7 @@
package org.apache.olingo.server.core.deserializer.batch;
public interface BatchPart {
public Header getHeaders();
Header getHeaders();
public boolean isStrict();
boolean isStrict();
}

View File

@ -27,6 +27,10 @@ import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerExceptio
public class BatchTransformatorCommon {
private BatchTransformatorCommon() {
//Private Utility Constructor
}
public static void validateContentType(final Header headers, final ContentType expected)
throws BatchDeserializerException {
final List<String> contentTypes = headers.getHeaders(HttpHeader.CONTENT_TYPE);
@ -78,7 +82,7 @@ public class BatchTransformatorCommon {
return contentLength;
} catch (NumberFormatException e) {
throw new BatchDeserializerException("Invalid header", MessageKeys.INVALID_HEADER,
throw new BatchDeserializerException("Invalid header", e, MessageKeys.INVALID_HEADER,
Integer.toString(contentLengthField.getLineNumber()));
}
}

View File

@ -72,6 +72,9 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
public class ODataJsonDeserializer implements ODataDeserializer {
private static final String AN_IO_EXCEPTION_OCCURRED_MSG = "An IOException occurred";
private static final String DUPLICATE_JSON_PROPERTY_DETECTED_MSG = "Duplicate json property detected";
private static final String AN_JSON_PARSE_EXCEPTION_OCCURRED_MSG = "An JsonParseException occurred";
private static final String ODATA_ANNOTATION_MARKER = "@";
private static final String ODATA_CONTROL_INFORMATION_PREFIX = "@odata.";
private static final EdmPrimitiveType EDM_INT64 = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int64);
@ -91,13 +94,13 @@ public class ODataJsonDeserializer implements ODataDeserializer {
return DeserializerResultImpl.with().entityCollection(consumeEntitySetNode(edmEntityType, tree, null))
.build();
} catch (JsonParseException e) {
throw new DeserializerException("An JsonParseException occurred", e,
throw new DeserializerException(AN_JSON_PARSE_EXCEPTION_OCCURRED_MSG, e,
DeserializerException.MessageKeys.JSON_SYNTAX_EXCEPTION);
} catch (JsonMappingException e) {
throw new DeserializerException("Duplicate json property detected", e,
throw new DeserializerException(DUPLICATE_JSON_PROPERTY_DETECTED_MSG, e,
DeserializerException.MessageKeys.DUPLICATE_JSON_PROPERTY);
} catch (IOException e) {
throw new DeserializerException("An IOException occurred", e, DeserializerException.MessageKeys.IO_EXCEPTION);
throw new DeserializerException(AN_IO_EXCEPTION_OCCURRED_MSG, e, DeserializerException.MessageKeys.IO_EXCEPTION);
}
}
@ -166,13 +169,13 @@ public class ODataJsonDeserializer implements ODataDeserializer {
.build();
} catch (JsonParseException e) {
throw new DeserializerException("An JsonParseException occurred", e,
throw new DeserializerException(AN_JSON_PARSE_EXCEPTION_OCCURRED_MSG, e,
DeserializerException.MessageKeys.JSON_SYNTAX_EXCEPTION);
} catch (JsonMappingException e) {
throw new DeserializerException("Duplicate property detected", e,
throw new DeserializerException(DUPLICATE_JSON_PROPERTY_DETECTED_MSG, e,
DeserializerException.MessageKeys.DUPLICATE_PROPERTY);
} catch (IOException e) {
throw new DeserializerException("An IOException occurred", e, DeserializerException.MessageKeys.IO_EXCEPTION);
throw new DeserializerException(AN_IO_EXCEPTION_OCCURRED_MSG, e, DeserializerException.MessageKeys.IO_EXCEPTION);
}
}
@ -225,13 +228,13 @@ public class ODataJsonDeserializer implements ODataDeserializer {
return DeserializerResultImpl.with().build();
} catch (final JsonParseException e) {
throw new DeserializerException("An JsonParseException occurred", e,
throw new DeserializerException(AN_JSON_PARSE_EXCEPTION_OCCURRED_MSG, e,
DeserializerException.MessageKeys.JSON_SYNTAX_EXCEPTION);
} catch (final JsonMappingException e) {
throw new DeserializerException("Duplicate property detected", e,
throw new DeserializerException(DUPLICATE_JSON_PROPERTY_DETECTED_MSG, e,
DeserializerException.MessageKeys.DUPLICATE_PROPERTY);
} catch (final IOException e) {
throw new DeserializerException("An IOException occurred", e,
throw new DeserializerException(AN_IO_EXCEPTION_OCCURRED_MSG, e,
DeserializerException.MessageKeys.IO_EXCEPTION);
}
}
@ -695,12 +698,12 @@ public class ODataJsonDeserializer implements ODataDeserializer {
Class<?> javaClass = getJavaClassForPrimitiveType(mapping, edmPrimitiveType);
String jsonNodeAsText = jsonNode.asText();
if (isIEEE754Compatible && (edmPrimitiveType.equals(EDM_INT64) || edmPrimitiveType.equals(EDM_DECIMAL))) {
if (jsonNodeAsText.length() == 0) {
if (isIEEE754Compatible
&& (edmPrimitiveType.equals(EDM_INT64) || edmPrimitiveType.equals(EDM_DECIMAL))
&& jsonNodeAsText.length() == 0) {
throw new DeserializerException("IEEE754Compatible values must not be of length 0",
MessageKeys.INVALID_NULL_PROPERTY, name);
}
}
return edmPrimitiveType.valueOfString(jsonNodeAsText, isNullable, maxLength, precision, scale, isUnicode,
javaClass);
@ -865,13 +868,13 @@ public class ODataJsonDeserializer implements ODataDeserializer {
}
return DeserializerResultImpl.with().property(property).build();
} catch (JsonParseException e) {
throw new DeserializerException("An JsonParseException occurred", e,
throw new DeserializerException(AN_JSON_PARSE_EXCEPTION_OCCURRED_MSG, e,
DeserializerException.MessageKeys.JSON_SYNTAX_EXCEPTION);
} catch (JsonMappingException e) {
throw new DeserializerException("Duplicate property detected", e,
throw new DeserializerException(DUPLICATE_JSON_PROPERTY_DETECTED_MSG, e,
DeserializerException.MessageKeys.DUPLICATE_PROPERTY);
} catch (IOException e) {
throw new DeserializerException("An IOException occurred", e, DeserializerException.MessageKeys.IO_EXCEPTION);
throw new DeserializerException(AN_IO_EXCEPTION_OCCURRED_MSG, e, DeserializerException.MessageKeys.IO_EXCEPTION);
}
}
@ -908,13 +911,13 @@ public class ODataJsonDeserializer implements ODataDeserializer {
}
return DeserializerResultImpl.with().entityReferences(parsedValues).build();
} catch (JsonParseException e) {
throw new DeserializerException("An JsonParseException occurred", e,
throw new DeserializerException(AN_JSON_PARSE_EXCEPTION_OCCURRED_MSG, e,
DeserializerException.MessageKeys.JSON_SYNTAX_EXCEPTION);
} catch (JsonMappingException e) {
throw new DeserializerException("Duplicate property detected", e,
throw new DeserializerException(DUPLICATE_JSON_PROPERTY_DETECTED_MSG, e,
DeserializerException.MessageKeys.DUPLICATE_PROPERTY);
} catch (IOException e) {
throw new DeserializerException("An IOException occurred", e,
throw new DeserializerException(AN_IO_EXCEPTION_OCCURRED_MSG, e,
DeserializerException.MessageKeys.IO_EXCEPTION);
} catch (URISyntaxException e) {
throw new DeserializerException("failed to read @odata.id", e,

View File

@ -24,12 +24,10 @@ import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import javax.xml.XMLConstants;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.stream.events.Attribute;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
@ -66,30 +64,30 @@ import com.fasterxml.aalto.stax.InputFactoryImpl;
public class ODataXmlDeserializer implements ODataDeserializer {
protected static final XMLInputFactory FACTORY = new InputFactoryImpl();
private static final XMLInputFactory FACTORY = new InputFactoryImpl();
private static final String ATOM = "a";
private static final String NS_ATOM = "http://www.w3.org/2005/Atom";
protected QName REF_ELEMENT = new QName("http://docs.oasis-open.org/odata/ns/metadata", "ref");
protected QName FEED_ELEMENT = new QName("http://www.w3.org/2005/Atom", "feed");
protected QName ID_ATTR = new QName(NS_ATOM, ATOM);
private static final QName REF_ELEMENT = new QName("http://docs.oasis-open.org/odata/ns/metadata", "ref");
// private static final QName FEED_ELEMENT = new QName("http://www.w3.org/2005/Atom", "feed");
private static final QName ID_ATTR = new QName(NS_ATOM, ATOM);
protected final QName propertiesQName = new QName(Constants.NS_METADATA, Constants.PROPERTIES);
protected final QName propertyValueQName = new QName(Constants.NS_METADATA, Constants.VALUE);
protected final QName contextQName = new QName(Constants.NS_METADATA, Constants.CONTEXT);
protected final QName nullQName = new QName(Constants.NS_METADATA, Constants.ATTR_NULL);
protected final QName inlineQName = new QName(Constants.NS_METADATA, Constants.ATOM_ELEM_INLINE);
protected final QName entryRefQName = new QName(Constants.NS_METADATA, Constants.ATOM_ELEM_ENTRY_REF);
protected final QName etagQName = new QName(Constants.NS_METADATA, Constants.ATOM_ATTR_ETAG);
protected final QName countQName = new QName(Constants.NS_METADATA, Constants.ATOM_ELEM_COUNT);
private final QName propertiesQName = new QName(Constants.NS_METADATA, Constants.PROPERTIES);
private final QName propertyValueQName = new QName(Constants.NS_METADATA, Constants.VALUE);
private final QName contextQName = new QName(Constants.NS_METADATA, Constants.CONTEXT);
private final QName nullQName = new QName(Constants.NS_METADATA, Constants.ATTR_NULL);
private final QName inlineQName = new QName(Constants.NS_METADATA, Constants.ATOM_ELEM_INLINE);
private final QName entryRefQName = new QName(Constants.NS_METADATA, Constants.ATOM_ELEM_ENTRY_REF);
private final QName etagQName = new QName(Constants.NS_METADATA, Constants.ATOM_ATTR_ETAG);
private final QName countQName = new QName(Constants.NS_METADATA, Constants.ATOM_ELEM_COUNT);
protected void namespaces(final XMLStreamWriter writer) throws XMLStreamException {
writer.writeNamespace(StringUtils.EMPTY, Constants.NS_ATOM);
writer.writeNamespace(XMLConstants.XML_NS_PREFIX, XMLConstants.XML_NS_URI);
writer.writeNamespace(Constants.PREFIX_METADATA, Constants.NS_METADATA);
writer.writeNamespace(Constants.PREFIX_DATASERVICES, Constants.NS_DATASERVICES);
writer.writeNamespace(Constants.PREFIX_GML, Constants.NS_GML);
writer.writeNamespace(Constants.PREFIX_GEORSS, Constants.NS_GEORSS);
}
// private void namespaces(final XMLStreamWriter writer) throws XMLStreamException {
// writer.writeNamespace(StringUtils.EMPTY, Constants.NS_ATOM);
// writer.writeNamespace(XMLConstants.XML_NS_PREFIX, XMLConstants.XML_NS_URI);
// writer.writeNamespace(Constants.PREFIX_METADATA, Constants.NS_METADATA);
// writer.writeNamespace(Constants.PREFIX_DATASERVICES, Constants.NS_DATASERVICES);
// writer.writeNamespace(Constants.PREFIX_GML, Constants.NS_GML);
// writer.writeNamespace(Constants.PREFIX_GEORSS, Constants.NS_GEORSS);
// }
protected XMLEventReader getReader(final InputStream input) throws XMLStreamException {
return FACTORY.createXMLEventReader(input);
@ -373,11 +371,9 @@ public class ODataXmlDeserializer implements ODataDeserializer {
while (reader.hasNext() && !foundEndElement) {
final XMLEvent event = reader.nextEvent();
if (event.isStartElement()) {
if (REF_ELEMENT.equals(event.asStartElement().getName())) {
if (event.isStartElement() && REF_ELEMENT.equals(event.asStartElement().getName())) {
references.add(entityRef(reader, event.asStartElement()));
}
}
if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
foundEndElement = true;
@ -689,7 +685,7 @@ public class ODataXmlDeserializer implements ODataDeserializer {
}
return DeserializerResultImpl.with().entityReferences(references).build();
} catch (XMLStreamException e) {
throw new DeserializerException("An IOException occurred", e.getCause(),
throw new DeserializerException("An IOException occurred", e,
DeserializerException.MessageKeys.IO_EXCEPTION);
}
}

View File

@ -44,6 +44,10 @@ public class ETagParser {
private static final Pattern ETAG = Pattern.compile("\\s*(,\\s*)+|((?:W/)?\"[!#-~\\x80-\\xFF]*\")");
private ETagParser (){
//Private constructor for utility classes
}
protected static Collection<String> parse(final Collection<String> values) {
if (values == null) {
return Collections.<String> emptySet();

View File

@ -59,6 +59,10 @@ public class PreferParser {
+ "(?:" + namedValue + "((?:\\s*;\\s*(?:" + namedValue + ")?)*))");
private static final Pattern PARAMETER = Pattern.compile("\\s*(;\\s*)+|(?:" + namedValue + ")");
private PreferParser (){
//Private constructor for utility classes
}
protected static Map<String, Preference> parse(final Collection<String> values) {
if (values == null || values.isEmpty()) {
return Collections.emptyMap();

View File

@ -26,6 +26,8 @@ import org.apache.olingo.server.api.serializer.SerializerException;
public abstract class AbstractODataSerializer implements ODataSerializer {
protected static final String IO_EXCEPTION_TEXT = "An I/O exception occurred.";
protected void closeCircleStreamBufferOutput(OutputStream outputStream, SerializerException cachedException)
throws SerializerException {
if (outputStream != null) {

View File

@ -258,7 +258,7 @@ public class BatchResponseSerializer {
}
return output.toByteArray();
} catch (IOException e) {
throw new ODataRuntimeException("Error on reading request content");
throw new ODataRuntimeException("Error on reading request content", e);
}
}
}

View File

@ -41,7 +41,12 @@ public class FixedFormatSerializerImpl implements FixedFormatSerializer {
@Override
public InputStream count(final Integer count) throws SerializerException {
return new ByteArrayInputStream(count.toString().getBytes());
try {
return new ByteArrayInputStream(count.toString().getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
throw new SerializerException("UTF-8 is nott supprted as an encoding", e,
SerializerException.MessageKeys.UNSUPPORTED_ENCODING, "UTF-8");
}
}
@Override

View File

@ -97,7 +97,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final IOException e) {
cachedException =
new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} finally {
closeCircleStreamBufferOutput(outputStream, cachedException);
@ -125,7 +125,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final IOException e) {
cachedException =
new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} finally {
closeCircleStreamBufferOutput(outputStream, cachedException);
@ -166,7 +166,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final IOException e) {
cachedException =
new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} finally {
closeCircleStreamBufferOutput(outputStream, cachedException);
@ -194,7 +194,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final IOException e) {
cachedException =
new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} finally {
closeCircleStreamBufferOutput(outputStream, cachedException);
@ -574,7 +574,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final IOException e) {
cachedException =
new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} catch (final EdmPrimitiveTypeException e) {
cachedException = new SerializerException("Wrong value for property!", e,
@ -617,7 +617,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final IOException e) {
cachedException =
new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} finally {
closeCircleStreamBufferOutput(outputStream, cachedException);
@ -651,7 +651,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final IOException e) {
cachedException =
new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} finally {
closeCircleStreamBufferOutput(outputStream, cachedException);
@ -680,7 +680,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final IOException e) {
cachedException =
new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} finally {
closeCircleStreamBufferOutput(outputStream, cachedException);
@ -710,7 +710,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final IOException e) {
cachedException =
new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} finally {
closeCircleStreamBufferOutput(outputStream, cachedException);
@ -754,7 +754,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final IOException e) {
cachedException =
new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} finally {
closeCircleStreamBufferOutput(outputStream, cachedException);
@ -796,7 +796,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
private boolean isODataIEEE754Compatible(final ContentType contentType) {
return contentType.getParameters().containsKey(ContentType.PARAMETER_IEEE754_COMPATIBLE)
&& Boolean.TRUE.toString().toLowerCase().equals(
&& Boolean.TRUE.toString().equalsIgnoreCase(
contentType.getParameter(ContentType.PARAMETER_IEEE754_COMPATIBLE).toLowerCase());
}
}

View File

@ -21,6 +21,11 @@ package org.apache.olingo.server.core.serializer.utils;
import org.apache.olingo.commons.api.format.ContentType;
public class ContentTypeHelper {
private ContentTypeHelper (){
//Private constructor for utility classes
}
public static boolean isODataMetadataNone(final ContentType contentType) {
return contentType.isCompatible(ContentType.APPLICATION_JSON)
&& ContentType.VALUE_ODATA_METADATA_NONE.equals(contentType.getParameter(ContentType.PARAMETER_ODATA_METADATA));

View File

@ -112,11 +112,11 @@ public class MetadataDocumentXmlSerializer {
private static final String DATA_SERVICES = "DataServices";
private static final String ABSTRACT = "Abstract";
private final static String EDMX = "Edmx";
private final static String PREFIX_EDMX = "edmx";
private final static String NS_EDMX = "http://docs.oasis-open.org/odata/ns/edmx";
private static final String EDMX = "Edmx";
private static final String PREFIX_EDMX = "edmx";
private static final String NS_EDMX = "http://docs.oasis-open.org/odata/ns/edmx";
private final static String NS_EDM = "http://docs.oasis-open.org/odata/ns/edm";
private static final String NS_EDM = "http://docs.oasis-open.org/odata/ns/edm";
private static final String XML_ENTITY_SET_PATH = "EntitySetPath";
private static final String XML_CONTAINS_TARGET = "ContainsTarget";
@ -401,7 +401,7 @@ public class MetadataDocumentXmlSerializer {
private void appendReturnTypeFacets(final XMLStreamWriter writer, final EdmReturnType returnType)
throws XMLStreamException {
if (returnType.isNullable() == false) {
if (!returnType.isNullable()) {
writer.writeAttribute(XML_NULLABLE, "" + returnType.isNullable());
}
if (returnType.getMaxLength() != null) {
@ -417,7 +417,7 @@ public class MetadataDocumentXmlSerializer {
private void appendParameterFacets(final XMLStreamWriter writer, final EdmParameter parameter)
throws XMLStreamException {
if (parameter.isNullable() == false) {
if (!parameter.isNullable()) {
writer.writeAttribute(XML_NULLABLE, "" + parameter.isNullable());
}
if (parameter.getMaxLength() != null) {
@ -494,7 +494,7 @@ public class MetadataDocumentXmlSerializer {
writer.writeAttribute(XML_NAME, navigationPropertyName);
writer.writeAttribute(XML_TYPE, getAliasedFullQualifiedName(navigationProperty.getType(), navigationProperty
.isCollection()));
if (navigationProperty.isNullable() == false) {
if (!navigationProperty.isNullable()) {
writer.writeAttribute(XML_NULLABLE, "" + navigationProperty.isNullable());
}
@ -537,11 +537,11 @@ public class MetadataDocumentXmlSerializer {
writer.writeAttribute(XML_TYPE, fqnString);
// Facets
if (property.isNullable() == false) {
if (!property.isNullable()) {
writer.writeAttribute(XML_NULLABLE, "" + property.isNullable());
}
if (property.isUnicode() == false) {
if (!property.isUnicode()) {
writer.writeAttribute(XML_UNICODE, "" + property.isUnicode());
}

View File

@ -73,6 +73,7 @@ import org.apache.olingo.server.core.serializer.utils.ContextURLBuilder;
import org.apache.olingo.server.core.serializer.utils.ExpandSelectHelper;
public class ODataXmlSerializer extends AbstractODataSerializer {
private static final String DATA = "d";
private static final String CONTEXT = "context";
/** The default character set is UTF-8. */
@ -103,11 +104,11 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final XMLStreamException e) {
cachedException =
new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} catch (IOException e) {
cachedException =
new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} finally {
closeCircleStreamBufferOutput(outputStream, cachedException);
@ -132,11 +133,11 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final XMLStreamException e) {
cachedException =
new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} catch (IOException e) {
cachedException =
new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} finally {
closeCircleStreamBufferOutput(outputStream, cachedException);
@ -178,11 +179,11 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final XMLStreamException e) {
cachedException =
new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} catch (IOException e) {
cachedException =
new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} finally {
closeCircleStreamBufferOutput(outputStream, cachedException);
@ -267,11 +268,11 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final XMLStreamException e) {
cachedException =
new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} catch (IOException e) {
cachedException =
new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} finally {
closeCircleStreamBufferOutput(outputStream, cachedException);
@ -309,11 +310,11 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final XMLStreamException e) {
cachedException =
new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} catch (IOException e) {
cachedException =
new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} finally {
closeCircleStreamBufferOutput(outputStream, cachedException);
@ -838,7 +839,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final XMLStreamException e) {
cachedException = new SerializerException("An I/O exception occurred.", e,
cachedException = new SerializerException(IO_EXCEPTION_TEXT, e,
SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} catch (final EdmPrimitiveTypeException e) {
@ -848,7 +849,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
throw cachedException;
} catch (IOException e) {
cachedException =
new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} finally {
closeCircleStreamBufferOutput(outputStream, cachedException);
@ -890,11 +891,11 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final XMLStreamException e) {
cachedException =
new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} catch (IOException e) {
cachedException =
new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} finally {
closeCircleStreamBufferOutput(outputStream, cachedException);
@ -937,7 +938,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final XMLStreamException e) {
cachedException = new SerializerException("An I/O exception occurred.", e,
cachedException = new SerializerException(IO_EXCEPTION_TEXT, e,
SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} catch (final EdmPrimitiveTypeException e) {
@ -947,7 +948,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
throw cachedException;
} catch (IOException e) {
cachedException =
new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} finally {
closeCircleStreamBufferOutput(outputStream, cachedException);
@ -982,11 +983,11 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final XMLStreamException e) {
cachedException =
new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} catch (IOException e) {
cachedException =
new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} finally {
closeCircleStreamBufferOutput(outputStream, cachedException);
@ -1017,11 +1018,11 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final XMLStreamException e) {
cachedException =
new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} catch (IOException e) {
cachedException =
new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} finally {
closeCircleStreamBufferOutput(outputStream, cachedException);
@ -1085,11 +1086,11 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final XMLStreamException e) {
cachedException =
new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} catch (IOException e) {
cachedException =
new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} finally {
closeCircleStreamBufferOutput(outputStream, cachedException);

View File

@ -85,7 +85,7 @@ public class UriHelperImpl implements UriHelper {
edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode()));
result.append(Encoder.encode(value));
} catch (final EdmPrimitiveTypeException e) {
throw new SerializerException("Wrong key value!",
throw new SerializerException("Wrong key value!", e,
SerializerException.MessageKeys.WRONG_PROPERTY_VALUE, edmProperty.getName(), propertyValue.toString());
}
}
@ -114,7 +114,7 @@ public class UriHelperImpl implements UriHelper {
throw new DeserializerException("Invalid entity binding link", MessageKeys.INVALID_ENTITY_BINDING_LINK,
entityId);
} catch (UriParserException e) {
throw new DeserializerException("Invalid entity binding link", MessageKeys.INVALID_ENTITY_BINDING_LINK,
throw new DeserializerException("Invalid entity binding link", e, MessageKeys.INVALID_ENTITY_BINDING_LINK,
entityId);
}
}

View File

@ -99,6 +99,7 @@ SerializerException.WRONG_PROPERTY_VALUE=The value '%2$s' is not valid for prope
SerializerException.WRONG_PRIMITIVE_VALUE=The value '%2$s' is not valid for the primitive type '%1$s' and the given facets.
SerializerException.UNKNOWN_TYPE=Type '%1s' not found in metadata.
SerializerException.WRONG_BASE_TYPE=Type '%1s' is not derived from '%2s'.
SerializerException.UNSUPPORTED_ENCODING=The encoding '%1s' is not supported.
DeserializerException.NOT_IMPLEMENTED=The requested deserialization method has not been implemented yet.
DeserializerException.IO_EXCEPTION=An I/O exception occurred.