Skip to Content

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.

To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

  1. Jun Wu

    better enrich it regarding how to use it in sap environment

    just dump some java code, what’s the point?

    (0) 
    1. Biplab Ray Post author

      If u want to post custom SOAP message to WMB or IEB end point, I don’t think there is any standard solution for that. Before implementation we have already discussed with SAP fellow regarding that, then we have implemented our custom solution.

      And one more point, am providing this blogs only to help other fellow who are working on the similar kind of work.

      If u have some better solution provide in the forum.

      And the blog is not just a dump of java code. If u have idea u could develop with help of the code.

      In the forum all the professional should communicate with other with respect.

      (0) 

Leave a Reply