Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Trying to call a rest service

  1. #1
    Junior Member
    Join Date
    Aug 2023
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Trying to call a rest service

    at the url there is my problem

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Trying to call a rest service

    Can you give more details?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Aug 2023
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Trying to call a rest service

    I'm trying to invoke my rest, get service at URL http://localhost:8080/ProvaMaven/rest/getuser but I always get not found.

    Here is my web.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlnssi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd Java EE: XML Schemas for Java EE Deployment Descriptors http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="5.0">
    <display-name>ProvaMaven</display-name>
    <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>

    <servlet>
    <servlet-name>jersey-servlet</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContaine r</servlet-class>
    <init-param>
    <param-name>org.glassfish.jersey.config.property.packages </param-name>
    <param-value>com</param-value>
    </init-param>
    <init-param>
    <param-name>org.glassfish.jersey.api.json.POJOMappingFeat ure</param-name>
    <param-value>true</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>Jersey Web Application</servlet-name>
    <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>



    </web-app>
    Here is my pom.xml

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlnssi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>MavenRest</groupId>
    <artifactId>ProvaMaven</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>


    <dependencies>


    <dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-client</artifactId>
    <version>3.1.3</version>
    </dependency>


    <dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-server</artifactId>
    <version>3.1.3</version>
    </dependency>


    <!-- https://mvnrepository.com/artifact/m...connector-java -->
    <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.33</version>
    </dependency>


    <!-- https://mvnrepository.com/artifact/o...r-servlet-core -->
    <dependency>
    <groupId>org.glassfish.jersey.containers</groupId>
    <artifactId>jersey-container-servlet-core</artifactId>
    <version>3.1.3</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/o...ect/jersey-hk2 -->
    <dependency>
    <groupId>org.glassfish.jersey.inject</groupId>
    <artifactId>jersey-hk2</artifactId>
    <version>3.1.3</version>
    </dependency>


    </dependencies>






    <build>

    <pluginManagement>
    <plugins>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.3.2</version>
    </plugin>

    <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
    <source>19</source>
    <target>19</target>
    </configuration>
    </plugin>

    </plugins>
    </pluginManagement>


    </build>



    </project>
    Here is my class

    package com;

    import jakarta.ws.rs.GET;
    import jakarta.ws.rs.Path;
    import jakarta.ws.rs.Produces;
    import jakarta.ws.rs.core.MediaType;

    @Path("/rest")
    public class Rest
    {
    @GET
    @Path("/getuser")
    @Produces(MediaType.APPLICATION_JSON)
    public User getUser()
    {
    User u = new User();
    u.setName("carmine");
    u.setSurname("armenante");


    return u;
    }
    }
    I tried to figure out what the config errors could be but nothing, I added stuff to my web and pom file but sadly nothing improved. I also cleaned and installed my maven project but nothing.

  4. #4
    Junior Member
    Join Date
    Aug 2023
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Error not found when i call my rest service

    I'm trying to call a rest service specifically get but when I type the url it gives me not found , I have already set up a web service soap in this maven project and it works for me by any chance am I missing some dependency or error in the web file?

    here is my pom.xml:

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlnssi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>MavenRest</groupId>
    <artifactId>ProvaMaven</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>


    <dependencies>


    <dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-client</artifactId>
    <version>3.1.3</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/j...akarta.jws-api -->
    <dependency>
    <groupId>jakarta.jws</groupId>
    <artifactId>jakarta.jws-api</artifactId>
    <version>3.0.0</version>
    </dependency>



    <dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-server</artifactId>
    <version>3.1.3</version>
    </dependency>


    <!-- https://mvnrepository.com/artifact/m...connector-java -->
    <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.33</version>
    </dependency>


    <!-- https://mvnrepository.com/artifact/o...r-servlet-core -->
    <dependency>
    <groupId>org.glassfish.jersey.containers</groupId>
    <artifactId>jersey-container-servlet-core</artifactId>
    <version>3.1.3</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/o...ect/jersey-hk2 -->
    <dependency>
    <groupId>org.glassfish.jersey.inject</groupId>
    <artifactId>jersey-hk2</artifactId>
    <version>3.1.3</version>
    </dependency>


    </dependencies>






    <build>

    <pluginManagement>
    <plugins>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.3.2</version>
    </plugin>

    <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
    <source>19</source>
    <target>19</target>
    </configuration>
    </plugin>

    </plugins>
    </pluginManagement>


    </build>



    </project>
    here is my web.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlnssi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd Java EE: XML Schemas for Java EE Deployment Descriptors http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="5.0">
    <display-name>ProvaMaven</display-name>
    <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>

    <servlet>
    <servlet-name>jersey-servlet</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContaine r</servlet-class>
    <init-param>
    <param-name>org.glassfish.jersey.config.property.packages </param-name>
    <param-value>com</param-value>
    </init-param>
    <init-param>
    <param-name>org.glassfish.jersey.api.json.POJOMappingFeat ure</param-name>
    <param-value>true</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>Jersey Web Application</servlet-name>
    <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>



    </web-app>
    here is my class:

    package com;

    import jakarta.ws.rs.GET;
    import jakarta.ws.rs.Path;
    import jakarta.ws.rs.Produces;
    import jakarta.ws.rs.core.MediaType;

    @Path("/rest")
    public class Rest
    {
    @GET
    @Path("/getuser")
    @Produces(MediaType.APPLICATION_JSON)
    public User getUser()
    {
    User u = new User();
    u.setName("carmine");
    u.setSurname("armenante");

    System.out.println("sono dentro");
    return u;
    }
    }

Similar Threads

  1. IOException: too many bytes written Feign Rest Call
    By testusr987 in forum Web Frameworks
    Replies: 0
    Last Post: May 25th, 2023, 11:34 AM
  2. consume the rest service by passing the json object
    By StarRocks in forum Object Oriented Programming
    Replies: 0
    Last Post: January 29th, 2013, 06:28 AM
  3. Call service() from init() in servlet
    By krupam790 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 10th, 2013, 09:00 PM
  4. Tutorial how to call OSGI service from EAR package
    By rcbandit2 in forum Java Theory & Questions
    Replies: 0
    Last Post: January 4th, 2012, 10:15 AM
  5. [SOLVED] Trying to call web service (and failing)
    By jamesruk21 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 15th, 2011, 12:35 PM

Tags for this Thread