Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
0 Kudos

Applies To: JDK 1.5 onwards

Author(s):      Biplab Ray

Company:      Tata Consultancy Services

Created on:    03rd March 2015

Author Bio:

Biplab Ray is working for Tata Consultancy Services as Assistant Consultant and development of SAP EP, composite applications using CAF, BPM, BRM, WebDynpro for Java. He also works in technologies like Java/J2EE and has depth understanding on eSOA, Webservice, Enterprise Service, XML.

Requirement:

In many businesses application we might encountered a situation when we have to hand shake between AS Java servers with Web Sphere Message Broker.

Implementation:

We have to write below method to communicate between two servers.

Imports are as below:

import java.net.URL;

import java.net.URLConnection;

import java.net.URLStreamHandler;

import javax.xml.soap.SOAPException;

import javax.xml.soap.SOAPMessage;

import javax.xml.soap.SOAPConnection;

import javax.xml.soap.SOAPConnectionFactory;

Method as below:

public static SOAPMessage SOAP_Connection_SAP(SOAPMessage message, String string_END_POINT){

            SOAPMessage reply = null;

            long begintime = -1;

            long endtime = -1;

            try {

                

                  SOAPConnection connection  = SOAPConnectionFactory.newInstance().createConnection();

                

                  URL endpoint = new URL(null, string_END_POINT,

               new URLStreamHandler() {

                  @Override

                  protected URLConnection openConnection(URL url) throws IOException {

                  URL target = new URL(url.toString());

                  URLConnection connection = target.openConnection();

                  // Connection settings

connection.setReadTimeout(1200000); // 20 mins

                  return(connection);

               }

            });

                  begintime=System.currentTimeMillis();

                  reply = connection.call(message, endpoint);

                

                  connection.close();

                

            }

            catch (IOException e) {

                  // TODO: handle exception

                  e.printStackTrace();

                

            }

            catch (UnsupportedOperationException e) {

                  // TODO Auto-generated catch block

                  e.printStackTrace();

            } catch (SOAPException e) {

                  // TODO Auto-generated catch block

                  e.printStackTrace();

            } catch (Exception e) {

                  // TODO Auto-generated catch block

                  e.printStackTrace();

            }

            finally{

                  endtime=System.currentTimeMillis();

            }

            return reply;

      }


So, from the application if we call the above method we will get a SOAP Message as response as well.

2 Comments
Labels in this area