Restlet framework with post method - rest

I am using restlet 1.0, and i am trying to post a new entry into my Mysql database. I am not using any HTML form, i want to do all operation on MY rest client. The problem i am facing is,
I want to post a new customer entry into mysql database,
I am not using any HTML form,
I am trying to achieve and create XML in Rest Client, and trying to send XML.
My REST url for post method is
http://localhost:8182/api/service/customers/
How to append the new customer information and how to get XML.
Please help.
Thanks
Karunjay Anand

If you rest client is a java based client, you can use the URLConnection (HTTPUrlConnection) to post data to the server.
URL url = new URL("http://localhost:8182/api/service/customers/");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(xml); // write your xml
wr.flush();
wr.close();
Alternatively you can also use the HTTPClient library to do posts.

Related

Restygwt download byte[]

I have only an array of byte on the client side.
Another server send me JSON
{
report - byte[]
}
I am looking for ways to save byte [] in browser
Send them to server or I can download from client side.
I can not find any solution at all.
So my question "Is it possible to save with restygwt byte [] an how???"
It is not possible to save the file directly from Resty.
https://github.com/resty-gwt/resty-gwt/issues/341
The most common workarounds to download files using AJAX are not using AJAX at all.
You can simply change the URL (using window.location) or (using javascript) create or;
create a form (using JS) and post that form.
In my projects, I simple create a URL to my REST endpoint attaching any query parameters needed and use it as the href to a link.
For instance, if your RestyGwt endpoint points to /entity/1/bytes
just do
new Anchor("Download", "/entity/1/bytes");
your endpoint must produce a downloadable file type say:
#Produces("text/txt")

Http post requests unsing NTLM Authentication (java)

I tried to send a HttpRest Call using NTLM Autentication in Java. I tried using the org.apache.http library. it was not a big problem to use the HttpClient to send a Post Request with anonymos authentication.
But i have some troubles with WindowsAuthentication. I even tried to use CredentialProvider with my own Windows credentials (as a compromise, i dont like that either) but i didn’t succeed.
Is there an easy way using NTLM Authentication sending post requests from Java code?
Is there another lib which fits better form my needs?
I still have no idea why the doku from https://hc.apache.org/httpcomponents-client-ga/tutorial/html/authentication.html about NTLM Authentication didn’t have worked for me.
I finally solved my problem doing it similar to the documentation for basic authentication as described on http://www.baeldung.com/httpclient-post-http-request
it now looks like this:
...
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY,
new NTCredentials("username", "passwd", hostname, "domain.at"));
HttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(credsProvider).build();
HttpPost post = new HttpPost("http://www.example.com"));
StringEntity input = new StringEntity(bodyAsString, HTTP.UTF_8);
input.setContentType("application/json");
input.setContentEncoding("UTF-8");
post.setEntity(input);
post.setHeader("Accept", "application/json");
post.setHeader("Content-type", "application/json");
HttpResponse response = client.execute(post);
...

How to POST a request in any of rest clients for mime type as "multipart/related"

I'm trying to do a POST request from any of rest client like (Advanced rest client, Postman etc) for posting a request with mime type "multipart/related" but none of rest client supports. So is there a way to quickly POST a request from any of rest clients or other alternate solutions?
Though I have not tried multipart/related, but multipart/mixed using jersey client.
Using Jersey client
Create a multipart request .. eg.
MultiPart multiPart = new MultiPart();
multiPart.bodyPart(....//
Then call the service like :
Client c = Client.create();
WebResource service = c.resource(Url);
ClientResponse response = service.type("multipart/mixed").header(headerkey,
headervalue).post(ClientResponse.class, multiPart);
Similarly try it for multipart/related.
you have download jersery client jar from https://jersey.java.net/download.html
Attached image will help you, This way you can try using Advance Rest Client plugin in Chrome, and also don't forget to upload the file under the Files tab.

Authentication Error in using Alfresco Rest API

I am trying to hit the alfresco rest api using my standalone rest code. i get the login ticket when i use the below url -
"http://host:port/alfresco/service/api/login?u=admin&pw=admin"
and i got the ticket but how do i use this ticket for further communication with alfresco without facing this authentication problem.
below is the code i am using for communicating with the alfresco rest client.
HttpGet getReq = new HttpGet(url);
getReq.addHeader("accept", "application/json");
StringEntity input = new StringEntity(args);
HttpResponse response = client.execute(getReq);
Kind Regards
Garvit Jain
Append the alf_ticket argument to your URL and pass in the ticket you retrieved from the /api/login call. See http://wiki.alfresco.com/wiki/Web_Scripts#Authenticating

Viewing SOAP returned by a web service

I created a web service reference in my VS2010 project, and configured it with a WSDL service address URL. VS2010 created a nice proxy class for me to consume the web service.
I am getting a result that I don't like, and, in an effort to troubleshoot, I'd like to see the XML coming back from the web service. What is the simplest way to do so? I'd like to be able to do it within my Visual Studio debugging session, but if I have to go outside that, so be it.
I am trying to make the following work:
Dim response As HttpWebResponse = Nothing
Dim reader As System.IO.StreamReader = Nothing
Dim hwrResponse As HttpWebResponse = DirectCast(**request**.GetResponse(), HttpWebResponse)
Dim responseStream As System.IO.Stream = hwrResponse.GetResponseStream()
Dim xtrSmp As New System.Xml.XmlTextReader(responseStream)
Dim strXm As String = xtrSmp.ReadInnerXml()
xtrSmp.Close()
hwrResponse.Close()
but I don't know what my request should be.
Your REQUEST should be a REQUEST Object whiich is configured to access the SOAP service you are trying to access...
You can find out more here...
HTTPWEBRESPONSE object http://msdn.microsoft.com/en-us/library/system.net.httpwebresponse.aspx
HTTPWEBREQUEST object http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx
Use one of theseWebServiceStudio (http://webservicestudio.codeplex.com/),
Storm (http://storm.codeplex.com/)
or the outstanding Eclipse WSDL Editor and Web Service Explorer (look at http://wiki.eclipse.org/index.php/Introduction_to_the_WSDL_Editor)
These will let you invoke your service methods with an ad-hoc GUI client generated from WSDL and access both request and response XML.
The list of tools above is of course incomplete.