use of java.lang.reflect.Method in project swagger-core by swagger-api.
the class ReflectionUtils method getParameterAnnotations.
public static Annotation[][] getParameterAnnotations(Method method) {
Annotation[][] methodAnnotations = method.getParameterAnnotations();
Method overriddenmethod = getOverriddenMethod(method);
if (overriddenmethod != null) {
Annotation[][] overriddenAnnotations = overriddenmethod.getParameterAnnotations();
for (int i = 0; i < methodAnnotations.length; i++) {
List<Type> types = new ArrayList<Type>();
for (int j = 0; j < methodAnnotations[i].length; j++) {
types.add(methodAnnotations[i][j].annotationType());
}
for (int j = 0; j < overriddenAnnotations[i].length; j++) {
if (!types.contains(overriddenAnnotations[i][j].annotationType())) {
methodAnnotations[i] = ArrayUtils.add(methodAnnotations[i], overriddenAnnotations[i][j]);
}
}
}
}
return methodAnnotations;
}
use of java.lang.reflect.Method in project swagger-core by swagger-api.
the class BaseReaderUtilsTest method extensionsTest.
@Test(dataProvider = "expectedData")
public void extensionsTest(String methodName, Map<String, Object> expected) throws NoSuchMethodException {
final Method method = getClass().getDeclaredMethod(methodName);
final Extension[] extensions = method.getAnnotation(ApiOperation.class).extensions();
final Map<String, Object> map = BaseReaderUtils.parseExtensions(extensions);
Assert.assertEquals(map, expected);
}
use of java.lang.reflect.Method in project swagger-core by swagger-api.
the class Reader method read.
private void read(ReaderContext context) {
final SwaggerDefinition swaggerDefinition = context.getCls().getAnnotation(SwaggerDefinition.class);
if (swaggerDefinition != null) {
readSwaggerConfig(swaggerDefinition);
}
for (Method method : context.getCls().getMethods()) {
if (ReflectionUtils.isOverriddenMethod(method, context.getCls())) {
continue;
}
final Operation operation = new Operation();
String operationPath = null;
String httpMethod = null;
final Type[] genericParameterTypes = method.getGenericParameterTypes();
final Annotation[][] paramAnnotations = method.getParameterAnnotations();
for (ReaderExtension extension : ReaderExtensions.getExtensions()) {
if (operationPath == null) {
operationPath = extension.getPath(context, method);
}
if (httpMethod == null) {
httpMethod = extension.getHttpMethod(context, method);
}
if (operationPath == null || httpMethod == null) {
continue;
}
if (extension.isReadable(context)) {
extension.setDeprecated(operation, method);
extension.applyConsumes(context, operation, method);
extension.applyProduces(context, operation, method);
extension.applyOperationId(operation, method);
extension.applySummary(operation, method);
extension.applyDescription(operation, method);
extension.applySchemes(context, operation, method);
extension.applySecurityRequirements(context, operation, method);
extension.applyTags(context, operation, method);
extension.applyResponses(context, operation, method);
extension.applyImplicitParameters(context, operation, method);
extension.applyExtensions(context, operation, method);
for (int i = 0; i < genericParameterTypes.length; i++) {
extension.applyParameters(context, operation, genericParameterTypes[i], paramAnnotations[i]);
}
}
}
if (httpMethod != null) {
if (operation.getResponses() == null) {
operation.defaultResponse(new Response().description("successful operation"));
}
final Map<String, String> regexMap = new HashMap<String, String>();
final String parsedPath = PathUtils.parsePath(operationPath, regexMap);
Path path = swagger.getPath(parsedPath);
if (path == null) {
path = new Path();
swagger.path(parsedPath, path);
}
path.set(httpMethod.toLowerCase(), operation);
}
}
}
use of java.lang.reflect.Method in project swagger-core by swagger-api.
the class ConsumesProducesTest method applyConsumesProducesTest1.
@Test(dataProvider = "resourceWithAnnotations")
public void applyConsumesProducesTest1(String methodName, List<String> expected) throws NoSuchMethodException {
final Operation operation = new Operation();
final ReaderContext context = createDefaultContext();
final Method method = findMethod(context, methodName);
extension.applyConsumes(context, operation, method);
extension.applyProduces(context, operation, method);
Assert.assertEquals(operation.getConsumes(), expected);
Assert.assertEquals(operation.getProduces(), expected);
}
use of java.lang.reflect.Method in project jpHolo by teusink.
the class Capture method createMediaFile.
/**
* Creates a JSONObject that represents a File from the Uri
*
* @param data the Uri of the audio/image/video
* @return a JSONObject that represents a File
* @throws IOException
*/
private JSONObject createMediaFile(Uri data) {
File fp = webView.getResourceApi().mapUriToFile(data);
JSONObject obj = new JSONObject();
Class webViewClass = webView.getClass();
PluginManager pm = null;
try {
Method gpm = webViewClass.getMethod("getPluginManager");
pm = (PluginManager) gpm.invoke(webView);
} catch (NoSuchMethodException e) {
} catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
}
if (pm == null) {
try {
Field pmf = webViewClass.getField("pluginManager");
pm = (PluginManager) pmf.get(webView);
} catch (NoSuchFieldException e) {
} catch (IllegalAccessException e) {
}
}
FileUtils filePlugin = (FileUtils) pm.getPlugin("File");
LocalFilesystemURL url = filePlugin.filesystemURLforLocalPath(fp.getAbsolutePath());
try {
// File properties
obj.put("name", fp.getName());
obj.put("fullPath", fp.toURI().toString());
if (url != null) {
obj.put("localURL", url.toString());
}
// is stored in the audio or video content store.
if (fp.getAbsoluteFile().toString().endsWith(".3gp") || fp.getAbsoluteFile().toString().endsWith(".3gpp")) {
if (data.toString().contains("/audio/")) {
obj.put("type", AUDIO_3GPP);
} else {
obj.put("type", VIDEO_3GPP);
}
} else {
obj.put("type", FileHelper.getMimeType(Uri.fromFile(fp), cordova));
}
obj.put("lastModifiedDate", fp.lastModified());
obj.put("size", fp.length());
} catch (JSONException e) {
// this will never happen
e.printStackTrace();
}
return obj;
}
Aggregations