[ https://issues.apache.org/jira/browse/AXIS2-6091?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17941904#comment-17941904 ]
Jeff Thomas commented on AXIS2-6091: ------------------------------------ I am testing the following in my fork at the moment...I am not sure if this is the way to go but its a quick workaround on my side: I added these to HTTTPConstants: {code:java} /** Base QName namespace for HTTP errors. */ public static final String QNAME_HTTP_NS = "http://ws.apache.org/axis2/http"; /** QName for faults caused by a 400 Bad Request HTTP response. */ public static final QName QNAME_HTTP_BAD_REQUEST = new QName(QNAME_HTTP_NS, "BAD_REQUEST"); /** QName for faults caused by a 404 Not Found HTTP response. */ public static final QName QNAME_HTTP_NOT_FOUND = new QName(QNAME_HTTP_NS, "NOT_FOUND"); /** QName for faults caused by a 500 Internal Server Error HTTP response. */ public static final QName QNAME_HTTP_INTERNAL_SERVER_ERROR = new QName(QNAME_HTTP_NS, "INTERNAL_SERVER_ERROR");{code} In HTTPSender, I chanced the 401/404/500 handing to special-case content-type "text/html" and "text/xml"...the addition of the QNames will allow us to distinguish between the error types. {code:java} else if (statusCode == HttpStatus.SC_INTERNAL_SERVER_ERROR || statusCode == HttpStatus.SC_BAD_REQUEST || statusCode == HttpStatus.SC_NOT_FOUND) { // if the response has a HTTP error code (401/404/500) but is *not* a SOAP response, handle it here if (contentType.startsWith("text/html") || contentType.startsWith("text/xml")) { final String message = Messages.getMessage("transportError", String.valueOf(statusCode), request.getStatusText()); // throw a fault with the appropriate HTTP error QName final AxisFault scFault; switch (statusCode) { case HttpStatus.SC_BAD_REQUEST: { scFault = new AxisFault(message, QNAME_HTTP_BAD_REQUEST); break; } case HttpStatus.SC_NOT_FOUND: { scFault = new AxisFault(message, QNAME_HTTP_NOT_FOUND); break; } default: { scFault = new AxisFault(message, QNAME_HTTP_INTERNAL_SERVER_ERROR); break; } } parseFaultDetailFromHTTPResponseContent(request).ifPresent(scFault::setDetail); throw scFault; } processResponse = true; fault = true; } {code} I added 2 private methods to put the response body into a fault-detail: {code:java} /** * Parse a fault-detail from the given HTTP request - reading its content to a string and adding it as * a 'Text' node. * * @param request the request to process * @return an optional containing the parsed response body or empty if none could be obtained */ private Optional<OMElement> parseFaultDetailFromHTTPResponseContent(Request request) { final InputStream responseContentInputStream; try { responseContentInputStream = request.getResponseContent(); } catch (final IOException ex) { return Optional.empty(); } if (responseContentInputStream == null) { return Optional.empty(); } final String responseContent; try (BufferedReader reader = new BufferedReader(new InputStreamReader(responseContentInputStream))) { responseContent = reader.lines().collect(Collectors.joining("\n")).trim(); } catch (final IOException ex) { return Optional.empty(); } final OMElement faultDetail = OMAbstractFactory.getOMFactory().createOMElement(new QName("http://ws.apache.org/axis2", "Details")); final OMElement textNode = OMAbstractFactory.getOMFactory().createOMElement(new QName("http://ws.apache.org/axis2", "Text")); textNode.setText(wrapWithCDATA(responseContent)); faultDetail.addChild(textNode); return Optional.of(faultDetail); } private String wrapWithCDATA(String responseContent) { if (responseContent == null || responseContent.isEmpty()) { return "<![CDATA[The endpoint returned no response content.]]>"; } // Replace closing CDATA sequences properly String safeContent = responseContent.replace("]]>", "]]]]><![CDATA[>").replace("\n", " "); return "<![CDATA[" + safeContent + "]]>"; } {code} > Problem handling HTTP Response in OutInAxisOperationClient / TransportUtils > --------------------------------------------------------------------------- > > Key: AXIS2-6091 > URL: https://issues.apache.org/jira/browse/AXIS2-6091 > Project: Axis2 > Issue Type: Bug > Components: kernel > Affects Versions: 2.0.0 > Reporter: Jeff Thomas > Priority: Major > > I am testing upgrading to Axis2 2.0.0 (and associated Axiom 2.0.0 upgrade). > I am seeing a processing error when a HTTP 404 is received by an > OutInAxisOperationClient when an endpoint is not available (target > application not running) but the Tomcat instance is running. > The returned response obtained from the input-stream is: > > {code:java} > <!doctype html> > <html lang="en"> > <head> > <title>HTTP Status 404 – Not Found</title> > <style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} > h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 > {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} > .line {height:1px;background-color:#525D76;border:none;}</style> > </head> > <body> > <h1>HTTP Status 404 – Not Found</h1> > <hr class="line"/> > <p> > <b>Type</b> Status Report</p> > <p> > <b>Description</b> The origin server did not find a current > representation for the target resource or is not willing to disclose that one > exists.</p> > <hr class="line"/> > <h3>Apache Tomcat/11.0.5</h3> > </body> > </html> {code} > The stacktrace for the fault is as follows: > > > {code:java} > org.apache.axis2.AxisFault: org.apache.axiom.core.stream.StreamException: > com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character 'd' (code > 100) after '<!' (malformed comment?) > at [row,col {unknown-source}]: [1,3] > at org.apache.axis2.AxisFault.makeFault(AxisFault.java:431) > ~[axis2-kernel-2.0.0.2-PWC.jar:2.0.0.2-PWC] > at > org.apache.axis2.kernel.TransportUtils.createSOAPMessage(TransportUtils.java:116) > ~[axis2-kernel-2.0.0.2-PWC.jar:2.0.0.2-PWC] > at > org.apache.axis2.kernel.TransportUtils.createSOAPMessage(TransportUtils.java:68) > ~[axis2-kernel-2.0.0.2-PWC.jar:2.0.0.2-PWC] > at > org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:347) > ~[axis2-kernel-2.0.0.2-PWC.jar:2.0.0.2-PWC] > {code} > Ultimately it lands in this chain: > > * OutInAxisOperationClient#processResponse -> > * TransportUtils#createSoapMessage -> > * ... > * TransportUtils#createDefaultDocumentElement > It lands here because it cannot find any configured MessageBuilder for the > content-type "text/html". > Here it comes in this code: > > {code:java} > private static OMElement createDefaultDocumentElement(MessageContext > msgContext, > InputStream inStream, > String type) { > OMElement documentElement; > if (msgContext.isDoingREST()) { > if (log.isDebugEnabled()) { > log.debug("Could not find a Builder for type (" + type + "). > Using REST."); > } > OMXMLParserWrapper builder = BuilderUtil.createPOXBuilder(inStream, > null); > documentElement = builder.getDocumentElement(); > } else { > // FIXME making soap defualt for the moment..might effect the > // performance > if (log.isDebugEnabled()) { > log.debug("Could not find a Builder for type (" + type + "). > Using SOAP."); > } > String charSetEnc = (String) msgContext > .getProperty(Constants.Configuration.CHARACTER_SET_ENCODING); > SOAPModelBuilder builder = > BuilderUtil.createSOAPModelBuilder(inStream, charSetEnc); > documentElement = builder.getDocumentElement(); > } > return documentElement; > } {code} > > The '{{{}isDoingRest{}}}' returns _false_ and the {{contentType}} is > 'text/html' and encoding 'UTF-8'. > The exception is thrown trying to parse the HTML to SOAP: > {code:java} > documentElement = builder.getDocumentElement(); {code} > Possibly this is also related to the code in {{HTTPSender#send}} for handling > 404/500 HTTP responses? > > > {code:java} > else if (statusCode == HttpStatus.SC_INTERNAL_SERVER_ERROR > || statusCode == HttpStatus.SC_BAD_REQUEST || > statusCode == HttpStatus.SC_NOT_FOUND) { > processResponse = true; > fault = true; > }{code} > We would really like to get off our custom forks of Axis2/Axiom/Rampart - or > at least as close to the current release as possible but this is currently a > blocker for us. Our monitoring continuously polls endpoints that may or may > not be available and this generates loads of errors / stacktraces in our logs. > > I enabled the following parameter as a test to use the "UnknownBuilder" > > {code:java} > <parameter name="useDefaultFallbackBuilder">true</parameter> {code} > I didn't get the Axiom exception, but it only leads to a follow-up exception: > > > {code:java} > java.lang.IllegalArgumentException: The MessageContext does not have an > associated SOAPFault. > at > org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:533) > ~[axis2-kernel-2.0.0.2-PWC.jar:2.0.0.2-PWC] > at > org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:368) > ~[axis2-kernel-2.0.0.2-PWC.jar:2.0.0.2-PWC] > {code} > So all in all, if I am not analyzing this incorrectly, Axis2 doesn't seem to > be handling the case where an endpoint returns a 404/500 response that is > HTML and not SOAP (and probably other HTTP status as well (400 BAD_REQUEST, > 401 UNAUTHORIZED, 403 FORBIDDEN, 418 (I am a teapot! :P), ...). > > -- This message was sent by Atlassian Jira (v8.20.10#820010) --------------------------------------------------------------------- To unsubscribe, e-mail: java-dev-unsubscr...@axis.apache.org For additional commands, e-mail: java-dev-h...@axis.apache.org