Skip to main content

NTLM based SOAP Implementation in OSB

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.
  • 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:
package com.teamshare.java.client.http;
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:









Comments

  1. getting below error, please suggest , with Java version ?


    Jul 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.

    ReplyDelete
  2. Replies
    1. Try to add ur domain before username, java7 nd 6 support it.

      Delete

Post a Comment

Popular posts from this blog

Oracle SOA 12C rest adapter with Custom HTTP headers

Most existing web applications are connected through web services, which are commonly known as SOAP services. More and more users are relying on mobile devices for communication, and they’re looking for lighter ways to access enterprise information on the go. REST services are the answer for the mobile device platform, because they get rapid responses and fast access to data. Oracle SOA Suite 12 c  provides a complete set of service infrastructure components for designing, deploying, and managing composite applications. Oracle SOA Suite 12 c  enables services to be created, managed, and orchestrated into composite applications and business processes. Some time we have need to send HTTP headers in REST service, In OSB we use header component and add what ever is needed but in oracle SOA 12C it's little bit different. Let see how we can do it. Create one SOA Application. Create one SOA Sample project inside SOA Application. Go to composite and drag drop REST adapt

Dynamic Routing in OSB 12C

Dynamic Routing in OSB cab be used when the BusinessService endpoint required to be determine at runtime in message flow. Consider a scenario where OSB has to route the incoming requests to 2 different services based on the CustomerType element value sent in the payload. So create a XQuery resource with the following contents. Observe that we are using the absolute path of business service in configuration as required by dynamic routing. Following is the XML schema that we use:>>  Customer.xsd <?xml version="1.0" encoding="windows-1252" ?> <xsd:schema targetNamespace="http://xmlns.oracle.com/schema/Customer" xmlns:xsd="http://www.w3.org/2001/XMLSchema"             xmlns:ns1="http://xmlns.oracle.com/schema/Customer">   <xsd:complexType name="Customer">     <xsd:sequence>       <xsd:element name="CustomerId" type="xsd:string"/>       <xsd:elemen

Swagger API document from Any WADL & Schema in Oracle SOA

Hi everyone, Hope everyone is doing well these days, Recently i started a project work over how to generate swagger API document for your any REST API, In case if you don't know what is swagger please go and check " https://swagger.io/tools/swagger-editor/ ". It's a great and easy to use tool which will help to create user friendly, human readable form API documentation with extension for generating API client in different languages with capability of testing your API from same. What is swagger editor, Design, describe, and document your API on the first open source editor fully dedicated to OpenAPI-based APIs. The Swagger Editor is great for quickly getting started with the OpenAPI (formerly known as the Swagger Specification) specification, with support for Swagger 2.0 and OpenAPI 3.0.  What benefits you will get by using swagger, Runs Anywhere, The Editor works in any development environment, be it locally or in the web. Smart Feedback, Validate you