Different response encoding REST using JAVA between my localhost and My Server - java

I'm trying to get a xml from a REST connection. In my local machine i receive it with the right encoding. e.g.: 수정완료 but in my server I receive the same request as 수정완료.
Using the web browser in both machines I receive the REST request correctly.
Any ideas?
I'm using Apache Tomcat 6.0 in both machines
EDITED:
I'm follow this example:
http://support.openview.hp.com/selfsolve/document/KM997956/binary/ALM11.00_REST_API.html?searchIdentifier=-765a98c0%3a12de84ca170%3a-27ac&resultType=document
user: exampleStack
pass: example
Direct source link: http://h30499.www3.hp.com/hpeb/attachments/hpeb/itrc-895/68767/1/alm_rest.zip
Thanks in advance.

I finally got the answer to solve this issue thanks to this post: https://forums.adobe.com/message/3602618
What I needed to do was instead get directly the string from the Rest response, get its bite[] and then encode it correctly: =)
String myXmlEncoded = new String(con.httpGet().getResponseData(), "UTF-8");
Thanks guys.

Related

Json can access the URL on the local computer, but not on the server

This is the key code.
val document =
Jsoup
.connect("http://waipian3.com/search-%E4%BD%A0----------1---/")
.get()
It works successfully in my local computer, but if I package it,and put it works on my server, it works wrong.
I tried to add an agent, but it didn't help.
It show me the org.jsoup.HttpStatusException: HTTP error fetching URL
Why does this code work differently in different places? Is it because of the configuration of my server?
I think I have solved the problem because the other party blocked my IP

Tomcat 7 , Spring rest template application producing err_invalid_chunked_encoding in browser

I have a Tomcat 7 , Spring 4.2 'RestController' implementation of REST API which seems to produce 'ERR_INVALID_CHUNKED_ENCODING' for few API calls on returning a JSON response.
It is the same code that creates a ResponseEntity. But for few API calls the "Content-Length" is set properly and other calls the "Transfer-Encoding" is set as Chunked.
private CacheControl cacheControl = CacheControl.noStore().mustRevalidate();
protected <T> ResponseEntity<TNRestResponse<T>> createEntity(TNRestResponse<T> res) {
return ResponseEntity.ok().cacheControl(cacheControl).body(res);
}
The weird part is the response for the same API call that creates ERR_INVALID_CHUNKED_ENCODING seems to work fine in another environment. The only difference is the client and service is running in the same server in the problematic scenario.
The solution already tried is to set the Content-Length manually which seems to result to premature end of file on the client.The JSON length is only around 468 characters but client receives only 409 characters , even though server logs shows that the full response has been sent and connection is closed.
We are so lost at the solution for this problem because it is the same code acting strangely in different environment.I tried to check the compression settings in server.xml on both the tomcat.But everything looks fine.
Also disabled the proxy setting in both IE and chrome.
Any helpful inputs or insights would be really good ? Thanks in advance.
Follow these steps:
1) Go to your OS's Control panel > internet options > Connections >
LAN Settings or to your browser settings.
2) Deselect "Use Proxy" for your LAN or for your browser.
ERR_INVALID_CHUNKED_ENCODING
Original answer
Another original answer

Java - Sending complete HTTP message (including headers, status line aso)

For some reasons I need to develope an own HTTP client. I managed working with the HTTP protocol, but I don't know how to send it via java...
For example, I got the following request message I want to send (I couldn't test it, so I am not sure that it is in a correct format):
GET http://example.com HTTP/1.1
Transfer-Encoding:UTF-8
someOtherParam=thatIsThis&name=value
All I could find was making up a connection using URL.openConnection() - but with that connection, I can't send the whole message, but have to put the header values via the connection.addRequestProperty() method.
Can anyone help me and tell me how to send such a message to a server?
(And yes; I do know libraries like Apache HttpComponents :))
Best greetings,
Martin Bories
thanks for your help - Sockets did it :).
For anyone who is running into the same problem: Use sockets - you can simply write and receive messages and implement an own HTTP implementation.

How to interact with a java servlet running on glassfish with telnet?

I have a servlet hosted in the glassfish server. i want to communicate with it using telnet to understand what is going on behind the scenes when using html form get method.
What should i give in the Host field of the HTTP request?
Get /WebApplication1/NServlet HTTP/1.1
Host: localhost
If i want to send custom properties in the HTTP request as below, is it possible to extract their value using request.getAttribute() method.
Get /WebApplication1/NServlet HTTP/1.1
Host: localhost
Custom-Attribute: xyz
Another doubt is that is javax.servlet package not a part of java SE sdk. i had to install java ee to get it running.
The Host field is just the hostname part of the URL, e.g. Host: google.com for http://google.com/
Custom-Attribute: xyz would be exposed in the HttpServletRequest using getHeader(), not getAttribute().
If you want to use HTTP for your protocol (as you've suggested in your comments), check out HttpClient. As the name suggests, it's the client-side of the client/server HTTP implementation, and it should be relatively easy to determine what to set on the client side such that you see it on the server.
There's a great tutorial here. I would perhaps get a simple page working in the servlet first, and check it via the browser, and then implement the client side.
Based on your question, I don't there's enough information for anyone to answer you. Tomcat/Jetty/etc are basically web servers that contain servlets (and therefore JSP/JSF/Wicket etc etc) processors for dynamically generating content.
So, what is it you're trying to figure out, and why?

XML-RPC PHP Java

I'm having a problem with the XML-RPC communication.
I have a XML-RPC Client made in Java with Apache XmlRpc and a XML-RPC Server made in PHP with PEAR's XML_RPC. The problem is that i get a "HTTP server returned unexpected status: Not Found" error. I tested the server with a PEAR XML-RPC Client and it works. I don't know what is the problem because i can't print the response of the server (i don't know how), but it seems that the authentication works, because if i don't input the correct username and passoword i get an authentication error.
Please help!
Thanks in advance.
Cristian
Start debugging, here some information from the PEAR XML_RPC documention:
setDebug()
$client->setDebug ( $debugOn )
$debugOn is either 0 or 1 depending on
whether you require the client to
print debugging information to the
browser. The default is not to output
this information.
The debugging information includes the
raw data returned from the XML-RPC
server it was querying, and the PHP
value the client attempts to create to
represent the value returned by the
server. This option can be very useful
when debugging servers as it allows
you to see exactly what the server
returns.
Source: http://pear.php.net/manual/en/package.webservices.xml-rpc.api.php
Make sure you are taking into account the package name with writing the interface stub in java, because by default it will tack that onto the from of the method it is trying to reference.

Categories