Quantcast
Channel: SmartClient Forums
Viewing all articles
Browse latest Browse all 4756

Issue Overriding transformrequest to add httpheaders

$
0
0
Version: Smartgwt4.0

Browser: Mozilla Firefox

Server side: Spring Rest service in apache Tomcat

Issue:
I want to add the user credentials in the httpheaders which can be authenticated at the server side SecurityFilter.

To add the httpheader, I'm overriding the transformrequest method in the class extends RestDatasource. But when I set the httpheader to the dsRequest, my request is getting changed from POST to OPTIONS which is not able to be processed by my server side code.

Please see the Original request and Request after adding httpheader below. Can you please review and let me know what I'm doing wrong.

Version Smartgwt4.0

Original Request
------------------
Code:

POST http://127.0.0.1:8080/bom/roleaccesscombo?isc_dataFormat=json HTTP/1.1
Host: 127.0.0.1:8080
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: application/json; charset=UTF-8
Referer: http://127.0.0.1:8888/BillOfMaterialUI.html?gwt.codesvr=127.0.0.1:9997
Content-Length: 169
Origin: http://127.0.0.1:8888
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache

{
    "dataSource":"RoleAccessComboDS",
    "operationType":"fetch",
    "data":{
        "loginID":"admin",
        "password":"admin"
    },
    "oldValues":null
}

Overriding code:
-----------------
Code:

        @Override
        protected Object transformRequest(DSRequest dsRequest) {
               
                Map mapHeader =  dsRequest.getHttpHeaders();
               
                if (mapHeader == null) {
                        mapHeader = new HashMap();
                }
                byte[] b = null;
                b = "user:passwordt".getBytes();
                byte[] result = Base64.encode(b);
                String sendString = new String(result);

                mapHeader.put("authorization","Basic "+ sendString);

                dsRequest.setHttpHeaders(mapHeader);

                Object data = super.transformRequest(dsRequest);
                return data;
        }

After overriding the transformrequest to add the httpheaders
------------------------------------------------------------

Code:

OPTIONS http://127.0.0.1:8080/bom/roleaccesscombo?isc_dataFormat=json HTTP/1.1
Host: 127.0.0.1:8080
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Origin: http://127.0.0.1:8888
Access-Control-Request-Method: POST
Access-Control-Request-Headers: authorization,content-type
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache

Thanks
Thiruppathy.R

Viewing all articles
Browse latest Browse all 4756