Optional Fields Are Not Working in Webservice

I am trying to hit your webservice using axis2 from a java application.With that the optinal fields are not working.i.e The optinal fields are made as mandatory in webservices.

I am not able to hit any api with mimimals fields.I have to hit every api api with all the fields as mandatory which is very frustrating for me.Is this the way i have deal with webservices or am i doing anything wrong .I have shared my code.Kindly help me on this ASAP…

But howMany and offset are offsets are working fine.

Code:

FlightXML2Stub stub = null;
try {
HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
auth.setUsername(FlightXmlConstants.USER_NAME);
auth.setPassword(FlightXmlConstants.PASSWORD);

		stub = new FlightXML2Stub();
		stub._getServiceClient().getOptions().setProperty(HTTPConstants.CHUNKED, false);
		stub._getServiceClient().getOptions().setProperty(HTTPConstants.AUTHENTICATE, auth);
	} catch (RemoteException x) {
		x.printStackTrace();
		System.err.println(x);
	}

FlightXML2Stub.AirlineFlightSchedulesRequest req3 = new FlightXML2Stub.AirlineFlightSchedulesRequest();
req3.setAirline(“EK”);
req3.setFlightno(“412”);
req3.setStartDate(1441065600);
req3.setEndDate(1441152000);
FlightXML2Stub.AirlineFlightSchedulesRequestE req3e = new FlightXML2Stub.AirlineFlightSchedulesRequestE();
req3e.setAirlineFlightSchedulesRequest(req3);
airlineFlightSchedulesResults = stub.airlineFlightSchedules(req3e).getAirlineFlightSchedulesResults();

Exception:

[http-nio-8080-exec-2] INFO org.apache.axis2.transport.http.HTTPSender - Unable to sendViaPost to url[flightxml.flightaware.com/soap/FlightXML2/op]
org.apache.axis2.AxisFault: origin cannot be null!!
at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
at org.apache.axis2.transport.http.SOAPMessageFormatter.getBytes(SOAPMessageFormatter.java:108)
at org.apache.axis2.transport.http.AxisRequestEntity.writeRequest(AxisRequestEntity.java:87)
at org.apache.commons.httpclient.methods.EntityEnclosingMethod.writeRequestBody(EntityEnclosingMethod.java:499)
at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:2114)
at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1096)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:621)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:193)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:404)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:231)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:443)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:406)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at org.axis2.FlightXML2Stub.airlineFlightSchedules(FlightXML2Stub.java:5004)

Specify empty string for any such arguments that your SOAP library requires. The field is optional in terms of what the server requires, not in what the WSDL is prototyped as.

I have also tried that And even tried with sending an space an argument for origin. But both are not working. It still gives me an exception…

Show the code and the resulting exception when you are supplying a blank string for the origin and destination. (Empty string, not space.)

I have tried

req3.setOrigin(“”);
req3.setOrigin (" ");

Both of these I am getting an null pointer exception if I give any of the above two values which is maybe coming from fromOM method.But I am not sure.I am actually out of office now. I will give the exact exception once I reach the office. How long will you still be there…

But the exception is null pointer exception at fromOM method…

The exceptions you are indicating appear to all be generated by the Apache Axis library prior to the request being sent to our server, so there will need to be some modification to the code on your side.

Have you intentionally enabled a strict validation mode of requests in Axis?

Although this should not normally be necessary, one possible workaround is to save the WSDL file locally, and manually edit it to change the definition of “AirlineFlightSchedulesRequest”. Part of it will show:

<s:element maxOccurs=“1” minOccurs=“1” name=“origin” type=“s:string”/>
<s:element maxOccurs=“1” minOccurs=“1” name=“destination” type=“s:string”/>

If you change the minOccurs=“0” and add nillable=“true” then I think Axis should allow you to form a request that completely omits that argument, or has a blank value. After editing the WSDL, you will need to regenerate your interface stubs. This is an unusual condition though, as we I have not had to recommend that anyone else make this change before.

Thanks it worked very well.I have set minoccurs to 0 for all the optional fields .Thank you . Usually for the optional fields the minoccurs should be 0 as i have seen in some other wsdl files. Can you kindly make a change on that may in the next version…

I have not enabled any strict validation mode of requests in Axis though…

Thanks…