Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I am trying to call a web-service from my servlet,the web-service interacts with the database and in this case I am trying to insert into the database,however I get a strange 403 status code in the response although I have not designated it so.
- This is me calling the web-service:
- public static void makePutRequest(String objtype,String objkey,String json)
- {
- String uri=BASE_URI+objtype+"/"+objkey;
- System.out.println("Making a put request to the url "+uri);
- HttpURLConnection conn=null;
- URL url=null;
- BufferedWriter writer=null;
- try {
- url=new URL(uri);
- } catch (MalformedURLException e) {
- e.printStackTrace();
- }
- try {
- conn=(HttpURLConnection) url.openConnection();
- conn.addRequestProperty("Content-Type", "application/json");
- conn.setRequestMethod("PUT");
- conn.setDoInput(true);
- conn.setDoOutput(true);
- System.out.println(json);
- writer=new BufferedWriter(new OutputStreamWriter(conn.getOutputStream()));
- writer.write(json);
- writer.flush();
- int rc=conn.getResponseCode();
- System.out.println("The response code is "+rc);
- } catch (IOException e) {
- e.printStackTrace();
- }
- finally
- {
- if(writer!=null)
- {
- try {
- writer.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- if(conn!=null)
- conn.disconnect();
- }
- }
- }
- This is the response in the console:
- Making a put request to the url http://localhost:8180/GoogleMapsErpProject/rest/GoogleMapsErp/EQUI/242423
- The response code is 403
- I have found that the web-service actually never gets called which might mean that my url is wrong,so I tried calling it with this:
- http://localhost:8180/rest/GoogleMapsErp/EQUI/242423
- GoogleMapErpProject is the name of my project.This is my web.xml file:
- <web-app xmlns:javaee="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
- <display-name></display-name>
- <servlet>
- <servlet-name>Jersey REST Services</servlet-name>
- <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
- <init-param>
- <param-name>com.sun.jersey.config.property.packages</param-name>
- <param-value>com.hastha.maperp.webservice</param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>Jersey REST Services</servlet-name>
- <url-pattern>/rest/*</url-pattern>
- </servlet-mapping>
- I have tried to make a cURL request to the web-service:
- curl -i -X PUT -H "Content-Type:application/json" -d
- '{"gisuniqkey":"2434fd22dv3","geometry":{"type":"Point","coordinates":
- [-17.895114303749143,150.908203125]}}'
- http://localhost:8180/GoogleMapsErpProject/rest/GoogleMapsErp/EQUI/123123
- HTTP/1.1 403 Forbidden
- Server: Apache-Coyote/1.1
- Content-Type: text/html;charset=utf-8
- Content-Length: 961
- Date: Thu, 15 May 2014 11:28:07 GMT
- curl -i -X PUT -H "Content-Type:application/son" -d
- '{"gisuniqkey":"2434fd22dv3","geometry":{"type":"Point","coordinates":
- [-17.895114303749143,150.908203125]}}'
- http://localhost:8180/rest/GoogleMapsErp/EQUI/123123
- HTTP/1.1 403 Forbidden
- Server: Apache-Coyote/1.1
- Content-Type: text/html;charset=utf-8
- Content-Length: 961
- Date: Thu, 15 May 2014 11:30:54 GMT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement