Thursday, December 7, 2017

WSO2 not getting carbon login page with host name or IP address but works well for localhost

I have started exploring the WSO2 Enterprise Integrator.  I am happy that the installation is as simple as tomcat installation (just copy the the root folder on to your system and start running it.) with prior JDK on your system.  After starting the server I am able to login to the Management console using the https://localhost:9443/carbon  or  https://127.0.0.1:9443/carbon URL.  However if I try to access the same with system name or the system dynamic IP when I am inside the intranet then say https://lpt-systemesb:9443/carbon   or  https://175.23.4.56:9443/carbon  then I am not able to access the server.  I didn't see any request going to the server as well.

After trying several blogs and documentations we have to set the  HostName  or the MgtHostName  values.  But still the issue is not resolved.  because the issue is not with this setting.  We don't have to do any changes in the WSO2 related any config files.

The resolution for this issue is DISABLE the firewall or allow the access on the ports. Uncheck the Enable Firewall checkbox. (Means disable the firewall). Now you should be able to access the WSO2 Management console without any issues on the same system during the development.



In the above image the Enable Firewall is checked, to work properly it needs to be unchecked.

Monday, October 30, 2017

How to consume NTLM (MSDynamics) authentication based SOAP services in JAVA using httpclient

I have a need to consume the Webservices published in MSDynamics applications.  This uses the Microsoft specific NTLM based authentication and authorization mechanism.  However to consume the SOAP services I did find any direct solution.  Below is the code that is working.  You have to change the credentials and the input SOAP message formation strings remaining all you can use as it is.

Note: Use the latest httpclient-4.2.3.jar or above ,  commons-codec-1.11  or above.  Few more other jars which you can take from Axis application.

CODE  ( TestCustomerRead.java )
============================

import java.io.InputStream;

import org.apache.commons.io.IOUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.NTCredentials;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;

public class TestCustomerRead {

static String HOST  = "120.142.157.189";
static int    PORT  = 81;
static String USER  = "yourusername";
static String PWD   = "slf#pwd";
static String DOMAIN    = "mcpdl";
static String PROTOCOL  = "http";
static String WSDL_PATH = "/MicrosoftDynamicsAXAif60/AXCustomerService/xppservice.svc?wsdl";
static String SERVICE_ENDPOINT = "/MicrosoftDynamicsAXAif60/AXCustomerService/xppservice.svc";

// soap action you can find in the WSDL at the action attribute of the operation you want to consume //
static String SOAP_ACTION    = "http://schemas.microsoft.com/dynamics/2008/01/services/CustomerService/read";

public static void main(String[] args) {

try {
CloseableHttpClient httpclient = HttpClientBuilder.create().build();
BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY, new NTCredentials(USER, PWD, HOST, DOMAIN));
HttpHost target = new HttpHost(HOST, PORT , PROTOCOL);

HttpClientContext context = HttpClientContext.create();
context.setCredentialsProvider(credsProvider);

System.out.println("authenticated started");

// Execute a cheap method first. This will trigger NTLM
// authentication  (optional )
HttpGet httpget = new HttpGet( WSDL_PATH );
CloseableHttpResponse response1 = httpclient.execute(target,
httpget, context);
try {
HttpEntity entity1 = response1.getEntity();
System.out.println("=====GET=======>>>>" + response1.toString());
} finally {
response1.close();
}

// Execute an expensive method next reusing the same context (and
// connection)
HttpPost httppost = new HttpPost( SERVICE_ENDPOINT );
httppost.setHeader("SOAPAction",SOAP_ACTION );
httppost.setHeader("Content-Type", "text/xml; charset=utf-8");
StringEntity stringEntity = new StringEntity(getReadRequestSOAP().toString(), "UTF-8");
stringEntity.setChunked(true);
httppost.setEntity(stringEntity);

CloseableHttpResponse response2 = httpclient.execute(target, httppost, context);
try {
HttpEntity entity2 = response2.getEntity();

if(response2.getStatusLine().getStatusCode()== 200){
System.out.println("=====POST=======>>>>HTTP Response Status :"
+ response2.getStatusLine().toString());

System.out.println("RESPONSE MESSAGE IS \n ===================="  );
InputStream in = entity2.getContent();
String body = IOUtils.toString(in, "UTF-8");
System.out.println(body);
System.out.println("\n ===================="  );

}else{
System.out.println("AUTHENTICATION ERROR WITH CODE " + response2.getStatusLine().toString());
}

} catch (Exception ex) {
ex.printStackTrace();
} finally {
response2.close();
System.out
.println("COMPLETED THE REQUEST/RESONSE.");
}

} catch (Exception ex) {
ex.printStackTrace();
}
}

  // replace the SOAP message with your request messages.
// change the the input values as per your request data

private static String getReadRequestSOAP() {
// Below just form the complete SOAP message as a string
String statusRequest = " "
+ "    "
+ "         "
+ "               mcpl"
+ "       
" + "   
" + "    "
+ "          "
+ "              "
+ "              "
+ "                "
+ "                      "
+ "                           AccountNum "
+ "                           C-1008 "
+ "                     
" + "               
" + "             
" + "             
" + "               
" + "             
" + "         
"; return statusRequest;
}

}

=====================END =============
References:

http://hc.apache.org/httpcomponents-client-ga/

https://hc.apache.org/httpcomponents-client-ga/tutorial/html/authentication.html

http://hc.apache.org/httpcomponents-client-4.5.x/ntlm.html


https://www.mkyong.com/java/apache-httpclient-examples/

