0

I have my service defined as:

@Path("/fileservice")
public class FileService {

@POST
@Path("/path")
@Consumes("application/xml")
public Response getFilePath(FileRequest fileRequest) {

    System.out.println("....." + fileRequest.client);

    (...)
}

My activator:

@ApplicationPath("/services")
public class JaxRsActivator extends Application{

}

And the XML file mapping is defined as:

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name="fileDetails")
public class FileRequest {
    @XmlElement public String path;
    @XmlElement public String client;

And my client is:

public static void main(String args[]) throws Exception {

    URI uri = new URI(SERVICE_URL);

    Client client = ClientBuilder.newClient();

    String xml = "<fileDetails> "
            + "<path>usr/test/a.pdf</path>"
            + "<client>abc</client>"
            +"</fileDetails>" ;

    Response response= client.target(uri).request().post(Entity.xml(xml));
    System.out.println("Request posted :"+ response.getAllowedMethods());
    System.out.println("Request posted, response status :"+ response.getStatus());

When I send request to the URL http://localhost:8080/xx/services/fileservice/path I'm getting response.getStatus() as 405.

What I'm doing wrong here?

António Ribeiro
  • 4,129
  • 5
  • 32
  • 49
Ratha
  • 9,434
  • 17
  • 85
  • 163
  • 1
    Have you tried following the approach given in [Java EE's REST example application](http://docs.oracle.com/javaee/7/tutorial/jaxrs-advanced008.htm#GKOIB)? `Response response = client.target(uri).request(MediaType.APPLICATION_XML).post(Entity.entity(fileDetailsInstance, MediaType.APPLICATION_XML), Response.class);` – António Ribeiro Mar 31 '16 at 23:46
  • @aribeiro Do you see issue in my post method? i think i follow similar way – Ratha Apr 01 '16 at 00:07
  • @aribeiro, i want to post my xml file which contains the details of files. SO, how can i create a file details from client side? since client does not know about that file details java bean – Ratha Apr 01 '16 at 00:28
  • What is the content of your `SERVICE_URL` variable? I've just created a project with your code and everything works fine. – António Ribeiro Apr 01 '16 at 09:23

0 Answers0