How to Set an Identity for J2SE Clients Invoking Direct Binding
A user identity can be established when authenticating to the server during the process of JNDI lookup by passing the JNDI security credential, as shown in the following example:
public static void main(String[] args) throws Exception {
String operation = "process";
// This is the request message XML
String ns = "http://xmlns.oracle.com/DirectBinding_jws/EchoBPEL/BPELProcess1";
String payloadXML = "<ns1:process xmlns:ns1=\"" + ns + "\">\n" +
" <ns1:input>wew</ns1:input>\n" +
"</ns1:process>";
String serviceAddress = "soadirect:/default/EchoBPEL!1.0/DService1";
// Specify the direct binding connection properties
Map<String, Object> props = new HashMap<String, Object>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
props.put(Context.PROVIDER_URL, "t3://" + hostname + ':' + portname);
props.put(Context.SECURITY_PRINCIPAL,username);
props.put(Context.SECURITY_CREDENTIALS, password);
// Create the direct binding connection, using those context properties
DirectConnectionFactory factory = JNDIDirectConnectionFactory.newInstance();
try {
DirectConnection dc = factory.createConnection(serviceAddress, props);
// Parse the XML request message
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
Document doc =
dbf.newDocumentBuilder().parse(new InputSource(new StringReader(payloadXML)));
// Prepare the payload for inclusion in the Message object
Map<String, Element> payload = new HashMap<String, Element>();
payload.put("payload", doc.getDocumentElement());
Message<Element> request = XMLMessageFactory.getInstance().createMessage(payload);
Message<Element> response = dc.request(operation, request);
} finally {
dc.close();
}
}