问题描述:

I'm currently struggling with some strange behavior of my Tomcat server in connection to Cross-Origin Requests. Here is the situation: My structure consists of two local running Tomcats. The first one (localhost:9090) schould fetch data from the second one (localhost:8080). Therefore I'm using REST-calls with JSON responses and some SOAP-calls to receive XML data. Now here comes the part which makes me worrying: If I make a REST-call all works perfectly fine but as soon as I'm trying to send a SOAP-call the answer is a HTTP 403 Forbidden error with the console warning Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8080/[SOAP-PATH]. (Reason: CORS header 'Access-Control-Allow-Origin' missing).

For both Tomcat servers I added an CORS filter at the web.xml

<filter>

<filter-name>CorsFilter</filter-name>

<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>

</filter>

<filter-mapping>

<filter-name>CorsFilter</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

Here you can see the both calls

REST call with JSON

SOAP call with XML


Both calls are sent from an AngularJS service.

For the REST call i´m using a simple $http-call

$http({

method: "GET",

url: "http://localhost:8080/[REST-CALL]"

});

For the SOAP call, it´s a bit more commplex:

var wsUrl = "http://localhost:8080/[SOAP-PATH]";

var soapRequest =

'<?xml version="1.0" encoding="UTF-8"?> \

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" \

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" \

xmlns:xsd="http://www.w3.org/2001/XMLSchema"> \

<soapenv:Header /> \

<soapenv:Body> \

[SOAP_DATA]

</soapenv:Body> \

</soapenv:Envelope>';

var config = {

headers : {

'SOAPAction': wsUrl,

'Content-Type': 'text/xml'

}

};

$http.post(wsUrl, soapRequest, config);

As you can see I'm adding the headers SOAPAction and Content-Type but they aren´t displayed correct in my opinion as you can see framed green in the picture of the SOAP call.

Can you guys help me to figure out whats wrong with the SOAP calls? At the end the SOAP-calls should work as well as the REST calls.

相关阅读:
Top