Using a Constructed Document Key to Manage Profile Data
Converged Application Server provides a helper class, com.bea.wcp.profile.ProfileService, to help you easily retrieve a profile data document. The getDocument() method takes a constructed document key, and returns a read-only org.w3c.dom.Document object. To modify the document, you make and edit a copy, then send the modified document and key as arguments to the putDocument() method.
Note:
If Diameter Sh client node services are not available on the Converged Application Server instance when getDocument() method is invoked, the profile service throws a "No registered provider for protocol" exception.
Converged Application Server caches the documents returned from the profile service for the duration of the service method invocation (for example, when a doRequest() method is invoked). If the service method requests the same profile document multiple times, the subsequent requests are served from the cache rather than by re-querying the HSS.
Example 2-1 shows a sample SIP Servlet that obtains and modifies profile data.
Example 2-1 Sample Servlet Using ProfileService to Retrieve and Write User Profile Data
package demo;
import com.bea.wcp.profile.*;
import javax.servlet.sip.SipServletRequest;
import javax.servlet.sip.SipServlet;
import org.w3c.dom.Document;
import java.io.IOException;
public class MyServlet extends SipServlet {
private ProfileService psvc;
public void init() {
psvc = (ProfileService) getServletContext().getAttribute(ProfileService.PROFILE_SERVICE);
}
protected void doInvite(SipServletRequest req) throws IOException {
String docSel = "sh://" + req.getTo() + "/IMSUserState/";
// Obtain and change a profile document.
Document doc = psvc.getDocument(docSel); // Document is read only.
Document docCopy = (Document) doc.cloneNode(true);
// Modify the copy using DOM.
psvc.putDocument(docSel, docCopy); // Apply the changes.
}
}