JMS sender client program needs to use WSDL file to specify the endpoint. I already have a wsdl file

myjobiscoding
myjobiscoding used Ask the Experts™
on
Very very urgent.

How do i write a java JMS client program to send message using WSDL file to specify the end point. I got the JMS Send working.. I need to know how to specify the end point using wsdl file.
I have been given a wsdl file from the client.

below is my codes:

             properties.put(Context.INITIAL_CONTEXT_FACTORY, sopConfig.getINITIAL_CONTEXT_FACTORY());
             properties.put(Context.PROVIDER_URL, sopConfig.getPROVIDER_URL());
             properties.put(Context.SECURITY_PRINCIPAL, sopConfig.getSECURITY_PRINCIPAL());
             properties.put(Context.SECURITY_CREDENTIALS, sopConfig.getSECURITY_CREDENTIALS());
.
.
.
             try {
                  message.setText(messageText);
             }
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
mccarlIT Business Systems Analyst / Software Developer
Top Expert 2015

Commented:
Can you post the WSDL file? This is somewhat of a standard for specifying JMS endpoints in WSDL but it would be less guessing if I could see the WSDL and confirm how they are specifying the JMS endpoint!

Author

Commented:
Many thanks for your reply.
I am a java beginner. I am very confuse about Web Service and JMS.

I have been given a WSDL file and the DBA has told me it has anything I need to know.

I got a soap message file, my program reads that soap file and convert to string then use JMS send over. my manager asked me how to i specify the end point as I am not sending as a web service. (confused..)

Below is my wsdl file i coped the most important part
===

<?xml version='1.0' encoding='UTF-8'?>
<s1:definitions name="emiOrderService" targetNamespace="http://xmlns.oracle.com/emiordermanagement" xmlns="" xmlns:s0="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:s1="http://schemas.xmlsoap.org/wsdl/">
  <s1:types>
      <xsd:schema xmlns:prov="http://xmlns.oracle.com/emiordermanagement" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsi="http://ws-i.org/profiles/basic/1.1/xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <xsd:import namespace="http://xmlns.oracle.com/emiordermanagement" schemaLocation="http://em.online.com:8202/orderapi?WSDL/EmiOrderWS.xsd"/>
    </xsd:schema>
  </s1:types>
 
  <s1:portType name="emiordermanagementWSPort">
    <s1:operation name="CreateOrder">
      <s1:input message="s2:CreateOrderRequest"/>
      <s1:output message="s2:CreateOrderResponse"/>
    </s1:operation>
  </s1:portType>
 
  <s1:binding name="emiordermanagementWebServicePortBindingHttp" type="s2:emiordermanagementWSPort">
    <s3:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <s1:operation name="CreateOrder">
      <s3:operation soapAction="http://xmlns.oracle.com/communications/emiordermanagement/CreateOrder"/>
      <s1:input>
        <s3:body use="literal"/>
      </s1:input>
    </s1:operation>
  </s1:binding>
 
  <s1:service name="emiOrderService">
    <s1:port binding="s2:emiordermanagementWebServicePortBindingHttp" name="emiordermanagementWebServicePort">
      <s3:address location="http://em.online.com:8202/osm/wsapi"/>
    </s1:port>
    <s1:port binding="s2:emiordermanagementWebServicePortBindingJms" name="emiordermanagementWebServiceJMSPort">
      <s3:address location="jms://151.432.26.9:8202/osm/wsemiapi?URI=oracle/communications/emiordermanagement/WebServiceQueue"/>
    </s1:port>
  </s1:service>
</s1:definitions>

=============
JMS port below


    <s1:port binding="s2:emiordermanagementWebServicePortBindingJms" name="emiordermanagementWebServiceJMSPort">
      <s3:address location="jms://151.432.26.9:8202/osm/wsemiapi?URI=oracle/communications/emiordermanagement/WebServiceQueue"/>
    </s1:port>

=====================
below is my java program:



package emi.jms.queue;
@WebService(serviceName = "emiOrderService",
            portName = "emiordermanagementWebServiceJMSPort",
            endpointInterface = "http://em.online.com:8202/wsemiapi",
            targetNamespace = "http://xmlns.oracle.com/emiordermanagement",
            wsdlLocation = "http://em.online.com:8202/orderapi?WSDL")
