Getting 500 internal server error when trying to use the put and post methods on postman to my spring rest app

Getting 500 internal server error when trying to use the put and post methods on postman to my spring rest app

500 internal server error postman get request
how to fix 500 internal server error in postman
500 internal server error postman api
500 internal server error postman post request
how to solve 500 internal server error in postman
500 internal server error postman web api
postman throwing 500 internal server error
post request works in postman but not in browser

I tried both with xml and json. When using POST it adds null elements to the list and gives java.lang.NoClassDefFoundError exception. When using PUT I receive a Runtime exception. The GET methods are running properly. Can you please help me debug the code? Here are my service and controller classes.

@Consumes("application/xml,application/json")
@Produces("application/xml,application/json")
@RestController
public class PatientController {

    @Autowired
    private PatientService patientService;

    @GetMapping("patientservice/patients")
    List<Patient> getPatients() {

        return patientService.getPatients();
    }

    @GetMapping("patientservice/patients/{id}")
    Patient getPatient(@PathVariable("id") Long id ) {
        return patientService.getPatient(id);
    }

    @PostMapping("patientservice/patients" )
    Response createPatient(Patient patient) {
        return patientService.createPatient(patient);
    }

    @PutMapping("patientservice/patients")
    Response updatePatient(Patient patient) {
        return patientService.updatePatient(patient);
    }
}

@Service
public class PatientServiceImpl implements PatientService {

    Map<Long, Patient> patients = new HashMap<>();
    Long currentId = new Long(123);

    public PatientServiceImpl() {
        init();
    }

    void init() {
        Patient patient = new Patient();
        patient.setId(currentId);
        patient.setName("John");
        Patient patient1 = new Patient();
        patient1.setId(new Long(++currentId));
        patient1.setName("Mike");
        Patient patient2 = new Patient();
        patient2.setId(new Long(++currentId));
        patient2.setName("Dave");
        patients.put(patient.getId(), patient);
        patients.put(patient1.getId(), patient1);
        patients.put(patient2.getId(), patient2);
    }

    @Override
    public List<Patient> getPatients() {
        Collection<Patient> results = patients.values();
        List<Patient> response = new ArrayList<>(results);
        return response;
    }

    @Override
    public Patient getPatient(Long id) {
        if (patients.get(id) == null) {
            throw new NotFoundException();
        }
        return patients.get(id);
    }

    @Override
    public Response createPatient(Patient patient) {
        patient.setId(++currentId);
        patients.put(patient.getId(), patient);
        return Response.ok(patient).build();
    }

    @Override
    public Response updatePatient(Patient patient) {

        Patient currentPatient = patients.get(patient.getId());

        Response response;
        if (currentPatient != null) {
            patients.put(patient.getId(), patient);
            response = Response.ok().build();
        } else {
            throw new PatientBusinessException();
        }
        return response;
    }

    @Override
    public Response deletePatient(Long id) {
        Patient patient = patients.get(id);

        Response response;

        if (patient != null) {
            patients.remove(id);
            response = Response.ok().build();
        } else {
            response = Response.notModified().build();
        }
        return response;
    }

}

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.bharath.restws</groupId>
    <artifactId>restws</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>restws</name>
    <description>Patient REST Services</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.9.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-spring-boot-starter-jaxrs</artifactId>
            <version>3.1.11</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-jaxrs</artifactId>
            <version>1.9.13</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-xc</artifactId>
            <version>1.9.13</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/logutil/logutil -->
        <!-- <dependency>
            <groupId>logutil</groupId>
            <artifactId>logutil</artifactId>
            <version>0.2.1</version>
        </dependency> -->
        <!-- https://mvnrepository.com/artifact/org.apache.cxf/cxf-common-utilities -->
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-common-utilities</artifactId>
            <version>2.0.6</version>
        </dependency>


    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

Looks like you're missing the @RequestBody annotation to indicate how the parameter is bound to the web request.

https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/bind/annotation/RequestBody.html

@PostMapping("patientservice/patients" )
Response createPatient(@RequestBody Patient patient) {
    return patientService.createPatient(patient);
}

Spring RESTful service returns 500 internal server error, I'm posting to a Spring REST endpoint using angularjs $http service. When I try querying this endpoint, I get back a 400 "Bad Request" error. Assuming your api endpoint will be like: #GetMapping(path do I get a 'selected resource doesn​'t support HTTP method get' error when making a put request to webapi service? I'm not sure whether you are building spring project of apache-cfx project. But if you want to create services using spring-boot, this can be useful for you to get started.


I'm not sure whether you are building spring project of apache-cfx project. But if you want to create services using spring-boot, this can be useful for you to get started.

PatientController.java

import org.springframework.web.bind.annotation.*;

@RestController
public class PatientController {



    @PostMapping("patientservice/patients" )
    Response createPatient(@RequestBody Patient patient) {
        System.out.println("createPatient"+patient.toString());
        return new Response("Sucess","200");
    }

    @PutMapping("patientservice/patients")
    Response updatePatient(@RequestBody Patient patient) {
        System.out.println("updatePatient"+patient.toString());
        return new Response("Sucess","200");
    }
}

Patient.java

public class Patient {

    String fName;
    String lName;
    String disease;

    public String getfName() {
        return fName;
    }

    public void setfName(String fName) {
        this.fName = fName;
    }

    public String getlName() {
        return lName;
    }

    public void setlName(String lName) {
        this.lName = lName;
    }

    public String getDisease() {
        return disease;
    }

    public void setDisease(String disease) {
        this.disease = disease;
    }

    @Override
    public String toString() {
        return "Patient{" +
                "fName='" + fName + '\'' +
                ", lName='" + lName + '\'' +
                ", disease='" + disease + '\'' +
                '}';
    }
}

On the main class of your spring-boot you have to use annotation like @ComponentScan("com.your.package")

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.your.package</groupId>
    <artifactId>patientservice</artifactId>
    <version>2.1.1</version>
    <packaging>war</packaging>

    <name>patientservice</name>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.10.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <maven.test.skip>true</maven.test.skip>
        <spring.version>5.0.3.RELEASE</spring.version>
        <jackson.version>2.9.4</jackson.version>
        <hibernate.version>5.2.11.Final</hibernate.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <dependency>
            <groupId>org.hibernate.validator</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>6.0.2.Final</version>
        </dependency>

        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.6</version>
        </dependency>
    </dependencies>
    <build>
        <finalName>patientservice</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

Solved: 500 Internal server error with POST api/tasks, Solved: When I'm trying to import Tasks using the POST /api/tasks I'm being returned an internal server error. I'm using the following: Postman to. Find out how to get set up to work from home or anywhere outside of your office. .​wordpress.com/2016/09/13/troubleshooting-tips-making-rest-calls/. global public with sharing class HttpCallout_CLS { Public static void sendRequest(){ String API_KEY = 'XXX';


Looks like you miss the cxf-api dependency:

<dependency>
 <groupId>org.apache.cxf</groupId>
 <artifactId>cxf-api</artifactId>
 <version>2.2.3</version>  
</dependency>

Error 500 java rest client , but works on postman, Hi Thank you everyone for your help. The error message appears correctly when testing web-server authorization. I found the solution accidentally while trying to implement the "web-server" authorization method . As of now Salesforce supports only TLS 1.2 for integration(Which might get updated with Net application. You received this message because you are subscribed to the Google Groups "REST assured" group. To unsubscribe from this group and stop receiving emails from it, send an email to rest-a@googlegroups.com.


Should a REST API return a 500 Internal Server Error to indicate that , because the resource you were trying to find (as represented by the URI I usually use request param only for filtering and when my endpoint returns an array. POST or GET, the better choice seems 404 NOT FOUND because error code, or methods that indicate problems by arbitrarily returning null . For 500 Internal server error, you ought to debug and check for the Issue on the server side code. Please debug putting the code block in try catch and then check for exception. Thanks


POST request works in Postman/cURL, but not in Requests · Issue , I have a POST request that works perfectly with both Postman an cURL (it returns a JSON blob of data). library, I get a 200 success response, but instead of my JSON bl. Explain:your python code and url of request all no error, I've tried multiple approaches; this is the Bash script I've been using to try  Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.


"Could not get any response" on all my api calls · Issue #3127 , I can sometimes resolve the issue by restarted Postman, but that no longer seems to "Could not get any response" on all my api calls #3127 Have a simple WebAPI service exposing a GET method with no auth and no params. It tried it only after comming across comment posted by viiicky over here. How, to overcome this and edit an existing issue using rest api with POST method. And also have questioned regarding Edit and Update issues here . Or if using CURL can fix this error, how to use this code based on CURL code within request.