Page 1 of 1
quick JSSE (PHP related) question...
Posted: Mon Oct 27, 2003 3:21 pm
by biz0r
have been asked to develop some software for the company I work for that ties into an XML transaction interface, I have some example code, however it uses JSSE. I don't use, nor really like java all that much and was wondering what lib/etc I would need to connect to the same service in PHP?
IE: What method does it use...proprietary? DCOM, RMI, XML-RPC, etc?
(please excude my ignorance about Java

)
Posted: Mon Oct 27, 2003 4:53 pm
by volka
can you show us the connector code from your java example?
Posted: Tue Oct 28, 2003 9:47 am
by biz0r
Surely...this is the example I was given:
Code: Select all
package com.b2b.test;
//Base Imports
import java.io.*;
import java.net.*;
import java.util.*;
import java.text.SimpleDateFormat;
public class TestClient {
public void test() {
System.out.println("Starting");
// URL to perform post()
String urlString =
"https://someplace.com/blah";
// setup SSL
try {
https.System.setProperty(
"java.protocol.handler.pkgs",
"com.sun.net.ssl.internal.www.protocol");
java.security.Security.addProvider(
(java.security.Provider) Class
.forName("com.sun.net.ssl.internal.ssl.Provider")
.newInstance());
} catch (Exception ex) {
// unable to setup SSL
System.out.println(
"Error in setting up SSL stuff, make sure youhave JSSE jars in classpath "
+ ex);
}
URL url = null;
try {
url = new URL(urlString);
} catch (Exception e) {
System.out.println("URL creation error");
e.printStackTrace();
}
URLConnection conn = null;
try {
conn = url.openConnection();
} catch (Exception e) {
System.out.println("connection error");
e.printStackTrace();
System.exit(1);
}
conn.setUseCaches(false);
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestProperty("Content-type", "text/xml");
// if you want to read the XML from a file
StringBuffer xmlStrBuff = new StringBuffer();
try {
FileReader fr = new FileReader("c\\:your_request_file.xml");
BufferedReader br = new BufferedReader(fr);
int ch;
while ((ch = br.read()) > -1) {
xmlStrBuff.append((char) ch);
}
} catch (IOException e) {
System.out.println("Error in reading file " + e);
e.printStackTrace();
}
String xmlstr = xmlStrBuff.toString();
System.out.println("Sending xml string = \n" + xmlstr);
OutputStream out = null;
try {
out = conn.getOutputStream();
out.write(xmlstr.getBytes());
out.close();
} catch (Exception e) {
System.out.println("output stream error");
e.printStackTrace();
System.exit(1);
}
InputStream in = null;
try {
System.out.println("\n\n////////////////////////////////////response times");
SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy h:m:s.SSS");
System.out.println(sdf.format(new Date()) + " - Sent Request to theServlet");
//finally, invoke the servlet
in = conn.getInputStream();
System.out.println(
sdf.format(new Date()) + " - Received Responsefrom the Servlet");
BufferedReader bufRead = new BufferedReader(new InputStreamReader(in));
StringBuffer xmlRespStringBuf = new StringBuffer(1024);
int c = in.read();
// while there is data to read
while (c != -1) {
// append the last char read
xmlRespStringBuf.append((char) c);
// read another char
c = in.read();
}
in.close();
System.out.println("Response = " + xmlRespStringBuf);
} catch (IOException e) {
System.out.println("input stream error");
e.printStackTrace();
}
System.out.println("Done");
}
}
Any help would be appreciated...thanks.
Posted: Tue Oct 28, 2003 12:13 pm
by volka
hm, this only transfers a stream to and from a https-service. There's no other abstraction layer or business logic implemented. From the code's point of view it's absolutly irrelevant what's posted and received, it works on character-streams. That input and output might be xml and/or soap messages is ..hmm.. accidental at this stage.
http://php.net/curl can provide the same functionality.
Do you know what's behind the service?
Posted: Tue Oct 28, 2003 12:17 pm
by biz0r
It is an XML transaction system...used for ordering new services essentially (I don't know that I should say more info than that, I may breach an NDA). I know the XML layout...I am just ignorant when it comes to Java (I prefer to code in something thats not so butt fugly) which is why I wasn't sure if it was using some sort of proprietary protocol over HTTPS.
The input and output are both XML streams...I am just not certain as to how to send the XML stream/etc to the service.
Posted: Tue Oct 28, 2003 1:42 pm
by volka
if the xml stream is the wrapper for a higher protocol you definitively should see to get as close to that specification as you can without coding yourself.
If it is soap you might find the one or the other module for php.
And consider wether it isn't easier (in the long term) to stay with java. I'm not saying php can't do it but think about it this way: When an application (EJB) server is involved you can expect almost any kind of support (examples, APIs, documentation, ...) for java but near to none for php.
java/(xml)webservices is a hype, php/(xml)webservices isn't (bitter truth imho)
Posted: Tue Oct 28, 2003 1:49 pm
by biz0r
I guess I'll just try to investigate it more....worst case senario is I'll have to force myself to learn Java...oh well.
Thanks for your help, volka...