FeaturesPluginsDocs & SupportCommunityPartners

Web Service Passing Binary Data, pt 5: Modifying the Schema and WSDL Files

In this section, you add the WSDL file and schema file to our application. Then you modify them to interpret arrays of bytes as Images. You also adjust various parts of the application to correctly locate the schema and WSDL file. In the process, you are introduced to various tools in the IDE that help you with WSDL and Schema files.

Tutorials In This Trail

Content on this page applies to NetBeans IDE 6.1
  1. Overview
  2. Creating the EJB Module
  3. Creating the Web Service
  4. Testing the Web Service
  5. => Modifying the Schema and WSDL Files to Pass Binary Data
  6. Creating the Swing Client
  7. Logging and Optimizing the Web Service

Modifying the Schema File and WSDL Files to Pass Binary Data

In the following procedure, you create modified WSDL and XML Schema files for the web service that you created in a previous tutorial. The modified WSDL and Schema files enable the web service and the clients that consume it to parse JPEG image data that is passed as binary data.

To modify the WSDL and Schema files:

  1. Expand the web application until you reach the wsdl node:
    Java application with consumed ws

    Note: Currently the node is empty. The WSDL file and schema are generated at deployment, because you have been using default setings. Therefore this node, which would normally house them, is empty. Now that you want to interpret arrays of bytes as Images, you need to provide your own WSDL file and schema. We will put them in this node.

  2. Right-click the wsdl node and choose New > Other. The New File wizard opens. Open the XML category and select XML Schema. Name the schema file FlowerService.xsd.
  3. Repeat Step 2, but this time from the XML category select WSDL Document. Name the file FlowerService.wsdl.

    You should now see the following in the wsdl node:
    Java application with consumed ws

  4. Copy the content of the WSDL file in the browser to the template you created above. If you used the defaults when creating and deploying the web service, the WSDL file should be here:

    http://localhost:8080/FlowerService/FlowerService?WSDL

    Edit the WSDL file and insert the namespace declarations. These decarations are necessary for the WSDL to be valid. Replace the lines at the beginning of the file:

    <!--
     Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.2-hudson-182-RC1.
    -->
    
    <!--
     Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.2-hudson-182-RC1.
    -->
    
            <definitions targetNamespace="http://album.flower/" name="FlowerService">

    with the following:

    <definitions 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:soap="http://schemas.xmlsoap.org/wsdl/soap/"
        targetNamespace="http://album.flower/"
        xmlns="http://schemas.xmlsoap.org/wsdl/"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        name="FlowerService"
            xmlns:tns="http://album.flower/">
  5. Similarly, copy the schema file into your template file. The schema file is here, by default:

    http://localhost:8080/FlowerService/FlowerService?xsd=1

    Edit the schema file and insert the namespace declarations. These decarations are necessary for the schema file to be valid. Replace the lines at the beginning of the file:

    <!--
     Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.2-hudson-182-RC1.
    -->
    
                <xs:schema version="1.0" targetNamespace="http://album.flower/">

    with the following:

    <xs:schema xmlns:tns="http://album.flower/"
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                version="1.0" targetNamespace="http://album.flower/">
  6. Next, we will change the WSDL file so that our local schema file is referenced instead of the one that is on-line. Open the WSDL file in the Design mode, as shown below.
    Java application with consumed ws

    Expand the Types node. Right-click the Referenced Schema node.Choose Add > Import. The Add Import dialog opens.
  7. As shown below, you can now browse to the schema file and select it:


    Java application with consumed ws

  8. Click OK.

  9. Delete the other schema reference, which refers to the online schema file, which we do not want to refer to anymore, and then you will see that you can access nodes from the schema file, indicating that you have now correctly referenced it:
    Java application with consumed ws
  10. We need to explicitly make the application server use our own version of the WSDL file, otherwise the application server will generate its own WSDL file, from our web service's annotations.
    @WebService(serviceName = "FlowerService",
            wsdlLocation = "WEB-INF/wsdl/FlowerService.wsdl")

    You should now see the following in the web service class:
    Java application with consumed ws

  11. Finally, the point of this whole section is to have a modified schema file that specifies the expected content type of the return element. To identify the return element in the schema file, open the schema file and look at the line below, as well as the code in line 39, both of which may be on different lines in your own application:
    Java application with consumed ws
  12. Keep all the existing elements, but add the following attributes to both:

    xmime:expectedContentTypes="image/jpeg" xmlns:xmime="http://www.w3.org/2005/05/xmlmime"

    You should now see the following in the same lines:
    Java application with consumed ws

  13. Now, when you redeploy the web service to the Tester application, and invoke one of the operations, you will see that an image is correctly returned:
    Java application with consumed ws

Now that the Tester application has confirmed that images are correctly being returned, we can create our Swing client to retrieve and display them.

Note: You can find correctly modified versions of the WSDL and Schema files in the downloaded sample project. Both files are in the folder web/WEB-INF/wsdl.

Next Step:

Creating the Swing Client

To send comments and suggestions, get support, and keep informed on the latest developments on the NetBeans IDE Java EE development features, join the mailing list.

Companion
Projects:
MySQL Database Server   Open JDK: an Open SourceJDK   GlassFish Community: an Open Source Application Server    Mobile & Embedded Community    Open Solaris   java.net - The Source for Java Technology Collaboration   Virtual Box - full virtualizer  Open ESB - The Open Enterprise Service Bus Powered by