Reputation: 11
I'm trying to call a web service from my client (Java project on Eclipse), I've used wsimport to generate the classes (models) from the xsd and the service interface that acts as a proxy to the actual web service. The method from the service I'm calling accepts a requestElement and then is supposed to return a responseElement but I'm receiving this error:
Exception in thread "main" com.sun.xml.internal.ws.server.UnsupportedMediaException: Unsupported Content-Type: text/xml; charset=utf-8 Supported ones are: [application/soap+xml]
at com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:220)
at com.sun.xml.internal.ws.encoding.StreamSOAP12Codec.decode(StreamSOAP12Codec.java:88)
at com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:151)
at com.sun.xml.internal.ws.encoding.SOAPBindingCodec.decode(SOAPBindingCodec.java:299)
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.createResponsePacket(HttpTransportPipe.java:268)
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:217)
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:130)
at com.sun.xml.internal.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:124)
at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:1121)
at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:1035)
at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:1004)
at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:862)
at com.sun.xml.internal.ws.client.Stub.process(Stub.java:448)
at com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(SEIStub.java:178)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:93)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:77)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:147)
at com.sun.proxy.$Proxy31.calculateQuoteApplyWeb(Unknown Source)
at TestDestinyTax.main(TestDestinyTax.java:96)
Here's what the main driver code looks like:
public class TestTax {
public static void main(String[] args) throws SabrixLayerException_Exception, MalformedURLException {
java.net.URL wsdlUrl = new URL(/*hidden wsdlUrl*/);
TaxSabrixService_Service service = new TaxSabrixService_Service(wsdlUrl, new QName(/*hidden namespace and servicename*/));
TaxSabrixService taxService = service.getPort(TaxSabrixService.class);
BindingProvider bindingProvider = (BindingProvider) taxService;
bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, wsdlUrl.toString());
CalculateQuoteApplyWebElement req = new CalculateQuoteApplyWebElement();
QuoteApplyWebRequest quoteReq = new QuoteApplyWebRequest();
/*
* calculateQuoteApplyWebElement
* QuoteApplyWebRequest
* UserCredentials
* -userName
* -password
* List<InvoiceApplyWeb> invoices
* (InvoiceApplyWeb)
* -List<LineApplyWeb> list
* -Address billToAddressShipToAddress
* -Address shipFromAddress
*
*
*/
// credentials
UserCredentials credentials = new UserCredentials();
credentials.setUserName("userName");
credentials.setPassword("password");
// itemAmountPrefix
ItemAmountPrefix itemAmount = new ItemAmountPrefix();
itemAmount.setAmount(100.0);
itemAmount.setInvoicePrefix("CR");
itemAmount.setDiscount(0.0);
itemAmount.setItemID("");
// lineApplyWeb
LineApplyWeb line = new LineApplyWeb();
line.setItemAmount(itemAmount);
// Address setup
Address billToAddressShipToAddress = new Address();
Address shipFromAddress = new Address();
billToAddressShipToAddress.setPostalCode("85040");
billToAddressShipToAddress.setCountry("US");
billToAddressShipToAddress.setState("HI");
billToAddressShipToAddress.setPostalCodePlus4("");
billToAddressShipToAddress.setCity("Kona");
shipFromAddress.setPostalCode("41423");
shipFromAddress.setCountry("US");
shipFromAddress.setState("NM");
shipFromAddress.setPostalCodePlus4("");
shipFromAddress.setCity("");
// InvoiceApplyWeb setup
InvoiceApplyWeb invoice = new InvoiceApplyWeb();
invoice.getLines().add(line);
invoice.setBillToAddressShipToAddress(billToAddressShipToAddress);
invoice.setShipFromAddress(shipFromAddress);
// QuoteApplyWeb setup
quoteReq.setUserCredentials(credentials);
quoteReq.getInvoices().add(invoice);
// finish CalculateQuoteApplyWebElement setup
req.setQuoteApplyWebRequest(quoteReq);
//System.out.println( quoteWebElementToString(req) );
try{
System.out.println(taxService.calculateQuoteApplyWeb(req));
} catch (@SuppressWarnings("restriction") com.sun.xml.internal.ws.server.UnsupportedMediaException u) {
System.out.println("CAUGHT EXCEPTION: "+u.getMessage());
}
}
}
How can I change that Content-Type to application/soap_xml for the response? I'm assuming that's where the issue is.
Upvotes: 0
Views: 8453
Reputation: 1267
The problem is that the SOAP server is sending a bad response.
text/xml
application/soap+xml
See:
As we can see in your stacktrace, the current code tries to process the response as SOAP v1.2: StreamSOAP12Codec.decode(StreamSOAP12Codec.java:88)
.
But the server is sending the content type text/xml
, which is not supported.
So either the server/WSDL is lying (it's actually SOAP 1.1) or the server is sending a bad response, in which case it's the responsibility of the server to fix it.
You can try to modify your local client/WSDL to version 1.1, regenerate your model, and see if that solves it. You also mention 'acts as a proxy', is that just the generated code, or are you actually running a proxy between the client and the server? In that case you need to reconfigure the proxy.
Otherwise you'll have to either:
Some references on that last point:
Upvotes: 1