Friday, 15 March 2019

OTRS Rest API integration

OTRS is a tool to log tickets online. This is very basic requirement to log tickets and track them online. OTRS gives this functionality but if you want to integrate this functionality in you application then OTRS provide you with some basic API's like to create ticket, get ticket by id, update ticket, search ticket. Please follow below screenshots to enable in it your OTRS tool. Here we are assuming that OTRS tool is already installed.

  1. Login in OTRS with admin user.
2. Goto "Admin" tab.


3. Find  WebService link as:



4. Click on WebService.



5. Click on "add web service".


6. Click on "Import web service"  and choose file from desktop (use Test.yaml file given below)
 

Test.yaml file

---
Debugger:
  DebugThreshold: debug
  TestMode: '0'
Description: Is used by me
FrameworkVersion: 4.0.5
Provider:
  Operation:
    TicketGet:
      Description: ''
      MappingInbound:
        Type: Simple
      MappingOutbound:
        Type: Simple
      Type: Ticket::TicketGet
    TicketUpdate:
      Description: ''
      MappingInbound:
        Type: Simple
      MappingOutbound:
        Type: Simple
      Type: Ticket::TicketUpdate
    TicketCreate:
      Description: ''
      MappingInbound:
        Type: Simple
      MappingOutbound:
        Type: Simple
      Type: Ticket::TicketCreate
    TicketSearch:
      Description: ''
      MappingInbound:
        Type: Simple
      MappingOutbound:
        Type: Simple
      Type: Ticket::TicketSearch
  Transport:
    Config:
      KeepAlive: ''
      MaxLength: '20000000'
      RouteOperationMapping:
        TicketGet:
          Route: /TicketGet/:TicketID
        TicketUpdate:
          RequestMethod:
          - POST
          Route: /TicketUpdate/:TicketID
        TicketCreate:
          RequestMethod:
          - POST
          Route: /TicketCreate
        TicketSearch:
          RequestMethod:
          - GET
          Route: /TicketSearch
    Type: HTTP::REST
RemoteSystem: ''
Requester:
  Transport:
    Type: ''

It will expose the web service and you can test it with any client tool like POSTMAN etc

You need to add parameter user name as UserLogin  and password as password to access any api.

Example of get API (GET)
 http://server address/otrs/nph-genericinterface.pl/Webservice/Test/TicketGet/Ticketno?UserLogin=username&Password=password

Example of Create API (POST)
http://server address/otrs/nph-genericinterface.pl/Webservice/Test/TicketCreate?UserLogin=user name&Password=password

JSON in Body as: 
 {
"Ticket" : {
"QueueID" : "1",
"PriorityID" : "5",
"CustomerUser" : "email id",
"Title" : "REST Create Test",
"State" : "open"
},
"Article" : {
"ContentType" : "text/plain; charset=utf8",
"Subject" : "Rest Create Test",
"Body" : "This is only a test"
}
}


Example of update API (POST)
http://server address/otrs/nph-genericinterface.pl/Webservice/Test/TicketUpdate/22645?UserLogin=user login&Password=password

JSON in Body as: 
 {
"Ticket" : {
"QueueID" : "1",
"PriorityID" : "5",
"CustomerUser" : "email id",
"Title" : "REST Create Test",
"State" : "open"
},
"Article" : {
"ContentType" : "text/plain; charset=utf8",
"Subject" : "Rest Create Test Update",
"Body" : "This is only a test updated"
}
}


Example of searc API
http://server address/otrs/nph-genericinterface.pl/Webservice/Test/TicketSearch?UserLogin=user name&Password=password



Monday, 28 December 2015

MySQL ERROR - Specified key was too long; max key length is 767 bytes

This is very old MySQL issue. MySQL engine like InnoDB or MyISAM has their own limit on the length of the columns where indexing can be applied. Usually it is 1000 for MyISAM and 767 for InnoDB. Problem occures when user try to change the length of the column where indexing was already applied or try to implement indexing on a column where length of column is already greater than 1000.
This problem can be solved in two ways:

1. Set the properties of MySQL engine. (It will only work for mysql 5.6+).

  • show engines;(Get the current Engine - Only to check).
  • show variables like 'innodb%'; (Get current engines properties)
  • Set properties as:
  • innodb_large_prefix=on;
  • innodb_file_format=barracuda;
  • innodb_file_per_table=true;
  • Run the alter command.
2. Set MySQL to no engine mode.
  • SELECT @@SESSION.sql_mode; (Check current SQL mode)
  • SET sql_mode = 'NO_ENGINE_SUBSTITUTION'; (Set SQL mode to no engine)
  • run your alter command.
  • Again set back to engine mode

Monday, 6 October 2014

Exceptions with method overriding in java

In java methods can throw the different checked/unchecked exceptions, this seems to be simple as long as we are talking about the single methods in java but when we deal with method overriding in java the concept of exception which can be thrown by overriding or overridden method are bit tricky. The overriding method cannot throw the new/broader exception than the overridden method is throwing but this case is only true for checked exception and not true for unchecked/runtime exception.

If overriding method is throwing a checked exception which is new/broader than your overridden method exception then your code will not compile.

The combination of base class overridden method and derived class overriding method with respect to exceptions can be categorized into the below five cases as:

1.    Base class method throwing no exception and derived class method is throwing exception.
       •    In case of checked exception code will not compile
       •    In case of runtimeException code will work fine.

2.    Base class method throwing less newer/broader exception than derived class method is throwing.   
       Suppose base class overridden method is throwing ArithmeticException and derived class overriding
       method is throwing general Exception so then code will not compile.
      •    In case of checked exception code will not compile
      •    In case of runtimeException code will work fine.

3.    Both base and derived class overridden method throw same exception
       •    Code will compile and run perfectly in both cases of checked and unchecked exception.

4.    Base class overridden method throwing newer/broader exception than derived class overriding method.
       Suppose base class overridden method is throwing general Exception and derived class overriding
       method is throwing ArithmeticException so then code will compile and work fine.
       •     Code will compile and run perfectly in both cases of checked and unchecked exception.

5.    Base class overridden method is throwing exception but Derived class overriding method is not 
       throwing  exception.
      •    Code will compile and run perfectly in both cases of checked and unchecked exception.