Jump to:
| Project: | netFORUM xWeb Interface |
| Version: | 6.x-1.0 |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | james.michael-hill |
| Status: | closed (fixed) |
Issue Summary
I am trying to create a user in netForum from a Drupal Webform.
Using a webform hook, I am calling two functions to take a users email address and first and last name, and create a netforum account when a user submits basic webforms.
However, the form times out when I hit submit, and the watchdog error from Netforum is 'could not fetch http headers'. Have I done something wrong in my implementation?
function inclind_form_webform_submission_insert($node, $submission) {
// find the email address in the form
$form_fields = $node->webform['components'];
foreach ($form_fields as $key => $value) {
$arguments = array();
$response = '';
if ($value['type'] == 'email') {
$arguments = array(
'emailToMatch' => $submission->data[$key]['value'][0]
);
$response = netforum_xweb_request('WEBWebUserFindUsersByEmail', $arguments, NULL);
if (!isset($response) || $response->{@attributes}['recordResult'] == 0) {
inclind_form_create_netforum_user($form_fields, $submission);
}
}
}
return;
}
/*
* Create a user in netForum based on form data
*
* @param $form_fields
* The form structure passed in from inclind_form_webform_submission_insert
* @param $submission
* The form data passed in from inclind_form_webform_submission_insert
*/
function inclind_form_create_netforum_user($form_fields, $submission) {
$arguments = array();
$arguments['oWebUser']['Individual'] = array();
$arguments['oWebUser']['Email'] = array();
$arguments['oWebUser']['Customer'] = array();
$arguments['oWebUser']['Business_Address'] = array();
$arguments['oWebUser']['Business_Phone'] = array();
$arguments['oWebUser']['Business_Phone_XRef'] = array();
$arguments['oWebUser']['Business_Fax'] = array();
$arguments['oWebUser']['Business_Fax_XRef'] = array();
foreach ($form_fields as $key => $value) {
if ($value['form_key'] == 'ind_first_name') {
$arguments['oWebUser']['Individual']['ind_first_name'] = $submission->data[$key]['value'][0];
}
if ($value['form_key'] == 'ind_last_name') {
$arguments['oWebUser']['Individual']['ind_last_name'] = $submission->data[$key]['value'][0];
}
if (strlen($arguments['oWebUser']['Individual']['ind_first_name']) && strlen($arguments['oWebUser']['Individual']['ind_last_name'])) {
$arguments['oWebUser']['Individual']['ind_full_name'] = $arguments['oWebUser']['Individual']['ind_first_name'] . ' ' . $arguments['oWebUser']['Individual']['ind_last_name'];
}
if ($value['form_key'] == 'eml_address') {
$arguments['oWebUser']['Email']['eml_address'] = $submission->data[$key]['value'][0];
$arguments['oWebUser']['Customer']['cst_web_login'] = $submission->data[$key]['value'][0];
$arguments['oWebUser']['Customer']['cst_new_password'] = user_password(20);
$arguments['oWebUser']['Customer']['cst_new_password_confirm'] = $arguments['oWebUser']['Customer']['cst_new_password'];
}
if ($value['form_key'] == 'adr_post_code') {
$arguments['oWebUser']['Business_Address']['adr_post_code'] = $submission->data[$key]['value'][0];
}
}
if (!isset($arguments['oWebUser']['Business_Address']['adr_city'])) {
$arguments['oWebUser']['Business_Address']['adr_city'] = 'Not Given';
}
if (!isset($arguments['oWebUser']['Business_Address']['adr_state'])) {
$arguments['oWebUser']['Business_Address']['adr_state'] = 'NA';
}
if (!isset($arguments['oWebUser']['Business_Address']['adr_post_code'])) {
$arguments['oWebUser']['Business_Address']['adr_post_code'] = '00000';
}
if (!isset($arguments['oWebUser']['Business_Address']['adr_country'])) {
$arguments['oWebUser']['Business_Address']['adr_country'] = 'Not Given';
}
if (!isset($arguments['oWebUser']['Business_Phone']['phn_number'])) {
$arguments['oWebUser']['Business_Phone']['phn_number'] = '000-000-0000';
}
if (!isset($arguments['oWebUser']['Business_Phone_XRef']['cph_extension'])) {
$arguments['oWebUser']['Business_Phone_XRef']['cph_extension'] = '000';
}
if (!isset($arguments['oWebUser']['Business_Fax']['fax_number'])) {
$arguments['oWebUser']['Business_Fax']['fax_number'] = '000-000-0000';
}
$response = netforum_xweb_request('WEBWebUserCreate', $arguments, '1 min');
watchdog('netforum', 'netforum user @user created', array('@user' => $arguments['oWebUser']['Email']['eml_address']), WATCHDOG_NOTICE);
}
Comments
#1
Guh... can't edit original post. Sorry:
<?php
function inclind_form_webform_submission_insert($node, $submission) {
// find the email address in the form
$form_fields = $node->webform['components'];
foreach ($form_fields as $key => $value) {
$arguments = array();
$response = '';
if ($value['type'] == 'email') {
$arguments = array(
'emailToMatch' => $submission->data[$key]['value'][0]
);
$response = netforum_xweb_request('WEBWebUserFindUsersByEmail', $arguments, NULL);
if (!isset($response) || $response->{@attributes}['recordResult'] == 0) {
inclind_form_create_netforum_user($form_fields, $submission);
}
}
}
return;
}
/*
* Create a user in netForum based on form data
*
* @param $form_fields
* The form structure passed in from inclind_form_webform_submission_insert
* @param $submission
* The form data passed in from inclind_form_webform_submission_insert
*/
function inclind_form_create_netforum_user($form_fields, $submission) {
$arguments = array();
$arguments['oWebUser']['Individual'] = array();
$arguments['oWebUser']['Email'] = array();
$arguments['oWebUser']['Customer'] = array();
$arguments['oWebUser']['Business_Address'] = array();
$arguments['oWebUser']['Business_Phone'] = array();
$arguments['oWebUser']['Business_Phone_XRef'] = array();
$arguments['oWebUser']['Business_Fax'] = array();
$arguments['oWebUser']['Business_Fax_XRef'] = array();
foreach ($form_fields as $key => $value) {
if ($value['form_key'] == 'ind_first_name') {
$arguments['oWebUser']['Individual']['ind_first_name'] = $submission->data[$key]['value'][0];
}
if ($value['form_key'] == 'ind_last_name') {
$arguments['oWebUser']['Individual']['ind_last_name'] = $submission->data[$key]['value'][0];
}
if (strlen($arguments['oWebUser']['Individual']['ind_first_name']) && strlen($arguments['oWebUser']['Individual']['ind_last_name'])) {
$arguments['oWebUser']['Individual']['ind_full_name'] = $arguments['oWebUser']['Individual']['ind_first_name'] . ' ' . $arguments['oWebUser']['Individual']['ind_last_name'];
}
if ($value['form_key'] == 'eml_address') {
$arguments['oWebUser']['Email']['eml_address'] = $submission->data[$key]['value'][0];
$arguments['oWebUser']['Customer']['cst_web_login'] = $submission->data[$key]['value'][0];
$arguments['oWebUser']['Customer']['cst_new_password'] = user_password(20);
$arguments['oWebUser']['Customer']['cst_new_password_confirm'] = $arguments['oWebUser']['Customer']['cst_new_password'];
}
if ($value['form_key'] == 'adr_post_code') {
$arguments['oWebUser']['Business_Address']['adr_post_code'] = $submission->data[$key]['value'][0];
}
}
if (!isset($arguments['oWebUser']['Business_Address']['adr_city'])) {
$arguments['oWebUser']['Business_Address']['adr_city'] = 'Not Given';
}
if (!isset($arguments['oWebUser']['Business_Address']['adr_state'])) {
$arguments['oWebUser']['Business_Address']['adr_state'] = 'NA';
}
if (!isset($arguments['oWebUser']['Business_Address']['adr_post_code'])) {
$arguments['oWebUser']['Business_Address']['adr_post_code'] = '00000';
}
if (!isset($arguments['oWebUser']['Business_Address']['adr_country'])) {
$arguments['oWebUser']['Business_Address']['adr_country'] = 'Not Given';
}
if (!isset($arguments['oWebUser']['Business_Phone']['phn_number'])) {
$arguments['oWebUser']['Business_Phone']['phn_number'] = '000-000-0000';
}
if (!isset($arguments['oWebUser']['Business_Phone_XRef']['cph_extension'])) {
$arguments['oWebUser']['Business_Phone_XRef']['cph_extension'] = '000';
}
if (!isset($arguments['oWebUser']['Business_Fax']['fax_number'])) {
$arguments['oWebUser']['Business_Fax']['fax_number'] = '000-000-0000';
}
$response = netforum_xweb_request('WEBWebUserCreate', $arguments, '1 min');
watchdog('netforum', 'netforum user @user created', array('@user' => $arguments['oWebUser']['Email']['eml_address']), WATCHDOG_NOTICE);
}
?>
#2
Nothing is jumping out at me there in the code as looking incorrect. Just to walk through the basics, have you confirmed that basic fetch queries work? What about running it in the xWeb testing page in the admin section with a basic set of information to see if it works there? That will show you the actual soap request and response which you may be able to put into something external, there is a chance that the request being generated is incorrect. Do you have access to the netFORUM server to check the logs there?
#3
Yeah, I tested the same info in the xWeb Test section of the admin, and, even though it took about 1-2 minutes to respond, I definitely got a response. The PHP array was right, the Response code had a populated object with customer key (brand new), and the SOAP header responded with 200 OK.
I have to have someone look into the netForum side of things- we are not allowed access.
#4
If it helps, this never gets called:
<?phpwatchdog('netforum', 'netforum user @user created', array('@user' => $arguments['oWebUser']['Email']['eml_address']), WATCHDOG_NOTICE);
?>
#5
Well, if it works for you everywhere else except in that section then I think the next thing is to try running it manually and catching your own error in that section of code so you can see the same request/response/wire dump that you would get from the xWeb testing page and compare for differences. Try something like this:
<?php$nfh = netforum_connect_xweb();
try{
$response = $nfh->WEBWebUserCreate($arguments);
}
catch(Exception $e) {
print "****CAUGHT EXCEPTION: \n";
print "xwebSecure class log:\n";
print $nfh->log;
print "exception contents:\n";
print_r($e);
print "soap headers, request and response strings:\n";
print "Last Request Headers:\n";
print_r($nfh -> __getLastRequestHeaders());
print "\nLast Request :\n";
print_r($nfh -> __getLastRequest());
print "\nLast Response Headers :\n";
print_r($nfh -> __getLastResponseHeaders());
print "\nLast Response :\n";
print_r($nfh -> __getLastResponse());
print "\n";
}
?>
Of course, print statements are probably not the best choice for output there in the page and I have not tested this, but I hope you get the gist of what I'm trying to have it do which is run the soap request more directly, and get more information about any errors.
#6
I'm upping default socket timeout to test what I read here: http://www.aidanfindlater.com/php-soap-client-giving-error-fetching-http...
<?php
ini_set('default_socket_timeout', 800);
?>
Even with that set, or a higher number like 10000, I still get 'error getting http headers'- HOWEVER, watchdog reports that the user was created. The page itself refreshes to a 'website is not responding' error, then when I refresh, I see a drupal message: "Could not retreive data from server or cache."
If this is a case of a slow SOAP server, it kind of makes this effort futile unless I ran a cron job against daily submissions to do this task, but even then the server would crap out.
Is this an issue on netForums side?
#7
Okay, trying whats in #5 right now.
#8
Good catch with the timeout bits, I remember munging them a little bit in a few other places but didn't connect them with your issue. As for speed, you can see if it is faster with a smaller set of information, like just the name and password or by building your own request and using curl as outlined on http://gaintest.net/blog/?p=7 - from the avectra wiki it sounds like netforum should be okay. Can you try the request from another machine in case it is something between the two servers?
#9
Initially I only had first name, last name, and email address, but it seems netForum requires more than that for an Web User (hence the dummy data).
This time, the page still timed out, but in watchdog there is a new error:
'SoapClient::__doRequest() [soapclient.--dorequest]: SSL: Connection reset by peer in (site root path)/netforum/xwebSecureClient.class.inc on line 144.'
#10
By commenting out line 144 __doRequest, it then fails with the same error on line 102:
<?php$response = parent::__soapCall($fname, $arguments, null, $this->getAuthHeaders(), $responseHeaders);
?>
It seems like the try() can't complete and the catch/print statements are not hit?
#11
Maybe this is a clue. I ran WEBWebUserCreate from the xWeb testing interface again, this time, I put in USA for the country, and this was the error:
"Could not get response to WEBWebUserCreate request: System.Web.Services.Protocols.SoapException: The statement has been terminated. The INSERT statement conflicted with the FOREIGN KEY constraint "FK_co_address_co_country". The conflict occurred in database "netFORUMTIATEST", table "dbo.co_country", column 'cty_code'. at Avectra.netForum.xWeb.xWebSecure.netForumXMLSecure.WEBWebUserCreate(CO_WebUser oWebUser)"
After changing it to UNITED STATES, I got a response in about 30 seconds with a populated object. I am going to change the dummy data to something real, like DC, 20001, and UNITED STATES, and see what the result is.
#12
I am being told the accounts are being created in netForum even though it is timing out. Hmm.
#13
Yeah, the only time I get the print statements is if I leave out a field like Business_Phone_XRef. Then it does the catch statements and it says that wasn't included. I put it back in, and the request times out.
It's odd how the backend interface seems to do it, but using the same construction from the testing code, it craps out.
#14
DOH! Now I see why!
<?php
if (!isset($arguments['oWebUser']['Business_Fax_XRef']['fax_number'])) {
$arguments['oWebUser']['Business_Fax_XRef']['fax_number'] = '000';
}
?>
Wrong key! fax_number should be cph_extension. My bad. Thanks for your help.
#15
#16
Ah! Glad you found it! It sounds like you picked up a lot of useful information, good luck with the continued integration!
#17
Automatically closed -- issue fixed for 2 weeks with no activity.