Service Virtualization

Expand all | Collapse all

I'm receiving a windows-1251 encoded body request. How do I convert it to UTF-8 in VSM?

  • 1.  I'm receiving a windows-1251 encoded body request. How do I convert it to UTF-8 in VSM?

    Posted 03-25-2019 05:15 PM

    I'm receiving a windows-1251 encoded body request. How do I convert it to UTF-8 in VSM? Request below:

     

    Request {id=0, operation="PUT /KC-Service", arguments=, attributes=HTTP-Segment-Attr-0=KC-Service, metaData=HTTP-Method=PUT&HTTP-URI=/KC-Service&HTTP-Version=1.1&Accept=application/json&Content-Type=application/json; charset=utf-16&Host=localhost:8003&Content-Length=960&Connection=Keep-Alive&lisa.vse.request.client.id=127.0.0.1:38635, matchTolerance=Exact, binary=false, body=(non-binary)[960 bytes] 笀ഀ਀  ∀挀栀愀渀渀攀氀䌀愀渀挀攀氀氀愀琀椀漀渀∀㨀 㤀Ⰰഀ਀  ∀渀愀洀攀倀爀漀最爀愀洀䌀愀氀氀攀爀∀㨀 ∀䄀倀䤀攀刀攀搀攀∀Ⰰഀ਀  ∀甀猀攀爀䌀愀渀挀攀氀氀愀琀椀漀渀∀㨀 ∀䄀倀䤀攀刀攀搀攀∀Ⰰഀ਀  ∀氀猀琀䤀琀攀渀猀∀㨀 嬀ഀ਀    笀ഀ਀      ∀氀攀琀琀攀爀䐀愀琀攀∀㨀 ∀㈀ ㄀㠀ⴀ 㜀ⴀ㄀㠀吀㈀㈀㨀㄀㄀㨀㔀㜀⸀㄀㜀㄀㘀㌀㐀㄀娀∀Ⰰഀ਀      ∀琀爀愀渀猀愀挀琀椀漀渀䐀愀琀攀∀㨀 ∀㈀ ㄀㠀ⴀ 㜀ⴀ㄀㈀吀㄀㈀㨀㈀㐀㨀 㘀娀∀Ⰰഀ਀      ∀渀猀甀∀㨀 ㄀㔀㌀㄀㐀 㤀 ㌀㌀㘀㄀⸀ Ⰰഀ਀      ∀愀昀昀椀氀椀愀琀椀漀渀一甀洀戀攀爀∀㨀 ㄀     㜀㠀Ⰰഀ਀      ∀琀椀搀∀㨀 ∀ 㜀㄀㈀㄀㈀㈀㌀㔀㄀    ㄀∀Ⰰഀ਀      ∀挀愀渀挀攀氀愀琀椀漀渀吀礀瀀攀∀㨀 ∀倀䄀刀吀䤀䄀䰀∀Ⰰഀ਀      ∀琀爀愀渀猀愀挀琀椀漀渀吀礀瀀攀∀㨀 ∀刀伀吀䄀吀䤀嘀䔀∀Ⰰഀ਀      ∀猀愀氀攀吀礀瀀攀∀㨀 ∀䌀刀䔀䐀䤀吀∀Ⰰഀ਀      ∀挀愀渀挀攀氀愀琀椀漀渀嘀愀氀甀攀∀㨀 ㄀ ⸀ ഀ਀    紀ഀ਀  崀ഀ਀紀}

     

    Thanks



  • 2.  Re: I'm receiving a windows-1251 encoded body request. How do I convert it to UTF-8 in VSM?

    Broadcom Employee
    Posted 03-29-2019 12:43 PM


  • 3.  Re: I'm receiving a windows-1251 encoded body request. How do I convert it to UTF-8 in VSM?

    Posted 03-29-2019 01:09 PM

    Thank you, Shiney.

     

    I've already done using Execute script (JSR-223) after Listerner step.

     

    I get the body, change it to UTF-16, get the values from json and save it to the ParameterList and save it to the Request.

     

    The java code to encode change is:

     

    String utf16 = "";
    try {
       utf16 = new String(body.getBytes("UTF-16LE"), Charset.forName("UTF-16"));
    } catch (UnsupportedEncodingException e){
       System.out.println(e);
    }

     

    PS: The encode was not windows-1251. It was UTF-16LE.