@Test public void simpleHappyTest() { Api api = RamlDocumentBuilder .document() .title("any") .withResources( ResourceBuilder.resource("/foo") .withMethods( MethodBuilder.method("post") .withBodies( BodyBuilder.body("multipart/form-data") .ofType(TypeBuilder.type("object") .withProperty(TypePropertyBuilder.property("one", "file")))))) .buildModel(); setupFetchTypes(api); JerseyMultipartFormDataResourceExtension extension = new JerseyMultipartFormDataResourceExtension(); V10GMethod method = setupResources(api); MethodSpec.Builder sp = extension.onMethod(null, method, method.body().get(0), MethodSpec.methodBuilder("foo")); MethodSpec m = sp.build(); assertEquals(2, m.parameters.size()); assertEquals("oneStream", m.parameters.get(0).name); assertEquals(ClassName.get(InputStream.class), m.parameters.get(0).type); assertEquals(ClassName.bestGuess("org.glassfish.jersey.media.multipart.FormDataParam"), m.parameters.get(0).annotations.get(0).type); assertEquals("\"one\"", m.parameters.get(0).annotations.get(0).members.get("value").get(0).toString()); assertEquals("oneDisposition", m.parameters.get(1).name); assertEquals(ClassName.bestGuess("org.glassfish.jersey.media.multipart.FormDataContentDisposition"), m.parameters.get(1).type); assertEquals(ClassName.bestGuess("org.glassfish.jersey.media.multipart.FormDataParam"), m.parameters.get(1).annotations.get(0).type); assertEquals("\"one\"", m.parameters.get(1).annotations.get(0).members.get("value").get(0).toString()); }
@Override public MethodSpec.Builder onMethod(ResourceContext context, GMethod method, GRequest gRequest, MethodSpec.Builder methodSpec) { if (gRequest != null && "multipart/form-data".equals(gRequest.mediaType())) { MethodSpec old = methodSpec.build(); MethodSpec.Builder newMethod = MethodSpec.methodBuilder(old.name) .returns(old.returnType); addExistingParameters(old, newMethod); for (AnnotationSpec annotation : old.annotations) { newMethod.addAnnotation(annotation); } for (TypeName exception : old.exceptions) { newMethod.addException(exception); } newMethod.addJavadoc("$L", old.javadoc); newMethod.addModifiers(old.modifiers); ObjectTypeDeclaration declaration = (ObjectTypeDeclaration) gRequest.type().implementation(); for (TypeDeclaration property : declaration.properties()) { if (property instanceof FileTypeDeclaration) { newMethod.addParameter( ParameterSpec .builder(ClassName.get(InputStream.class), property.name() + "Stream") .addAnnotation( AnnotationSpec .builder(ClassName.bestGuess("org.glassfish.jersey.media.multipart.FormDataParam")) .addMember("value", "$S", property.name()).build()).build()); newMethod.addParameter( ParameterSpec .builder(ClassName.bestGuess("org.glassfish.jersey.media.multipart.FormDataContentDisposition"), property.name() + "Disposition") .addAnnotation( AnnotationSpec .builder(ClassName.bestGuess("org.glassfish.jersey.media.multipart.FormDataParam")) .addMember("value", "$S", property.name()).build()).build()); } else { TypeName typeName = context.fetchRamlToPojoBuilder().fetchType(property.type(), property); newMethod.addParameter( ParameterSpec .builder(typeName, property.name()) .addAnnotation(AnnotationSpec .builder(ClassName.bestGuess("org.glassfish.jersey.media.multipart.FormDataParam")) .addMember("value", "$S", property.name()).build()) .build()); } } return newMethod; } else { return methodSpec; } }
JerseyMultipartFormDataResourceExtension implements GlobalResourceExtension { @Override public MethodSpec.Builder onMethod(ResourceContext context, GMethod method, GRequest gRequest, MethodSpec.Builder methodSpec) { if (gRequest != null && "multipart/form-data".equals(gRequest.mediaType())) { MethodSpec old = methodSpec.build(); MethodSpec.Builder newMethod = MethodSpec.methodBuilder(old.name) .returns(old.returnType); addExistingParameters(old, newMethod); for (AnnotationSpec annotation : old.annotations) { newMethod.addAnnotation(annotation); } for (TypeName exception : old.exceptions) { newMethod.addException(exception); } newMethod.addJavadoc("$L", old.javadoc); newMethod.addModifiers(old.modifiers); ObjectTypeDeclaration declaration = (ObjectTypeDeclaration) gRequest.type().implementation(); for (TypeDeclaration property : declaration.properties()) { if (property instanceof FileTypeDeclaration) { newMethod.addParameter( ParameterSpec .builder(ClassName.get(InputStream.class), property.name() + "Stream") .addAnnotation( AnnotationSpec .builder(ClassName.bestGuess("org.glassfish.jersey.media.multipart.FormDataParam")) .addMember("value", "$S", property.name()).build()).build()); newMethod.addParameter( ParameterSpec .builder(ClassName.bestGuess("org.glassfish.jersey.media.multipart.FormDataContentDisposition"), property.name() + "Disposition") .addAnnotation( AnnotationSpec .builder(ClassName.bestGuess("org.glassfish.jersey.media.multipart.FormDataParam")) .addMember("value", "$S", property.name()).build()).build()); } else { TypeName typeName = context.fetchRamlToPojoBuilder().fetchType(property.type(), property); newMethod.addParameter( ParameterSpec .builder(typeName, property.name()) .addAnnotation(AnnotationSpec .builder(ClassName.bestGuess("org.glassfish.jersey.media.multipart.FormDataParam")) .addMember("value", "$S", property.name()).build()) .build()); } } return newMethod; } else { return methodSpec; } } }
JerseyMultipartFormDataResourceExtension implements GlobalResourceExtension { @Override public MethodSpec.Builder onMethod(ResourceContext context, GMethod method, GRequest gRequest, MethodSpec.Builder methodSpec) { if (gRequest != null && "multipart/form-data".equals(gRequest.mediaType())) { MethodSpec old = methodSpec.build(); MethodSpec.Builder newMethod = MethodSpec.methodBuilder(old.name) .returns(old.returnType); addExistingParameters(old, newMethod); for (AnnotationSpec annotation : old.annotations) { newMethod.addAnnotation(annotation); } for (TypeName exception : old.exceptions) { newMethod.addException(exception); } newMethod.addJavadoc("$L", old.javadoc); newMethod.addModifiers(old.modifiers); ObjectTypeDeclaration declaration = (ObjectTypeDeclaration) gRequest.type().implementation(); for (TypeDeclaration property : declaration.properties()) { if (property instanceof FileTypeDeclaration) { newMethod.addParameter( ParameterSpec .builder(ClassName.get(InputStream.class), property.name() + "Stream") .addAnnotation( AnnotationSpec .builder(ClassName.bestGuess("org.glassfish.jersey.media.multipart.FormDataParam")) .addMember("value", "$S", property.name()).build()).build()); newMethod.addParameter( ParameterSpec .builder(ClassName.bestGuess("org.glassfish.jersey.media.multipart.FormDataContentDisposition"), property.name() + "Disposition") .addAnnotation( AnnotationSpec .builder(ClassName.bestGuess("org.glassfish.jersey.media.multipart.FormDataParam")) .addMember("value", "$S", property.name()).build()).build()); } else { TypeName typeName = context.fetchRamlToPojoBuilder().fetchType(property.type(), property); newMethod.addParameter( ParameterSpec .builder(typeName, property.name()) .addAnnotation(AnnotationSpec .builder(ClassName.bestGuess("org.glassfish.jersey.media.multipart.FormDataParam")) .addMember("value", "$S", property.name()).build()) .build()); } } return newMethod; } else { return methodSpec; } }  }
JerseyMultipartFormDataResourceExtension implements GlobalResourceExtension { @Override public MethodSpec.Builder onMethod(ResourceContext context, GMethod method, GRequest gRequest, MethodSpec.Builder methodSpec) { if (gRequest != null && "multipart/form-data".equals(gRequest.mediaType())) { MethodSpec old = methodSpec.build(); MethodSpec.Builder newMethod = MethodSpec.methodBuilder(old.name) .returns(old.returnType); addExistingParameters(old, newMethod); for (AnnotationSpec annotation : old.annotations) { newMethod.addAnnotation(annotation); } for (TypeName exception : old.exceptions) { newMethod.addException(exception); } newMethod.addJavadoc("$L", old.javadoc); newMethod.addModifiers(old.modifiers); ObjectTypeDeclaration declaration = (ObjectTypeDeclaration) gRequest.type().implementation(); for (TypeDeclaration property : declaration.properties()) { if (property instanceof FileTypeDeclaration) { newMethod.addParameter( ParameterSpec .builder(ClassName.get(InputStream.class), property.name() + "Stream") .addAnnotation( AnnotationSpec .builder(ClassName.bestGuess("org.glassfish.jersey.media.multipart.FormDataParam")) .addMember("value", "$S", property.name()).build()).build()); newMethod.addParameter( ParameterSpec .builder(ClassName.bestGuess("org.glassfish.jersey.media.multipart.FormDataContentDisposition"), property.name() + "Disposition") .addAnnotation( AnnotationSpec .builder(ClassName.bestGuess("org.glassfish.jersey.media.multipart.FormDataParam")) .addMember("value", "$S", property.name()).build()).build()); } else { TypeName typeName = context.fetchRamlToPojoBuilder().fetchType(property.type(), property); newMethod.addParameter( ParameterSpec .builder(typeName, property.name()) .addAnnotation(AnnotationSpec .builder(ClassName.bestGuess("org.glassfish.jersey.media.multipart.FormDataParam")) .addMember("value", "$S", property.name()).build()) .build()); } } return newMethod; } else { return methodSpec; } }  @Override TypeSpec.Builder onResource(ResourceContext context, GResource resource, TypeSpec.Builder typeSpec); @Override MethodSpec.Builder onMethod(ResourceContext context, GMethod method, GRequest gRequest, MethodSpec.Builder methodSpec); @Override TypeSpec.Builder onResponseClass(ResourceContext context, GMethod method, TypeSpec.Builder typeSpec); @Override MethodSpec.Builder onMethod(ResourceContext context, GResponse responseMethod, MethodSpec.Builder methodSpec); }
JerseyMultipartFormDataResourceExtension implements GlobalResourceExtension { @Override public MethodSpec.Builder onMethod(ResourceContext context, GMethod method, GRequest gRequest, MethodSpec.Builder methodSpec) { if (gRequest != null && "multipart/form-data".equals(gRequest.mediaType())) { MethodSpec old = methodSpec.build(); MethodSpec.Builder newMethod = MethodSpec.methodBuilder(old.name) .returns(old.returnType); addExistingParameters(old, newMethod); for (AnnotationSpec annotation : old.annotations) { newMethod.addAnnotation(annotation); } for (TypeName exception : old.exceptions) { newMethod.addException(exception); } newMethod.addJavadoc("$L", old.javadoc); newMethod.addModifiers(old.modifiers); ObjectTypeDeclaration declaration = (ObjectTypeDeclaration) gRequest.type().implementation(); for (TypeDeclaration property : declaration.properties()) { if (property instanceof FileTypeDeclaration) { newMethod.addParameter( ParameterSpec .builder(ClassName.get(InputStream.class), property.name() + "Stream") .addAnnotation( AnnotationSpec .builder(ClassName.bestGuess("org.glassfish.jersey.media.multipart.FormDataParam")) .addMember("value", "$S", property.name()).build()).build()); newMethod.addParameter( ParameterSpec .builder(ClassName.bestGuess("org.glassfish.jersey.media.multipart.FormDataContentDisposition"), property.name() + "Disposition") .addAnnotation( AnnotationSpec .builder(ClassName.bestGuess("org.glassfish.jersey.media.multipart.FormDataParam")) .addMember("value", "$S", property.name()).build()).build()); } else { TypeName typeName = context.fetchRamlToPojoBuilder().fetchType(property.type(), property); newMethod.addParameter( ParameterSpec .builder(typeName, property.name()) .addAnnotation(AnnotationSpec .builder(ClassName.bestGuess("org.glassfish.jersey.media.multipart.FormDataParam")) .addMember("value", "$S", property.name()).build()) .build()); } } return newMethod; } else { return methodSpec; } }  @Override TypeSpec.Builder onResource(ResourceContext context, GResource resource, TypeSpec.Builder typeSpec); @Override MethodSpec.Builder onMethod(ResourceContext context, GMethod method, GRequest gRequest, MethodSpec.Builder methodSpec); @Override TypeSpec.Builder onResponseClass(ResourceContext context, GMethod method, TypeSpec.Builder typeSpec); @Override MethodSpec.Builder onMethod(ResourceContext context, GResponse responseMethod, MethodSpec.Builder methodSpec);  }