1

I have a Java code base that returns me a java.util.List that I consume in my Scala layer as below:

    import scala.collection.JavaConverters._

    val myList = myServiceClient.getMyList.asScala.toList //fails here!

    println(myList)

I then hit the following error:

Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: scala.collection.immutable.$colon$colon cannot be cast to java.util.List
    at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:161)
    at com.sun.proxy.$Proxy49.getSlaveList(Unknown Source)
    at Test$.main(Test.scala:35)
    at Test.main(Test.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: java.lang.ClassCastException: scala.collection.immutable.$colon$colon cannot be cast to java.util.List
    at org.apache.cxf.binding.soap.SoapMessage.getHeaders(SoapMessage.java:56)
    at org.apache.cxf.binding.soap.interceptor.SoapHeaderOutFilterInterceptor.handleMessage(SoapHeaderOutFilterInterceptor.java:37)
    at org.apache.cxf.binding.soap.interceptor.SoapHeaderOutFilterInterceptor.handleMessage(SoapHeaderOutFilterInterceptor.java:29)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
    at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:514)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:423)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:324)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:277)
    at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
    at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:139)
    ... 8 more
6
  • Which Scala version? Commented Nov 12, 2015 at 16:38
  • I'm on 2.11.6 scala! Commented Nov 12, 2015 at 16:39
  • All I'm doing is just using Java classes generated by Apache CXF Client generator in my Scala code base! Commented Nov 12, 2015 at 16:41
  • Can you give a reproducible code snippet (with a Java collection that is causing the issue)? Commented Nov 12, 2015 at 17:12
  • According to the stack trace, I suspect you are not even making it to the conversion part. It seems to me that you are having a problem calling the web service. Are you sure you are not passing in a scala type to some java service? What happen if you remove the conversion part? Commented Nov 12, 2015 at 19:20

1 Answer 1

1

So the original problem was a couple of lines above in my code base to what I posted in my original question:

I had to do the following when I pass the List to the Apache CXF library:

   val headerList = Seq(
        new Header(new QName("http://www.myService.com/MyServices/", "UserName"), "", new JAXBDataBinding(classOf[String])),
        new Header(new QName("http://www.myService.com/MyServices//", "Password"), "", new JAXBDataBinding(classOf[String]))
    )

    import scala.collection.JavaConverters._
    proxy.getRequestContext.put(Header.HEADER_LIST, headerList.asJava)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.