JSP to connect to a web service
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I then wanted to learn to use JSP so I can learn how to really connect to the web service. I bought a book on JSP however it only teaches how to connect to the database directly and it teaches how to use java beans. What it did not teach is how to connect to a web service. A EJB.
Now, when I created the EJB web service, the tutorial which taught me this did teach how to connect to the EJB but this only worked as long as the service was on the same server. What I am trying to do is connect to the EJB service from a diff server. Lets say my JSP is on localhost for now and my web service is on exthost. And lets say my wsdl is located at http"//exthost:8080:/WorkBeanService/WorkBean?wsdl which basically tells you the service is at http"//exthost:8080:/WorkBeanService/WorkBean and it contains a function called count().
So how do I connect to this ejb service and call the function in a JSP or Servlet?
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
If you want to learn JSP, I'd find a more suitable use for JSPs; connecting to a web service isn't one of them.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Now, I have accomplished this using flash builder. But Flash builder did most of the work for me. I am now trying to learn how to do it for myself. If JSP is not the answer, then maybe servlets. If not servlets then what? I am trying to stay away from frameworkds because they can be buggy and my front end is dependant on how well they developed their front end. Now, reread my first question.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Remember that in modern JSPs, there should be no Java code -- that's a practice that's been discredited for almost 10 years now. All "heavy lifting" (such as consuming web services" should be done in servlet controllers or their delegates.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
They should be helpful in understanding JSP and where it fits into the web app ecosystem.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
And yeah, there are Java tools which do the work of generating that code for you, just like there were in Flash. But again those tools don't care where you plan to run that code, so you won't find out about them if you're looking for things related to web applications.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
If you read my first question, you will know I already have a web service working fine. It originally started when I was working a tutorial and we first created the web service and had it attached to a database. Which I tweaked to work with my database and my data. In the tutorial, at first, we used SOAPUI to test the web service to see if the data we wanted was working. Then we created a servlet to display the data on the front end. However, in the tutorial, the servlet resided on the same server as the service. When I finished the tutorial, I had a working web service with a pretty basic front end. I then asked the tutorial owner what front end designer did he recommend and at first he recommended Flash Builder. So I purchased flash builder and like I stated earlier, flash builder asked me where the wsdl file was and it created the interface to work with my service. I then created some really good apps using my service backend. great. But then I started running into bugs flash builder had and so I again asked the tutorial guy what front end did he recommend if I were not to use a framework. Even JSF is a framework. He suggested JSP. So I purchased a book on JSP but the book did not address EJB Only JB. hence why I am asking how to consume WDSL files to create non framework font ends with. Be it JSP, Servlet, or whatever. I am posing the question with the service being on a separate server so I can somewhat accomplish what flash builder did. So if someone would point me in the right direction rather than just telling me I am going in the wrong, it would be great.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
When I had to have my web application connect to a web service and send it requests, here's what I did:
(1) Produce Java code which did that
(2) Insert said Java code into one of the servlets
I'm just totally baffled by all this talk of "non framework front ends"... as far as I'm concerned you're fishing in the wrong pond. Why do you think you need a "front end designer"?
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I also have a Flash Builder front end that does consume the service and it does this from any server I wish. I does not require to be on the same server.
And so I decided I wanted to design a better front end without a framework like Flash Builder but do the things Flash builder did. In essense create a servlet or JSP page that works from any server and not just the same one my service is on.
Now, based upon Bears comment, I think he is suggesting I keep using a servlet to access my service. Which is fine. Its just I need to learn how. Funny thing, after I read the second article that Bear sent me, it gave an example of how to connect to a service using JSP. Which I found to be ironical. (Sortof quoting how Robin Williams did it in Good Will Hunting)
Since I am only speaking from my perspective, I have no idea how you are coming up with me saying the things you, Paul think I am saying. I have said it over and over again how I got here and that I do have a servlet working but only on the same server. Would like something similar which runs on a diff server. Kinda how flash builder did it.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
So would it be fair to say that you do indeed have Java code that acts as a client to a web service? I asked you this already, but you haven't answered. It isn't fair to accuse me of failing to understand you if you don't answer questions that I ask, don't you agree?
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I did a search on JSP and WSDL and the result of the search put me on this site in this forum. And so I posted my question here because of the that search. So I think you maybe saying you think my question belongs somewhere else rather than in the web services section of this site. Which might be true. But I posted a similar question before in the JSP section and nobody responded.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Michelle Streeter wrote:As stated before, yes I do have a front end servlet that does display the service backend data. But it is very basic. And it resides on the same server and refers to the service directly without a url.
I also have a Flash Builder front end that does consume the service and it does this from any server I wish. I does not require to be on the same server.
Paul Clapham wrote:So would it be fair to say that you do indeed have Java code that acts as a client to a web service? I asked you this already, but you haven't answered. It isn't fair to accuse me of failing to understand you if you don't answer questions that I ask, don't you agree?
Exactly how is this not answering your question.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Therefore, consuming web services in a JSP is not a possibility. Now, displaying the results of fetching data elsewhere (controller, bean, model, etc) is a perfect use of a JSP. But as Paul pointed out, the Java code to consume the web service should be independent of where you want to use it.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
When I created the flashbuilder version it used the wsdl to recreate the dto objects and interface with the service
I now have a new session in Eclipse which does not have the service code in it. I do however have the jar files and I am trying to get some kind of front end to work with the service like Flashbuilder did so if I ever want to create a front end for a service I did not create I can.
Hopefully this is more what you were asking for. Oh and btw, the side says it is a friendly place for greenhorns and so if I am not able to frame the question as you wish just remember this is suppose to be a friendly place for those of us who do not know how to frame the question better.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Yes, I think I got the message. Do you suggest then that I use servlets? Just servets unlike the one in my tutorial that will connect to a different server using a url rather than directly from within itself.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
http://programming.manessinger.com/tutorials/an-eclipse-glassfish-java-ee-6-tutorial/
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Michelle Streeter wrote:
Michelle Streeter wrote:As stated before, yes I do have a front end servlet that does display the service backend data. But it is very basic. And it resides on the same server and refers to the service directly without a url.
I also have a Flash Builder front end that does consume the service and it does this from any server I wish. I does not require to be on the same server.
Paul Clapham wrote:So would it be fair to say that you do indeed have Java code that acts as a client to a web service? I asked you this already, but you haven't answered. It isn't fair to accuse me of failing to understand you if you don't answer questions that I ask, don't you agree?
Exactly how is this not answering your question.
Well, the problem is that it doesn't use the word "Yes" or the word "No". Either of those would be a satisfactory answer. As it is, it sounds like the answer is "Yes", but you already complained about me misquoting you, so I'm not sure where to go from here.
Anyway it seems like I'm in over my head here, since I haven't ever had to use large-scale frameworks to consume a web service. As I said, I just used Axis to generate the client and then put the generated code in the place I needed to run it. But you don't seem to be going down that road. So let me just say that to get from something which connects only to your own server, to something which connects to some other server, shouldn't require a major tooling change. At least I wouldn't think so. Seems to me you should be able to redo whatever you did before, only changing some of the parameters. Of course I could be wrong, you might have chosen an unsuitable tool which can't be changed in that way, but I have no way of telling that.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Paul Clapham wrote:
Michelle Streeter wrote:
Michelle Streeter wrote:As stated before, yes I do have a front end servlet that does display the service backend data. But it is very basic. And it resides on the same server and refers to the service directly without a url.
I also have a Flash Builder front end that does consume the service and it does this from any server I wish. I does not require to be on the same server.
Paul Clapham wrote:So would it be fair to say that you do indeed have Java code that acts as a client to a web service? I asked you this already, but you haven't answered. It isn't fair to accuse me of failing to understand you if you don't answer questions that I ask, don't you agree?
Exactly how is this not answering your question.
Well, the problem is that it doesn't use the word "Yes" or the word "No". Either of those would be a satisfactory answer. As it is, it sounds like the answer is "Yes", but you already complained about me misquoting you, so I'm not sure where to go from here.
Anyway it seems like I'm in over my head here, since I haven't ever had to use large-scale frameworks to consume a web service. As I said, I just used Axis to generate the client and then put the generated code in the place I needed to run it. But you don't seem to be going down that road. So let me just say that to get from something which connects only to your own server, to something which connects to some other server, shouldn't require a major tooling change. At least I wouldn't think so. Seems to me you should be able to redo whatever you did before, only changing some of the parameters. Of course I could be wrong, you might have chosen an unsuitable tool which can't be changed in that way, but I have no way of telling that.
Read the fourth word in. I believe it is the word YES. And it has been there all along. But just for you.
YES YES YES YES YES I have a client. A working Client
YES, I have a working front end that implements that client and even on a diff server. But that one was created for me. Now I would like to create my own. I do believe this is over your head though. Good luck.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
1. Create a web service to connect to a Java application, e.g. application that connects to RDBMS
2. Create a plain Java class that connects to the web service. Make sure to include a main method for testing. This is your web service object.
3. Create another plain Java class that contains any business logic and any data access logic such as using the data-oriented web service.
4. Use an object from the class created in step #3 above from within a Java servlet and create a data object that can be displayed in Java Server Page
5. Create Java Server Page using data object created in step #4 above.
JSP1 ----> Servlet1 -----> Business Object1 ------> Web Service Object -------> RDBMS
.NET1 ------> Web Service Object -------> RDBMS
C++ ------> Web Service Object -------> RDBMS
Swing GUI -----> Business Object2 ------> Web Service Object -------> RDBMS
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I have a web service I create. Its an EJB service. It is a customer management service. Now you are writing an app that does lets say inventory. Rather than rewrite a customer aspect of your app, you deside to implement my customer management service so the only part you have to write is your inventory part. Saves you a ton of time and money. My customer management service resides on my server. I am not giving out my source code. You have access to my WSDL files and I if needed, I may even provide compiled jar files. Now how do you add my customer management service to your inventory program? Your program will reside on your server, not mine. How do you do it?
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Write a Java class with methods that can consume your web service. Test them from a command-line program. And then you'll be ready to call them from a servlet or something else.
You should either be focusing on the java.net classes, or looking into a 3rd-party library such as HttpClient.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
A google search on "consuming SOAP web services with java" seemed to bring up some likely resources.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
It's a common misconception that information passed in the body of the request is more secure than information on the URL. Both are as vulnerable to attacks as the other.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
There are plenty of resources on the Web that discuss RESTful services vs. SOAP and other approaches. If this is a topic that interests you, I recommend following up with them. I'd start with this article.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
http://java.dzone.com/articles/jax-ws-hello-world
I am at the part where I ran wsimport and it generated six java classes. However, in one of the classes it generated, it already has errors.
Description Resource Path Location Type
The constructor Service(URL, QName, WebServiceFeature[]) is undefined GreetingImpService.java /WS-Client/src/com/lmco/greeting/service line 46 Java Problem
Did I do something wrong?
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I wonder if there are better tools than wsimport? Apparently Flashbuilder is using or designed a better one.
btw Bear,
I went back to the original tutorial and tried to implement the RESTful part of the tutorial but the tutorial did not follow through and so I will have to figure it out some other way. But here is how it started:
http://programming.manessinger.com/tutorials/an-eclipse-glassfish-java-ee-6-tutorial/
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
http://javaeenotes.blogspot.com/2011/02/rest-using-jax-rs.html
after this tutorial, I figured out how the url's worked for REST and so now I got the previous J2EE Restful tutorial to work as well.
Now, I need to figure out how to consume the xml which is returned from the RESTful urls.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
is there are tools like wsimport that read the wsdl file and generate the service for you so you can test while creating whatever front end you want.
There are different types of usages for "web services." Some may facilitate access to data. Some may facilitate access to some sort of business logic. In both cases, they are integration components, not implementation. They facilitate communication between applications. An application or component implements the functionality that the web service connects to, i.e. the web service is there for access, i.e. integration.
In terms of your statement above, a WSDL-based file describes a web service at a very high-level and is limited. There are no tools that will read a WSDL file and generate the code for a web service. At best, you will get a skeleton based on what is provided in the WSDL file. A programmer will always have to develop the code further.
| This is my favorite tiny ad: Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |













