Hi Tomek,

here is attached working version of weather client.

Could you add it to jaxb2 example?

Thanks.

Regards,
Zdenek

On 5/2/07, Zdeněk Vráblík <[EMAIL PROTECTED]> wrote:
Hi all,

I have found it. I created anohter ServiceFactory.

New code:
ServiceFactory factory = new JaxbServiceFactory();

    Service serviceModel = factory.create(WeatherService.class,
                                            "WeatherService",
                                            "http://www.webservicex.net";,
                                            null);

But it still doesn't work.
There is  <GetWeatherByZipCodeResult> element in response and
unmarshalling fails.

Shouldn't be there this element?
Do I have ommited any settings?

request:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/";
xmlns:xsd="http://www.w3.org/2001/XMLSchema";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
        <soap:Body>
                <GetWeatherByZipCode xmlns="http://www.webservicex.net";>
                        <in0 xmlns="http://www.webservicex.net";>
                                <zipCode 
xmlns="http://webservicex.net";>1234</zipCode>
                        </in0>
                </GetWeatherByZipCode>
        </soap:Body>
</soap:Envelope>

response:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/";
xmlns:xsd="http://www.w3.org/2001/XMLSchema";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
   <soap:Body>
      <GetWeatherByZipCodeResponse xmlns="http://www.webservicex.net";>
         <GetWeatherByZipCodeResult>
            <Latitude>1.0</Latitude>
            <Longitude>1.0</Longitude>
            <AllocationFactor>1.0</AllocationFactor>
            <PlaceName>Vienna, AT</PlaceName>
         </GetWeatherByZipCodeResult>
      </GetWeatherByZipCodeResponse>
   </soap:Body>
</soap:Envelope>

exception:
SEVERE: javax.xml.bind.UnmarshalException: unexpected element
(uri:"http://www.webservicex.net";, local:"GetWeatherByZipCodeResult").
Expected elements are
<{http://www.webservicex.net}GetWeatherByZipCode>,<{http://www.webservicex.net}GetWeatherByZipCodeResponse>
Exception in thread "main" org.codehaus.xfire.XFireRuntimeException:
Could not invoke service.. Nested exception is
org.codehaus.xfire.fault.XFireFault: Could not unmarshall type :
unexpected element (uri:"http://www.webservicex.net";,
local:"GetWeatherByZipCodeResult"). Expected elements are
<{http://www.webservicex.net}GetWeatherByZipCode>,<{http://www.webservicex.net}GetWeatherByZipCodeResponse>
org.codehaus.xfire.fault.XFireFault: Could not unmarshall type :
unexpected element (uri:"http://www.webservicex.net";,
local:"GetWeatherByZipCodeResult"). Expected elements are
<{http://www.webservicex.net}GetWeatherByZipCode>,<{http://www.webservicex.net}GetWeatherByZipCodeResponse>
        at org.codehaus.xfire.jaxb2.JaxbType.readObject(JaxbType.java:216)
        at 
org.codehaus.xfire.aegis.AegisBindingProvider.readParameter(AegisBindingProvider.java:162)
        at 
org.codehaus.xfire.service.binding.AbstractBinding.read(AbstractBinding.java:206)
        at 
org.codehaus.xfire.service.binding.WrappedBinding.readMessage(WrappedBinding.java:50)
        at 
org.codehaus.xfire.soap.handler.SoapBodyHandler.invoke(SoapBodyHandler.java:42)
        at 
org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
        at org.codehaus.xfire.client.Client.onReceive(Client.java:387)
        at 
org.codehaus.xfire.transport.http.HttpChannel.sendViaClient(HttpChannel.java:139)
        at 
org.codehaus.xfire.transport.http.HttpChannel.send(HttpChannel.java:48)
        at 
org.codehaus.xfire.handler.OutMessageSender.invoke(OutMessageSender.java:26)
        at 
org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
        at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:75)
        at org.codehaus.xfire.client.Client.invoke(Client.java:335)
        at 
org.codehaus.xfire.client.XFireProxy.handleRequest(XFireProxy.java:77)
        at org.codehaus.xfire.client.XFireProxy.invoke(XFireProxy.java:57)
        at $Proxy11.GetWeatherByZipCode(Unknown Source)
        at 
org.codehaus.xfire.jaxb.WeatherServiceClient.main(WeatherServiceClient.java:39)
Caused by: javax.xml.bind.UnmarshalException: unexpected element
(uri:"http://www.webservicex.net";, local:"GetWeatherByZipCodeResult").
Expected elements are
<{http://www.webservicex.net}GetWeatherByZipCode>,<{http://www.webservicex.net}GetWeatherByZipCodeResponse>
        at 
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:525)
        at 
com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:199)
        at 
com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:194)
        at 
