I am collaborating with others and am using Visual Studio Code for doing the Java projects. As we are only sharing the source .java files only, I have no idea on how to run the code from others that imports java.net.http module. How should I run the code as VSCode is reporting problems?
As mentioned by andrewJames, java.net.http was introduced in Java version 11. Setup VS Code with JDK-17 under Command Palette (Ctrl+Shift+P) - Java: Configure Java Runtime resolve the issue. You might need to download JDK 11+ installer from online.
I'm trying to get one of my projects ready for Java 11 but for some reason Intellij can't find java.net.http. It isn't underlining it as not found in module-info.java like it would if I typed it wrong but when I try build the project I get the error below. I've tried reinstalling Intellij 2018.2.3 and uninstalling all other versions of Java. Any advice on how to get this working would be appreciated.
fr.app.AppException: java.io.IOException: class fr.app.MyClass$BodySubscribers (in unnamed module @0x6537cf78) cannot access class jdk.internal.net.http.ResponseSubscribers$ByteArraySubscriber (in module java.net.http) because module java.net.http does not export jdk.internal.net.http to unnamed module @0x6537cf78
On another note, the class you've mentioned seems to be packaged internal to the java.net.http module and should not be relied upon from your code. You must implement your own subscriber even if you desire a similar functionality as the code you're looking at. Since the module wouldn't be exporting it for a public use anyway.
Regardless to the API is not a good idea for an ongoing project. However, for greenfield projects, it might be tempting. The migration can be considered as a good move. I recommend using the java.net.http library in that case.
I've been writing an API at work that uses the java.net.http.* library, which was added in Java 11. My manager asked me what it would take to refactor so we could set the minimum Java level down to 8.
Does anyone have a working sample of Java code using java.net.http to upload an attachment for URI "/api/now/attachment/upload"? I've tried various combinations of multipart uploads, all ending up with:
Rather than ditch java.net.http and switch back to Apache HTTPComponents, I thought I'd ask here first. Among other things, java.net.http is missing a multipart publisher (e.g., see Methanol at _GUIDE.md), as well as a list of HTTP status codes.
My latest experiments are using Apache HttpMime (4.5.14) with java.net.http.HttpClient under Java 17. The code is still failing as shown in the TODO. All of the MIME parts are set to multipart/form-data ContentType, but I've tried other ContentType's shown in the commented out code /* whatever */.
So the java.se Java module is no longer added to the runtime options. I see a couple of ways to get past this. One is what Tomaz mentioned in his reply and the other is to just added a dependency on "java.net.http" (Java) module from within your application (either through the use of a jboss-deployment-structure.xml or the "Dependencies" attribute in MANIFEST.MF - more details here Developer Guide )
Having said that, I still don't think these dependencies should be explicitly added. The reason I say this is - the java.net.http.* class are just like any other Java runtime classes and should be available by default to deployments. dmlloyd or brian.stansberry may perhaps have some inputs on this.
The HTTP Client API is now part of the Java SE 11 standard. The module name and the package name of the standard API is java.net.http. The new APIs provide high-level client interfaces to HTTP (versions 1.1 and 2) and low-level client interfaces to WebSocket.
dca57bae1f