Win a copy of Head First Android this week in the Android forum!

Jack Rooney

Greenhorn
+ Follow
since Dec 04, 2012
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jack Rooney

I am using CURL to issue a POST request and sending a JSON to populate a mysql db. The issue it that curl hangs when I issue this command. If I use the RESTClient with firefox, it works perfectly and I can populate the db with the json passed. Its only when I am issuing the CURL that this happens.

If I remove my implementation inside the POST and just do a simple System.Out.Print, this works just fine.

Here is my curl command :


Kindly let me know where I am going wrong.

Thanks, Jack
8 years ago
I am trying to pass a JSON string to a POST method via a curl command. However, i am receiving a HTTP 1.1 404 Not Found error. I am trying to create a simple web service which will have the JSON string passed to it to populate a mysql db.

Here is my DAO class which is used to do the GETS and the POSTS.


My POJO


My Person Resource class for my annotations:


When i issue the GET curl command it works fine and It returns all the values in the person table. However, if I issue a POST curl command I get the following error :


Kindly let me know where I am going wrong. Thanks for your time and help.

Regards,
Jack
Hi Bear,

Thanks a lot for the reply. I have already used GSON to parse the JSON string to a Java object. However, I am using a hard-coded JSON. I want to dynamicaly pass the JSON string in a URI and use that string to populate a mysql db.
Right now my URI is something like this :
http://localhost:8080/stack

I actually want the URI to be something like this :

curl -X POST -H'Content-Type:application/json' -d'{"stock_name":"GOOG"}' http://localhost:8080/stack

Kindly help me out.

Thanks,
Jack
8 years ago
Hello,

I am trying to pass a dynamic JSON string to my REST Web service which will in turn be used to populate a mysql db.
I can do this using a hard-coded JSON string,however I dont know how to pass a dynamic JSON string. Any insight is appreciated
as I am very new to this topic. Thanks a lot for all your time. I am attaching my code which I have for the hard-coded JSON
string parsing and adding to a mysql db.

My POJO:


My HibernateUtil class :


My SessionFactoryContextListener class :

My StackService.java

My Hibernate.cfg


Thanks,
Jack
8 years ago
Hello Bear,

Kindly help me regarding this topic by seeing my PUT annotation from this post here .

Thanks,
Regards,
Jack
8 years ago
Hello,

I am using MAven,Hibernate 3/JPA ,Eclipse to implement a PUT method for populating a Mysql db.

Here is my POJO


Here is my main class.


Here is my Hibernate.Util.


Here is my SessionFactory Context Listener class


When I try to run this using Tomcat Server, i get the following error.


I am very new to this. Kindly let me know what I am doing wrong. I trying to insert a
record into a mysql db using the above values. Kindly help me out.

Thanks,
Jack
8 years ago
Hello,

I am sorry, I am very new to this topic. Here is what I am using to create my Web Service. JDK 1.6, Maven 2.2.1, Tomcat 7, Eclipse Juno (Enterprise Edition), Hibernate 3 /JPA.

Kindly let me know.

Thanks,
Jack
8 years ago
Hi Praful,

I have my framework decided. I am using Hibernate/JPA and Maven. Could you please point me to a starting point. I am still stuck.

Thanks,
Regards,
Jack
8 years ago
Hello,

I am using JDK 1.6, Maven 2.2.1, Tomcat 7, Eclipse Juno (Enterprise Edition), Hibernate 3 /JPA, and MySQL 5.

Am relatively new to Hibernate / JPA. What I am seeking to do is have my tomcat 7
connect to the database as soon as my webapp is loaded by tomcat 7's classloader (during server startup).

hibernate.cfg.xml (Located in myapp/src/main/resources):



HibernateUtil.java:



I created this class do use my HibernateUtil during server startup:



Registerd it with my web.xml:



So, far everything seem to look like its works... However, on the Internet after googling it,
I saw that people are using EntityManagerFactory... What's the difference between the two?

What's the standard way to setup a Tomcat based web app using Hibernate / JPA against a MySQL database?

What I am seeking to do is being able to save my POJOs (after setting them) and then issuing something like



without having to constantly open and close connections to my database.

Thanks for all your help...

Regards,

Jack
Hello,

I am using JDK 1.6, Maven 2.2.1, Tomcat 7 and Eclipse Juno (Enterprise Edition).

When trying to import packages such as javax.servlet.*; Eclipse complained
that it does not have it inside its classpath (build path).

So, what I did was include the following dependencies in my pom.xml file:



During tomcat server startup:



Why is it logging this message?

Also, I can't seem to find the right versions for servlet-api 3.0 or jsp 2.2 in the maven repository

http://mvnrepository.com/

Kindly help me...
8 years ago
Hello I am trying to create a Web service that will have a JSON string passed which will then be used to populate a mysql db using POST method. So the CURL command could be something like this :

curl -X POST -H'Content-Type:application/json'-d{"Name:Jack","LastName":"Rooney"}'http://localhost:8080/SampleWS/Name

Can you kindly point me to a starting point ? I am very new to REST WS. Any help is appreciated.

Thanks,
Regards,
Jack
8 years ago
Hi Praful,

Here is the complete error :

HTTP Status 405 - Method Not Allowed

type Status report

message Method Not Allowed

description The specified HTTP method is not allowed for the requested resource.

I dont understand what you mean by the content type. Kindly let me know.

Thanks,
Regards,
Jack
8 years ago
Hello Praful,

Thanks for responding. In my code, I dont know if the POST annotation that I have written is correct or not. My URI is this : http://localhost:8080/HibernateApp/rest/save. When i run this on the localhost:8080, it gives me an error saying that "The specified HTTP method is not allowed for the requested resource." I am developing this using Hibernate3/JPA. Here is my web.xml .



Thanks for you time.
Regards,
Achal
8 years ago
I am trying to create a restful webservice with Hibernate3/JPA that will be used populate a mysql db. I want to know how the post annotation will look like. I am new to Rest web services. I appreciate all your help and time.

This is my Stock class.


This is my HibernateUtil class .


This is my hibernate.cfg.xml file.

Here is my App class which will have the POST annotation.I know my implementation of the App class is incorrect. But I have been trying to look at a lot of tutorials,but couldnt understand what to do to post to the database.

Kindly help me out.

Thanks.






8 years ago