private static boolean isSupported(Class<?> type) { return InjectionUtils.isPrimitive(type); }
private CollectionCheck getCollectionCheck(String propName, boolean isCollection, Class<?> actualCls) { if (isCollection) { if (InjectionUtils.isPrimitive(actualCls)) { if (propName.startsWith(EXTENSION_COUNT_OPEN)) { return CollectionCheck.SIZE; } } else { return CollectionCheck.SIZE; } } return null; }
private CollectionCheck getCollectionCheck(String propName, boolean isCollection, Class<?> actualCls) { if (isCollection) { if (InjectionUtils.isPrimitive(actualCls)) { if (isCount(propName)) { return CollectionCheck.SIZE; } } else { return CollectionCheck.SIZE; } } return null; }
private CollectionCheck getCollectionCheck(String propName, boolean isCollection, Class<?> actualCls) { if (isCollection) { if (InjectionUtils.isPrimitive(actualCls)) { if (isCount(propName)) { return CollectionCheck.SIZE; } } else { return CollectionCheck.SIZE; } } return null; }
private static boolean allowedMapListValue(Class<?> cls, Type type) { if (List.class.isAssignableFrom(cls)) { Class<?> listtype = getRawType( getType(((ParameterizedType)type).getActualTypeArguments(), 0)); return InjectionUtils.isPrimitive(listtype); } return false; }
private static boolean allowedMapListValue(Class<?> cls, Type type) { if (List.class.isAssignableFrom(cls)) { Class<?> listtype = getRawType( getType(((ParameterizedType)type).getActualTypeArguments(), 0)); return InjectionUtils.isPrimitive(listtype); } return false; }
protected static Object getPrimitiveValue(String name, Object value) { int index = name.indexOf("."); if (index != -1) { String[] names = name.split("\\."); name = name.substring(index + 1); if (value != null && !InjectionUtils.isPrimitive(value.getClass())) { try { String nextPart = names[1]; if (nextPart.length() == 1) { nextPart = nextPart.toUpperCase(); } else { nextPart = Character.toUpperCase(nextPart.charAt(0)) + nextPart.substring(1); } Method m = value.getClass().getMethod("get" + nextPart, new Class[]{}); value = m.invoke(value, new Object[]{}); } catch (Throwable ex) { throw new RuntimeException(); } } return getPrimitiveValue(name, value); } return value; } }
private void injectProperties(Object instance, Map<String, List<String>> props) { if (props == null || props.isEmpty()) { return; } Method[] methods = instance.getClass().getMethods(); Map<String, Method> methodsMap = new HashMap<>(); for (Method m : methods) { methodsMap.put(m.getName(), m); } for (Map.Entry<String, List<String>> entry : props.entrySet()) { Method m = methodsMap.get("set" + Character.toUpperCase(entry.getKey().charAt(0)) + entry.getKey().substring(1)); if (m != null) { Class<?> type = m.getParameterTypes()[0]; Object value; if (InjectionUtils.isPrimitive(type)) { value = PrimitiveUtils.read(entry.getValue().get(0), type); } else { value = entry.getValue(); } InjectionUtils.injectThroughMethod(instance, m, value); } } }
private static boolean isSupportedMap(Type genericType) { Class<?> rawType = getRawType(genericType); if (Map.class.isAssignableFrom(rawType) && genericType instanceof ParameterizedType) { ParameterizedType paramType = (ParameterizedType) genericType; if (paramType.getActualTypeArguments().length == 2) { Class<?> firstType = getRawType(getType(paramType.getActualTypeArguments(), 0)); Type secondType = getType(paramType.getActualTypeArguments(), 1); Class<?> secondRawType = getRawType(secondType); return InjectionUtils.isPrimitive(firstType) && (InjectionUtils.isPrimitive(secondRawType) || allowedMapListValue(secondRawType, secondType)); } } return false; }
private static boolean isSupportedMap(Type genericType) { Class<?> rawType = getRawType(genericType); if (Map.class.isAssignableFrom(rawType) && genericType instanceof ParameterizedType) { ParameterizedType paramType = (ParameterizedType) genericType; if (paramType.getActualTypeArguments().length == 2) { Class<?> firstType = getRawType(getType(paramType.getActualTypeArguments(), 0)); Type secondType = getType(paramType.getActualTypeArguments(), 1); Class<?> secondRawType = getRawType(secondType); return InjectionUtils.isPrimitive(firstType) && (InjectionUtils.isPrimitive(secondRawType) || allowedMapListValue(secondRawType, secondType)); } } return false; }
private void doWriteBeanParam(StringBuilder sb, Class<?> type, Parameter pm, String parentName, List<Class<?>> parentBeanClasses, boolean isJson) { Map<Parameter, Class<?>> pms = InjectionUtils.getParametersFromBeanClass(type, pm.getType(), true); for (Map.Entry<Parameter, Class<?>> entry : pms.entrySet()) { String name = entry.getKey().getName(); if (parentName != null) { name = parentName + "." + name; } Class<?> paramCls = entry.getValue(); boolean isPrimitive = InjectionUtils.isPrimitive(paramCls) || paramCls.isEnum(); if (isPrimitive || Date.class.isAssignableFrom(paramCls) || InjectionUtils.isSupportedCollectionOrArray(paramCls)) { doWriteParam(sb, entry.getKey(), paramCls, paramCls, name, new Annotation[] {}, isJson); } else if (!parentBeanClasses.contains(paramCls)) { parentBeanClasses.add(paramCls); doWriteBeanParam(sb, paramCls, entry.getKey(), name, parentBeanClasses, isJson); parentBeanClasses.remove(paramCls); } } }
private boolean isFormParameter(Parameter pm, Class<?> type, Annotation[] anns) { return ParameterType.FORM == pm.getType() || ParameterType.REQUEST_BODY == pm.getType() && AnnotationUtils.getAnnotation(anns, Multipart.class) != null && (InjectionUtils.isPrimitive(type) || type == InputStream.class); }
private boolean isFormParameter(Parameter pm, Class<?> type, Annotation[] anns) { return ParameterType.FORM == pm.getType() || ParameterType.REQUEST_BODY == pm.getType() && AnnotationUtils.getAnnotation(anns, Multipart.class) != null && (InjectionUtils.isPrimitive(type) || type == InputStream.class); }
private boolean isFormParameter(Parameter pm, Class<?> type, Annotation[] anns) { return ParameterType.FORM == pm.getType() || ParameterType.REQUEST_BODY == pm.getType() && AnnotationUtils.getAnnotation(anns, Multipart.class) != null && (InjectionUtils.isPrimitive(type) || type == InputStream.class); }
public static boolean isFormParameter(final Parameter pm, final Class<?> type, final Annotation[] anns) { return ParameterType.FORM == pm.getType() || ParameterType.REQUEST_BODY == pm.getType() && AnnotationUtils.getAnnotation(anns, Multipart.class) != null && (InjectionUtils.isPrimitive(type) || type == InputStream.class); }
@Override public T readFrom(Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> headers, InputStream is) throws IOException, WebApplicationException { if (!supportSimpleTypesOnly && !InjectionUtils.isPrimitive(type)) { MessageBodyReader<T> next = providers.getMessageBodyReader(type, genericType, annotations, mediaType); JAXRSUtils.getCurrentMessage().put(ProviderFactory.ACTIVE_JAXRS_PROVIDER_KEY, this); try { return next.readFrom(type, genericType, annotations, mediaType, headers, is); } finally { JAXRSUtils.getCurrentMessage().put(ProviderFactory.ACTIVE_JAXRS_PROVIDER_KEY, null); } } String data = IOUtils.toString(is).trim(); int index = data.indexOf(':'); data = data.substring(index + 1, data.length() - 1).trim(); if (data.startsWith("\"")) { data = data.substring(1, data.length() - 1); } return primitiveHelper.readFrom(type, genericType, annotations, mediaType, headers, new ByteArrayInputStream(StringUtils.toBytesUTF8(data))); }
private void createMessagePartInfo(OperationInfo oi, Class<?> type, QName qname, Method m, boolean input) { if (type == void.class || Source.class.isAssignableFrom(type)) { return; } if (InjectionUtils.isPrimitive(type) || Response.class == type) { return; } QName mName = new QName(qname.getNamespaceURI(), (input ? "in" : "out") + m.getName()); MessageInfo ms = oi.createMessage(mName, input ? MessageInfo.Type.INPUT : MessageInfo.Type.OUTPUT); if (input) { oi.setInput("in", ms); } else { oi.setOutput("out", ms); } QName mpQName = JAXRSUtils.getClassQName(type); MessagePartInfo mpi = ms.addMessagePart(mpQName); mpi.setConcreteName(mpQName); mpi.setTypeQName(mpQName); mpi.setTypeClass(type); }
private void createMessagePartInfo(OperationInfo oi, Class<?> type, QName qname, Method m, boolean input) { if (type == void.class || Source.class.isAssignableFrom(type)) { return; } if (InjectionUtils.isPrimitive(type) || Response.class == type) { return; } QName mName = new QName(qname.getNamespaceURI(), (input ? "in" : "out") + m.getName()); MessageInfo ms = oi.createMessage(mName, input ? MessageInfo.Type.INPUT : MessageInfo.Type.OUTPUT); if (input) { oi.setInput("in", ms); } else { oi.setOutput("out", ms); } QName mpQName = JAXRSUtils.getClassQName(type); MessagePartInfo mpi = ms.addMessagePart(mpQName); mpi.setConcreteName(mpQName); mpi.setTypeQName(mpQName); mpi.setTypeClass(type); }
@Override public void writeTo(T t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException, WebApplicationException { if (!supportSimpleTypesOnly && !InjectionUtils.isPrimitive(type)) { @SuppressWarnings("unchecked") MessageBodyWriter<T> next = (MessageBodyWriter<T>)providers.getMessageBodyWriter(type, genericType, annotations, mediaType); JAXRSUtils.getCurrentMessage().put(ProviderFactory.ACTIVE_JAXRS_PROVIDER_KEY, this); try { next.writeTo(t, type, genericType, annotations, mediaType, headers, os); } finally { JAXRSUtils.getCurrentMessage().put(ProviderFactory.ACTIVE_JAXRS_PROVIDER_KEY, null); } } else { os.write(StringUtils.toBytesASCII("{\"" + type.getSimpleName().toLowerCase() + "\":")); writeQuote(os, type); primitiveHelper.writeTo(t, type, genericType, annotations, mediaType, headers, os); writeQuote(os, type); os.write(StringUtils.toBytesASCII("}")); } }
@Override public void writeTo(T t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException, WebApplicationException { if (!supportSimpleTypesOnly && !InjectionUtils.isPrimitive(type)) { @SuppressWarnings("unchecked") MessageBodyWriter<T> next = (MessageBodyWriter<T>)providers.getMessageBodyWriter(type, genericType, annotations, mediaType); JAXRSUtils.getCurrentMessage().put(ProviderFactory.ACTIVE_JAXRS_PROVIDER_KEY, this); try { next.writeTo(t, type, genericType, annotations, mediaType, headers, os); } finally { JAXRSUtils.getCurrentMessage().put(ProviderFactory.ACTIVE_JAXRS_PROVIDER_KEY, null); } } else { os.write(StringUtils.toBytesASCII("{\"" + type.getSimpleName().toLowerCase() + "\":")); writeQuote(os, type); primitiveHelper.writeTo(t, type, genericType, annotations, mediaType, headers, os); writeQuote(os, type); os.write(StringUtils.toBytesASCII("}")); } }