Dropped data in SAXParser client xml over http
Hi all, I need some expert help.
I have succeeded in getting our server to encode small gif image files using base64, and transmitting the resulting text in XML back to a client using SAXParser via http. The client overrides characters(char[] ch, int start, int length) in the content handler and decodes the text back to bytes, then reconstructs the gif file and displays it in the client GUI.
Now I've moved on to some extremely large images and am running into problems. The server still appears to encode the image correctly. For this test image the server sends 886 character buffers 200 bytes long and 1 buffer 168 bytes long for a total of 887 buffers and 177368 characters, generated from 133026 bytes.
My client parses the HttpURLConnection InputStream and parses it using SAXParser. The content handler characters() method handles 887 char[] reads. I would expect the first 886 times for the length argument in characters() to be 200 and the last to be 168, exactly like what the server generated, but there are a few intermittent times when length is less than 200. Some data has been lost.
Does something need to be flushed on the server side that could be causing this? The server creates a Writer from the HttpURLConnection outputstream and writes to the writer each time a buffer of bytes has been decoded, like so:
write("<dcm2:image>");
char[] cdata = Base64.encode(bdata);
// bdata.length = 150, cdata.length = 200
write(cdata);
write("</dcm2:image>");
Or does the HttpURLConnection inputstream on the client side need to be wrapped in a particular input stream or stream reader? I've tried:
parser.parse(new InputSource(new BufferedReader(new InputStreamReader(urlconn.getInputStream()))));
I'm using Apache's Xerces 1.3.0, by the way.
The cure appears to be to use a raw input stream. Do NOT wrap the input stream in any kind of reader!
In other words, do this:
parser.parse(new InputSource(conn.getInputStream()));
But do NOT do this:
parser.parse(new InputSource(new InputStreamReader(conn.getInputStream())));
Similar Messages
-
Designing services for xml over http client requests
Hi
I am new to WebServices and Weblogic Integration. I have been using it for only over a month. I have a very basic design issue.
We have to provide a service that
1. accepts xml over http requests
2. Returns a request ack
3. Process Form a response -This activity consumes time so it will be made asynchronous
4. Send the response as xml over http
5. Wait for response ack
6. Get another type of request from client, the processign of which depends on the result of the previous request .. and so on..
The problem here is that Webservices accepts only SOAP messages but our client will send raw xml messages. Also we need to remember the condition of the previous state.
I dont know if my assumption that SOAP is used is right.
Please tell me how to design a raw xml based system without using SOAP messages.
Thanks
nithyaI don't see nothing wrong with your code, there must be something else happening.
You sure you are not being some proxy server?? but even then you are making a post request so it shouldn't be happening.
MeTitus -
Client call using XML over Http using HttpClient
Using HTTPClient while calling HTTPPost method to generate request for external system using XML over http using below code
client.getState().setCredentials(new AuthScope(ipAddress,portNumber),new UsernamePasswordCredentials(username, password));
PostMethod method = new PostMethod(url);
String str = accDoc.toString();
method.setRequestEntity(new InputStreamRequestEntity(new ByteArrayInputStream(str.getBytes())));
method.setDoAuthentication( true );
int result = client.executeMethod(method);
server system getting 2 request. first request without basic authentcation details and second request with full auhentication details.
So unnecessary eatra call without authentication details is going during calling the client program using above code.
Please let me know which part of the above code is generationg extra call.
Thanks in advance for your helpI don't see nothing wrong with your code, there must be something else happening.
You sure you are not being some proxy server?? but even then you are making a post request so it shouldn't be happening.
MeTitus -
We are trying to do the following. Can anyone help by providing any pointers as how to do it.
1. A java client will be posting XML over http(s) to the Tomcat server.
2. The Tomcat server has to do the following:
- Validate the user credentails and verify that it is an valid user on IDM
- Do some DB operations and return back a response XML
We are trying to do this by having the Java client post XML over http to a jsp hosted on the Tomcat server
How do i retrieve the XML data from the HTTP post (from the HTTP body) ?
Thankstry the below example to read data over https,
import java.net.*;
import java.io.*;
import javax.net.ssl.*;
public class SSLSocketClient {
public static void main(String[] args) throws Exception {
String url="https://secure.com";
try {
SSLSocketFactory factory = (SSLSocketFactory)SSLSocketFactory.getDefault();
SSLSocket socket = (SSLSocket)factory.createSocket(url, 443);
socket.startHandshake();
/* read response */
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
socket.close();
} catch (Exception e) {
e.printStackTrace();
} -
XML over HTTP using BPEL (not using SOAP)... is this possible?
Hi there.
We're trying to expose a BPEL process which will be exclusively triggered from a HTTP POST. The Client Partner Link in the BPEL process models Oracle's Transparent PunchOut standard. This standard is strict XML-over-HTTP, SOAP is not involved.
However, I am getting issues when I POST the XML to BPEL. It is telling me that it requires a SOAPAction in the header. Again, the design dictates that this is raw XML over HTTP, so we are not to use any SOAP specific header values nor any kind of SOAP wrapper.
I deployed the sample 'HTTPPostService' process which was delivered with BPEL. I am seeing the same error when I try to POST XML to this process as well. I get a response (in a SOAP wrapper) saying that it wants a SOAPAction in the header. The WSDL used to create this sample process clearly does not bind to SOAP, (there are no mentions of the SOAPAction in the operation, etc) so I do not understand.
So, my question is: Is is possible to POST raw XML to a BPEL process? Or does BPEL require all processes to follow the SOAP 'protocol' ?
Thanks for any help.
Message was edited by:
[email protected]I am also trying to do the same stuff. If i deploy the sample application HttpGetService, will i be able to send the request from browser the way we send typical http get request?
here is the url which i want to use to invoke Http get BPEL
http://cybage1:9700/httpbinding/default/HTTPGetService?ssn=10&id=20
but i am getting following exception
500 Internal Server Error
java.lang.IndexOutOfBoundsException: Index: 3, Size: 3
at java.util.ArrayList.RangeCheck(ArrayList.java:507)
at java.util.ArrayList.get(ArrayList.java:324)
at com.collaxa.cube.ws.http.HttpBindingServlet.call(HttpBindingServlet.java:113)
at com.collaxa.cube.ws.http.HttpBindingServlet.doGet(HttpBindingServlet.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.0)].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:810)
at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.0)].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:322)
at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.0)].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:798)
at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.0)].server.http.HttpRequestHandler.run(HttpRequestHandler.java:278)
at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.0)].server.http.HttpRequestHandler.run(HttpRequestHandler.java:120)
at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.0)].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:186)
at java.lang.Thread.run(Thread.java:534) -
Using Business Service that supports XML over HTTP in OSB
Hi,
I needed to integrate my system with another legacy system that supports communication only through XML over HTTP. I am just trying to understand much about this XML over HTTP. I think in OSB, this is possible only possible through REST interfaces.
Is there any other way and what about HTTP bindings in WSDLs? can you please let me know if you have any insights.
I have gone through the urls about REST interfaces given in these forums. But just wanted to confirm the following scenaiors possible in OSB.
- Client will connect to SOAP based proxy service which will in turn call REST based business service.
- Client will connect to REST base proxy service which will in turn call SOAP based business service.
Following point is not clear from the URLs i went through so just wanted to confirm the following too:
- Client will connect to REST base proxy service which will in turn call SOAP based business service. And is it possible to add anything in soap header before calling soap based business service..
Thanks & Regards
SivaHi Siva,
XML over HTTP is a general use case and OSB supports it very well. REST is a special case and should be used when required. To know more about REST you may refer -
http://www.infoq.com/articles/rest-introduction
Now coming to OSB, SOAP and simple XML are two different cases. If you are creating XML type service then it is not binded to a WSDL/XSD but SOAP based service should always be binded with a WSDL. You may add/modify transport headers in OSB.
Evaluate your requirements and then decide what exactly you need to use. Few links which may be of your use -
http://download.oracle.com/docs/cd/E13159_01/osb/docs10gr3/userguide/configuringandusingservices.html#wp1150438
http://download.oracle.com/docs/cd/E13159_01/osb/docs10gr3/userguide/configuringandusingservices.html#wp1154255
http://download.oracle.com/docs/cd/E13159_01/osb/docs10gr3/userguide/configuringandusingservices.html#wp1141071
section "Configuring Business Services using the HTTP Transport" here - http://download.oracle.com/docs/cd/E13159_01/osb/docs10gr3/httppollertransport/transports.html#wp1083292
http://blogs.oracle.com/jeffdavies/2009/06/restful_services_with_oracle_s_1.html
http://blogs.oracle.com/jamesbayer/2008/07/using_rest_with_oracle_service.html
Regards,
Anuj -
Basic Question: plain XML over HTTP
I would be getting messages in plain XML over HTTP. What should I use to receive those messages. Server is not SOAP based, so client cannot be SOAP based. Should I use JAX-RPC, but when I looked at the documentation, it is giving info regarding SOAP and plain xml over http. Can anyone help me?
ThanksFrom my understanding, you would be getting a plain xml string by connecting to a server over http.
You can is DOM or SAX apis to parse this xml input stream.
For eg: if you are using DOM apis, then you can pass the input stream of the HttpURLConnection as follow...
DocumentBuilderFactory buildFactory = DocumentBuilderFactory.newInstance();
buildFactory.setIgnoringElementContentWhitespace(false);
buildFactory.setValidating(false);
DocumentBuilder docBuilder = buildFactory.newDocumentBuilder();
URL url=new URL("http://someserver.com/abc.jsp");
HttpURLConnection conn= (HttpURLConnection)url.openConnection();
InputStream in= conn.getInputStream();
Document doc = docBuilder.parse(in);
..Hope this helps... -
Hi Team,
I need to access Java web service which is simple service and accepts and returns XML over HTTP. No credentials are needed to access the service. We need to pass following two HTTP headers (Content-Type and Authorization) along with XML request message:
<GetStatus> message is being constructed in the orchestration and URI is constant to access.
Which adapter shall I use to get the response back? I tried using WCF-WSHttp with Security Mode = Transport, and different options of client credential types but every time, error returned stating:
System.Net.WebException:
The HTTP request is unauthorized with client authentication scheme 'Basic'. The
authentication header received from the server was 'Basic realm='.
Authentication failed for principal Basic. Message payload is of type:
String
In Fiddler, request looks line following
POST <https://URL/GetServiceReopnse HTTP/1.1
Content-Type: application/xml
Authorization: Basic cmVmU3RhdHN2Y19kgeRfsdfs=
Host: <Server name>
<GetStatus XMLNS="http://server.com/.....">
<OrgId>232323</OrgId>
<HubId>3232342323</HubId>
</GetStatus>
MMK-007First, you should not use the HTTP Adapter because it's been deprecated and replaced by WCF.
Start with the WCF-Custom Adapter and select the customBinding.
You should start with the textMessageEncoder and httpTransport and go from there. -
XML over HTTP out of the EJB container
I need to communicate with a legacy system via XML over HTTP from the EJB layer. I created a custom solution for this on a previous assignment using Castor for the marshaling etc. and standard JDK classes for the opening the HTTP connection, posting etc. I am thinking of implementing a similar solution in the using the DAO pattern. Are there any new open-source implementations for such XML/HTTP connectivity (non-SOAP)? Surely there is somethign out there!
Thanks,
-ChrisIn general, it is bad design to make network calls from the EJB layer, just as it is against the spec to do things such as create threads, write to the file system, etc.
I know this doesn't answer your question but it is something to consider. -
HI,
I have a requirement to post XMLs over HTTPS. I also am supposed to retrieve the response XML, interpret it and do some processing based on the response status in the response XML. This has to be done for each XML.
Currently I am establishing a new HTTPsURLConnection for each XML, wrting the XML to output stream, retrieving the response from input stream and then releasing the connection using disconnect() method.
Is this the recommended approach or should I be creating just one connection for posting all the XMLs? Also, does java use some kind of connection pooling while creating HTTPURLConnection?
I am frequently getting "SocketTimeoutException Exception --> connect timed out" while processing large number of XMLs. Is this exception due to large number of connections that I am creating?
This program is running as a stand alone program on unix box.
Regards,
JacobIs this the recommended approachYes.
or should I be creating just one connection for posting all the XMLs?No.
Also, does java use some kind of connection pooling while creating HTTPURLConnection? Yes.
I am frequently getting "SocketTimeoutException Exception --> connect timed out" while processing large number of XMLs. Is this exception due to large number of connections that I am creating?Could be, especially if you're doing them in parallel. -
Any good XML over HTTP examples?
Hi,
Does anyone know of a good example of using a XML over HTTP web service? Especially one that would be easily graspable by someone who's new to web services (read: me)?
Is there a way to generate stub classes from a WSDL? I tried to do it in NetBeans but it didn't work, maybe NetBeans expects SOAP web services?
ThanksHi,
This use case seems to be best handled using a RESTful Web Service. Check the Restlet project for a supporting framework:
http://www.restlet.org/documentation/1.0/tutorial
Best regards,
Jerome
http://www.restlet.org -
Can we send XML over HTTPS ?
Can we send XML over HTTPS ?
malcolmmc wrote:
meacod wrote:
rabbits?
Rabbits
http://www.rabbitmq.com/
They wrote
+RabbitMQ is designed from the ground up to interoperate with other messaging systems: it is the leading implementation of AMQP, the open standard for business messaging, and, through adapters, supports XMPP, SMTP, STOMP and HTTP for lightweight web messaging.+
They mentioned only HTTP ....Does HTTPS implied here ? -
XML over HTTP between client and server
We are trying to pass XML between a client and servlet over HTTP.
We used the code from the StockClient/StockServlet examples as a
starting point but cannot get it to work. Basically we
have a simple command line java client that is trying to access
a VERY simple servlet. When the client tries to write data into
the output stream associated with the connection I get:
"Connection rejected: 'Login timed out after: '15000' ms....."
I have read several postings that instruct me to raise the
timeout limit, but as you can see, I surely don't need 15 seconds
to write this data out! Is there something special I need to do?
Does this have anything to do with known issue #10065
(http://www.weblogic.com/docs51/release_notes/rn_knownprob51.html)
I have followed all of the instructions in the example code
(http://www.weblogic.com/docs51/classdocs/xml.html)...
Any assistance is appreciated...
here is the client code:
import java.io.*;
import java.net.*;
public class TestClient
public static void main(String aa[])
URL url = null;
HttpURLConnection urlc = null;
PrintWriter pw = null;
file://Commented lines indicate other things I have tried
try
url = new URL("http://localhost:7001/ParserServlet");
file://urlc = url.openConnection();
urlc = (HttpURLConnection)url.openConnection();
file://urlc.setRequestProperty("Content-Type", "text/xml");
urlc.setDoOutput(true);
urlc.setDoInput(true);
file://urlc.connect();
pw = new PrintWriter(new OutputStreamWriter
(urlc.getOutputStream()), true);
pw.println("<?xml version='1.0'?><test>testing123</test>");
pw.flush();
file://urlc.disconnect();
} catch(IOException ex) {
System.out.println(ex.getMessage());
Here is the servlet code:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.net.*;
public class TestServlet extends HttpServlet
public synchronized void init(ServletConfig config) throws
ServletException
super.init(config);
System.out.println("Inside init()");
public final void doPost(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException
System.out.println("Inside doPost()");
protected void doGet(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException,
java.io.IOException
System.out.println("Inside doGet()");
Jon,
One thing is missed in your client code. When you use HTTP POST to send request,
you have two ways to tell the Web server when to stop reading from your input and
to start process your input: the first one is using "Content-Lenght" header property
to specify how many bytes you want to send to your servlet, the seocnd is use "Transfer-Code:
Chunked" and is much more complicated. I didn't see you pass "Content-Length" in
your client code, in which case, the Web server (Weblogic) cannot know the end of
your request data and could keep waiting for last byte to come out or waiting for
the socket time out (that is what you get).
Since you use servlet, not JSP, I would recommend to code in this way (it works fine
for me, no guranttee for your situation):
Client code: Use a big temprary string, or StringBuffer, or StringWriter to store
all the request data (your xml file content) before you send out the request. After
you finish to form your XML string, calculate the number of bytes (should equal to
the length of the string) and add the request header as
urlc.setRequestProperty("Content-Length", bytes_length);
I will not suggest you using PrintWriter. Think use BufferedOutputStream constructed
from URLConnection and write the bytes (use String.getBytes()) to the servlet and
then flush.
Servlet code: in the doPost() of your servlet, try to find the request data length
by calling request.getContentLength(), then open the InputStream (think to use BufferedInputStream
for performance). Read the contents from the InputStream byte by byte and counter
the number of bytes. Once you get the number of bytes as specified via request Content-Length,
break your reading loop and start whatever you want.
Hope it helps.
"Jon Clark" <[email protected]> wrote:
>We are trying to pass XML between a client and servlet over HTTP.
>We used the code from the StockClient/StockServlet examples as a
>starting point but cannot get it to work. Basically we
>have a simple command line java client that is trying to access
>a VERY simple servlet. When the client tries to write data into
>the output stream associated with the connection I get:
>"Connection rejected: 'Login timed out after: '15000' ms....."
>I have read several postings that instruct me to raise the
>timeout limit, but as you can see, I surely don't need 15 seconds
>to write this data out! Is there something special I need to do?
>Does this have anything to do with known issue #10065
>(http://www.weblogic.com/docs51/release_notes/rn_knownprob51.html)
>I have followed all of the instructions in the example code
>(http://www.weblogic.com/docs51/classdocs/xml.html)...
>
>Any assistance is appreciated...
>
>here is the client code:
>import java.io.*;
>import java.net.*;
>
>public class TestClient
>{
> public static void main(String aa[])
> {
> URL url = null;
> HttpURLConnection urlc = null;
> PrintWriter pw = null;
>
> file://Commented lines indicate other things I have tried
> try
> {
> url = new URL("http://localhost:7001/ParserServlet");
> file://urlc = url.openConnection();
> urlc = (HttpURLConnection)url.openConnection();
> file://urlc.setRequestProperty("Content-Type", "text/xml");
> urlc.setDoOutput(true);
> urlc.setDoInput(true);
> file://urlc.connect();
> pw = new PrintWriter(new OutputStreamWriter
> (urlc.getOutputStream()), true);
> pw.println("<?xml version='1.0'?><test>testing123</test>");
> pw.flush();
> file://urlc.disconnect();
> } catch(IOException ex) {
> System.out.println(ex.getMessage());
> }
> }
>}
>
>
>
>Here is the servlet code:
>
>import javax.servlet.*;
>import javax.servlet.http.*;
>import java.io.*;
>import java.net.*;
>
>public class TestServlet extends HttpServlet
>{
> public synchronized void init(ServletConfig config) throws
>ServletException
>
>
> super.init(config);
> System.out.println("Inside init()");
> }
>
> public final void doPost(HttpServletRequest request, HttpServletResponse
>response)
> throws ServletException, IOException
> {
> System.out.println("Inside doPost()");
> }
>
> protected void doGet(HttpServletRequest req,
> HttpServletResponse resp)
> throws ServletException,
> java.io.IOException
> {
> System.out.println("Inside doGet()");
> }
>}
>
>
>
>
-
Server to Rich Client sending XML over Http
I need to send XML data from a Servlet to a rich client over http.
Currently I am using HttpURLConnection and SaxTransformerFactory to do this.
Is it better to use SOAP or XML-RPC in this scenario?
Are there any good online tutorials comparing SOAP, XML-RPC and AXP-Java Net API?
What are the factors that I need to consider for choosing between these alternatives?
Please advice. Thanks in advance.XML-RPC and SOAP use XML as a way to communicate, but they are used to invoke certain function calls in an application independend manner, not to be used to send XML data. So I'd say it depends on:
a) what do you do with the XML data?
b) will you be expanding the application?
c) how difficult is it to rework the current implementation? -
Query regarding encoding/decoding of XML over HTTP Post request
Hello,
I am working on a project where I need to put SMS inside XML and
eventually transfer this XML via HTTP post from/to server/client.
Assuming the SMS to be 7-bit text the XML may look something like
<?xml+version="1.0"?>
<SMS
TESTMESSAGE
</SMS>
This XML when encoded in a HTML post may look something like
http://<IP Address>:<port>/
POST /MessageReceiver.jsp HTTP/1.0
Host: www.SomeHost.net
Content-Type: application/x-www-form-urlencoded
Content-Length: 90
xmlMsg=%3C%3Fxml+version%3D%221.0%22%3F%3E%0D%0A%3CSMS%0D%0A%09TESTMESSAGE0D%0A%3C%2FSMS%3E
This xml is UTF-8 (7-bit ASCII) by default since no encoding format has been specified.
My question - how will the encoding of xml change to - when 8 bit binary data
is transferred via xml.
for e.g.
<?xml+version="1.0"?>
<SMS
<!!!!!BINARY DATA!!!!!>
</SMS>
for such a file how/what shld the encoding be set to.
Further my spec-states the following.
"The content of the XML must respect the encoding. Thus a SMS
containing typically french characters must use ISO-8859-1 encoding"
"This code needs to work with both UTF-8 and UTF-16 standards (ASCII and Unicode). Because of this the parsing code should work internally with UTF-16 and translate up/down to/from UTF-8 (ASCII) only when dealing with the basic HTTP."
could anyone clarify this for me.The first thing you need to do is clear up some fundamental misconceptions about character encodings. UTF-8 is not the same thing as "7-bit ASCII", and UTF-16 is not the same as "Unicode". Anyway, you're making this a lot more difficult than it needs to be. Just use UTF-8 to encode and decode all messages; it can handle all the characters from any language you're likely to run into.
Maybe you are looking for
-
Creation of Index taking lot of time!!
DB:10.2.0.3.0 OS:AIX 64 bits Application Server:10133 Hi All, When we try to create Normal Index, it takes more than 9 hrs to create whereas on other similar environment instance it takes not more than 3 to 4 hrs. We modified PGA_AGGREGATE_TARGET to
-
i have the latest Adobe reader from the app store (11.3.2) however i am struggling to open PDF's on ipad and getting error that the file is corrupt!! any help or suggestions welcome
-
I know that it's possible to create Placeholder Text. However I'm looking for dynamic text. I frequently deal with documents where I need to update 30 fields with the same information. Rather than going 30 times and replacing the Placeholder Texts wi
-
Acrobat 9 Std Thinapp not lunching
I recently downloaded and installed Acrobat 9 ThinApp (on Win 7). The installation went without errors. However, the app does not launch. Made several attempts to remove and reinstall the app, but it still won't launch. Any help will be much apprecia
-
Also the tab key ti jump from one form window to the next to fill them in, does not work anymore. It is especially annoying typing emails using webmail. I can only navigate trough the text using my mouse. I am sorry to post in here but I was not able