Community in read only mode June 18 & 19
This community will be set in READ ONLY mode for a while on Tuesday June 18 into Wednesday June 19 while we import content and users from our Micro Focus Forums community site. MORE INFORMATION
ejsvera Absent Member.
Absent Member.
4656 views

Java consuming a Cobol Web Service

Jump to solution

I have testing Cobol web services using Visual Cobol 2.2.

My two webservices are: a simple calc with two methods, add and subtract; and my second WS with four operations read, write, rewrite and delete on a indexed file. Both WS work in a simplest way and testing from a Cobol client created by Eclipse.

Now i wish to access webservices with a Java program: Java client consuming data from a Cobol web service, but i can't and need a documentation reference.

With Java and .NET i use a SOAP webservice and i have a WSDL file; then use the reference "?wsdl" in the url for create the connection (using the wizard on Eclipse and VStudio). This method does not work with the Cobol web services.

Any help?, Thanks.

Enrique.

0 Likes
1 Solution

Accepted Solutions
Highlighted
andres_heredia Absent Member.
Absent Member.

RE: Java consuming a Cobol Web Service

Jump to solution

Hola Enrique,

creo que la solución ya la proporcionó de manera clara Yvon, con el cuarto enlace que compartió, lo que necesitas es una solución java, no COBOL, es decir, la manera de generar un cliente de servicio web a partir de un archivo wsdl y no desde una url. (Generate a JAX-WS Web Service Client from a WSDL document using Apache CXF).

Por respeto a los demás miembros del foro voy a continuar en inglés.

Enrique, I think that you should use the resources that Yvon suggest before, because how to consume and generate a java web service client is all in that web links.

But I going to demonstrate to you in a few images that the Eclipse has the appropriate wizard to do the job.

First Create a Java project, then create a new web service cliente (File->new->others->web service client)

Then use the wizard to do all the job. Select or write the WSDL location (this could be an url or a file location on the computer), in this case is a wsdl file located in the project servicedemo 

Finish the wizard and create a class to consume the web service like any other Java application.

I hope that this illustrate in a positive way one of the multiples possibilities to do this in java.

This is an extreme basic example and should not be consider the properly way to do in a corporate application.

regards,

Andrés Mauricio Heredia G.
Software Engineer
EMA HOLDINGS S.A.S
Cali - Colombia

0 Likes
14 Replies
andres_heredia Absent Member.
Absent Member.

RE: Java consuming a Cobol Web Service

Jump to solution

Hi Enrique,

Can you check the video tutorials on this forum post by Blair McDonald? community.microfocus.com/.../16050.aspx

Maybe his tutorial has an answer for your question, cause he is using Enterprise Server to expose the web services.

regards,

Andrés Mauricio.

Andrés Mauricio Heredia G.
Software Engineer
EMA HOLDINGS S.A.S
Cali - Colombia

0 Likes
ejsvera Absent Member.
Absent Member.

RE: Java consuming a Cobol Web Service

Jump to solution

Hi Andres,

I see this videos but this tutorial how to show create a web service from Cobol and test it with a Cobol program consuming this web service. So, is a Cobol program consuming a Cobol web service; but i need a Java program consuming a Cobol web service.

Thank you anyway,

Enrique.

0 Likes
andres_heredia Absent Member.
Absent Member.

RE: Java consuming a Cobol Web Service

Jump to solution

Hi Enrique,

that's why I suggested those videos I personally recreated the project and test the web service with SOAPUI and it works.

I don't have much experience with Enterprise Server, but this tutorial was really easy to reproduce, check this image with the wsdl file that was generated by the automatic process:

So I could test it with SOAPUI, which is a tool to test integrations betweens systems with web services. Check this test sending two values and getting the result from the COBOL SOAP Web Service deployed on the Enterprise Server. (and yes that client is running on java, so you can easily build a client with any library available to do that using the top down strategy)

  

I hope that this help you.

regards,

Andrés Mauricio.

Andrés Mauricio Heredia G.
Software Engineer
EMA HOLDINGS S.A.S
Cali - Colombia