public class JMSSender {         
         public void sendMessage() throws JMSException, NamingException, JMSException {
             Hashtable<String, String> properties = new Hashtable();
             properties.put(Context.INITIAL_CONTEXT_FACTORY, jmsConfig.getINITIAL_CONTEXT_FACTORY());
             properties.put(Context.PROVIDER_URL, jmsConfig.getPROVIDER_URL());
             properties.put(Context.SECURITY_PRINCIPAL, jmsConfig.getSECURITY_PRINCIPAL());
             properties.put(Context.SECURITY_CREDENTIALS, jmsConfig.getSECURITY_CREDENTIALS());  
                 ctx = new InitialContext(properties);
                 queueConnectionFactory = (QueueConnectionFactory)ctx.lookup(jmsConfig.getQCF_NAME());
                 qc = queueConnectionFactory.createQueueConnection();
                 qsess = qc.createQueueSession(false, 0);
                 q = (Queue) ctx.lookup(jmsConfig.getSOP_QUEUE_NAME());
                 qsndr = qsess.createSender(q);
                 message = qsess.createTextMessage();
                 message.setText(messageText);
                 qsndr.send((Message) message);
         }
}

===================================
My question of the above jms sender program is,
can i invoke webservice call so that it can pick up the endpoint

@WebService(serviceName = "emiOrderService",
            portName = "emiordermanagementWebServiceJMSPort",
            endpointInterface = "http://em.online.com:8202/wsemiapi",
            targetNamespace = "http://xmlns.oracle.com/emiordermanagement",
            wsdlLocation = "http://em.online.com:8202/orderapi?WSDL")


please help. i am confused my self
mccarlIT Business Systems Analyst / Software Developer
Top Expert 2015

Commented:
(It is a bit hard to follow exactly what you are doing since you have initiated so many different questions on this topic, but I will do my best)


First, let's get some things straight...

