반응형

1. HTTP 400 : the request sent by the client was syntactically incorrect 400

 -> json데이터를 넘겨야하는데 엉뚱한 데이터 셋을 넘겼을 때 나는 에러

     만약 jqgrid에서 postData를 "" 로 해두었거나 datatype이 json이 아닌지

     확인해 보자.

     

     빈값으로 테스트를 하려면 반드시 postData: "{}"를 사용한다.

     아니면 JSON.stringify로 Object를 만들던가...



2. HTTP 415 : Unsupported Media Type

  -> jqgrid 에서 requestMapping 컨트롤러 처리부분으로 보내는 html header값에서

      content type과 accept 값이 application/json 이 아닌경우 발생한다.


      jqgrid의 옵션 값에



mtype : "post",

datatype:"json",

ajaxGridOptions: { contentType: "application/json; charset=UTF-8" },

ajaxRowOptions: { contentType: "application/json; charset=UTF-8", async: true },

ajaxSelectOptions: { contentType: "application/json; charset=UTF-8", dataType: "JSON" },



와 같이 contentType을 지정해주는 부분이 잘 설정 되어있는지 확인한다.



 3. HTTP 400 : Request method 'GET' not supported

     -> 너무 간단한거라 안쓰려다가 분량을 늘리려고 혹시 도움이 될까 남겨본다.


    컨트롤러 단에서 말그대로 GET 방식을 지원하지 않는데 GET 방식으로 호출한

    경우의 에러이다.


    jqGrid에 mtype: "post"로 설정을 하던가 

    컨트롤러 @RequestMapping 프로퍼티로 method = RequestMethod.GET 을

    추가하자.



   4. Jackson 설정 확인

     pom 부분은 다음과 같이


<!-- MappingJacksonJsonView -->

<dependency>

    <groupId>com.fasterxml.jackson.core</groupId>

    <artifactId>jackson-core</artifactId>

    <version>2.5.4</version>

</dependency>

<dependency>

    <groupId>com.fasterxml.jackson.core</groupId>

    <artifactId>jackson-databind</artifactId>

    <version>2.5.4</version>

</dependency>

<dependency>

    <groupId>com.fasterxml.jackson.core</groupId>

    <artifactId>jackson-annotations</artifactId>

    <version>2.5.4</version>

</dependency>



    servlet 은 다음과 같이 (tiles 를 쓴다면 타일즈 아래에)

<mvc:annotation-driven>

    <mvc:message-converters>

        <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">

        <property name="supportedMediaTypes">

                <list>

                    <value>text/html;charset=UTF-8</value>

                    <value>application/json;charset=UTF-8</value>

                </list>

            </property>

        </bean>

        <!-- <bean class="org.springframework.http.converter.ResourceHttpMessageConverter"/> -->

    </mvc:message-converters>

</mvc:annotation-driven>



   5. Jackson이 잘되는지는 jqgrid로 보지 말자 암걸린다

       Jackson으로 Request를 잘 받는지는 HTTP 테스트 유틸로 테스트하자.

       가장 쉬운 방법은 크롬앱에서 쉽게 깔 수 있는 ARC이다.

       POST / Content-Type : application/json; charset=UTF-8 등을 잘 확인해서


      컨트롤러를 실행해서 200이 뜨는지 확인하고 jqgrid를 확인하자.


      안그러면 Jackson이 제대로 안되는지 jqgrid가 제대로 안되는지 영 헛갈린다.






여담


스프링을 쓰다보면 공통 잡는 사람이 잡아둔 대로 개발만 하게 된다.

그러면 이 안에 Request / Response 부분이 어떻게 세팅되있는지

lib는 뭘 쓰는지 영 관심이 없게 되는데


그러지말고 프로젝트 말미나 초기에 시간이 있을 때 어떻게 세팅이 되어있는지

유심히 보자.


여지껏 스프링 프로젝트만 10번을 넘게 했는데 

직접 스프링 세팅을 해보면서 이제서야 뭔가 머리가 정리되는 느낌이다.

반응형

WRITTEN BY
데르벨준

,