0 Likes
Yvon Abgrall Absent Member.
Absent Member.

RE: Java consuming a Cobol Web Service

Jump to solution

I would believe the why MF does not document the consumption of Web Service from Java is because it’s a 100% Java question.

Most programming languages , from a .WSDL, will be able to create stubs of the Web Service…

See this:

And/or JAX-WS (Java Api for XML Web Services) - en.wikipedia.org/.../Java_API_for_XML_Web_Services  

And/or docs.oracle.com/.../bnayn.html Creating a Simple Web Service and Client with JAX-WS

And/or docs.oracle.com/.../bnayn.html The Java EE 5 Tutorial

And/or help.eclipse.org/.../index.jsp Generate a JAX-WS Web Service Client from a WSDL document using Apache CXF

As an example, This Web Service www.w3schools.com/.../tempconvert.asmx www.w3schools.com/.../tempconvert.asmx

is being consumed below using either AXIS or AXIX2 or CXF. It would work the same with a COBOL Web Service…, the keyword entry point here being the .WSDL from which stubs are created using JAX-WS

>> AXIS technology

package mf.cc;

import java.rmi.RemoteException;

import org.apache.axis.AxisFault;

import com.w3schools.www.xml.*;

public class WSclient_AXIS {

public static void main(String[] args) {

try {

TempConvertSoapProxy Axis_WS_JavaStub = new TempConvertSoapProxy();

String celsius = "123.45";

String fahrenheit = "567.89";

System.out.println("-->  celsiusToFahrenheit("+ celsius +  ") --> " + Axis_WS_JavaStub.celsiusToFahrenheit(celsius));

System.out.println("-->  fahrenheitToCelsius("+ fahrenheit +  ") --> " + Axis_WS_JavaStub.fahrenheitToCelsius(fahrenheit));

} catch (AxisFault e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (RemoteException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

>> AXIS2 technology

package mf.cc;

import java.rmi.RemoteException;

import org.apache.axis2.AxisFault;

import org.apache.axis2.addressing.EndpointReference;

import org.apache.axis2.client.Options;

import org.apache.axis2.transport.http.HTTPConstants;

import com.w3schools.www.xml.*;

import com.w3schools.www.xml.TempConvertStub.CelsiusToFahrenheit;

import com.w3schools.www.xml.TempConvertStub.CelsiusToFahrenheitResponse;

import com.w3schools.www.xml.TempConvertStub.FahrenheitToCelsius;

import com.w3schools.www.xml.TempConvertStub.FahrenheitToCelsiusResponse;

public class WSclient_AXIS2 {

public static void main(String[] args) {

try {

String celsius = "123.45";

String fahrenheit = "567.89";

TempConvertStub  Axis2_WS_JavaStub = new TempConvertStub();

Options hOptions = Axis2_WS_JavaStub._getServiceClient().getOptions();

hOptions.setProperty(HTTPConstants.CHUNKED,false);

Axis2_WS_JavaStub._getServiceClient().setOptions(hOptions);

// org.apache.axis2.AxisFault: Transport error: 411 Error: Length Required

CelsiusToFahrenheit hCelsiusToFahrenheit = new CelsiusToFahrenheit();

hCelsiusToFahrenheit.setCelsius(celsius);

CelsiusToFahrenheitResponse hCelsiusToFahrenheitResponse = null;

hCelsiusToFahrenheitResponse = Axis2_WS_JavaStub.celsiusToFahrenheit(hCelsiusToFahrenheit);

System.out.println("-->  celsiusToFahrenheit("+ hCelsiusToFahrenheit.getCelsius() +  ") --> " + hCelsiusToFahrenheitResponse.getCelsiusToFahrenheitResult());

FahrenheitToCelsius hFahrenheitToCelsius = new FahrenheitToCelsius();

hFahrenheitToCelsius.setFahrenheit(fahrenheit);

FahrenheitToCelsiusResponse hFahrenheitToCelsiusResponse = null;

hFahrenheitToCelsiusResponse = Axis2_WS_JavaStub.fahrenheitToCelsius(hFahrenheitToCelsius);

System.out.println("-->  fahrenheitToCelsius("+ hFahrenheitToCelsius.getFahrenheit() +  ") --> " + hFahrenheitToCelsiusResponse.getFahrenheitToCelsiusResult());

} catch (AxisFault e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (RemoteException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

>> CXF technology

package mf.cc;

import java.net.URL;

import javax.xml.namespace.QName;

import com.w3schools.xml.TempConvert;

import com.w3schools.xml.TempConvertSoap;

public class WSclient_CXF {

private static final QName SERVICE_NAME = new QName("www.w3schools.com/.../", "TempConvert");

public static void main(String[] args) {

URL wsdlURL = TempConvert.WSDL_LOCATION; // from generated CXF class TempConvertSoap_TempConvertSoap_Client

      TempConvert ss = new TempConvert(wsdlURL, SERVICE_NAME);

        TempConvertSoap port = ss.getTempConvertSoap();  

String celsius = "123.45";

String fahrenheit = "567.89";

System.out.println("-->  celsiusToFahrenheit("+ celsius +  ") --> " + port.celsiusToFahrenheit(celsius));

System.out.println("-->  fahrenheitToCelsius("+ fahrenheit +  ") --> " + port.fahrenheitToCelsius(fahrenheit));

}

}

 Yvon

0 Likes
ejsvera Absent Member.
Absent Member.

RE: Java consuming a Cobol Web Service

Jump to solution

Hi Yvon,

Yes, I know that sound like a Java question, but not.

You say "Most programming languages , from a .WSDL, will be able to create stubs of the Web Service" and this is my question, how to find the wsdl file create with Cobol web service?, because my first movement is an application Java with Eclipse, select the wizard for create a new Web service cliente and i need a url with <host>/service?wsdl and the wizard do the job, but that isn´t working for me with a web service Cobol.

Sure i need do something more or something in other way, and maybe try many options (like your answer) until find the right one, but i prefer a reference for my specific question.

Thanks,

Enrique.

0 Likes
ejsvera Absent Member.
Absent Member.

RE: Java consuming a Cobol Web Service

Jump to solution

Hola Andres,

Tambien segui ese video y reproduje el funcionamiento (en Linux) y veo el archivo wsdl en webcalc.deploy tambien. Y lo pruebo con el cliente cobol que genera el mismo Eclipse y conecta bien.

Mi problema es que ahora quiero hacer una aplicacion Java que se conecte al mismo servicio y consuma los metodos Add y Subtract, pero al generar el cliente web service debo indicar la ruta solicitando el wsdl y no lo encuentra; asumo que debo hacer algo diferente para que el asistente de Eclipse lo encuentre y genere los codigos para accesar a ese web service, y esa es la informacion que no encuentro aun.

Asumi que alguien ya hizo esto y queria el tip de donde revisar o que ajustar para lograr esa parte y no ocupar mucho tiempo en investigar, probar hasta dar con lo que me esta faltando.

Agradezco tu interes es ayudarme, saludos desde Chile,.

Enrique.

0 Likes
Yvon Abgrall Absent Member.
Absent Member.

RE: Java consuming a Cobol Web Service

Jump to solution

Andrés's screenshot does show the .WSDL is created on the repos/[Web Service Name].deploy sub-directory.

Don't you see your .WSDL there?

Regards

Yvon

0 Likes
ejsvera Absent Member.
Absent Member.

RE: Java consuming a Cobol Web Service

Jump to solution

Yvon,

English is not my language, but i think that my question is clear.

Step 1:

a) Create a web service with Java, see the wsdl = Ok.

b) Create a web service with Cobol, see the wsdl = Ok.

Step 2:

a) Create a Java client for the Java web service and test = Ok

b) Create a Cobol client for the Cobol web service and test = Ok

Step 3:

a) Create a Java client for the Cobol web service = Fail

b) Create a Cobol client for the Java web service = No need now, but i find some documentation.

Why fail step 3a?

I use the Eclipse wizard create a client for a web service and i use the url with "?wsdl" for step 2a, but the wizard not found any wsdl file. This is my problem.

Do you have a funcional program with this specific situation for share any tip or reference?

Regards,

Enrique.

0 Likes
Yvon Abgrall Absent Member.
Absent Member.

RE: Java consuming a Cobol Web Service

Jump to solution

I possibly understand what the issue is | was..

The .WSDL is on the repos sub-directory and Eclipse does ask for an URI (https://en.wikipedia.org/wiki/File_URI_scheme

In the Eclipse Web Service client" wizard, I had to specify such an URI  file:///C:/tmp/WStest/COBOL_CALC/repos/COBOL_CALC_WS.deploy/COBOL_CALC_WS.wsdl, the Windows pathname of the .COBOL Web Service .WSDL being C:\tmp\WStest\COBOL_CALC\repos\COBOL_CALC_WS.deploy\COBOL_CALC_WS.wsdl.

Then, I was able to create the Java WS client

(

package mf.cc;
import java.rmi.RemoteException;

import org.tempuri.COBOL_CALC_WS.*;

import com.microfocus.xml.cobol.mapperfault.Errordetail;

public class WSclient_AXIS {

 public static void main(String[] args) {
  COBOL_CALC_WSProxy Axis_WS_JavaStub = new COBOL_CALC_WSProxy();
  int p1 = 2;
  int p2 = 5;
  try {
   System.out.println("-->  ADD(" + p1 + "+" + p2 +  ") --> " + Axis_WS_JavaStub.ADD(p1, p2));
   System.out.println("-->  SUBTRACT(" + p1 + "+" + p2 +  ") --> " + Axis_WS_JavaStub.SUBTRACT(p1, p2));   
  } catch (Errordetail e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (RemoteException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }
}

)

0 Likes
Micro Focus Expert
Micro Focus Expert

RE: Java consuming a Cobol Web Service

Jump to solution

Yvon has provided an example that you can download here:

0 Likes
Highlighted
andres_heredia Absent Member.
Absent Member.

RE: Java consuming a Cobol Web Service

Jump to solution

Hola Enrique,

creo que la solución ya la proporcionó de manera clara Yvon, con el cuarto enlace que compartió, lo que necesitas es una solución java, no COBOL, es decir, la manera de generar un cliente de servicio web a partir de un archivo wsdl y no desde una url. (Generate a JAX-WS Web Service Client from a WSDL document using Apache CXF).

Por respeto a los demás miembros del foro voy a continuar en inglés.

Enrique, I think that you should use the resources that Yvon suggest before, because how to consume and generate a java web service client is all in that web links.

But I going to demonstrate to you in a few images that the Eclipse has the appropriate wizard to do the job.

First Create a Java project, then create a new web service cliente (File->new->others->web service client)

Then use the wizard to do all the job. Select or write the WSDL location (this could be an url or a file location on the computer), in this case is a wsdl file located in the project servicedemo 

Finish the wizard and create a class to consume the web service like any other Java application.

I hope that this illustrate in a positive way one of the multiples possibilities to do this in java.

This is an extreme basic example and should not be consider the properly way to do in a corporate application.

regards,

Andrés Mauricio Heredia G.
Software Engineer
EMA HOLDINGS S.A.S
Cali - Colombia

0 Likes
ejsvera Absent Member.
Absent Member.

RE: Java consuming a Cobol Web Service

Jump to solution

Yvon,

This look fine. I will try.

Thanks.

Enrique.

0 Likes
ejsvera Absent Member.
Absent Member.

RE: Java consuming a Cobol Web Service

Jump to solution

Andres,

Yes, the reply from Yvon is useful.

Your example show a good example for my question..

Thanks.

Enrique.

0 Likes
Micro Focus Expert
Micro Focus Expert

RE: Java consuming a Cobol Web Service

Jump to solution

Just following up on Yvon's reply. Enterprise Server does not serve the WSDL file for the service in response to a request with the query string "?wsdl" tacked onto the URL. That's a convention of some servers, not a requirement of the SOAP specification.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.