use of org.springframework.beans.BeanWrapperImpl in project spring-framework by spring-projects.
the class WebLogicRequestUpgradeStrategy method handleSuccess.
@Override
protected void handleSuccess(HttpServletRequest request, HttpServletResponse response, UpgradeInfo upgradeInfo, TyrusUpgradeResponse upgradeResponse) throws IOException, ServletException {
response.setStatus(upgradeResponse.getStatus());
upgradeResponse.getHeaders().forEach((key, value) -> response.addHeader(key, Utils.getHeaderFromList(value)));
AsyncContext asyncContext = request.startAsync();
asyncContext.setTimeout(-1L);
Object nativeRequest = getNativeRequest(request);
BeanWrapper beanWrapper = new BeanWrapperImpl(nativeRequest);
Object httpSocket = beanWrapper.getPropertyValue("connection.connectionHandler.rawConnection");
Object webSocket = webSocketHelper.newInstance(request, httpSocket);
webSocketHelper.upgrade(webSocket, httpSocket, request.getServletContext());
response.flushBuffer();
boolean isProtected = request.getUserPrincipal() != null;
Writer servletWriter = servletWriterHelper.newInstance(webSocket, isProtected);
Connection connection = upgradeInfo.createConnection(servletWriter, noOpCloseListener);
new BeanWrapperImpl(webSocket).setPropertyValue("connection", connection);
new BeanWrapperImpl(servletWriter).setPropertyValue("connection", connection);
webSocketHelper.registerForReadEvent(webSocket);
}
use of org.springframework.beans.BeanWrapperImpl in project spring-framework by spring-projects.
the class JmxUtilsTests method getAttributeNameWithoutStrictCasing.
@Test
void getAttributeNameWithoutStrictCasing() {
PropertyDescriptor pd = new BeanWrapperImpl(AttributeTestBean.class).getPropertyDescriptor("name");
String attributeName = JmxUtils.getAttributeName(pd, false);
assertThat(attributeName).as("Incorrect casing on attribute name").isEqualTo("name");
}
use of org.springframework.beans.BeanWrapperImpl in project spring-framework by spring-projects.
the class BeanPropertyRowMapper method mapRow.
/**
* Extract the values for all columns in the current row.
* <p>Utilizes public setters and result set meta-data.
* @see java.sql.ResultSetMetaData
*/
@Override
public T mapRow(ResultSet rs, int rowNumber) throws SQLException {
BeanWrapperImpl bw = new BeanWrapperImpl();
initBeanWrapper(bw);
T mappedObject = constructMappedInstance(rs, bw);
bw.setBeanInstance(mappedObject);
ResultSetMetaData rsmd = rs.getMetaData();
int columnCount = rsmd.getColumnCount();
Set<String> populatedProperties = (isCheckFullyPopulated() ? new HashSet<>() : null);
for (int index = 1; index <= columnCount; index++) {
String column = JdbcUtils.lookupColumnName(rsmd, index);
String field = lowerCaseName(StringUtils.delete(column, " "));
PropertyDescriptor pd = (this.mappedFields != null ? this.mappedFields.get(field) : null);
if (pd != null) {
try {
Object value = getColumnValue(rs, index, pd);
if (rowNumber == 0 && logger.isDebugEnabled()) {
logger.debug("Mapping column '" + column + "' to property '" + pd.getName() + "' of type '" + ClassUtils.getQualifiedName(pd.getPropertyType()) + "'");
}
try {
bw.setPropertyValue(pd.getName(), value);
} catch (TypeMismatchException ex) {
if (value == null && this.primitivesDefaultedForNullValue) {
if (logger.isDebugEnabled()) {
logger.debug("Intercepted TypeMismatchException for row " + rowNumber + " and column '" + column + "' with null value when setting property '" + pd.getName() + "' of type '" + ClassUtils.getQualifiedName(pd.getPropertyType()) + "' on object: " + mappedObject, ex);
}
} else {
throw ex;
}
}
if (populatedProperties != null) {
populatedProperties.add(pd.getName());
}
} catch (NotWritablePropertyException ex) {
throw new DataRetrievalFailureException("Unable to map column '" + column + "' to property '" + pd.getName() + "'", ex);
}
} else {
// No PropertyDescriptor found
if (rowNumber == 0 && logger.isDebugEnabled()) {
logger.debug("No property found for column '" + column + "' mapped to field '" + field + "'");
}
}
}
if (populatedProperties != null && !populatedProperties.equals(this.mappedProperties)) {
throw new InvalidDataAccessApiUsageException("Given ResultSet does not contain all fields " + "necessary to populate object of " + this.mappedClass + ": " + this.mappedProperties);
}
return mappedObject;
}
use of org.springframework.beans.BeanWrapperImpl in project midpoint by Evolveum.
the class AbstractManagedConnectorInstance method applyConfigurationToConfigurationClass.
private void applyConfigurationToConfigurationClass(PrismContainerValue<?> configurationContainer) throws ConfigurationException {
BeanWrapper connectorBean = new BeanWrapperImpl(this);
PropertyDescriptor connectorConfigurationProp = UcfUtil.findAnnotatedProperty(connectorBean, ManagedConnectorConfiguration.class);
if (connectorConfigurationProp == null) {
return;
}
Class<?> configurationClass = connectorConfigurationProp.getPropertyType();
Object configurationObject;
try {
configurationObject = configurationClass.getDeclaredConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
throw new ConfigurationException("Cannot instantiate configuration " + configurationClass);
}
BeanWrapper configurationClassBean = new BeanWrapperImpl(configurationObject);
for (Item<?, ?> configurationItem : configurationContainer.getItems()) {
ItemDefinition<?> configurationItemDefinition = configurationItem.getDefinition();
String itemLocalName = configurationItem.getElementName().getLocalPart();
if (configurationItemDefinition != null && configurationItemDefinition.isMultiValue()) {
Object[] realValuesArray = configurationItem.getRealValuesArray(Object.class);
configurationClassBean.setPropertyValue(itemLocalName, realValuesArray);
} else {
Object realValue = configurationItem.getRealValue();
configurationClassBean.setPropertyValue(itemLocalName, realValue);
}
}
connectorBean.setPropertyValue(connectorConfigurationProp.getName(), configurationObject);
}
use of org.springframework.beans.BeanWrapperImpl in project midpoint by Evolveum.
the class ConnectorFactoryBuiltinImpl method generateConnectorConfigurationSchema.
private PrismSchema generateConnectorConfigurationSchema(ConnectorStruct struct) {
Class<? extends ConnectorInstance> connectorClass = struct.connectorClass;
PropertyDescriptor connectorConfigurationProp = UcfUtil.findAnnotatedProperty(connectorClass, ManagedConnectorConfiguration.class);
MutablePrismSchema connectorSchema = prismContext.schemaFactory().createPrismSchema(struct.connectorObject.getNamespace());
// Create configuration type - the type used by the "configuration" element
MutablePrismContainerDefinition<?> configurationContainerDef = connectorSchema.createContainerDefinition(ResourceType.F_CONNECTOR_CONFIGURATION.getLocalPart(), SchemaConstants.CONNECTOR_SCHEMA_CONFIGURATION_TYPE_LOCAL_NAME);
Class<?> configurationClass = connectorConfigurationProp.getPropertyType();
BeanWrapper configurationClassBean = new BeanWrapperImpl(configurationClass);
for (PropertyDescriptor prop : configurationClassBean.getPropertyDescriptors()) {
if (UcfUtil.hasAnnotation(prop, ConfigurationItem.class)) {
ItemDefinition<?> itemDef = createConfigurationItemDefinition(configurationContainerDef, prop);
LOGGER.trace("Configuration item definition for {}: {}", prop.getName(), itemDef);
}
}
return connectorSchema;
}
Aggregations