I am so confusing.
There is an Jakarta application that is run by GrizzlyHttpServer and the following configuration:
1- JDK 17
2- hibernate 5
3- hk2 for DI
The pom.xml is :
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-grizzly2-http</artifactId>
</dependency>
<!-- Jersey DI and core-->
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.hk2</groupId>
<artifactId>hk2-metadata-generator</artifactId>
<version>3.0.2</version>
</dependency>
<!-- add jackson as json provider -->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
</dependency>
<!-- Need this to hide warning for jakarta.activation.DataSource -->
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<version>2.0.1</version>
</dependency>
<!-- JUnit 5 -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<!-- test json data -->
<dependency>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
<version>${jsonassert.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>6.1.5.Final</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.6.12.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.11</version>
</dependency>
<dependency>
<groupId>com.art.vesal</groupId>
<artifactId>common</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0.1</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.4</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>com.behsa</groupId>
<artifactId>behsa-utils</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>net.freeutils</groupId>
<artifactId>jcharset</artifactId>
<version>1.5</version>
</dependency>
<dependency>
<groupId>ir.ghasemkiani</groupId>
<artifactId>persiancalendar</artifactId>
<version>2.1.7</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-all</artifactId>
<version>5.15.2</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-jms-client</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>org.mongodb.morphia</groupId>
<artifactId>morphia</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.12</version>
</dependency>
<dependency>
<groupId>org.jdom</groupId>
<artifactId>com.springsource.org.jdom</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>com.art</groupId>
<artifactId>dataserver_api</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.jodd</groupId>
<artifactId>jodd-http</artifactId>
<version>3.6.7</version>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.1</version>
</dependency>
and the Jersey endpoint is :
@Path("/backend")
public class MessageRelayRest {
@Inject
private UserDaoInf log;
@Inject
private ArtMTSMSRemoteInf relay;
@Path("/many2many")
@POST
@Produces("application/json")
@Consumes(MediaType.APPLICATION_JSON)
public ReferenceResultModel sendMessageManyToMany(MessageRelayModel messageRelayModel) {
System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
ReferenceResultModel result = relay.sendMessageManyToMany(messageRelayModel.getUsername(), messageRelayModel.getPassword(), messageRelayModel.getOriginator(), messageRelayModel.getDestination(), messageRelayModel.getContent(), messageRelayModel.getUserSuppliedIds(), messageRelayModel.getIp());
return result;
}
.....
Everything is working correctly as expected in Intellij IDEA but when I make as uber jar by the following maven plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>
com.art.vesal.MainApp
</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
and run the jar by java -jar, when request to the endpoint, the following error is raised:
POST http://localhost:8081/backend/many2many returned a response status of 415 Unsupported Media Type
14-Nov-2022 15:58:36.811 SEVERE [http-nio-8080-exec-78] com.sun.jersey.api.client.ClientResponse.getEntity A message body reader for Java class com.art.vesal.common.model.ReferenceResultModel, and Java type class com.art.vesal.common.model.ReferenceResultModel, and MIME media type application/octet-stream was not found 14-Nov-2022 15:58:36.812 SEVERE [http-nio-8080-exec-78] com.sun.jersey.api.client.ClientResponse.getEntity The registered message body readers compatible with the MIME media type are: application/octet-stream ->
com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
com.sun.jersey.core.impl.provider.entity.FileProvider
com.sun.jersey.core.impl.provider.entity.InputStreamProvider
com.sun.jersey.core.impl.provider.entity.DataSourceProvider
com.sun.jersey.core.impl.provider.entity.RenderedImageProvider / -> com.sun.jersey.core.impl.provider.entity.FormProvider com.sun.jersey.core.impl.provider.entity.StringProvider
com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
com.sun.jersey.core.impl.provider.entity.FileProvider
com.sun.jersey.core.impl.provider.entity.InputStreamProvider
com.sun.jersey.core.impl.provider.entity.DataSourceProvider
com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$General com.sun.jersey.core.impl.provider.entity.ReaderProvider
com.sun.jersey.core.impl.provider.entity.DocumentProvider
com.sun.jersey.core.impl.provider.entity.SourceProvider$StreamSourceReader com.sun.jersey.core.impl.provider.entity.SourceProvider$SAXSourceReader com.sun.jersey.core.impl.provider.entity.SourceProvider$DOMSourceReader com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider
com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$General com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General com.sun.jersey.core.impl.provider.entity.XMLRootObjectProvider$General com.sun.jersey.core.impl.provider.entity.EntityHolderReader
Where is wrong? I am so confusing!!
EDIT 1 This is main class:
public class MainApp {
public static final URI BASE_URI = URI.create("http://localhost:8081");
// Starts Grizzly HTTP server
public static HttpServer startHttpServer() {
final ResourceConfig config = new ResourceConfig();
config.register(MessageRelayRest.class);
config.register(CustomJacksonMapperProvider.class);
config.register(CustomJsonExceptionMapper.class);
config.register(Binder.class);
// JacksonFeature for JAXB/POJO, for pure JSON, no need this JacksonFeature
// config.register(JacksonFeature.class);
return GrizzlyHttpServerFactory.createHttpServer(BASE_URI, config);
}
public static void main(String[] args) {
try {
final HttpServer server = startHttpServer();
server.start();
// shut down hook
Runtime.getRuntime().addShutdownHook(new Thread(server::shutdownNow));
System.out.println(String.format("Application started.%nStop the application using CTRL+C"));
// block and wait shut down signal, like CTRL+C
Thread.currentThread().join();
} catch (InterruptedException | IOException ex) {
//Logger.getLogger(MainApp.class.getName()).log(Level.SEVERE, null, ex);
}
}
}