Thursday, April 25, 2013

Generate Random Numbers Java service

// pipeline
IDataCursor pipelineCursor = pipeline.getCursor();
String    length = IDataUtil.getString( pipelineCursor, "length" );
int Length = Integer.parseInt(length);

//initialising the variables
long min =1,max =1,Number =1;
String randomNumber = null ;

//looping in order to obtain minimum and maximum Range.
for(int i=1;i min = min*10;
 max = min*9;
pipelineCursor.destroy();

//Calculating the Random Number and Storing it to a temporary Variable.
Number = (long) Math.floor(Math.random() * max) + min;

//converting Long into String Output.
randomNumber = Long.toString(Number);

// pipeline
IDataCursor pipelineCursor_1 = pipeline.getCursor();
IDataUtil.put( pipelineCursor_1, "randomNumber", randomNumber );
pipelineCursor_1.destroy();

MD5 encrypte password java service

MD5 encrypte password java service

// pipeline
IDataCursor pipelineCursor = pipeline.getCursor();
    String    password = IDataUtil.getString( pipelineCursor, "password" );
        String encodedPasswrd = null ;
try{
MessageDigest md = MessageDigest.getInstance("MD5");
      md.update(password.getBytes());
              byte byteData[] = md.digest();
              //convert the byte to hex format method
              StringBuffer sb = new StringBuffer();
              for (int i = 0; i < byteData.length; i++) {
                      sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
              }
        encodedPasswrd = sb.toString();
}
catch(NoSuchAlgorithmException e){
e.printStackTrace();
}
pipelineCursor.destroy();
// pipeline
IDataCursor pipelineCursor_1 = pipeline.getCursor();
IDataUtil.put( pipelineCursor_1, "encodedPassword", encodedPasswrd );
pipelineCursor_1.destroy();


Add Users into Role and add LADP user into MWS

Add Users into Role in MWS webMethods

and add LADP user into MWS


// get inputs from pipeline
IDataCursor pipelineCursor = pipeline.getCursor();
String roleName = IDataUtil.getString(pipelineCursor,"sRoleName");
String userName = IDataUtil.getString(pipelineCursor,"sUserID");

// Create default directory session with no permissions restrictions
IDirectorySession ds = DirectorySystemFactory.getDirectorySystem().createSession();

// Find specified username in LDAP directory
IDirectoryUser ldapUser = (IDirectoryUser) ds.lookupPrincipalByName(userName, IDirectoryPrincipal.TYPE_USER);
if(null == ldapUser) {
    //set status
    IDataUtil.put(pipelineCursor,"bSuccess","false");
    IDataUtil.put(pipelineCursor,"sMessage","Unable to find the user");
} else {
    // Find specified rolename
    IDirectoryPrincipal role = ds.lookupPrincipalByName(roleName, IDirectoryPrincipal.TYPE_ROLE);

    // Assign user to role
    ds.addPrincipalToRole(ldapUser.getID(), role.getID());
   
    //set status
    IDataUtil.put(pipelineCursor,"bSuccess","true");
    IDataUtil.put(pipelineCursor,"sMsg","");
}

// Destroys previously created IDirectorySession
DirectorySystemFactory.getDirectorySystem().destroySession(ds);

// destroy cursor
pipelineCursor.destroy();

Thursday, April 18, 2013

MTOM attachment in Webmethods.

Mtom attachment will work for only soap 1.2 version 
so that while creating wsdl choose the soap 1.2 version.
and in the WSDL enable the mtom attachment property true .
Please fallow the below steps for the attachments in Integration server:

1. Create a flow service 
2.pub.file.getFile 
   in the get file service pipeline  add the file location and loadAs bytes.
3.   convert the loded file into base 64 encoding format.
      pub.string.base64 encode 
     in the  base 64 encode pipeline set useNewLine field false.
4. create a xop object for encoded string.
    pub.soap.utils.createXop Object     
    in the createXop service pipeline provice the contentType 
  EX: MIME type of the file. 
         application/pdf

For same service create the WSDL .
 


Wednesday, April 3, 2013

REST Services in Webmethod

From the designer directly we can create the rest services.
In the designer we can right click on the flow service and create the REST service .

in the REST service you have to write the fallowing code.

1. convert the xml node to document
2. Remove the any prefixs from the xml file .
3.call your service and map the input doc .
4. Convert the Document to XML String  (Doc is your service input)
5. replace the prefixs
6. call the pub.flow.setResponce service to set the response to your service .