0

I need to connect to SOAP using WSDL file. I found some solutions in the Internet. For example:

I can use 'wsimport -keep -d src path-fo.wsdl' to generate Java classes from WSDL. But it makes some problems.

1) When i use wsimport -keep -d src local-file.wsdl wsimport will generate Java classes with full paths to this file. It means it will work only in my computer and nobody else, because of different path. Also unless i delete this file. I can use wsimport with http://, but somebody told me to better keep wsdl file as local file. Maybe i have to use it with http:// and it was bad suggestion.

2) I want use the same code to connect to different instance of the same system. So each time i need to use different URL for WSDL connection, but urls are coded into Java files everywhere.

So what i need:

SOAP (WSDL) connection flexible for different URL to WSDL file to talk with other instance of the same system.

How to do it in Clojure / Java?

kabra
  • 1,306
  • 1
  • 17
  • 24
  • Get Clojure out of the equation for a more efficient search. I'm pretty sure there are tons of resources on how to do this in Java. Once you've managed that, including the appropriate classes / resources in your Clojure project should be a breeze. – Valentin Waeselynck Mar 26 '16 at 11:07
  • That is true. Thera are tons of resources how to do it in Java, but i didn't find the right one. Like my example from point 1). It is solution. It work's but i can't use it with other URL (other instance of system) then it was generated. – kabra Mar 26 '16 at 12:08
  • https://stackoverflow.com/a/53187641/1779015 – zarkone Nov 07 '18 at 10:31

2 Answers2

2

After all i decide to use wsimport

(import java.net.URL)
(import javax.xml.namespace.QName)
(import com.example.schema.Auth)
(import javax.xml.ws.Service) 
(import com.example.schema.AtomApiService)
(import com.example.schema.AtomApiServicePortType)

(let [url (URL. "https://www.foo.com")
      qname (QName. "http://schema.example.com", "AtomApiService")
      auth (doto (new Auth) (.setLogin "login") (.setPassword "password"))
      service (Service/create url qname)
      port (-> service (.getPort AtomApiServicePortType))
      orders (-> port (.getOrdersSpecified auth "0" 0 3 0 "2016-03-24 12:00:00"))]
  orders)

Why?

I found Apache CXF and others solution as old and very not nice to use. Even installation of Apache CXF is not so easy. Like solution from 2000. Just don't want use solutions like that. It is my subjective opinion! If you feel comfortable to use Apache CXF probably you should use it.

What fooled me? wsimport generate in FooPortType many lines looking like that:

@WebMethod(operationName = "GetOrdersStatuses", action = "https://www.foo.com/atom_api/call/atom_api&method=GetOrdersStatuses")
@WebResult(name = "GetOrdersStatusesReturn", partName = "GetOrdersStatusesReturn")
public String getOrdersStatuses(
    @WebParam(name = "authenticate", partName = "authenticate")
    Auth authenticate);

So i expected call of SOAP will use this url, but not! If i create the connection as i wrote on the beginning of this post the urls in this lines are ignore. I think also ignore normally, but i didn't test it on 100%. But this lines fooled me.

Maybe somebody can explain why this lines are there with hardcoded url.

kabra
  • 1,306
  • 1
  • 17
  • 24
1

This is not an area where web searches and some suggestions will get you where you need to reach. To educate yourself, possibly with help of a guru, is definitely helpful. I know that is bad news for someone who doesn't need to do this on a regular basis. An IDE like Eclipse, a framework like CXF or Axis2 will help greatly. soapUI, a free download, is indispensable.

See this as a start for resources: Introductory JAX-WS tutorial for Eclipse using a top down approach

Until you're ready to make your decisions stick to: wsdl-first development and document literal style.

Community
  • 1
  • 1
MikeC
  • 960
  • 1
  • 7
  • 15
  • ok so step by step. I found a lot of stuff about wsimport and using it. Binding other url for each url in Port.... i don't feel it is the right way. It looks messy. It looks like a solution what i don't want to use if i don't have to... Can you confirm my conclusion is good and i should abandon solution with wsimport? – kabra Mar 26 '16 at 19:02
  • A lot depends on: are you free to choose the tools and framework of your choice? Are you going to be in web services development for a while or is this a one-off job? – MikeC Mar 26 '16 at 19:13
  • I need solution which provide me possibility to integrate with system X. I want integrate with this system with many instance (one for client). I want have the same code as service using to communicate with system X. So i want create service X API and use it without any change of code with all integrations to that system for different clients. – kabra Mar 26 '16 at 19:18
  • PS I can choose what i want but prefer really simple solution with as less dependency as possible. – kabra Mar 26 '16 at 19:24
  • You'll need a good ide to help with managing project files and provide debugging support. You'll benefit from a framework so you don't have to do everything yourself. SoapUI for ad hoc testing. If you're doing this for a lot of users as you indicate, you need robust tools and development set up like this. – MikeC Mar 26 '16 at 19:29
  • I am using Intellij Idea with Clojure. Clojure doesn't support WSDL, so i am looking solution in Java. What can you recommend in that case? I can parse XML etc. in Clojure. Just need SOAP communication. ( I don't know too much about Java world) – kabra Mar 26 '16 at 19:31
  • Somebody already said this above: stick to Java. It is a lot of work even in Java if you don't use a framework like CXF or axis2. – MikeC Mar 26 '16 at 19:34
  • I will read more about CXF, Axis2 and soapUI and back. Generally in Clojure world i don't want to use any framework, it works so different there. Just need to fill this missing part about SOAP using Java. – kabra Mar 26 '16 at 19:37