REST ful java web service on heroku? - java

how to write java REST Web service and Deploy it on heroku? Till now I just worked on simple java application on heroku, first time I am trying to deploy a web service.

Spring MVC's REST support is one option that is pretty easy to use. Or you can use Play Framework's REST support. Or there are many other options. They should virtually all run on Heroku so try a few and see what works for you.

Here's an example of a JAX-RS REST service, complete with Procfile and README for deploying to Heroku (not much to do).
https://github.com/jesperfj/jax-rs-upload-file
It uses Grizzly as embedded server and is super lightweight. Let me know what path you decide to take. Curious about what works best for you.

Related

Deploy Java restful web service to live server

I have just learned to create java rest API using jersey and Oracle database.
I'm developing in eclipse and using weblogic server to run and test web service on localhost.
My question is what are the options of live servers to deploy this service so that I can access this API in my android application or any web application???
You can do that. But you have to make sure that all the dependent jars are packaged with the your WAR project(eg; Oracle db related things).
Some blog entries which give you an idea about what are all these servers and which one to pick for open development and common standards - http://blogs.forrester.com/mike_gualtieri/11-07-15-stop_wasting_money_on_weblogic_websphere_and_jboss_application_servers,
and this one http://zeroturnaround.com/rebellabs/the-great-java-application-server-debate-with-tomcat-jboss-glassfish-jetty-and-liberty-profile/
This will give pretty good idea about what is all these servers :)

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

WCF Self-Hosting capabilities in Java

Hi guys is there a way to self-host a web service in Java just like WCF?
Jersey using Grizzly embedded within it would seem like a good fit for your needs. It wouldn't require and outside application server and would be fairly lightweight to get setup. You can just read the Jersey getting started documents to get going with that exact path:
Jersey User Guide
If by self-hosting you mean generating a web service endpoint for invocation, there are a number of ways to go on this, depending on your potential deployment environment.
I'd start off looking at Oracle's JAX-WS implementation, which includes RESTful capabilities. If you want to run a relatively simple stack, you could use Apache Axis2. And then JBoss has JBossWS, which can run standalone or in the JBoss Application Server. I'm pretty sure most of the major application server engines have a Web Services component as well.

java: basic web service interface without a web server

how hard is adding a basic web services interface to an existing java server application without having to turn it into a .war, or embedding a small web server like jetty?
say, xml-rpc instead of more modern approaches, if it helps.
if not too hard, can you suggest a starting point?
thank you in advance :)
It sounds like you're asking for the impossible: expose an HTTP service without plugging into or embedding an HTTP server!
Unless you want to reimplement what Jetty already does, I'd reccommend using Jetty as a library. That way you don't need to conform to the more awkward aspects of the Servlet spec. E.g. your servlets can have real constructors with parameters.
There is also a simple HTTP server implementation in JDK 6, but it's in the com.sun namespace so I'd avoid it for production code.
Check out the Restlet API which provides a painless way to implement RESTful web services that can run inside a web container or standalone.
I don't know what you are doing, but what about rmi?
RMI # stackoverflow
Spring-WS has the facility for using JRE 1.6's embedded web server, if that's an option for you. Spring-WS gives you a very nice SOAP server layer, if that's what you're after.
If not, then an embedded Jetty instance is probably the best idea.

Categories

Resources