diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerException.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerException.java index 4e1a0356f..64eb5d27d 100644 --- a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerException.java +++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerException.java @@ -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() { diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataDispatcher.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataDispatcher.java index ff2b599be..459c1aed4 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataDispatcher.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataDispatcher.java @@ -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()); } } diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataExceptionHelper.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataExceptionHelper.java index 8c48d5ff2..830867b23 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataExceptionHelper.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataExceptionHelper.java @@ -34,6 +34,10 @@ import org.apache.olingo.server.core.uri.parser.UriParserSyntaxException; 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) { diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java index 80d548a86..5dedc116a 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java @@ -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,11 +162,9 @@ 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); - } } } diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandlerException.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandlerException.java index 145bae9dd..62adf1969 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandlerException.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandlerException.java @@ -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; diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java index 59fa697b5..517018569 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java @@ -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()); } } diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugResponseHelperImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugResponseHelperImpl.java index aec88586f..f81a256aa 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugResponseHelperImpl.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugResponseHelperImpl.java @@ -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("\n\n") .append("\n") .append("\n\n"); - for (final String name : entries.keySet()) { - final String value = entries.get(name); - writer.append("") + for (final Entry entry : entries.entrySet()) { + writer.append("") .append("
NameValue
").append(name).append("
").append(entry.getKey()).append(""); - if (value != null) { - writer.append(escapeHtml(value)); + if (entry.getValue() != null) { + writer.append(escapeHtml(entry.getValue())); } else { writer.append("null"); } diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTab.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTab.java index 8847e3301..76384b047 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTab.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTab.java @@ -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; } diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabBody.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabBody.java index 317f3762f..ab489b0b6 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabBody.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabBody.java @@ -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: diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabRequest.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabRequest.java index be38f681a..4f9bc5c3c 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabRequest.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabRequest.java @@ -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(); } } diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabRuntime.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabRuntime.java index 312b4cdfe..c7657908e 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabRuntime.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabRuntime.java @@ -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 children = new ArrayList(); + private String className; + private String methodName; + private long timeStarted; + private long timeStopped; + private List children = new ArrayList(); protected RuntimeNode() { timeStarted = 0; diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabException.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabStacktrace.java similarity index 97% rename from lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabException.java rename to lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabStacktrace.java index 6bc69e485..0d79e855a 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabException.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabStacktrace.java @@ -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; } diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/ExpressionJsonVisitor.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/ExpressionJsonVisitor.java index 773ea485c..5e130e9ab 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/ExpressionJsonVisitor.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/ExpressionJsonVisitor.java @@ -43,19 +43,49 @@ import org.apache.olingo.server.api.uri.queryoption.expression.UnaryOperatorKind */ public class ExpressionJsonVisitor implements ExpressionVisitor { + 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 { 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 { 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 { 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 { 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 { 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 { 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 { StringWriter writer = new StringWriter(); JsonStreamWriter jsonStreamWriter = new JsonStreamWriter(writer); List 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { case MOD: case ADD: case SUB: - return "Number"; + return NUMBER_NAME; case HAS: case GT: @@ -332,10 +364,10 @@ public class ExpressionJsonVisitor implements ExpressionVisitor { 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 { if (lastSegment instanceof UriResourcePartTyped) { type = ((UriResourcePartTyped) lastSegment).getType(); } - return type == null ? "unknown" : type.getFullQualifiedName().getFullQualifiedNameAsString(); + return type == null ? UNKNOWN_NAME : type.getFullQualifiedName().getFullQualifiedNameAsString(); } } diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchPart.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchPart.java index 9ee642de2..13986c424 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchPart.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchPart.java @@ -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(); } diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchTransformatorCommon.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchTransformatorCommon.java index 57576437c..1543c43c5 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchTransformatorCommon.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchTransformatorCommon.java @@ -26,6 +26,10 @@ import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerExceptio import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerException.MessageKeys; public class BatchTransformatorCommon { + + private BatchTransformatorCommon() { + //Private Utility Constructor + } public static void validateContentType(final Header headers, final ContentType expected) throws BatchDeserializerException { @@ -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())); } } diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java index abcb95830..759cf6682 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java @@ -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,11 +698,11 @@ 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) { - throw new DeserializerException("IEEE754Compatible values must not be of length 0", - MessageKeys.INVALID_NULL_PROPERTY, name); - } + 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, @@ -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, diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/xml/ODataXmlDeserializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/xml/ODataXmlDeserializer.java index c130ebbcd..efbad9507 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/xml/ODataXmlDeserializer.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/xml/ODataXmlDeserializer.java @@ -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,10 +371,8 @@ 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())) { @@ -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); } } diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/etag/ETagParser.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/etag/ETagParser.java index b8534dd2a..805a29c15 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/etag/ETagParser.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/etag/ETagParser.java @@ -43,6 +43,10 @@ import java.util.regex.Pattern; 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 parse(final Collection values) { if (values == null) { diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/prefer/PreferParser.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/prefer/PreferParser.java index f963703c9..eee795959 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/prefer/PreferParser.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/prefer/PreferParser.java @@ -58,6 +58,10 @@ public class PreferParser { private static final Pattern PREFERENCE = Pattern.compile("\\s*(,\\s*)+|" + "(?:" + namedValue + "((?:\\s*;\\s*(?:" + namedValue + ")?)*))"); private static final Pattern PARAMETER = Pattern.compile("\\s*(;\\s*)+|(?:" + namedValue + ")"); + + private PreferParser (){ + //Private constructor for utility classes + } protected static Map parse(final Collection values) { if (values == null || values.isEmpty()) { diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/AbstractODataSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/AbstractODataSerializer.java index ee472c62e..c27958654 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/AbstractODataSerializer.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/AbstractODataSerializer.java @@ -25,6 +25,8 @@ import org.apache.olingo.server.api.serializer.ODataSerializer; 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 { diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/BatchResponseSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/BatchResponseSerializer.java index 8cd470681..95a33f5cd 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/BatchResponseSerializer.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/BatchResponseSerializer.java @@ -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); } } } diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/FixedFormatSerializerImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/FixedFormatSerializerImpl.java index 0a401b23d..3066839d2 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/FixedFormatSerializerImpl.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/FixedFormatSerializerImpl.java @@ -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 diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java index 57fc4712b..f9c0c8f99 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java @@ -84,7 +84,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer { public SerializerResult serviceDocument(final ServiceMetadata metadata, final String serviceRoot) throws SerializerException { OutputStream outputStream = null; - SerializerException cachedException = null; + SerializerException cachedException = null; try { CircleStreamBuffer buffer = new CircleStreamBuffer(); @@ -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()); } } diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContentTypeHelper.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContentTypeHelper.java index 1e8066652..87101587c 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContentTypeHelper.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContentTypeHelper.java @@ -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)); diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java index 2957bceac..045783cfc 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java @@ -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()); } diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java index b40d4efa4..899226feb 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java @@ -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); diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriHelperImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriHelperImpl.java index 850a5d2d4..ae2700d1a 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriHelperImpl.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriHelperImpl.java @@ -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); } } diff --git a/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties b/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties index 312b32403..0e3ab995c 100644 --- a/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties +++ b/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties @@ -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.