0

I've got a bundle which needs to communicate with a web service. The client was generated using Apache CXF, the WSDL of the web service is a local file, because the target system doesn't host the WSDL.

How can I integrate the WSDL into my OSGi bundle? Currently the web service client points to a file path of the WSDL which is pretty unuseful for deployment. Is there any way I can put the WSDL into the OSGi bundle? I tought about the resources folder, but there is none in my OSGi bundle.

This is the relevant part of the Java class:

@WebServiceClient(name = "WebService", targetNamespace = "http://company.com/target/namespace", wsdlLocation = "/tmp/WebService.wsdl")
public class WebService

After trying out this article, my code looks like this:

static {
        URL url = null;
        WebServiceException e = null;
        try {
            url =  XI07D2B3188DService.class.getClassLoader().getResource("WebService.wsdl");
        } catch (Exception ex) {
            e = new WebServiceException(ex);
        }
        XI07D2B3188DSERVICE_WSDL_LOCATION = url;
        XI07D2B3188DSERVICE_EXCEPTION = e;
    }

The error with the not found WSDL is now gone, but I've got a new error:

500 XML reader error: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]
Message: Content is not allowed in prolog.

This is the beginning of my WSDL:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="SI_PARTNER_OPENTIMES_OA" targetNamespace="http://company.ch/xi/partnernet/partner" xmlns:p1="http://company.ch/xi/partnernet/partner" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <wsdl:documentation />
  <wsp:UsingPolicy wsdl:required="true" />
  <wsp:Policy wsu:Id="OP_SI_PARTNER_OPENTIMES_OA" />

I have already checked this question on SO. I tried changing it to UTF-16 but that didn't help. I also copied the content within Eclipse into a new file, but I've still got this error. Any idea?

Community
  • 1
  • 1
Ahatius
  • 4,777
  • 11
  • 49
  • 79
  • See [here](http://illegalargumentexception.blogspot.co.uk/2011/04/java-jax-ws-web-services-and-clients.html#ws_client) for a JAX-WS example loading the WSDL from the classpath in an unmanaged client. – McDowell Apr 18 '14 at 18:32
  • @McDowell While this works as normal Java Code, I have to specify my WSDL location as parameter of an annotation (updated the question for clarification). I don't know if and how I can reference the file from there. – Ahatius Apr 18 '14 at 20:37
  • _wsdlLocation_ is only a logical path and can be ignored at runtime. If you have a specific exception in your code state what that is and what exception you are getting. Show some code. – McDowell Apr 18 '14 at 20:57
  • @McDowell I now tried your link. See updated question for more details. I can post you the whole web service code, but it's autogenerated and actually looks pretty ugly. – Ahatius Apr 18 '14 at 21:31
  • _Content is not allowed in prolog_ can be caused by a number of reasons but the `encoding="UTF-8"` declaration needs to match the [actual encoding](http://illegalargumentexception.blogspot.co.uk/2010/09/java-content-is-not-allowed-in-prolog.html) of the document. This is a separate issue to any OSGi-related problems. – McDowell Apr 20 '14 at 21:32
  • @McDowell I have checked the document with a hex editor, and the hex values of the characters do match the UTF-8 table - doesn't look like a formatting problem to me :\. Also I can't see any "invisible" signs using the hex-editor, the XML seems fine (it works as it is when referenced from disk). – Ahatius Apr 21 '14 at 08:25

1 Answers1

0

Since I couldn't get it to include the WSDL into the classpath, I did it another way. I've created a directory for my application under /etc/ in CRXDE (I'm using Adobe CQ5) and put the WSDL file in there. Then I've just pointed my web service client to the http address of the directory (which would've been http://localhost:4503/etc/projectname/webservice.wsdl).

I'm still open for a cleaner approach (this will only work on Publish instances, since on a author instance it'll require login credentials), but so far it does what I need and allows me to deploy everything at once.

Ahatius
  • 4,777
  • 11
  • 49
  • 79