https://rathinasaba.wordpress.com/2013/02/01/call-webservice-wsdl-based-using-apache-httpconnection/

https://stackoverflow.com/questions/12561503/how-to-call-a-soap-webservice-with-a-simple-string-xml-in-string-format 

Tuesday, August 29, 2017

SOA 11g Transaction timing configuration

Reference taken from other blog. at ( http://soadiscovery.blogspot.in/2011/04/soa-11g-configuring-transaction-timeout.html )

We have set our environment with below values and worked fine.

The gist of the blog the following value should be set (SyncMaxWaitTime < BPEL EJB's transaction timeout < Global Transaction)

SyncMaxWaitTime à300

All the EJB Beans values à 1200

JTA (Global Transaction Timeout)à1800


================================================================

SOA 11g : Configuring Transaction timeout in BPEL
Transaction timeout can be configured for BPEL in 11g using the below properties.
1. SyncMaxWaitTime
Maximum time BPEL process wait before returning result to client(or another Sync process)
To set this property
a. Login to EM console
b. Expand SOA and right click on “soa-infra”
c. From context menu, select SOA Administration –> BPEL properties
d. Click on “More BPEL Configuration properties…”
 SyncMaxWaitTime
 2.Transaction Time-out for BPEL EJB’s
The following EJB’s need to be configured for transaction time outs.
  • BPELActivityManagerBean
  • BPELDeliveryBean
  • BPELDispatcherBean
  • BPELEngineBean
  • BPELFinderBean
  • BPELInstanceManagerBean
  • BPELProcessManagerBean
  • BPELSensorValuesBean
  • BPELServerManagerBean
To change time out for these beans ,
a. Login to Administration Console
b. Click on Deployments
c. Expand soa-infra –> EJB’s
Transaction-EJB1of3 Transaction-EJB2of3
d. Click on EJB for which you want to change the timeout
e. Click on Configuration
f. Change value for field “Transacion Timeout”
g. Click Save.
Transaction-EJB3of3
 3. Global Transaction Timeout
This property is timeout in seconds for active transactions. After this time, if the transaction is still “Active”, then it gets rolled back.
To change this value
a. Login to Administration Console
b. Expand “Services” –> Click on “JTA”
c. Click on “JTA” tab if it’s on a different tab
d. Change value for field “Timeout Seconds”
GlobalTransactionTimeout
Very Important :
SyncMaxWaitTime < BPEL EJB's transaction timeout <  Global Transaction Timeout

Monday, May 22, 2017

SOA 11g BPEL process or the Sub Process goes in recovery mode resolution

In the SOA if a BPEL process is always going in recovery mode then the main problem would be one of the end points inside the BPEL process consuming services is not reachable.

Check if your deployment configuration file has the right targets when moving from one environment to another environment.

Check if the external service that is pointing is up and running.

DB Adapter stopped polling the record from the database table however the process health looks good

If the BPEL process health looks good, there is a chance that you could find error message in the log files about primary key value null.

If the DB Adapter is polling using the logical primary key (ie. database table doesn't have primary key on the table)  and the primary key value is null in at least one field of a record then that record will be picked and after that stops proceeding further.  This record will be in stuck positon.  And all the subsequent records won’t be polled.    So, delete all the bad primary key based records.  Then the remaining process will continue picking up by the Db adapter as usual.

Monday, April 10, 2017

How to send email opaque data as email attachment in soa 11g

Sometimes its required for us to read the file using file adapter and then send it as an email attachment.  When the file is read by DB adapter in binary format, means as an opaque  type variable then the data is in the encoded  format.

When we send the email in the attachment we have to add the original file contents as  a string.
So, we have to decode the content using base64 then attache it to the email activity.

To send the email as an attachment then below are the three key steps we need to do.

1. Import the java classes in the  bpel file, as the sub element of    ...
<process> element.
      <bpelx:exec import="oracle.soa.common.util.Base64Decoder"/&g

t;















































































&

amp;
lt
;bp
elx:exec import="oracle.soa.common.util.Base64Encoder"/>

2. Create a simple string type variable say , fileCont










ent




































;

 
 










 




































&lt
;variablefi name="leName" type="xsd:string"/>

3.  Assign the input variable's  opaque value to the string variable, to make the code











s

im









































































ple













;



 







































































































 

 





























  <assign name="Assign1">
            &lt;copy>
             <from>$Receive_Read_InputVariable.opaque
             <to>$fil









eCo



























nte

























nt





































 










































 








 


























  <c/opy&g
t;



 
 
  </assign>

4.  Now ad a JEmbededava activity  Write the below cod



















e.





















   addAuditTrailEntry("decoding












sta
rte

d")











;
 
























e
nco

Std











ed











St











rring ing











= (String)getVariableData("fileContent");
     oracle.soa.common.util.Base64Decoder Decoder = new oracle.soa.common.util.Base64Decoder();      addAuditTrailEntry("encoded String = "+encodedString);
     try
    {
        String decoded = oracle.soa.common.util.Base64Decoder.decode(encodedString);
        addAuditTrailEntry("decoded string = "+decoded);











   








    setVariableData("fileContent,"decod


ed)




;




 







}



    c





atc


h(E



xcepti

on e)






 {




 


 








addAud

itTrailEntry("Exception: "+e.getMessage());
    }


5.  Now finally in the email activity, go to the  Attachment tab and add new attachment button (+ green symbol)  then you see new line add the below content as shown below.  The file name you need to select either static or the dynamically through a variable as shown below.
In the encoding you can add manually  charset=UTF-8 



6. Here is the sample BPEL flow you can see for testing.

Now compile and test it.  Thats it.