2

Currently I use the JavaScript code to send XML data in GWT. Is there an easier way to send them?

 sendRequest.addClickHandler(new ClickHandler() {

      @Override
      public void onClick(ClickEvent event) {
        // RegisterBuiltin.register(ResteasyProviderFactory.getInstance());
        // ItemExtension client = ProxyFactory.create(ItemExtension.class, "http://localhost:8081");

        sendXMLFFI(restInput.getText());

 protected native void sendXMLFFI(String text)
  /*-{
    var xmlhttp=false;

    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
      try {
      xmlhttp = new XMLHttpRequest();
      } catch (e) {
      xmlhttp=false;
      }
    }

    if (!xmlhttp && window.createRequest) {
      try {
          xmlhttp = window.createRequest();
        } catch (e) {
          xmlhttp=false;
        }
    }

    xmlhttp.open("POST", "./REST/Items",true);
    xmlhttp.setRequestHeader("Content-Type", "application/xml")
    xmlhttp.send("<?xml version='1.0' encoding='UTF-8'?>\n\n"+ 
           "<item barcode='111'><name>Foo</name><quantity>100</quantity></item>");
  }-*/;

1 Answer 1

7
RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, "./REST/Items");
rb.setHeader("Content-Type", "application/xml");
rb.sendRequest("<?xml version='1.0' encoding='UTF-8'?>\n\n"+  
    "<item barcode='111'><name>Foo</name><quantity>100</quantity></item>",
    new RequestCallback() { ... }
);
Sign up to request clarification or add additional context in comments.

1 Comment

Is it RequestBuilder.POST instead of RequestBuilder.Method.POST?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.