Independent Rest API service and Website - java

I have designed a independent Angular 4 application in Node.js and also design a rest api service using dropwizard. I have tried to connect website as static asset for dropwizard service but I could not integrate it properly. I had gone through several links on google, everywhere repeating same thing which I have tried many a times.
One thing I thought of deploying both of these independently but a question rises how?? How can I deploy two thing on server under same domain?
Another thing which can be possible is Integrate Dropwizard with angular app, which I have tried and read many docs. but still If someone can give some sort of link related to creating these in maven is most welcome.
I need some insight regarding this.
Thanks.

How can I deploy two thing on server under same domain?
Deploy them behind a reverse proxy like nginx and use different context paths.

You could serve the result of package Angular app as a Dropwizard asset
Then you can call the rest API from Angular.
Remember that Dropwizard is just some code to glue together Jersey (for rest), Jetty (webserver) and Jackson (JSON), with the main purpose of simplifying configuration.

Related

Advise: Two way Communication between Applications using spring boot

I have two Applications Application A and Application B which needs to send two way messages. Any advise how to achieve using spring boot? I should not use any Messaging services. Please advise what can be used to solve the problem.
Below is a diagram on the scenario.
You might consider WebSockets. Quite simple to implement.
Here is a link to the Spring WebSockets documentation:
https://docs.spring.io/spring/docs/5.0.0.BUILD-SNAPSHOT/spring-framework-reference/html/websocket.html#websocket
And here is a Spring.io tutorial:
https://spring.io/guides/gs/messaging-stomp-websocket/
This will get you started using a Server with Browser as client. Simply duplicate the server (rather than use a browser) and you'll have one solution.

how to build a spring boot jar exposing both rest and soap service

I have been contemplating on building a test jar for a community of developers in order to expose a preview of a next release of an API (having stubs returning expected response with exact format etc). We do have both REST and SOAP API. I guess it won't be any problem building the REST Service as the net is flooded with example. It was quite surprising there isn't much of concrete example of how to build SOAP service (JAXWS) with spring boot with embedded jetty.
What I expect to achieve is one single jar with both APIs. I am rather comfortable developing a java first services. I have seen a post in stackoverflow but it doesn't clearly outline steps to achieve that. I know it's possible because dropwizard guys have similar project.
I will be grateful if there is any resource with example on how to handle SOAP web services in spring boot.
Thanks you in advance
Spring already supports JAXWS through *JaxWsServiceExporter and SpringBeanAutowiringSupport (in spring-web). The *Exporter approach doesn't quite mesh with the REST stuff because it isn't in the embedded container. You'd end up with an app listening on 2 ports (one for XML and one for JSON). If either of those works then you have a solution. If you don't really care that much about SOAP and just want XML representations, you can use normal content negotiation features (e.g. #ResponseBody or #RestController for everything).

Communication between rest services hosted on different tomcat servers

I have a scenario where i am hosting different java Rest Services on different Tomcat instances (different machines). These projects running on the tomcats do not have any UI. For simplicity's sake, lets assume that the user will directly enter some URL in the browser (or curl) to avail these services. Now I need this service to be able to talk to (call functions) the services available in the other tomcat instance.
For eg. If TomcatInstance1 gets the call, and all this does is act as a 'router' to the different services, i want it to be able to place the Rest call for the other 'service' available on, say, TomcatInstance2. Is this possible?. If so, how to achieve that? (Tried searching for similar questions on SO, couldnt find any). Are there any online reference for the same?
PS: Hosting the services in the same Tomcat Instance is against the requirement that I'm having.
That is completely possible. You can use (for example) Jersey-client (http://jersey.java.net/) to make the queries to the other RESTful web services in the other Tomcat instances. Only need to define the correct URIs of the end points and query them according the the API exposed and call it (like you were a client from a browser, or curl).
See here a nice example of using Jersey-client to do that: http://www.mkyong.com/webservices/jax-rs/restful-java-client-with-jersey-client/
I would suggest Spring Restful api ( http://static.springsource.org/spring/docs/3.0.0.M3/reference/html/ch18s02.html , http://www.mkyong.com/spring-mvc/spring-3-rest-hello-world-example/ ).
As #emgsilva mentioned the only thing you need to do is to point correct uris between each other.
The beauty of spring restful api is it is simple to use and you don't deal with any serialization - deserialization.

What do I need to create a RESTful API Server in Java?

I would like to build my own RESTful API Server and I have no idea what I need for that.
I'll tell you a bit about the project:
On a Webservice (www.mysite.com/) users can register and manage their account and so on. But they also can use the RESTful API (mysite.com/api/...) and can do there pretty much the same via REST.
What is a good way to realize that? Do I need to use jetty or something similar?
Should I split web service and restful api ? what I a good architecture for that?
Thanks :)
You can use Spring controller for building a restful server. You can run it on tomcat or jetty doesn't matter.
Check this url : http://static.springsource.org/spring/docs/3.0.0.M3/spring-framework-reference/html/ch18s02.html
Tomcat and Jersey are easy to get up and running. I've had some issues with Tomcat 7 and Jersey, but with Tomcat 6 it was straight forward.
This tutorial is quite easy to follow. It's a bit old, but the principle remains the same.
IBM provides good set of information and tutorials about building RESTful web service with Java (Link). After getting your web service running, you can deploy it to Amazon. Take a look at AWS Elastic Beanstalk.
In 2017 one of the best solutions would be to use spring boot. Gives you great effects without writing tons of code.
#RestController
public class HelloController {
#RequestMapping("/")
public String index() {
return "Greetings from Spring Boot!";
}
}
I found a simple example at http://coder2design.com/rest-web-services/
to build a REST application.
XML Schema(xsd) is used to build domain classes.
Eclipse EE is used as IDE and Maven for building.
Jersey as a framework for REST
Hibernate for persistence layer.
MySQL as DB
All other configurations are nicely explained.

Java-ws tomcat invoke methods through http?

I made a web project in Java, using Java-WS.
How can I invoke service methods through HTTP only.
I don't want to generate (or worse write) any java web clients, and similar stuff.
I'd just like to invoke the method with a HTTP request.
And parse the result (manually) from response.
In .NET web services I invoke methods just with:
http://serviceUrl/serviceName.asmx/operationName?parametars=...
How to do the same thing in java + tomcat?
Edit: Let me rephrase my question.
So this is what I have done so far:
Created a web application (btw. using NetBeans IDE)
Added all the necessary source files
Added web service classes with WebMethods defined
I deploy the app on tomcat and it deploys fine.
Now, what do I need to do to be able to invoke my WebMethods via HTTP?
Typing:
http://localhost:8084/MyService/MyMethod
doesn't work.
Sorry if this is a stupid question, but I'm not really a Java guru, I've been working mostly on .NET.
Multiple possibilities:
use new URL(url).openConnection().getInputStream()
use apache http components
use a REST client (if you invoke restful services), like http://code.google.com/p/rest-client/">this, or these. Or spring's RestTemplate
In this case, if you want to do an HTTP Web Service that returns an HTTP 200 Web Response, why not look at doing a RESTFul application?
JavaWorld briefly explains the role/use of REST. There's been similar questions on REST tutorials in SO. I hope this helps you.
Apache CXF has a 'plain http binding', but we recommend that people write JAX-RS services, instead. They are very, very, simple. However, the plain HTTP binding is there and supports GET.
I generate a RESTful Web Service in NetBeans by clicking on "Generate SOAP-over-HTTP Wrapper" in my service context menu.
It generated successfully, compiles and deploys fine.
But I still can't figure out how to make a HTTP invoke

Categories

Resources