view · edit · sidebar · attach · print · history


<< 20160726-migrate-davaz-com-fix-unit-test-sandoz-xmlconv-bbmb-ch | Index | 20160722-debug-incoming-request-conversion-sandoz-xmlconv-bbmb-ch >>


  • Debug request encoding on

Commits / Patches / Pull Requests, Scripts


Debug request encoding might have still strange encoding trouble..
Today, I would like to make sure that encoding (internal/external, in Ruby 1.8.6 world and drb) is fine.

Fix plugin loading issue

At first, I've started to clean boot process, because it is a little bit noisy.
This disturbs debugging of another issues.

I've faced this issue on Unit-Test.

[1] 2.3.1-p112(XmlConv::Util)> rpath
=> "conversion/wbmb_bdd"
[2] 2.3.1-p112(XmlConv::Util)> require rpath
/path/to/gems/ruby/2.3.0/gems/soap4r-1.5.8/lib/xsd/xmlparser.rb:22: warning: already initialized constant \
/path/to/gems/ruby/2.3.0/gems/soap4r-1.5.8/lib/xsd/xmlparser.rb:22: warning: previous definition of NSParseRegexp was here
RuntimeError: XML processor module not found.

This patch avoids this loading error.
I moved this patch from unit-test to application.

module XSD                                                                      
  module XMLParser                                                              
    class << self                                                               
      alias :orig_constants :constants                                          
      def constants                                                                                                          

Commit:Fix xml processor module not found issue

Fix kcode warning from soap4r

D, [2016-07-25T09:18:12.906745 #12305] DEBUG -- XmlConv2: loading plugin: 'conversion/wbmb_bdd' (wbmb_bdd.rb)
/path/to/gems/ruby/2.3.0/gems/soap4r-1.5.8/lib/xsd/charset.rb:13: warning: variable $KCODE is no longer effective

I know already also about this.
Then I've change to no convert encoding in xsd (soap4r) library. (because it uses iconv for old ruby)

Commit:Fix charset encoding issue

Meta tag and http-equiv

Xmlconv does not valid meta tag for utf-8 and does not have http response header for encoding.
I think this causes strange character error on browser (ui).

Then append following meta tag (HTML 4.01, same as <meta charset="UTF-8"> in HTML5)

<meta content="tex/html;charset=UTF-8" http-equiv="content-type">

And also update http-respones header to provide encoding.


This provides fine characters :)



* Add charset as utf-8 in HTTP_HEADER and META_TAGS []

Other strange character issues were also fixed by this.

Debug incoming request encoding

We have still encoding issue:
# this order is recorded twice. this means does not return 200.

This request is ISO-8859-1 encoding.

# client number and password are masked
<?xml version="1.0" encoding="ISO-8859-1"?>
<customerOrder xmlns:xsd="" ... version="1.0">
	<client number="XXXXXXXXXXX" password="XXXXX" />
	<orderHeader deliveryDate="2016-07-22"
		referenceNumber="220720161" mannerOfTransport="tour"
		phoneCallDesired="false" urgent="false">
		<deliveryAddress line1="Rt Cantonale 90 CP. 16"
			line4="Pharmacie Vétroz" line5PostalCode="1963"
			<addressLine2And3Text line2="Vétroz" line3="Vétroz" />
		<productOrderLine orderQuantity="3"
			roundUpForCondition="true" backLogDesired="true">
			<pharmaCode id="5195126" />
		<productOrderLine orderQuantity="10"
			roundUpForCondition="true" backLogDesired="true">
			<pharmaCode id="2323960" />
		<productOrderLine orderQuantity="2"
			roundUpForCondition="true" backLogDesired="true">
			<pharmaCode id="5006763" />
		<productOrderLine orderQuantity="2"
			roundUpForCondition="true" backLogDesired="true">
			<pharmaCode id="5356500" />


How to change and Open with encoding with vim.
I do it like this:

# change encoding
:set fileencoding=latin1

# re:open with encoding
:e ++enc=latin1

Return (api) response with charset in header

API Response body has still strange character. Encoding is already UTF-8.
I think this is caused also because api response header has not valid charset.

% curl -H "Content-Type: text/xml" -d @tool/double.xml
<?xml version='1.0' encoding='UTF-8'?>
<customerOrderResponse backLogDesired='false' ...>
<clientResponse number='xxxxxxxxx'/>
  <orderHeaderResponse referenceNumber='220720161'>
    <deliveryAddress line1='Rt Cantonale 90 CP. 16' line4='Pharmacie VĂ©troz' line5City='VĂ©troz' line5PostalCode='1963'>
    <addressLine2And3Text line2='VĂ©troz' line3='VĂ©troz'/>

Commit: Fix incoming request encoding issue [commit, xmlconv]

Fix Encoding in XmlParser

There 2 points to fix this:

  • API does not return valid charset (UTF-8) in response header. (body is already utf-8, some clients might confuse this)
  • Remove unnecessary encoding conversion in (I've changed it in xmlconv gem)

* Create base xml-parser

Note about (current) production setup

On production, some strange characters are still there.
But its are already fixed.

I think this is caused by load path issue.

RubyAddPath (in Apache config) adds just path at the end of $LOAD_PATH.
This does not mean that application use specified version.
Currently, production server has many applications against same gem environment.
So we cannot uninstall easily old version from this gem environment.

If environment has other version gem in path, other version might be used.
So, current these issue on production needs dependency management by Bundler.
In addition,
We have 2 rubies for application.

  • mod_ruby use ruby 1.8.6
  • mod_ruby run *.rbx via Apache and search gems from gem186 environment.
  • Apache configuration has many RubyAddPath to control gem dependencies.
  • Request is passed to Ruby 2.3.1 world (via DRb), and this ruby has another load path.
This just append path at the End.
RubyAddPath /path/to/ruby/gems/ruby/2.3.0/gems/sbsm-1.2.3/lib

This avoids unnecessary these setup issues...

# setup (install gems only for this application)
$ bundle install --path /path/to/somewhere

# run script (z.B. in daemontools)
$ bundle exec xmlconvd \                                                          

Maybe next time.

view · edit · sidebar · attach · print · history
Page last modified on July 25, 2016, at 07:20 PM