protected String getBodyText() { try { return request.getBodyText(UTF_8.name()); } catch (UnsupportedEncodingException e) { throw new ODataSystemException(e); } }
protected String getBodyText() { try { return request.getBodyText(UTF_8.name()); } catch (UnsupportedEncodingException e) { throw new ODataSystemException(e); } }
private void doWireLogging(ODataRequest request) throws UnsupportedEncodingException { if (LOG.isTraceEnabled()) { LOG.trace("RAW REQUEST LOGGING"); LOG.trace("{} request for URL: {}", request.getMethod().name(), request.getUri()); for (Map.Entry<String, String> headerEntry : request.getHeaders().entrySet()) { LOG.trace("Header: {} value: {}", headerEntry.getKey(), headerEntry.getValue()); } LOG.trace("BODY: {}", request.getBodyText(UTF_8.name())); } } }
private void doWireLogging(ODataRequest request) throws UnsupportedEncodingException { if (LOG.isTraceEnabled()) { LOG.trace("RAW REQUEST LOGGING"); LOG.trace("{} request for URL: {}", request.getMethod().name(), request.getUri()); for (Map.Entry<String, String> headerEntry : request.getHeaders().entrySet()) { LOG.trace("Header: {} value: {}", headerEntry.getKey(), headerEntry.getValue()); } LOG.trace("BODY: {}", request.getBodyText(UTF_8.name())); } } }
@Override protected String getToEntityId(ODataRequestContext requestContext) throws ODataUnmarshallingException { // The body is expected to contain a single entity reference // See OData Atom XML specification chapter 13 String bodyText; try { bodyText = requestContext.getRequest().getBodyText(StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { throw new ODataSystemException("UTF-8 is not supported", e); } Document document = parseXML(bodyText); Element rootElement = document.getDocumentElement(); if (!rootElement.getNodeName().equals(REF)) { throw new ODataUnmarshallingException("A " + requestContext.getRequest().getMethod() + " request to an entity reference URI must contain a single entity reference in the body," + " but something else was found instead: " + rootElement.getNodeName()); } String idAttr = rootElement.getAttribute(ID); if (isNullOrEmpty(idAttr)) { throw new ODataUnmarshallingException("The <metadata:ref> element in the body has no 'id' attribute," + " or the attribute is empty. The element must have an 'id' attribute that refers" + " to the entity to link to."); } return idAttr; }
bodyText = requestContext.getRequest().getBodyText(StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { throw new ODataSystemException("UTF-8 is not supported", e);
@Override protected String getToEntityId(ODataRequestContext requestContext) throws ODataUnmarshallingException { // The body is expected to contain a single entity reference // See OData Atom XML specification chapter 13 String bodyText; try { bodyText = requestContext.getRequest().getBodyText(StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { throw new ODataSystemException("UTF-8 is not supported", e); } Document document = parseXML(bodyText); Element rootElement = document.getDocumentElement(); if (!rootElement.getNodeName().equals(REF)) { throw new ODataUnmarshallingException("A " + requestContext.getRequest().getMethod() + " request to an entity reference URI must contain a single entity reference in the body," + " but something else was found instead: " + rootElement.getNodeName()); } String idAttr = rootElement.getAttribute(ID); if (isNullOrEmpty(idAttr)) { throw new ODataUnmarshallingException("The <metadata:ref> element in the body has no 'id' attribute," + " or the attribute is empty. The element must have an 'id' attribute that refers" + " to the entity to link to."); } return idAttr; }
bodyText = requestContext.getRequest().getBodyText(StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { throw new ODataSystemException("UTF-8 is not supported", e);
private Object parseAction(String fullyQualifiedName) throws ODataException { int delimiterIndex = fullyQualifiedName.lastIndexOf("."); if (delimiterIndex < 0) { throw new ODataUnmarshallingException("The action should have a fully qualified name"); } String namespace = fullyQualifiedName.substring(0, delimiterIndex); String actionSimpleName = fullyQualifiedName.substring(delimiterIndex + 1); Schema schema = checkNotNull(entityDataModel.getSchema(namespace), "There is no schema with name: {}", namespace); Action action = checkNotNull(schema.getAction(actionSimpleName), "There is no action {} within schema {}", actionSimpleName, namespace); Object actionObject; try { actionObject = action.getJavaClass().newInstance(); } catch (ReflectiveOperationException e) { throw new ODataUnmarshallingException("Error during instantiation of action: " + action.getName()); } Set<Parameter> actionParameters = action.getParameters(); Map<String, Object> bodyParameters; try { bodyParameters = parseRequestBody(requestContext.getRequest().getBodyText(UTF_8.name())); } catch (IOException e) { throw new ODataUnmarshallingException("Error has occurred during parameter parsing", e); } assignParametersToAction(bodyParameters, actionParameters, actionObject); return actionObject; }
private Object parseAction(String fullyQualifiedName) throws ODataException { int delimiterIndex = fullyQualifiedName.lastIndexOf("."); if (delimiterIndex < 0) { throw new ODataUnmarshallingException("The action should have a fully qualified name"); } String namespace = fullyQualifiedName.substring(0, delimiterIndex); String actionSimpleName = fullyQualifiedName.substring(delimiterIndex + 1); Schema schema = checkNotNull(entityDataModel.getSchema(namespace), "There is no schema with name: {}", namespace); Action action = checkNotNull(schema.getAction(actionSimpleName), "There is no action {} within schema {}", actionSimpleName, namespace); Object actionObject; try { actionObject = action.getJavaClass().newInstance(); } catch (ReflectiveOperationException e) { throw new ODataUnmarshallingException("Error during instantiation of action: " + action.getName()); } Set<Parameter> actionParameters = action.getParameters(); Map<String, Object> bodyParameters; try { bodyParameters = parseRequestBody(requestContext.getRequest().getBodyText(UTF_8.name())); } catch (IOException e) { throw new ODataUnmarshallingException("Error has occurred during parameter parsing", e); } assignParametersToAction(bodyParameters, actionParameters, actionObject); return actionObject; }
private Object parseActionImport(String actionImportName) throws ODataException { ActionImport actionImport = checkNotNull(entityDataModel.getEntityContainer().getActionImport(actionImportName), "Not able to get the action import {} from entity container", actionImportName); Action action = actionImport.getAction(); Object actionObject; try { actionObject = action.getJavaClass().newInstance(); } catch (ReflectiveOperationException e) { throw new ODataUnmarshallingException("Error during instantiation of action: " + action.getName()); } Set<Parameter> actionParameters = action.getParameters(); Map<String, Object> bodyParameters; try { bodyParameters = parseRequestBody(requestContext.getRequest().getBodyText(UTF_8.name())); } catch (IOException e) { throw new ODataUnmarshallingException("Error during request body parsing", e); } assignParametersToAction(bodyParameters, actionParameters, actionObject); return actionObject; } }
private Object parseActionImport(String actionImportName) throws ODataException { ActionImport actionImport = checkNotNull(entityDataModel.getEntityContainer().getActionImport(actionImportName), "Not able to get the action import {} from entity container", actionImportName); Action action = actionImport.getAction(); Object actionObject; try { actionObject = action.getJavaClass().newInstance(); } catch (ReflectiveOperationException e) { throw new ODataUnmarshallingException("Error during instantiation of action: " + action.getName()); } Set<Parameter> actionParameters = action.getParameters(); Map<String, Object> bodyParameters; try { bodyParameters = parseRequestBody(requestContext.getRequest().getBodyText(UTF_8.name())); } catch (IOException e) { throw new ODataUnmarshallingException("Error during request body parsing", e); } assignParametersToAction(bodyParameters, actionParameters, actionObject); return actionObject; } }