use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.
the class WebMethodHandler method cookie.
public static WebParameterHandler cookie(final WebAnnotationMethodHandlerAdapter adapter, final Parameter parameter, final Annotation annotation) {
final Class<?> parameterClass = parameter.getType();
final DataType dataType = DataTypes.getDataType(parameterClass);
final CookieValue cookieValue = (CookieValue) annotation;
final String name = getName(parameter, cookieValue.value());
final boolean required = cookieValue.required();
final Object defaultValue = parseDefaultValueAttribute(dataType, cookieValue.defaultValue());
BiFunction<HttpServletRequest, HttpServletResponse, Object> function;
if (Cookie.class.equals(parameterClass)) {
function = (request, response) -> {
final Cookie cookie = WebUtils.getCookie(request, name);
return cookie;
};
} else {
function = (request, response) -> {
final Cookie cookie = WebUtils.getCookie(request, name);
if (cookie == null) {
return null;
} else {
return cookie.getValue();
}
};
}
return //
WebParameterHandler.function(//
name, //
function, //
dataType, //
required, //
defaultValue);
}
use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.
the class WebMethodHandler method body.
@SuppressWarnings({ "unchecked", "rawtypes" })
public static WebParameterHandler body(final WebAnnotationMethodHandlerAdapter adapter, final Parameter parameter, final Annotation annotation) {
final boolean required = ((RequestBody) annotation).required();
final String parameterName = parameter.getName();
final Class parameterClass = parameter.getType();
final DataType dataType = DataTypes.getDataType(parameterClass);
return //
WebParameterHandler.function(//
parameterName, (request, response) -> {
try {
final HttpInputMessage inputMessage = new ServletServerHttpRequest(request);
MediaType contentType = MediaTypeUtil.getContentType(request);
if (contentType == null) {
contentType = MediaType.APPLICATION_FORM_URLENCODED;
}
if (!MediaType.APPLICATION_FORM_URLENCODED.includes(contentType) && !MediaType.MULTIPART_FORM_DATA.includes(contentType)) {
contentType = MediaTypeUtil.getRequestMediaType(request, adapter.mediaTypes, adapter.mediaTypeOrder, adapter.urlPathHelper, adapter.parameterName, adapter.defaultMediaType, "");
}
final HttpHeaders headers = inputMessage.getHeaders();
if (contentType == null) {
final StringBuilder builder = new StringBuilder(ClassUtils.getShortName(parameterClass));
final String paramName = parameterName;
if (paramName != null) {
builder.append(' ');
builder.append(paramName);
}
throw new HttpMediaTypeNotSupportedException("Cannot extract @RequestBody parameter (" + builder.toString() + "): no Content-Type found");
} else {
HttpServletUtils.setContentTypeWithCharset(headers, contentType);
}
final List<MediaType> allSupportedMediaTypes = new ArrayList<>();
if (adapter.messageConverters != null) {
for (final HttpMessageConverter<?> messageConverter : adapter.messageConverters) {
allSupportedMediaTypes.addAll(messageConverter.getSupportedMediaTypes());
if (messageConverter.canRead(parameterClass, contentType)) {
return messageConverter.read(parameterClass, inputMessage);
}
}
String body = null;
if (MediaType.APPLICATION_FORM_URLENCODED.includes(contentType)) {
Charset charset = contentType.getCharSet();
if (charset == null) {
charset = StandardCharsets.UTF_8;
}
final String urlBody = FileCopyUtils.copyToString(new InputStreamReader(inputMessage.getBody(), charset));
final String[] pairs = StringUtils.tokenizeToStringArray(urlBody, "&");
final MultiValueMap<String, String> values = new LinkedMultiValueMap<>(pairs.length);
for (final String pair : pairs) {
final int idx = pair.indexOf('=');
if (idx == -1) {
values.add(URLDecoder.decode(pair, charset.name()), null);
} else {
final String name = URLDecoder.decode(pair.substring(0, idx), charset.name());
final String value = URLDecoder.decode(pair.substring(idx + 1), charset.name());
values.add(name, value);
}
}
body = values.getFirst("body");
} else if (request instanceof MultipartHttpServletRequest) {
final MultipartHttpServletRequest multiPartRequest = (MultipartHttpServletRequest) request;
final MultipartFile bodyFile = multiPartRequest.getFile("body");
contentType = MediaTypeUtil.getRequestMediaType(request, adapter.mediaTypes, adapter.mediaTypeOrder, adapter.urlPathHelper, adapter.parameterName, adapter.defaultMediaType, bodyFile.getOriginalFilename());
HttpServletUtils.setContentTypeWithCharset(headers, contentType);
final HttpInputMessage newInputMessage = new HttpInputMessage() {
@Override
public InputStream getBody() throws IOException {
return bodyFile.getInputStream();
}
@Override
public HttpHeaders getHeaders() {
return headers;
}
};
for (final HttpMessageConverter<?> messageConverter : adapter.messageConverters) {
if (messageConverter.canRead(parameterClass, contentType)) {
return messageConverter.read(parameterClass, newInputMessage);
}
}
}
if (body == null) {
body = request.getParameter("body");
}
if (body != null) {
contentType = MediaTypeUtil.getRequestMediaType(request, adapter.mediaTypes, adapter.mediaTypeOrder, adapter.urlPathHelper, adapter.parameterName, adapter.defaultMediaType, "");
HttpServletUtils.setContentTypeWithCharset(headers, contentType);
byte[] bytes;
bytes = body.getBytes();
final InputStream bodyIn = new ByteArrayInputStream(bytes);
final HttpInputMessage newInputMessage = new HttpInputMessage() {
@Override
public InputStream getBody() throws IOException {
return bodyIn;
}
@Override
public HttpHeaders getHeaders() {
return headers;
}
};
for (final HttpMessageConverter<?> messageConverter : adapter.messageConverters) {
if (messageConverter.canRead(parameterClass, contentType)) {
return messageConverter.read(parameterClass, newInputMessage);
}
}
}
}
throw new HttpMediaTypeNotSupportedException(contentType, allSupportedMediaTypes);
} catch (final Exception e) {
return Exceptions.throwUncheckedException(e);
}
}, //
dataType, //
required, //
null);
}
use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.
the class GmlFieldTypeRegistry method addFieldType.
public void addFieldType(final GmlFieldType fieldType) {
final DataType dataType = fieldType.getDataType();
addFieldType(dataType, fieldType);
}
use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.
the class FeatureLayer method initialize.
@Override
protected void initialize(final MapEx properties) {
super.initialize(properties);
this.boundingBox = ArcGisResponse.newBoundingBox(properties, "extent");
final PathName pathName = getPathName();
final List<MapEx> fields = properties.getValue("fields");
if (fields != null) {
final RecordDefinitionImpl newRecordDefinition = new RecordDefinitionImpl(pathName);
newRecordDefinition.setPolygonRingDirection(ClockDirection.CLOCKWISE);
final String description = properties.getString("description");
newRecordDefinition.setDescription(description);
final String geometryType = properties.getString("geometryType");
for (final MapEx field : fields) {
addField(newRecordDefinition, geometryType, field);
}
if (Property.hasValue(geometryType)) {
if (!newRecordDefinition.hasGeometryField()) {
final DataType geometryDataType = getGeometryDataType(geometryType);
if (geometryDataType == null) {
throw new IllegalArgumentException("No geometryType specified for " + getServiceUrl());
} else {
newRecordDefinition.addField("GEOMETRY", geometryDataType);
}
}
}
if (this.boundingBox != null) {
final GeometryFactory geometryFactory = this.boundingBox.getGeometryFactory();
newRecordDefinition.setGeometryFactory(geometryFactory);
}
final FieldDefinition objectIdField = newRecordDefinition.getField("OBJECTID");
if (newRecordDefinition.getIdField() == null && objectIdField != null) {
final int fieldIndex = objectIdField.getIndex();
newRecordDefinition.setIdFieldIndex(fieldIndex);
objectIdField.setRequired(true);
}
this.recordDefinition = newRecordDefinition;
}
}
use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.
the class GeometryFieldDefinition method clone.
@Override
public FieldDefinition clone() {
final String name = getName();
final DataType dataType = getDataType();
final boolean required = isRequired();
return new GeometryFieldDefinition(this.geometryFactory, name, dataType, required);
}
Aggregations