You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jmeter.apache.org by Sanjay Chaurasia <Sa...@india.nec.com> on 2019/06/03 05:30:14 UTC

RE: Build error "unmappable character encoding for Japanese characters"

Dear Felix,



Thank you for your response.



>     [java] 1)

>testWithFix(org.apache.jmeter.protocol.http.util.TestHTTPArgument)

>   [java] org.junit.ComparisonFailure: arg.getValue() should be equal to 初期値大阪市 expected:<初期[値大阪市]> but was:<初期[ l大阪 s]>

>     [java]     at org.junit.Assert.assertEquals(Assert.java:115)



You are getting the above error because existing JMeter code don’t encode some of the special Japanese characters using  URLDecoder.

You could refer the https://github.com/apache/jmeter/pull/440 for the above issue solution and with that solution we were able to execute this Junit test case via running as Junit.

But when we trying to build this via ant test command we were getting “unmappable character encoding for Japanese characters”.

So to resolve this error we have proposed below solution.



We have analyzed some existing test cases (e.g. TextMessageRendererTest) and found that while testing the different encodings we should use external file instead of hardcoding in source code. So, I  chose  to read Japanese characters from the property file instead of hardcoded in the source code. Please find below snapshot for property file.



[cid:image001.png@01D519F2.C7CD53C0]

>What is your intention for "withFix"? HTTPArgument stores the value as is, if you pass "true" for the alreadyEncoded parameter.

Intent for “WithFix” was to check the Japanese character decoding via Shift_JIS.



Below are the “WithFix” and “WithoutFix” Junit written to test the special Japanese characters decoding using org.apache.commons.codec.net.URLCodec (Replaced from URLDecoder)

@Test

        public void testWithFix() throws Exception {

            String filename = getResourceFile("test63130.properties");

            File fileDir = new File(filename);

            BufferedReader reader = new BufferedReader(new InputStreamReader(

                                     new FileInputStream(fileDir), "Shift_JIS"));

            Properties property=new Properties();

            property.load(reader);



            HTTPArgument arg;

            //Passing real encoded value of Japanese character as %8F%89%8A%FA%92l%91%E5%8D%E3%8Es and try to decode with Shift_JIS encoding

            arg = new HTTPArgument("name.?",property.getProperty("encodedValue") , true, "Shift_JIS");

            assertEquals("arg.getValue() should be equal to "+property.getProperty("value"),property.get("value"), arg.getValue());

        }



        @Test

        public void testWithoutFix() throws Exception {

               String filename = getResourceFile("test63130.properties");

               File fileDir = new File(filename);

               BufferedReader reader = new BufferedReader(

                                                  new InputStreamReader(

                                     new FileInputStream(fileDir), "Shift_JIS"));

               Properties property=new Properties();

               property.load(reader);



            HTTPArgument arg;

            //Passing real encoded value of Japanese character as %8F%89%8A%FA%92l%91%E5%8D%E3%8Es and try to decode with UTF-8 encoding

            arg = new HTTPArgument("name.?", property.getProperty("encodedValue"), true, "UTF-8");

            assertNotEquals("arg.getValue() should not be equal to "+property.getProperty("value"),property.getProperty("value"), arg.getValue());

        }

Regards,

Sanjay Chaurasia



-----Original Message-----
From: Felix Schumacher [mailto:felix.schumacher@internetallee.de]
Sent: Friday, May 31, 2019 4:49 PM
To: dev@jmeter.apache.org
Subject: Re: Build error "unmappable character encoding for Japanese characters"





Am 31.05.19 um 12:36 schrieb Sanjay Chaurasia:

> Hi Team,

>

> I have added some JUnit test cases in TestHTTPArgument.java file to test some Japanese characters. Below is the code snippet for same.

>

> @Test

>         public void testWithFix() throws Exception {

>             HTTPArgument arg;

>             //Passing real encoded value of 初期値大阪市 as %8F%89%8A%FA%92l%91%E5%8D%E3%8Es and try to decode with Shift_JIS encoding

>             arg = new HTTPArgument("name.?", "%8F%89%8A%FA%92l%91%E5%8D%E3%8Es", true, "Shift_JIS");

>             assertEquals("arg.getValue() should be equal to 初期値大阪市","初期値大阪市", arg.getValue());

>         }

>

>

> When I run the test from the eclipse (right click on method name -> run as -> Junit test), it is working fine but when I am trying to build the JMeter code using ant test, getting error as  “ unmappable character encoding for Japanese characters”.



I get a different error:



     [java] 1)

testWithFix(org.apache.jmeter.protocol.http.util.TestHTTPArgument)

     [java] org.junit.ComparisonFailure: arg.getValue() should be equal to 初期値大阪市 expected:<初期[値大阪市]> but was:<初期[ l大阪 s]>

     [java]     at org.junit.Assert.assertEquals(Assert.java:115)

     [java]     at

org.apache.jmeter.protocol.http.util.TestHTTPArgument.testWithFix(TestHTTPArgument.java:103)

     [java]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native

Method)

     [java]     at

sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

     [java]     at

sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

     [java]     at java.lang.reflect.Method.invoke(Method.java:498)

     [java]     at

org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)

     [java]     at

org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

     [java]     at

org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)

     [java]     at

org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

     [java]     at

org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)

     [java]     at

org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)

     [java]     at

org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)

     [java]     at

org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)

     [java]     at

java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)

     [java]     at java.util.concurrent.FutureTask.run(FutureTask.java:266)

     [java]     at

java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)

     [java]     at

java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

     [java]     at java.lang.Thread.run(Thread.java:748)

     [java]



When using eclipse together with ant, you have to use 'ant clean install ...' to remove the properties files from the classpath that eclipse copied there. That should probably haven been taken care of by the gradle conversion that Vladimir mentioned.



What is your intention for "withFix"? HTTPArgument stores the value as is, if you pass "true" for the alreadyEncoded parameter.



Felix



>

> To resolve this issue I am reading Japanese characters from the property file and using it in the test method testWithFix().

>

> Could you please confirm if it is good way to solve the issue, else suggest me any other solution if any.

>

>

> Regards,

> Sanjay Chaurasia

>

>