1. You are writing a "client" program to connect to a web service (not developed by yourself) and consume it's services? Yes?
2. You have been given the WSDL that corresponds to that web service? (You haven't made this WSDL yourself?)
3. Are you constrained to use JMS as the transport or was that a choice that you made? (The WSDL specifies a HTTP transport aswell that could be used for this, and is the more traditional way of consuming web services)


Also, the code that you have posted looks as though it is probably not what you are after. It appears as though that is trying to "implement" the web service (ie. trying to be the server side of the web service) and by receiving requests from clients, and posting those requests on to a JMS queue for processing. If my assumptions above are correct, this is not what you are after.
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

Author

Commented:
1. You are writing a "client" program to connect to a web service (not developed by yourself) and consume it's services? Yes?
Yes. I need to make a Web Service call over JMS. Call Web Service method "CreatedOrder".

2. You have been given the WSDL that corresponds to that web service? (You haven't made this WSDL yourself?)
Yes. I have been given the WSDL file.

3. Are you constrained to use JMS as the transport or was that a choice that you made? (The WSDL specifies a HTTP transport aswell that could be used for this,
and is the more traditional way of consuming web services)
I have been asked to make a Web service call over JMS. (This is what I dont know how to do)


Also, the code that you have posted looks as though it is probably not what you are after. It appears as though that is trying to "implement" the web service
(ie. trying to be the server side of the web service) and by receiving requests from clients,
and posting those requests on to a JMS queue for processing. If my assumptions above are correct, this is not what you are after.

That is exactly, you see my codes already know what my problem is. This is because I dont know what to do. As I mentioned to Answer 1. I only need to make a web service call "CreateOrder" over JMS.

My team leader keep saying this is very easy "just a few hours job"  then away for 1 month holiday, I got no one to ask. If you can resolve my issue. I will pay you AU$30 as an appreicated
your help. this is not much money. but my job is just a junior developer.. keep learning..

below is my sample WSDL file
============================

<?xml version='1.0' encoding='UTF-8'?>
<s1:definitions name="emiOrderService" targetNamespace="http://xmlns.oracle.com/emiordermanagement" xmlns="" xmlns:s0="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:s1="http://schemas.xmlsoap.org/wsdl/">
  <s1:types>
      <xsd:schema xmlns:prov="http://xmlns.oracle.com/emiordermanagement" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsi="http://ws-i.org/profiles/basic/1.1/xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <xsd:import namespace="http://xmlns.oracle.com/emiordermanagement" schemaLocation="http://em.online.com:8202/orderapi?WSDL/EmiOrderWS.xsd"/>
    </xsd:schema>
  </s1:types>
 
  <s1:portType name="emiordermanagementWSPort">
    <s1:operation name="CreateOrder">
      <s1:input message="s2:CreateOrderRequest"/>
      <s1:output message="s2:CreateOrderResponse"/>
    </s1:operation>
  </s1:portType>
 
  <s1:binding name="emiordermanagementWebServicePortBindingHttp" type="s2:emiordermanagementWSPort">
    <s3:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <s1:operation name="CreateOrder">
      <s3:operation soapAction="http://xmlns.oracle.com/communications/emiordermanagement/CreateOrder"/>
      <s1:input>
        <s3:body use="literal"/>
      </s1:input>
    </s1:operation>
  </s1:binding>
 
  <s1:service name="emiOrderService">
    <s1:port binding="s2:emiordermanagementWebServicePortBindingHttp" name="emiordermanagementWebServicePort">
      <s3:address location="http://em.online.com:8202/osm/wsapi"/>
    </s1:port>
    <s1:port binding="s2:emiordermanagementWebServicePortBindingJms" name="emiordermanagementWebServiceJMSPort">
      <s3:address location="jms://151.432.26.9:8202/osm/wsemiapi?URI=oracle/communications/emiordermanagement/WebServiceQueue"/>
    </s1:port>
  </s1:service>
</s1:definitions>

==========================================================


package emi.jms.queue;
@WebService(serviceName = "emiOrderService",
            portName = "emiordermanagementWebServiceJMSPort",
            endpointInterface = "http://em.online.com:8202/wsemiapi",
            targetNamespace = "http://xmlns.oracle.com/emiordermanagement",
            wsdlLocation = "http://em.online.com:8202/orderapi?WSDL")
public class JMSSender {        
  public void sendmessage() throws jmsexception, namingexception, jmsexception {
      hashtable<string, string> properties = new hashtable();
      properties.put(context.initial_context_factory, jmsconfig.getinitial_context_factory());
      properties.put(context.provider_url, jmsconfig.getprovider_url());
      properties.put(context.security_principal, jmsconfig.getsecurity_principal());
      properties.put(context.security_credentials, jmsconfig.getsecurity_credentials());  
      ctx = new initialcontext(properties);
      queueconnectionfactory = (queueconnectionfactory)ctx.lookup(jmsconfig.getqcf_name());
      qc = queueconnectionfactory.createqueueconnection();
      qsess = qc.createqueuesession(false, 0);
      q = (queue) ctx.lookup(jmsconfig.getsop_queue_name());
      qsndr = qsess.createsender(q);
      message = qsess.createtextmessage();
      message.settext(messagetext);
      qsndr.send((message) message);
  }
}
mccarlIT Business Systems Analyst / Software Developer
Top Expert 2015

Commented:
Are you able to use any libraries? If you can it will help A LOT to get what you want done. If I were doing this myself, I would be using Spring. It is made up of a number of modules; you would want Spring JMS, Spring WS (aswell as the core Spring stuff). Do you use maven to manage dependencies and help with the build? (Also very recommended for making your life easier)

Also, there is some extra stuff that you will NEED to know that doesn't appear to be in the WSDL. If you look at the s3:address line (the 2nd one), it gives you the JMS server IP and port, check. It gives you the Queue name, check. But it doesn't say what type of JMS server it is! Or if that is supposed to be some JNDI URI, it still needs more info. So you need to get that before you can really do much more at all.

Also, you can see a line near the top of the WSDL (the <xsd:import .../> line) that refers to an external .xsd file. You will NEED this .xsd file so that you know how to format the request that is sent to the web service and how to understand the response that is returned.

Author

Commented:
I am not using Spring and I dont know Spring. That is a problem
I just write java code.
I use JDeveloper to generate the Java Stud based on the given WSDL file.

I have all the information about JMS Server. That's why I wrote the JMS Sender to test the given JMS configuration. It works for testing a message.

I am sorry to raise this question again before. Just to worry about this task as this is my first project.
mccarlIT Business Systems Analyst / Software Developer
Top Expert 2015

Commented:
> I am not using Spring and I dont know Spring.

Ok, you will just have to do it another way.


> I use JDeveloper to generate the Java Stud based on the given WSDL file.

I haven't used JDeveloper but that shouldn't be too much of an issue. I don't know exactly how far it would go in creating classes to represent the schema types or not. However, either you have that additional .xsd file (or JDeveloper has found it itself) and generated classes to represent the request (CreateOrderRequest) and the response (CreateOrderResponse) OR it does go that far and it has just created stubs to call the service leaving the marshalling/unmarshalling up to you. However these stubs are probably only useful for calling the web service via the HTTP transport not the JMS transport.

**** If you can post all the classes that JDeveloper has created, that will help a lot in determining where you are at.


> test the given JMS configuration. It works for testing a message

How exactly have you confirmed that it works? Have you gone to the JMS server and confirmed that there is a message there in a queue, or that the web service has consumed the message and attempted to process it?
If so then, ok, I was assuming that the code you wrote was just a cut/paste of something of the net, since it looks like something I have seen before. So you are saying that the "jmsconfig" object has all the details of the JMS that you need?

Then really it should just be a matter of sending the correct bit of text in the JMS message rather than some test string. The first part of this should be as I answered in a previous question, where you built a SOAP message object and then I showed you how to write that to the ByteArrayOutputStream and then set that as your message text. The last part of that is that you need to setContent() of the soap body to have the correct content. This is reliant on this *extra* xsd that the wsdl is referring to. As I said above, maybe JDeveloper has created classes that will help you, or maybe it doesn't and you will need the .xsd to manually create the SOAP body's content.

Author

Commented:
Many thanks for your info.
I think I will try using Spring as I am sure my team leader means using Spring as he keeps telling me this is quite simple. Yes. he did mentioned about Spring before but i didn't even pay attention on his advice as I dont know Spring. But have to try this week end.

Ok, I failed to plugin Spring IDE in my eclipse because of some dependance.
Any IDE You can suggest to use for Spring development.

and also I look at the following, it seems to be exactly what I am after.

http://static.springsource.org/spring-ws/site/reference/html/client.

Do you have any web sites I can follow step by step.?

thanks again.

Author

Commented:
Sorry I keep asking you for help.

I am now creating a Spring Web service client based on the following link
http://static.springsource.org/spring-ws/site/reference/html/client.

Do you know which Spring jar files using the following

import org.springframework.ws.WebServiceMessageFactory;
import org.springframework.ws.client.core.WebServiceTemplate;
import org.springframework.ws.transport.WebServiceMessageSender

===========================
The following configuration file. what name should be?
How does Spring find this file?

=====================================================
<beans>

    <bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory"/>

    <bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
        <property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
    </bean>

    <bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
        <constructor-arg ref="messageFactory"/>
        <property name="messageSender">
            <bean class="org.springframework.ws.transport.jms.JmsMessageSender">
                <property name="connectionFactory" ref="connectionFactory"/>
            </bean>
        </property>
        <property name="defaultUri" value="jms:RequestQueue?deliveryMode=NON_PERSISTENT"/>
    </bean>

</beans>
======================================================
IT Business Systems Analyst / Software Developer
Top Expert 2015
Commented:
> Do you know which Spring jar files using the following

You just download Spring WS (link), it will be a zip file with the JAR that you need in it.

> The following configuration file. what name should be?

You can name it whatever you like. A common convention is to call it "appContext.xml"


> How does Spring find this file?

Generally, you tell it how/where to find it. Is your program just a standard J2SE program, ie. does it just have a "main" method? If so, you would do something like...
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("appContext.xml");
context.refresh();

WebServiceTemplate webServiceTemplate = context.getBean("webServiceTemplate", WebServiceTemplate.class);

webServiceTemplate.sendSourceAndReceiveToResult(....);

Open in new window

(Note: I have just typed that in so there maybe a few typos not corrected, but it gives the idea)

Then the main work will be dealing with webServiceTemplate, ie. creating a Source object, and processing the Result object. And these will correspond to the CreateOrderRequest and CreateOrderResponse that the WSDL refers to.

Author

Commented:
Many thanks mccarl.

I think I should close this one as you have already given me a lot of information. I will spend this weekend working 10 hours a day to try and get this one done in Spring. Of course, not even including reading. I have already spent hours reading Spring yesterday.

I think I will raise other questions if I have encountered any programming issues in Spring. I hope I get your help if you are able to..

Again... Many thanks

Not many experts in here willing to spend time to help people.. i do realise that.
mccarlIT Business Systems Analyst / Software Developer
Top Expert 2015

Commented:
Not a problem.

Yeah, there is probably a bit to get your head around in Spring, but once you do, I am sure that you will like working with it.

Can I give a few hints for posting new questions in the future (hopefully it will get more people looking at them also)

- If you have code to post, post the full class, cut and paste, from code that you are actually compiling and testing with, unedited, unless there is company IP in there that you need to protect. I have noticed that coed that you have posted is generally incomplete, eg. missing import statements, variable declarations, etc. And either style code,xml, etc as code, embed it as a code snippet, or attach it as a file. Check the toolbar of the textbox for styling/embeding, or the link just under the textbox for attaching.

- If you are asking about an error/exception that you are getting, include the full stack trace of the exception and the full class source where the exception occurs, if you really need to edit that source, just blank out the line rather than delete it so that line numbering stays consistent (helps with lining up the info in the stack trace)


> Not many experts in here willing to spend time to help people.. i do realise that.

Also note, that although your boss just gave you this and said it should be easy, it is not something that is all that common or easy (SOAP over JMS that is). So it is probably not necessarily a case of experts not willing to spend the time (there are a great number of very helpful experts here) but possibly more a case of not many experts have experience in this area. Just my 2 cents worth, anyway! ;)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial