bad request

User 870ab5b546

21-01-2016 15:12:01

Trying to get an MRV out of this drawing in Marvin JS:


<cml><MDocument><MChemicalStruct><molecule molID="m1"><atomArray><atom id="a1" elementType="C" x2="-6.159999847412109" y2="2.0693750083446503"/><atom id="a2" elementType="C" x2="-5.389999847412109" y2="0.7356958865166148" formalCharge="1"/><atom id="a3" elementType="C" x2="-6.1599998474121085" y2="-0.597983235311421"/><atom id="a4" elementType="N" x2="-3.849999847412109" y2="0.7356958865166148" lonePair="1"/><atom id="a5" elementType="C" x2="-3.0799998474121084" y2="-0.5979832353114207"/><atom id="a6" elementType="C" x2="-3.0799998474121084" y2="2.0693750083446503"/><atom id="a7" elementType="C" x2="2.0212499713897705" y2="2.007429105138735"/><atom id="a8" elementType="C" x2="2.791249971389771" y2="0.6737499833106997"/><atom id="a9" elementType="C" x2="2.0212499713897714" y2="-0.659929138517336"/><atom id="a10" elementType="N" x2="4.331249971389771" y2="0.6737499833106997" formalCharge="1"/><atom id="a11" elementType="C" x2="5.101249971389771" y2="-0.6599291385173358"/><atom id="a12" elementType="C" x2="5.101249971389771" y2="2.007429105138735"/></atomArray><bondArray><bond atomRefs2="a1 a2" order="1" id="b1"/><bond atomRefs2="a2 a3" order="1" id="b2"/><bond atomRefs2="a2 a4" order="1" id="b3"/><bond atomRefs2="a4 a5" order="1" id="b4"/><bond atomRefs2="a4 a6" order="1" id="b5"/><bond atomRefs2="a7 a8" order="1" id="b6"/><bond atomRefs2="a8 a9" order="1" id="b7"/><bond atomRefs2="a8 a10" order="2" id="b8"/><bond atomRefs2="a10 a11" order="1" id="b9"/><bond atomRefs2="a10 a12" order="1" id="b10"/></bondArray></molecule></MChemicalStruct><MElectronContainer occupation="1 1" radical="0" id="o1"><MElectron atomRefs="m1.a4" difLoc="0.0 0.0 0.0"/><MElectron atomRefs="m1.a4" difLoc="0.0 0.0 0.0"/></MElectronContainer><MEFlow id="o2" arcAngle="270" baseElectronContainerIndex="0" baseElectronIndexInContainer="-1"><MEFlowBasePoint atomRef="m1.a4"/><MAtomSetPoint atomRefs="m1.a2 m1.a4"/></MEFlow><MRectangle lineColor="#000000" id="o3"><MPoint x="-7.349999904632568" y="-2.0999999046325684"/><MPoint x="-1.8083332777023315" y="-2.0999999046325684"/><MPoint x="-1.8083332777023315" y="3.616666555404663"/><MPoint x="-7.349999904632568" y="3.616666555404663"/></MRectangle><MRectangle lineColor="#000000" id="o4"><MPoint x="0.7291671633720398" y="-2.0999999046325684"/><MPoint x="6.270833790302277" y="-2.0999999046325684"/><MPoint x="6.270833790302277" y="3.616666555404663"/><MPoint x="0.7291671633720398" y="3.616666555404663"/></MRectangle><MPolyline headLength="0.6" headWidth="0.4" tailLength="0.6" tailWidth="0.4" tailFlags="1" id="o5"><MPoint x="-1.8083332777023315" y="0.7583333253860474"/><MRectanglePoint rectRef="o4" pos="7"/></MPolyline></MDocument></cml>

I get these errors in the Javascript console:


[Error] Failed to load resource: The network connection was lost. (answerframe.jsp, line 0)
[Error] Failed to load resource: the server responded with a status of 400 (Bad Request) (molExport, line 0)

Happens on both Chrome for PC and Safari for Mac. No such problem when I submit the same structure without the electron-flow arrow. ???


Could this problem be related to this one? If so, will upgrading Java WebServices solve the problem?


Using MarvinJS 15.12.14.


Javascript code is:


function callServer(evaluate) {

marvinSketcherInstance.exportStructure('mrv').then(function(source) {
if (marvinSketcherInstance.getStructureInfo
&& marvinSketcherInstance.getStructureInfo().
atomCount === 0) {
toAlert('ACE could not acquire your response to this question. Please submit a response that is not empty.');
return;
} // if response is empty

if (navigator.appName.toUpperCase().match(/NETSCAPE/)) { // breaks on Internet Explorer
if (getSelection().removeAllRanges) { // must check availability for Safari
getSelection().removeAllRanges(); // unselect for Firefox
} // if can remove all ranges
} // if browser
var submissionBld = new String.builder();
var selections = '';
var rxnIds = null;



selections =

marvinSketcherInstance.getSelection()['atoms'];


var molstruct =

source;

// alert('got molstruct from applet:\n' + molstruct);
if (molstruct.indexOf('mrvAlias') >= 0 && true) {
toAlert('You probably meant to add a shortcut group such as Ph or Et to your structure, but you added an atom alias instead. (Aliases and shortcut groups look alike, but ACE cannot interpret aliases properly.) To replace the alias with a shortcut group, type the name of the shortcut group in the Marvin window (not in the textbox in the More window), then click on the alias.');
return;
} // if response contains an alias
if (molstruct.indexOf('z3=') > 0
&& (molstruct.indexOf('<bondStereo>W') > 0
|| molstruct.indexOf('<bondStereo>H') > 0)) {
if (!toConfirm('Your response appears to be in 3D mode and to contain stereo bonds such as bold or hashed wedges. When a drawing is in 3D mode, ACE ignores the stereochemical information conveyed by stereo bonds. Do you still want to submit your response?')) {
toAlert('To convert your drawing back into 2D mode, either click on "3D" in the lower left corner of the applet, or choose Structure &rarr; Clean 2D &rarr; Clean in 2D. Then you can redraw your wedge bonds.');
return;
} // if no confirm
} // if response is in 3D and has wedge bonds
submissionBld.append(molstruct);

var submissionStr = submissionBld.toString();
// alert('submission =\n' + submissionStr);
if (isEmpty(submissionStr)) {
toAlert('ACE could not acquire your response to this question. Please submit a response that is not empty.');
return;
} // if response is empty string
var toSend = new String.builder();

toSend.append('submission=').
append(encodeURIComponent(submissionStr));

// evaluate is false for save without submitting
toSend.append('&currentQNum=4&haveNewResponse=true'
+ '&evaluate=').append(evaluate);
if (!isEmpty(selections)) toSend.append('&selections=').append(selections);
if (!isEmpty(rxnIds)) toSend.append('&rxnIds=').append(rxnIds);
// alert('calling 'answerframe.jsp' with params ' + toSend.toString());
setInnerHTML('submitCell', '<span class="boldtext">Processing... Please wait...<\/span>');
clearInnerHTML('statusText');
clearInnerHTML('status2Text');
clearInnerHTML('feedbackText');
callAJAX('answerframe.jsp', toSend.toString());

}, function(error) {
alert('Molecule export failed:' + error);
});

} // callServer

User 870ab5b546

21-01-2016 19:59:42

OK, I upgraded to JChem WebServices 16.1.18. No change in behavior.


If I click on the bad request error in the Javascript console, I get this further information:


{"errorCode":3,"errorMessage":"Cannot read molecule file.","rootCause":"java.io.IOException","rootErrorMessage":"Cannot read empty molecule file"}

Here's what's really weird. If I add a single H atom to one of the C atoms on either structure, then I can submit the drawing (I don't get a bad request error). If I remove the electron-flow arrow or add a second one to the structure on the left, I can submit. However, if I replace any of the CH3 groups (or more than one) in either structure with H atoms, then I can't submit. Also, if I shift the position of either structure upwards or downwards by a sufficient amount (staying within the existing boxes), then I can submit.


What is going on here???

ChemAxon 7c2d26e5cf

22-01-2016 11:24:32

Hi Bob,


By checking the error message, I assume the problem may be in the AJAX request.


I am curios how you call the molconvert webservice.


I have tested the given structure with JChem WS 16.1.18 and I have not found any error.


My Ajax request was built up like this:


{ url: "/webservices2/rest-v0/util/calculat…", type: "post", data: "{"structure":"<cml><MDocument><MChe…", contentType: "application/json" }


Are you sure that you used "post" type and "application/json" contentType?

User 870ab5b546

22-01-2016 14:47:51

We've been using the same code for years and years. Here it is:


// create the AJAX object
function getXmlHttp() {
"use strict";
/* Create a new XMLHttpRequest object to talk to the Web server
* Code from
* http://www-128.ibm.com/developerworks/web/library/wa-ajaxintro1.html
*/
xmlHttp = false;
if (!xmlHttp && XMLHttpRequest !== undefined) {
xmlHttp = new XMLHttpRequest();
}
return xmlHttp;
} // getXmlHttp

// send the response to the server
function callAJAX(url, toSend, method) {
"use strict";
xmlHttp.open('POST', url, true);
xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlHttp.onreadystatechange = (!method ? updatePage : method);
xmlHttp.setRequestHeader('Accept', 'message/x-jl-formresult');
xmlHttp.send(toSend);
}

Note that the error occurs only with a very specific set of responses.


One more bit of information: The error does not occur on a system using JChem Web Services 15.9.14 and Marvin JS 15.7.20. So the bug seems to have been introduced more recently.


Another bit of information: The AJAX request is going through. The failure occurs in the processing of answerframe.jsp, where the following line throws a NullPointerException:


final String prefersJavaParam = request.getParameter("prefersJava");

Again, this error only occurs with a very narrow range of responses. What about this very narrow range of responses could make the HTTP request null?

User 870ab5b546

26-01-2016 18:47:31

I've created a way for you to duplicate the problem.



  1. Go to https://epoch.uky.edu/ace and login as student2, password doh! (with the exclamation point).

  2. Click on Test course, then Assignments, then Structure won't submit.

  3. Next to question 1, press Practice. On the lower left, note where it says, Please submit your first response.

  4. Press Submit Response. On the lower left, note that the box where it used to say, Please submit your first response, now has no feedback. That's the problem. Feedback that begins, Excellent! should appear there.

  5. Now alter the response by moving the structures and by expanding the sides of one or more rectangles, and submit. Eventually, you will find a structure that submits, and you will get feedback that begins, Excellent!

  6. If you press Switch to MarvinSketch above the Marvin JS canvas, you will also be able to submit the initial structure.


I'd really appreciate some help solving this problem before it manifests for another student. Thanks.

ChemAxon 7c2d26e5cf

01-02-2016 09:49:01

Hi Bob,


Thanks for the access to the site. It helps a lot to detect the problem.


Indeed, the molExport services returns with 400 error code because it can not parse the empty string as MRV. See the request:



  1. {"structure":"", "parameters":"mrv"}

ChemAxon 7c2d26e5cf

01-02-2016 11:05:48

Hi Bob,


Something is still not clear for me in the code. I drop you an email to discuss it.

User 870ab5b546

22-02-2016 17:55:14

With help from Stack Overflow, we diagnosed and eliminated the problem.


We recently switched from http to https. Under https, the browser and server use certain SSL cipher protocols to communicate. Apparently, there's a bug associated with the AES ciphers (whatever those are). Changing the server configuration to remove AES/GCM from the list of acceptable ciphers eliminated the problem. 


We also found that among the Mac browsers, although Safari and Chrome chose the AES protocol if it was available, and thereby manifested the bug, Firefox did not.


I still don't know what property of a URI causes the AES bug to manifest, but I guess I don't need to know anymore.


Thanks for your help on this problem. Good to know it's unrelated to Marvin JS.

ChemAxon 76c88f5366

23-02-2016 10:17:47

Hi,


We are happy to hear that the problem has been solved.


Thank you for the feedback.