私は、CRMとElastixコールセンターモジュールを統合するためにECCPプロトコルを使用しています。次のようにプロトコルが定義されたXML構造を使用しています。JAX-BカスタマイズされたXML出力
<request id="1">
<request_type> <!-- this will be mapped to the Java request class -->
<attributes>
</attributes>
</request_type>
</request>
と
<response id="1">
<response_type> <!-- this will be mapped to the Java response class -->
<attributes>
</attributes>
</response_type>
</response>
私はJavaクラスにXMLをマッピングするためにJAX-Bを使用していますが、問題は、私はJAX-を置く必要があるということですBはすべての要求でXMLを<request></request>
XML内に生成し、すべての応答で<response></response>
からコンテンツを抽出します。これは、ECCPプロトコルでは、すべての要求と応答をそれぞれの要素にネストする必要があるためです。ここで
document = createDocument();
Element requestWrapper = document.createElement("request");
requestWrapper.setAttribute("id", String.valueOf(wrapped.getId()));
document.appendChild(requestWrapper);
JAXBContext jc = JAXBContext.newInstance(wrapped.getClass());
Marshaller marshaller = jc.createMarshaller();
marshaller.marshal(wrapped, requestWrapper);
を例示する:
ECCPのプロトコル動作の一つは、JAX-B-マッピングされ、このようなクラスの中にある(ゲッターとセッターは省略されました):
@XmlRootElement(name = "loginagent")
@XmlAccessorType(XmlAccessType.FIELD)
public class EccpLoginAgentRequest implements IEccpRequest {
@XmlElement(name = "agent_number")
private String agentNumber;
@XmlElement(name = "password")
private String password;
}
そしてJAX-Bは、次を出力:
<loginagent>
<agent_number>username</agent_number>
<password>password</password>
</loginagent>
しかし、何ECCPのプロトコルが必要とすることである。
<request id="1"> <!-- id is an auto-increment number to identify the request -->
<loginagent>
<username>username</username>
<password>password</password>
</loginagent>
</request>
質問は次のとおりです。他のより良い方法で達成するための他の方法はありますか? ありがとうございます。
[OK]を見つけることができ、私は@XmlSeeAlso注釈のドキュメントを見ていたが、私は、問題をよりよく説明するために、私の質問を向上させます。 – Jaumzera
もう一度質問を確認できたら嬉しいです。前もって感謝します。 – Jaumzera
もう一度@reallolに感謝します。ただし、EccpLoginAgentRequestオブジェクトを送信したときにのみ動作します。実際に必要なのは、EccpRequestを拡張する任意のクラスからオブジェクトを送信できることです。 – Jaumzera