Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Trouble using HTTPS POST from Java component

Reply
Thread Tools

Trouble using HTTPS POST from Java component

 
 
CopperJ
Guest
Posts: n/a
 
      06-30-2004
Hello,

I'm trying to use a Java component running inside EA Server to do an
HTTPS POST to a 3rd party vendor and I'm not having much luck.

The component times out after five minutes when it attempts to open
the input stream. I receive a stack trace with an error
"getInputStream: Server returned a response code of 400 or greater."

The vendor says that they see me connect and disconnect, but nothing
in between. I've written the contents of the s_xml variable I am
reading in to the system log and it is as I expect, so I know that
part is working.

Does anyone have any insight into what I am doing wrong?

Thanks!






package com.metavante.n_sns_java_https_post;
import org.omg.CORBA.*;
import java.util.*;
import java.lang.Object;
import java.io.*;
import java.net.*;
import com.sybase.jaguar.net.HttpsURLConnection;

public class n_sns_java_https_postImpl
{
// This is the main public interface.
public java.lang.String of_httpsPOST (java.lang.String s_file,
java.lang.String s_url)
{
java.lang.String s_xml;
java.lang.String s_rc = new java.lang.String("");
String s_inputLine;

System.err.println("n_sns_java_https_postf_https POST: Request to
post " + s_file + " to " + s_url);
s_xml = of_readInputFile(s_file);

try
{
s_rc = "";

URL url = new URL( s_url );

URLConnection conn = url.openConnection();

if (conn instanceof HttpsURLConnection)
{
HttpsURLConnection https_conn = (HttpsURLConnection) conn;
try
{
https_conn.setSSLProperty( "qop","sybpks_intl" );
https_conn.setSSLProperty( "pin", "sybase");
}
catch ( CtsSecurity.InvalidPropertyException ipe )
{
System.err.println( ipe );
}
catch ( CtsSecurity.InvalidValueException ive )
{
System.err.println( ive );
}

https_conn.setRequestMethod("POST");
https_conn.setRequestProperty("Content-type", "text/plain");

conn.setDoOutput(true);
conn.setDoInput(true);
conn.connect();
PrintWriter out = new PrintWriter(conn.getOutputStream());

String s_payload = s_xml;
out.println(s_payload);

out.flush();
out.close();

BufferedReader l_inputStream = new BufferedReader(new
InputStreamReader(conn.getInputStream()));
System.err.println("n_sns_java_https_postf_https POST: --
input stream open");

while ((s_inputLine = l_inputStream.readLine()) != null)
{
s_rc = s_rc + s_inputLine;
}
l_inputStream.close();
}
}

catch (Exception e)
{
e.printStackTrace();
return e.getMessage();
}
return s_rc;
}


// This function reads in a file from disk
private java.lang.String of_readInputFile (java.lang.String sFile)
{
java.lang.String sLine;
java.lang.String s_xml = new java.lang.String("");

try
{
FileReader fr = new FileReader (sFile);
BufferedReader inFile = new BufferedReader (fr);

sLine = inFile.readLine();

while (sLine != null)
{
s_xml = s_xml + sLine;
sLine = inFile.readLine();
}
inFile.close();
}


catch (FileNotFoundException exception)
{
s_xml = "ERROR: File " + sFile + " not found.";
}

catch (IOException exception)
{
s_xml = "ERROR: " + exception;
}
return s_xml;
}


}





OUTPUT IN LOG:

Jun 29 18:31:33 2004: java.io.IOException: getInputStream: Server
returned a response code of 400 or greater.
Jun 29 18:31:33 2004: at
com.sybase.jaguar.net.HttpsURLConnection.getInputS tream(HttpsURLConnection.java:524)
Jun 29 18:31:33 2004: at
com.metavante.n_sns_java_https_post.n_sns_java_htt ps_postImpl.of_httpsPOST(n_sns_java_https_postImpl .java:84)
Jun 29 18:31:33 2004: at
com.metavante.n_sns_java_https_post._sk_ROCK_n_sns _java_https_post.invoke(_sk_ROCK_n_sns_java_https_ post.java:60)
Jun 29 18:31:33 2004: at com.sybase.CORBA.local.Socket.call(Native
Method)
Jun 29 18:31:33 2004: at
com.sybase.CORBA.local.OutputStream.write(OutputSt ream.java:29)
Jun 29 18:31:33 2004: at
com.sybase.CORBA.iiop.Connection.invoke(Connection .java:3365)
Jun 29 18:31:33 2004: at
ROCK._st_n_sns_java_https_post.of_httpsPOST(_st_n_ sns_java_https_post.java:32)
Jun 29 18:31:33 2004: at
com.sybase.jsp.ROCK_0005fplayground_0005fhttps$jsp ._jspService(ROCK_0005fplayground_0005fhttps$jsp.j ava:110)
Jun 29 18:31:33 2004: at
org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:107)
Jun 29 18:31:33 2004: at
javax.servlet.http.HttpServlet.service(HttpServlet .java:853)
Jun 29 18:31:33 2004: at
org.apache.jasper.servlet.JspServlet$JspServletWra pper.service(JspServlet.java:26
Jun 29 18:31:33 2004: at
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:461)
Jun 29 18:31:33 2004: at
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:553)
Jun 29 18:31:33 2004: at
javax.servlet.http.HttpServlet.service(HttpServlet .java:853)
Jun 29 18:31:33 2004: at
com.sybase.jaguar.servlet.JagServlet.service(JagSe rvlet.java:656)
Jun 29 18:31:33 2004: at
com.sybase.jaguar.servlet.JagRequestDispatcher.ser vice(JagRequestDispatcher.java:922)
Jun 29 18:31:33 2004: at
com.sybase.jaguar.servlet.JagWebResource.service(J agWebResource.java:90)
Jun 29 18:31:33 2004: at
com.sybase.jaguar.servlet.JagFilterChain.doFilter( JagFilterChain.java:131)
Jun 29 18:31:33 2004: at
com.sybase.jaguar.servlet.ServletEngine._service(S ervletEngine.java:804)
Jun 29 18:31:33 2004: at
com.sybase.jaguar.servlet.ServletEngine.service(Se rvletEngine.java:33
Jun 29 18:31:33 2004: at
com.sybase.jaguar.servlet.ServletServiceImpl.doSer vice(ServletServiceImpl.java:52)
Jun 29 18:31:33 2004: at
com.sybase.jaguar.servlet._sk_JaguarServlet_Servle tService.invoke(_sk_JaguarServlet_ServletService.j ava:151)
 
Reply With Quote
 
 
 
 
Lothar Kimmeringer
Guest
Posts: n/a
 
      06-30-2004
On 29 Jun 2004 18:22:08 -0700, CopperJ wrote:

> Does anyone have any insight into what I am doing wrong?
>
> conn.setDoOutput(true);
> conn.setDoInput(true);
> conn.connect();
> PrintWriter out = new PrintWriter(conn.getOutputStream());
>
> String s_payload = s_xml;
> out.println(s_payload);
>
> out.flush();
> out.close();


Don't close the output-stream. Keep it open until

> while ((s_inputLine = l_inputStream.readLine()) != null)
> {
> s_rc = s_rc + s_inputLine;
> }


you finished reading from the input-stream.

> l_inputStream.close();


So, close it here (before or after).


Regards, Lothar
--
Lothar Kimmeringer E-Mail: http://www.velocityreviews.com/forums/(E-Mail Removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      06-30-2004
On Wed, 30 Jun 2004 08:15:37 +0200, Lothar Kimmeringer
<(E-Mail Removed)> wrote or quoted :

>conn.setDoOutput(true);
>> conn.setDoInput(true);
>> conn.connect();
>> PrintWriter out = new PrintWriter(conn.getOutputStream());


for sample code, see http://mindprod.com/fileio.html
tell it you want to do an HTTP-CGI-POST-write.

Then make a little test case for http and test that. Then modify for
https. Then if that works, slowly modify to what you need, step by
step.

HTTPS depends(depended?) on browser support. Check the class of the
connection object. You may be making an unwarranted assumption.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
CopperJ
Guest
Posts: n/a
 
      06-30-2004
That had some effect - it no longer takes 5 minutes for it to time
out, but I still get the error "getInputStream: Server returned a
response code of 400 or greater.". What does this error mean? Does
it mean the server is rejecting my request?

Could I have the wrong classpath or bootclasspath values?

(I'm a Java novice)


Lothar Kimmeringer <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> On 29 Jun 2004 18:22:08 -0700, CopperJ wrote:
>
> > Does anyone have any insight into what I am doing wrong?
> >
> > conn.setDoOutput(true);
> > conn.setDoInput(true);
> > conn.connect();
> > PrintWriter out = new PrintWriter(conn.getOutputStream());
> >
> > String s_payload = s_xml;
> > out.println(s_payload);
> >
> > out.flush();
> > out.close();

>
> Don't close the output-stream. Keep it open until
>
> > while ((s_inputLine = l_inputStream.readLine()) != null)
> > {
> > s_rc = s_rc + s_inputLine;
> > }

>
> you finished reading from the input-stream.
>
> > l_inputStream.close();

>
> So, close it here (before or after).
>
>
> Regards, Lothar

 
Reply With Quote
 
Lothar Kimmeringer
Guest
Posts: n/a
 
      06-30-2004
On 30 Jun 2004 05:30:40 -0700, CopperJ wrote:

> That had some effect - it no longer takes 5 minutes for it to time
> out, but I still get the error "getInputStream: Server returned a
> response code of 400 or greater.". What does this error mean? Does
> it mean the server is rejecting my request?


It means that you should have a look into the log-file of
the server, because there seems to be a response by the
server telling you, that something went wrong. What it
is should be inside the response-body (that your
HttpUrlConnection-implementation is not willing to give you).
But looking into the http-access-log of you server and your
http-error-log should help a little bit.

Before calling getInputStream, you might check the return-
code of the server. AFAIR HttpUrlConnection has something
like getReturnCode().

If it is 404 the URL you specified is not valid (maybe a
type or something completely different). If it's something
like 500 or greater, an error occured in the server-side
cgi-script. First things can be found in the access-log,
errors of the second type can be found in the error-log.

> Could I have the wrong classpath or bootclasspath values?


No, otherwise you would get something like exceptions that
a specific class can't be found or something similar.


Regards, Lothar
--
Lothar Kimmeringer E-Mail: (E-Mail Removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
server side redirect https => https NOT working Axel ASP General 8 04-27-2009 02:02 AM
https authentication & storing https page in string Naveen Dhanuka Ruby 1 09-19-2007 02:05 PM
Post over https using HttpUrlConnection axel Java 0 10-10-2006 04:02 AM
open-uri and HTTPS, or net/https with a redirect jotto Ruby 4 10-02-2006 07:26 AM
using client-side component keeps calling component's init Jim Hammond ASP .Net 1 11-12-2003 08:13 PM



Advertisments