메시지 페이로드에 대한 작업
기존 메시지 핸들러에서 메시지 페이로드에 대해 작업하며 메시지 페이로드를 한 메시지 형식에서 다른 메시지 형식으로 코드 변환할 수 있습니다.
시작하기 전에
이 태스크 정보
- 메시지 페이로드 내에서 데이터 오브젝트 찾기
- 페이로드를 다른 형식으로 변환
- 예를 들어, 중개가 메시지를 로그하도록 하려면 페이로드를 바이트 배열로 변환하십시오.
메시지 내의 특정 필드에 대해 작업하려면 SDO(Service Data Objects) 버전 1 데이터 그래프를 사용하십시오. 자세한 정보는 SDO 데이터 그래프의 내용을 참조하십시오. 지원되는 메시지 유형의 형식 및 이에 대한 작업 방법의 예제에 대한 자세한 정보는 웹 서비스 메시지의 SDO 데이터 그래프 맵핑 내용을 참조하십시오.
메시지 페이로드에 대해 작업하려면 다음 단계를 수행하십시오.
프로시저
메시지 필드에 대한 예제 코드
public boolean handle(MessageContext context) throws MessageContextException {
/* Get the SIMessage from the MessageContext object */
SIMessage message = ((SIMessageContext)context).getSIMessage();
/* Get the message format string */
String messageFormat = message.getFormat();
/* If you have a JMS TextMessage then extract the text contained in the message. */
if(messageFormat.equals("JMS:text"))
{
/* Retrieve the DataGraph object from the message */
DataGraph dataGraph = message.getDataGraph();
/* Navigate down the DataGraph to the DataObject named 'data'. */
DataObject dataObject = dataGraph.getRootObject().getDataObject("data");
/* Retrieve the text information contained in the DataObject. */
String textInfo = dataObject.get("value");
/* Use the text information retrieved */
System.out.println(textInfo);
}
/* Return true so the MessageContext is passed to any other mediation handlers
* in the handler list */
return true;
}
바이트 스트림으로서 메시지 페이로드에 대한 작업을 위한 전체 중개 기능 코드는
다음 예제와 유사합니다. public boolean handle(MessageContext context)throws MessageContextException {
/* Get the SIMessage from the MessageContext object */
SIMessage message = ((SIMessageContext)context).getSIMessage();
if (!SIApiConstants.JMS_FORMAT_MAP.equals(msg.getFormat()))
{
try
{
dumpBytes(msg.getDataGraphAsBytes());
}
catch (Exception e)
{
System.out.println("The message contents could not be retrieved due to a "+e);
}
}
else
{
System.out.println("The bytes for a JMS:map format message cannot be shown.");
}
return true;
}
private static void dumpBytes(byte[] bytes)
{
// Subroutine to dump the bytes in a readable form to System.out
}
}