Jump to content

Java - PHP webservice issue


v2kea412

Recommended Posts

I have a need to synchronously communicate XML over HTTPS using POST.  The originating server is using Java servlets to call my URL.  I can see the XML payload in $HTTP_RAW_POST_DATA and can process what I need to do on my end just fine.  Part of the synchronous transmission is to let the Java servlet that I received the XML just fine.  My PHP code simply echo's back the XML response as such:

if (isset($HTTP_RAW_POST_DATA)) {

// Setup variables

// $errors = array();

 

$act = new Activity(4,1);

$xml = $HTTP_RAW_POST_DATA;

$transaction = new xmlTransaction($xml, $act->Id);

$transaction->writeXaction();

$xmlOut = $transaction->sendResponse();

// Send Header with payload

header("Content-type: text/xml");

echo $xmlOut;

}

 

In my test environment, using cURL, I can retrieve the XML verifying the send, but on their end, they say they see nothing...  It is almost as if they are expecting something to be sent back to them, but not sure how to accomplish that.

 

Perhaps it is my ignorance of web services, but I think I am missing something....  Any ideas out there?

Link to comment
Share on other sites

What does your cURL code look like? it should be something like:

 

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_exec($ch);
?>

Link to comment
Share on other sites

Here is what my test environment client has, omitted purposely is the xml payload and url...

 

//open connection   
$ch = curl_init();   
  
//set the url, number of POST vars, POST data   
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch,CURLOPT_URL,$url);   
curl_setopt($ch,CURLOPT_POST,false);   
curl_setopt($ch,CURLOPT_POSTFIELDS,$xml);   
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  
//execute post   
$result = curl_exec($ch);   

echo $result;  
//close connection   
curl_close($ch);  

 

And like I said, this does show me what I thought they would see when called from their Java Servlet...But they say they are not receiving anything...

 

The only other thing to note, and not sure if it would make a difference, is that I am also emailing the XML response to myself for debugging purposes in my listening script...

Link to comment
Share on other sites

I believe I had the POST set to true in an earlier test.  That said, my issue is not necessarily with my client-side test.  I am more focused on what I have to do differently to get the acknowledgment back to them after I process the request.

 

Here is the code of my listener:

<?php

require("trex.classes.inc.php");

if (isset($HTTP_RAW_POST_DATA)) {
// Setup variables
// $errors = array();

$act = new Activity(4,1);
$xml			= $HTTP_RAW_POST_DATA;
$transaction	= new xmlTransaction($xml, $act->Id);
$transaction->writeXaction();
$xmlOut = $transaction->sendResponse();
// Send Header with payload
header("Content-type: text/xml");
echo $xmlOut;
sendRequest($transaction->raw, $xmlOut);
unset($transaction);
unset($act);
}
?>

 

Should I be using some other functions to get the $xmlOut to them? like HTTPResponse class or something similar?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.