Hello Everyone,
Today i am going to discuss how we can invoke a NTLM based SOAP service into OSB, Oracle SOA 12C have this feature in-built but you can use it only when you have env up to date with latest patch.
Here i am going to discuss how we can do it in OSB. There is no direct way to do it in OSB too but with help of JAVA HTTP we can do it.
Today i am going to discuss how we can invoke a NTLM based SOAP service into OSB, Oracle SOA 12C have this feature in-built but you can use it only when you have env up to date with latest patch.
Here i am going to discuss how we can do it in OSB. There is no direct way to do it in OSB too but with help of JAVA HTTP we can do it.
- Create a JAVA project in Eclipse.
- Import below three jars and attach them in build path so it can be used as class path.
- Java class Code:
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.NTCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;
public class TeamShareClient {
public TeamShareClient() {
}
public static void main(String[] args) {
StringBuilder messageBody = new StringBuilder();
messageBody.append("<soapenv:Body>");
messageBody.append("<soap:GetList>");
messageBody.append("<soap:listName>Calendar1</soap:listName>");
messageBody.append("</soap:GetList>");
messageBody.append("</soapenv:Body>");
try {
invokeExService(
"URL.com/sites/IT/eis/_vti_bin/Lists.asmx",
"<soapenv:Header/>", messageBody.toString(), "username",
"password", "GetList", "hostName", "domainName");
} catch (Exception e) {
e.printStackTrace();
}
}
public static String invokeExService(String endPoint, String messageHeader,
String messageBody, String userName, String password,
String operation, String hostName, String domainName)
throws Exception {
String userAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13";
StringBuffer soapMessage = new StringBuffer();
soapMessage.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
soapMessage
.append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:soap=\"http://schemas.microsoft.com/sharepoint/soap/\">");
soapMessage.append(messageHeader);
soapMessage.append(messageBody);
soapMessage.append("</soapenv:Envelope>\n");
System.out.print("Request : " + soapMessage.toString());
HttpClient client = new HttpClient();
String soapAction = "http://schemas.microsoft.com/sharepoint/soap/"
+ operation;
PostMethod postMethod = new PostMethod(endPoint.trim());
postMethod.setRequestHeader("SOAPAction", soapAction);
postMethod.setRequestHeader("Content-Type", "text/xml; charset=UTF-8");
postMethod.setRequestHeader("SOAPAction", soapAction);
postMethod.setRequestHeader("User-Agent", userAgent);
postMethod.setRequestEntity(new StringRequestEntity(soapMessage
.toString().trim(), "text/xml; charset=UTF-8", null));
String responseBodyString = "";
NTCredentials ntCredentials = new NTCredentials(userName, password,
hostName, domainName);
client.getState().setCredentials(new AuthScope(null, -1, null),
ntCredentials);
int status = client.executeMethod(postMethod);
if (status != HttpStatus.SC_OK) {
responseBodyString = postMethod.getResponseBodyAsString();
responseBodyString = responseBodyString.split("<soap:Body>")[1]
.split("</soap:Body>")[0];
responseBodyString=responseBodyString.replaceAll("<soap:", "<soapenv:");
responseBodyString=responseBodyString.replaceAll("</soap:", "</soapenv:");
String soapEnvNameSpace="<soapenv:Fault xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">";
responseBodyString=responseBodyString.replaceAll("<soapenv:Fault>", soapEnvNameSpace);
} else {
responseBodyString = postMethod.getResponseBodyAsString();
responseBodyString = responseBodyString.split("<soap:Body>")[1]
.split("</soap:Body>")[0];
}
System.out.println("Response Message ;" + responseBodyString);
return responseBodyString;
}
}
- This java code will return you error & success case response without BODY tag, because in OSB we are going to use replace/assign in body variable only.
- Export this JAVA project into one JAR file, This JAR is going to be used inside OSB JAVA CALLOUT.
- Before OSB development, we have to configure CLASSPATH with these JAR files that we used in JAVA project so when OSB make a JAVA CALLOUT over our newly created JAR, it don't throw CLASS NOT FOUND EXCEPPTION.
- commons-codec-1.9.jar
- commons-logging-1.2.jar
- org.apache.commons.httpclient.jar
- Copy all three JAR's to any location on OSB server.
- Need to edit “setDomainEnv.sh” file.
- Add below CLASSPATH entry in this file.
- POST_CLASSPATH="JAR_LOCATION/org.apache.commons.httpclient.jar${CLASSPATHSEP}${POST_CLASSPATH}"
- POST_CLASSPATH="JAR_LOCATION/commons-codec-1.9.jar${CLASSPATHSEP}${POST_CLASSPATH}"
- POST_CLASSPATH="JAR_LOCATION/commons-logging-1.2.jar${CLASSPATHSEP}${POST_CLASSPATH}"
- export POST_CLASSPATH.
- Complete bounce so server can update it's class path entry.
OSB Development:
- Create one OSB project.
- Design a WSDL/XSD based on your need, In my case i am using same WSDL of team share for my proxy.
- In case you design your own, then you have to do transformation based on your need so you can send correct SOAP request to java client.
- Below will be OSB project structure.
- In my OSB project, I used a DVM to put all values that will be passed to JAVA class from OSB.
- Below is OSB proxy implementation design.
- Copying input body to a TEMP variable so same variable can be passed to JAVA callout.
- Below is JAVA call out activity, where you can see how JAR is associated and what all parameters has been passed into java static method.
- Our JAVA HTTP client will return response as string, so we need to convert it into XML in response pipe line and same response need to be updated in body.
Test results:
getting below error, please suggest , with Java version ?
ReplyDeleteJul 12, 2019 4:35:26 PM org.apache.commons.httpclient.auth.AuthChallengeProcessor selectAuthScheme
INFO: ntlm authentication scheme selected
Jul 12, 2019 4:35:27 PM org.apache.commons.httpclient.HttpMethodDirector processWWWAuthChallenge
INFO: Failure authenticating with NTLM @capita-axa-aviva.integration.dev.egportal.co.uk:443
401 - Unauthorized: Access is denied due to invalid credentials.
You do not have permission to view this directory or page using the credentials that you supplied.
credentials are correct
ReplyDeleteTry to add ur domain before username, java7 nd 6 support it.
DeleteFantastic article post.Really thank you! Awesome.
ReplyDeletejava training
salesforce training
hadoop training
mulesoft training
linux training