com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:71)
        at 
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext$DefaultRootLoader.childElement(UnmarshallingContext.java:922)
        at 
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:366)
        at 
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:347)
        at 
com.sun.xml.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(InterningXmlVisitor.java:35)
        at 
com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.handleStartElement(StAXStreamConnector.java:201)
        at 
com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:135)
        at 
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:337)
        at 
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:309)
        at org.codehaus.xfire.jaxb2.JaxbType.readObject(JaxbType.java:200)
        ... 16 more
Caused by: javax.xml.bind.UnmarshalException: unexpected element
(uri:"http://www.webservicex.net";, local:"GetWeatherByZipCodeResult").
Expected elements are
<{http://www.webservicex.net}GetWeatherByZipCode>,<{http://www.webservicex.net}GetWeatherByZipCodeResponse>
        ... 29 more

Thanks.

Regards,
Zdenek

On 5/2/07, Zdeněk Vráblík <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I have an error in client for weather example.
>
> The same problem was mentioned here one week ago.
>
> The service is called and returned message is correct (tested with soapUI).
> There is error in my client. Service works fine.
>
> This message is in log:
> INFO: Discarding unexpected response: HTTP/1.1 100 Continue
>
> The client code is in attachment.
>
> Why is the response unexpected and discarded?
> I am using xfire 1.2.5.
>
> Thanks.
>
> Regards,
> Zdenek
>
>

package org.codehaus.xfire.jaxb;

import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.Map;

import net.webservicex.GetWeatherByZipCode;
import net.webservicex.GetWeatherByZipCodeResponse;
import net.webservicex.WeatherForecastsType;

import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.jaxb2.JaxbServiceFactory;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.ServiceFactory;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;
import org.codehaus.xfire.soap.SoapConstants;

/**
 * 
 * @author <a href="mailto:[EMAIL PROTECTED]">Zdenek Vrablik</a>
 *
 */

public class WeatherServiceClient
  {
  public static final String serverURL = "http://192.168.100.119:7021/xfire-jaxb2/services/WeatherService";;
  /**
   * @param args
   */
  public static void main ( String[] args )
    throws MalformedURLException
    {
    
    // create service factory - it depends on binding type
    ServiceFactory factory = new JaxbServiceFactory();
    
    // set SOAP message style
    // more on http://www-128.ibm.com/developerworks/webservices/library/ws-whichwsdl/
    // this must corespond to STYLE defined in META-INF/xfire/services.xml
    Map props = new HashMap();
    props.put(ObjectServiceFactory.STYLE, SoapConstants.STYLE_DOCUMENT);
    
    Service serviceModel = factory.create(WeatherService.class,
                                            "WeatherService",
                                            "http://www.webservicex.net";,
                                            props);

    WeatherService service = (WeatherService) new XFireProxyFactory().create(serviceModel, serverURL);
     
    System.out.println("Start request");
     
    GetWeatherByZipCode requestData = new GetWeatherByZipCode();
    requestData.setZipCode( "1234" );
     
    GetWeatherByZipCodeResponse responseData = service.GetWeatherByZipCode( requestData );
     
    WeatherForecastsType forecastType = responseData.getGetWeatherByZipCodeResult();
    
    System.out.println("allocationFactor: " + forecastType.getAllocationFactor());
    System.out.println("latitude: " + forecastType.getLatitude());
    System.out.println("longitude: " + forecastType.getLongitude());
    
    System.out.println("End request");
    }
  }
---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply via email to