Sei sulla pagina 1di 2

2/16/2016

WritingaCustomContentHandlerforIntegrationServerWiki

(https://techcommunity.softwareag.com/pwiki/-/wiki/Main/ESB+and+Integration+Articles/pop_up) Writing a Custom Content

Handler for Integration Server


Details (https://techcommunity.softwareag.com/pwiki?
p_p_id=36&p_p_lifecycle=0&p_p_state=pop_up&p_p_mode=view&_36_struts_action=%2Fwiki%2Fview_page_details&p_r_p_185834411_nodeName=Main&p_r_p_185834411_title=Writing+a+Custom+Content+Handler+for+Integration+Server&_36_redirect=https%3A%2F%2Ftechcommunity.softwareag.com%2Fpwiki%2F
%2Fwiki%2FMain%2FWriting%2Ba%2BCustom%2BContent%2BHandler%2Bfor%2BIntegration%2BServer%2Fpop_up)
Tags:

webmethods (https://techcommunity.softwareag.com/pwiki//wiki/tag/webmethods/pop_up)

articles (https://techcommunity.softwareag.com/pwiki//wiki/tag/articles/pop_up)

server (https://techcommunity.softwareag.com/pwiki//wiki/tag/integration+server/pop_up)

esb (https://techcommunity.softwareag.com/pwiki//wiki/tag/esb/pop_up)

(https://techcommunity.softwareag.com/pwiki//wiki/tag/custom+content+handler/pop_up)

products (https://techcommunity.softwareag.com/pwiki//wiki/tag/products/pop_up)

esb_and_integration (https://techcommunity.softwareag.com/pwiki//wiki/tag/esb_and_integration/pop_up)
products/pop_up)

Print

integration

custom content handler

sagproducts (https://techcommunity.softwareag.com/pwiki//wiki/tag/sag

esbandintegration (https://techcommunity.softwareag.com/pwiki//wiki/tag/esbandintegration/pop_up)

integrationcloud

(https://techcommunity.softwareag.com/pwiki//wiki/tag/integrationcloud/pop_up)

by Jonathan Heywood Manager, Product Management Software AG


Table of Contents[]
0.0.1 Applicability
0.0.2 Abstract
0.0.3 What is a content handler?
0.0.4 mime.types
0.0.5 Writing a content handler
0.0.6 The ContentHandler class
0.0.7 The ContentHandlerFactory class
0.0.8 Registering content handlers
Applicability#
Product: Integration Server
Versions: 6.5, 7.1.x, 8.0
Abstract#
When a document is posted to a port on Integration Server (IS), then a Content Handler is invoked to convert the content into an IS pipeline (IData) object for processing by the
service being invoked. This document describes what a content handler does, how IS determines which content handler to use and how to write and register your own customer
content handler for IS.
What is a content handler?#
As the name implies, a content handler is a piece of code that takes a generic input in the form of an InputStream and knows how to parse that content and convert it into a format
more easily consumable by the service being invoked. To do this, an appropriate content handler needs to be selected based on the contenttype of the document being received. The
method of determining the contenttype differs depending on the protocol of the receiving port:
Port protocol and Method of determining content type
HTTP(S)
ContentType HTTP header
FTP(S)
Two possibilities:
1) If a contenttype is supplied as part of the FTP PUT command, then that contenttype is used: put srcFile destFile;text/xml
2) Otherwise, the filename extension is used to determine the contenttype using the mime.types table (see below)
File polling
Two possibilities:
1) If a contenttype has been specified in the configuration of the file polling port, then that contenttype is used for all files received through that port
2) Otherwise, the filename extension is used to determine the contenttype using the mime.types table (see below)
Email
The contenttype specified in the MIME header of the email message. If the option Invoke service for each part of multipart message has been selected, then the content type
for each service invocation will be that of the relevant MIME part, otherwise it will be the contenttype of the entire message.
A content handler has two parts; one for parsing the received document and converting it to an IData (pipeline) object that the service can process easily, and the other for
converting the output pipeline from the service back into a format that the calling client can handle. Most content handlers only implement the input handler, but the output handler
can also be used to customformat the output of a service, although there are other ways of doing this, such as using pub.flow:setResponse.
mime.types #
In the cases mentioned above where the filename extension determines the contenttype, this is determined based on a file called mime.types, which can be found in the
<IntegrationServer>/lib directory. It contains lines like the following:
text/plainbaschtxt
This indicates that any files ending in .bas, .c, .h or .txt will be treated as content type text/plain. If you need to add new file extension mappings, then you can add them to this
file. NOTE: Make sure you shut down IS before modifying this file.
Writing a content handler #
The content handler itself consists of two parts:
the content handler class, an implementation of com.wm.app.b2b.server.ContentHandler
the content handler factory, an instance of com.wm.app.b2b.server.ContentHandlerFactory

These cannot be written inside webMethods Developer and need to be written an compiled using your favorite Java IDE, or using the JDK from a commandline. The class files can be
placed in the <IntegrationServer>/packages/<yourpackage>/code/classes directory for easy access from the register and remove services.
The ContentHandler class #
The following is a simple skeleton for this class. This is the class that does all the work.
NOTE: It is not necessary to implement both getInputValues and putOutputValues. Often the putOutputValues method is left empty if the calling client is merely posting a document
and not expecting any specific output.
publicclassMyContentHandlerimplementsContentHandler
{
privateStringcontentType;
publicMyContentHandler()
{
contentType=<default_content_type>;
}
publicMyContentHandler(StringcontentType)
{
this.contentType=contentType;
}
publicStringgetContentType()
{
returncontentType;
}
//thisserviceparsesthereceiveddocumentandcreates//theinputpipelinefortheservicebeinginvoked
publicValuesgetInputValues(java.io.InputStreamis,
InvokeStatestate)
throwsIOException
{
//addcodeheretoreadfromInputStreamandcreatea//Valuesobjectrepresentingthedatacontent
}
//thisserviceparsestheoutputpipelineoftheservice//andconvertsittoastreamformatfordeliveringtothe
//callingclientpublicvoidputOutputValues(OutputStreamos,Valuesout,InvokeStatestate)throwsIOException{//addcodeheretoreadfromtheVal
uesobjectand
//writeitscontentinthedesiredformattothe//OutputStream
}
}

https://techcommunity.softwareag.com/pwiki//wiki/Main/Writing+a+Custom+Content+Handler+for+Integration+Server/pop_up

1/2

2/16/2016

WritingaCustomContentHandlerforIntegrationServerWiki

}
The ContentHandlerFactory class #
The following is all that is needed in the ContentHandlerFactory class.
publicclassMyContentHandlerFactory
extendsContentHandlerFactory
{
privateStringcontentType;
publicMyContentHandlerFactory()
{
contentType="<default_content_type>";
}
publicMyContentHandlerFactory(Stringcontenttype)
{
contentType=contenttype;
}
publicContentHandlercreate()
{
returnnewMyContentHandler(contentType);
}
}
Registering content handlers #
Once the contenttype has been determined using the methods described above, IS will try to invoke a suitable content handler. IS contains a number of standard content handlers,
such as for XML or flat files. Others may have been registered by adapters, eStandards modules or by custom code.
A content handler can be registered at any time while an IS is running by calling
ServerAPI.registerContentHandler(java.lang.Stringcontent_type,
ContentHandlerFactoryfactory)
To this, you provide the contenttype (for example application/vnd.msexcel) and a new instance of com.wm.app.b2b.server.ContentHandlerFactory, like the example above.
NOTE: See the IS Java API documentation for more details on these APIs.
Registering a content handler is best done in a oneline Java service in IS. Then specify that service as a startup service of that package to ensure that the content handler gets
registered each time IS starts up. And to complete the picture you should create a second Java service that removes the content handler again when the package is unloaded:
ServerAPI.removeContentHandler(java.lang.Stringcontent_type)
The information in this document is provided asis and with no warrantywhatsoever. Software AG cannot be held responsible for the results of anyinaccuracies.
0 Attachments (https://techcommunity.softwareag.com/pwiki?
p_p_id=36&p_p_lifecycle=0&p_p_state=pop_up&p_p_mode=view&_36_struts_action=%2Fwiki%2Fview_page_attachments&p_r_p_185834411_nodeName=Main&p_r_p_185834411_title=Writing+a+Custom+Content+Handler+for+Integration+Server&_36_redirect=https%3A%2F%2Ftechcommunity.softwareag.com%2Fpwiki%2F
%2Fwiki%2FMain%2FWriting%2Ba%2BCustom%2BContent%2BHandler%2Bfor%2BIntegration%2BServer%2Fpop_up)
42840 Views

Average (2 Votes)

Comments

https://techcommunity.softwareag.com/pwiki//wiki/Main/Writing+a+Custom+Content+Handler+for+Integration+Server/pop_up

2/2

Potrebbero piacerti anche