Problem with special characters using Web Service

Moderator: crythias

Locked
jovemfelix
Znuny newbie
Posts: 5
Joined: 04 May 2012, 21:43
Znuny Version: 2.4.7
Real Name: Renato Alves Felix
Company: DPF

Problem with special characters using Web Service

Post by jovemfelix »

Hi,


I'm testing the web service integration (OTRS version 3.1.6, at SUSE Linux 10) using the script bellow and it works fine when the ticket returned doesn't have special characters (like ç, ã... from portugues language...) any body know why?

Code: Select all

#!/usr/bin/perl -w
# --

use strict;
use warnings;

# use ../ as lib location
use File::Basename;
use FindBin qw($RealBin);
use lib dirname($RealBin);

use SOAP::Lite;
use Data::Dumper;
use diagnostics;

# ---
# Variables to be defined.

my $URL ='http://my-host/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnector';

# this name space should match the specified name space in the SOAP transport for the web service.
my $NameSpace = 'http://www.otrs.org/TicketConnector/';

# this is operation to execute, it could be TicketCreate, TicketUpdate, TicketGet, TicketSearch
# or SessionCreate. and they must to be defined in the web service.
my $Operation = 'TicketGet';

# this variable is used to store all the parameters to be included on a request in XML format, each
# operation has a determined set of mandatory and non mandatory parameters to work correctly, please
# check OTRS Admin Manual in order to get the complete list.
my $XMLData = '
<UserLogin>renato.raf</UserLogin>
<Password>psw</Password>
<TicketID>25715</TicketID>
';

# ---

# create a SOAP::Lite data structure from the provided XML data structure.
my $SOAPData = SOAP::Data->type( 'xml' => $XMLData );

my $SOAPObject =
  SOAP::Lite->uri($NameSpace)->proxy($URL)->$Operation($SOAPData);

# check for a fault in the soap code.
if ( $SOAPObject->fault ) {
	print $SOAPObject->faultcode, " ", $SOAPObject->faultstring, "\n";
}

# otherwise print the results.
else {

	# get the XML response part from the SOAP message.
	my $XMLResponse =
	  $SOAPObject->context()->transport()->proxy()->http_response()->content();

	print $XMLResponse;

	# deserialize response (convert it into a perl structure).
	my $Deserialized = eval { SOAP::Deserializer->deserialize($XMLResponse); };

	# remove all the headers and other not needed parts of the SOAP message.
	my $Body = $Deserialized->body();

# just output relevant data and no the operation name key (like TicketCreateResponse).
	for my $ResponseKey ( keys %{$Body} ) {
		print Dumper( $Body->{$ResponseKey} );
	}
}

The erros is:
Uncaught exception from user code:

not well-formed (invalid token) at line 1, column 1861, byte 1861 at /usr/lib/perl5/vendor_perl/5.8.8/i586-linux-thread-multi/XML/Parser.pm line 187

<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:namesp1="http://www.otrs.org/TicketConnector/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelop ... 2012-06-18 17:17:30</Changed><CreateBy>144</CreateBy><CreateTimeUnix>1340028937</CreateTimeUnix><Created>2012-06-18 11:15:37</Created><CustomerID /><CustomerUserID /><EscalationDestinationDate>2012-06-19 11:15:37</EscalationDestinationDate><EscalationDestinationIn>-365m</EscalationDestinationIn><EscalationDestinationTime>1340115337</EscalationDestinationTime><EscalationResponseTime>0</EscalationResponseTime><EscalationSolutionTime>1340201737</EscalationSolutionTime><EscalationTime>-21885</EscalationTime><EscalationTimeWorkingTime>-21900</EscalationTimeWorkingTime><EscalationUpdateTime>1340115337</EscalationUpdateTime><GroupID>9</GroupID><Lock>unlock</Lock><LockID>1</LockID><Owner>amanda.am</Owner><OwnerID>33</OwnerID><Priority>3 Normal</Priority><PriorityID>3</PriorityID><Queue>CGTI - Redes</Queue><QueueID>1</QueueID><RealTillTimeNotUsed>0</RealTillTimeNotUsed><Responsible>renato.raf</Responsible><ResponsibleID>144</ResponsibleID><SLAID /><ServiceID /><SolutionTime>64515</SolutionTime><SolutionTimeDestinationDate>2012-06-20 11:15:37</SolutionTimeDestinationDate><SolutionTimeDestinationTime>1340201737</SolutionTimeDestinationTime><SolutionTimeWorkingTime>64500</SolutionTimeWorkingTime><State>new</State><StateID>1</StateID><StateType>new</StateType><TicketID>25660</TicketID><TicketNumber>010025747</TicketNumber><Title>Portuguese Title: a??o</Title><Type>N?o Cadastrado</Type><TypeID>1</TypeID><UnlockTimeout>1340028937</UnlockTimeout><UntilTime>0</UntilTime><UpdateTime>-21885</UpdateTime><UpdateTimeDestinationDate>2012-06-19 11:15:37</UpdateTimeDestinationDate><UpdateTimeDestinationTime>1340115337</UpdateTimeDestinationTime><UpdateTimeEscalation>1</UpdateTimeEscalation><UpdateTimeWorkingTime>-21900</UpdateTimeWorkingTime></Ticket></namesp1:TicketGetResponse></soap:Body></soap:Envelope> at ./TicketGet.pl line 46
at /usr/lib/perl5/site_perl/5.8.8/SOAP/Lite.pm line 3554
SOAP::Lite::__ANON__('SOAP::Lite=HASH(0x85024f8)', '\x{a}not well-formed (invalid token) at line 1, column 1861, byte...') called at /usr/lib/perl5/site_perl/5.8.8/SOAP/Lite.pm line 3737
SOAP::Lite::call('SOAP::Lite=HASH(0x85024f8)', 'TicketGet', 'SOAP::Data=HASH(0x8481e40)') called at /usr/lib/perl5/site_perl/5.8.8/SOAP/Lite.pm line 3702
SOAP::Lite::__ANON__('SOAP::Lite=HASH(0x85024f8)', 'SOAP::Data=HASH(0x8481e40)') called at ./TicketGet.pl line 46
Any help I'll appreciate!

Thanks,

Renato.
jovemfelix
Znuny newbie
Posts: 5
Joined: 04 May 2012, 21:43
Znuny Version: 2.4.7
Real Name: Renato Alves Felix
Company: DPF

Re: Problem with special characters using Web Service

Post by jovemfelix »

I had to hack the source code... as bellow, and as need only the the tickets info - I put the encode output for the texts outputs:

# vi /opt/otrs/Kernel/System/Ticket.pm
# line 1230 - put:

Code: Select all

my $tt = $ENV{REQUEST_URI} eq "/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnector/";
if ($tt) {
	$Self->{EncodeObject}->EncodeOutput( \$Ticket{Queue} );
	$Self->{EncodeObject}->EncodeOutput( \$Ticket{Owner} );
	$Self->{EncodeObject}->EncodeOutput( \$Ticket{Priority} );
	$Self->{EncodeObject}->EncodeOutput( \$Ticket{Responsible} );
	$Self->{EncodeObject}->EncodeOutput( \$Ticket{State} );
	$Self->{EncodeObject}->EncodeOutput( \$Ticket{Title} );
	$Self->{EncodeObject}->EncodeOutput( \$Ticket{Type} );
}
Locked