-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhances extension compatibility with file upload changes from vaadin/hilla#3165. Updates EndpointController to utilize a custom HttpServletRequest, ensuring seamless integration with Quarkus Multipart Form data handling.
- Loading branch information
1 parent
5e2a573
commit aa5b05e
Showing
17 changed files
with
586 additions
and
31 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
...in/java/com/github/mcollovati/quarkus/hilla/deployment/asm/EndpointControllerVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright 2025 Marco Collovati, Dario Götze | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.github.mcollovati.quarkus.hilla.deployment.asm; | ||
|
||
import io.quarkus.gizmo.Gizmo; | ||
import org.objectweb.asm.ClassVisitor; | ||
import org.objectweb.asm.MethodVisitor; | ||
import org.objectweb.asm.Opcodes; | ||
import org.objectweb.asm.tree.MethodInsnNode; | ||
import org.objectweb.asm.tree.MethodNode; | ||
import org.objectweb.asm.tree.TypeInsnNode; | ||
|
||
/** | ||
* Modifies EndpointController class to use the extension MultipartRequest | ||
* wrapper instead of Spring MultipartHttpServletRequest. | ||
*/ | ||
public class EndpointControllerVisitor extends ClassVisitor { | ||
|
||
public static final String SPRING_MULTIPART_HTTP_SERVLET_REQUEST = | ||
"org/springframework/web/multipart/MultipartHttpServletRequest"; | ||
public static final String QH_MULTIPART_HTTP_SERVLET_REQUEST = | ||
"com/github/mcollovati/quarkus/hilla/multipart/MultipartRequest"; | ||
|
||
public EndpointControllerVisitor(ClassVisitor classVisitor) { | ||
super(Gizmo.ASM_API_VERSION, classVisitor); | ||
} | ||
|
||
@Override | ||
public MethodVisitor visitMethod( | ||
int access, String name, String descriptor, String signature, String[] exceptions) { | ||
MethodVisitor superVisitor = super.visitMethod(access, name, descriptor, signature, exceptions); | ||
if ("doServeEndpoint".equals(name)) { | ||
return new MethodNode(Gizmo.ASM_API_VERSION, access, name, descriptor, signature, exceptions) { | ||
@Override | ||
public void visitEnd() { | ||
var iterator = instructions.iterator(); | ||
TypeInsnNode checkCastNode = AsmUtils.findNextInsnNode( | ||
iterator, | ||
node -> node.getOpcode() == Opcodes.CHECKCAST | ||
&& node.desc.equals(SPRING_MULTIPART_HTTP_SERVLET_REQUEST), | ||
TypeInsnNode.class); | ||
checkCastNode.desc = QH_MULTIPART_HTTP_SERVLET_REQUEST; | ||
MethodInsnNode getParameterNode = AsmUtils.findNextInsnNode( | ||
iterator, | ||
node -> node.getOpcode() == Opcodes.INVOKEINTERFACE | ||
&& node.owner.equals(SPRING_MULTIPART_HTTP_SERVLET_REQUEST) | ||
&& node.name.equals("getParameter"), | ||
MethodInsnNode.class); | ||
getParameterNode.setOpcode(Opcodes.INVOKEVIRTUAL); | ||
getParameterNode.owner = QH_MULTIPART_HTTP_SERVLET_REQUEST; | ||
getParameterNode.itf = false; | ||
|
||
MethodInsnNode getFileMapNode = AsmUtils.findNextInsnNode( | ||
iterator, | ||
node -> node.getOpcode() == Opcodes.INVOKEINTERFACE | ||
&& node.owner.equals(SPRING_MULTIPART_HTTP_SERVLET_REQUEST) | ||
&& node.name.equals("getFileMap"), | ||
MethodInsnNode.class); | ||
getFileMapNode.setOpcode(Opcodes.INVOKEVIRTUAL); | ||
getFileMapNode.owner = QH_MULTIPART_HTTP_SERVLET_REQUEST; | ||
getFileMapNode.itf = false; | ||
accept(superVisitor); | ||
} | ||
}; | ||
} | ||
return superVisitor; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...rc/test/java/com/github/mcollovati/quarkus/hilla/deployment/endpoints/UploadEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2025 Marco Collovati, Dario Götze | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.github.mcollovati.quarkus.hilla.deployment.endpoints; | ||
|
||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.time.LocalDate; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import com.vaadin.flow.server.auth.AnonymousAllowed; | ||
import com.vaadin.hilla.BrowserCallable; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@BrowserCallable | ||
@AnonymousAllowed | ||
public class UploadEndpoint { | ||
|
||
public Object upload(Info info, MultipartFile file) { | ||
try { | ||
Path tempFile = Files.createTempFile("upload", "test"); | ||
file.transferTo(tempFile); | ||
return new Result(info, tempFile.toUri().toString()); | ||
} catch (IOException e) { | ||
throw new UncheckedIOException(e); | ||
} | ||
} | ||
|
||
public record Info(String id, @JsonFormat(pattern = "yyyy-MM-dd") LocalDate date) {} | ||
|
||
public record Result(Info info, String uri) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.