About Question enthuware.ocejws.v6.2.86 :
Moderators: Site Manager, fjwalraven
-
- Posts: 358
- Joined: Fri Nov 29, 2013 8:26 pm
- Contact:
About Question enthuware.ocejws.v6.2.86 :
Hi, all mock exam users,
As there was a discussion in another forum, that service.createDispatch(portName,jaxbContext, Message.Mode.MESSAGE) will be very tricky. Most books provides examples that using jaxbcontext with Payload mode.
However, be aware that in MZ's notes, p. 95, there is a paragraph :
"JAXB objects may be used with any protocol binding in either message or message payload mode....Service provides a createDispatch factory method for creating Dispatch instances that contain an embedded JAXBContext. The context parameter contains the JAXBContext instance that the created Dispatch instance will use to marshall and unmarshall message or message payload."
Also, from Apache CXF JAX-WS dispatch API at https://cxf.apache.org/docs/jax-ws-dispatch-api.html,
there is a statement: "Message mode is not ideal when you wish to work with JAXB objects."
It seems that in createDispatch method, we are allowed to use jaxbContext with message mode or payload mode. But it will be tricky to implement that.
Any feedback?
As there was a discussion in another forum, that service.createDispatch(portName,jaxbContext, Message.Mode.MESSAGE) will be very tricky. Most books provides examples that using jaxbcontext with Payload mode.
However, be aware that in MZ's notes, p. 95, there is a paragraph :
"JAXB objects may be used with any protocol binding in either message or message payload mode....Service provides a createDispatch factory method for creating Dispatch instances that contain an embedded JAXBContext. The context parameter contains the JAXBContext instance that the created Dispatch instance will use to marshall and unmarshall message or message payload."
Also, from Apache CXF JAX-WS dispatch API at https://cxf.apache.org/docs/jax-ws-dispatch-api.html,
there is a statement: "Message mode is not ideal when you wish to work with JAXB objects."
It seems that in createDispatch method, we are allowed to use jaxbContext with message mode or payload mode. But it will be tricky to implement that.
Any feedback?
-
- Posts: 429
- Joined: Tue Jul 24, 2012 2:43 am
- Contact:
Re: About Question enthuware.ocejws.v6.2.86 :
Hi Himai,
Please stick in these threads to questions about the mock exam questions.
Frits
Please stick in these threads to questions about the mock exam questions.
Note that this can be found the JAX-WS specifications:However, be aware that in MZ's notes, p. 95, there is a paragraph :
Regards,4.3 javax.xml.ws.Dispatch
JAXB Objects Use of JAXB allows clients to use JAXB objects generated from an XML Schema to create and manipulate XML representations and to use these objects with JAX-WS without requiring an intermediate XML serialization. JAXB objects may be used with any protocol binding in either message or message payload mode.
Frits
-
- Posts: 41
- Joined: Mon Oct 27, 2014 11:35 pm
- Contact:
Re: About Question enthuware.ocejws.v6.2.86 :
For the question:
The 1st of the 4 choices, with the explanation for why it is wrong, is:
Based on the above Explanation, would the following line make the above-coded client work... ?
Code: Select all
We are creating a dispatch client against the following Web Service implementation. The Web Service's endpoint is published at the address "http://localhost:9999/math". The GetTable class has a @XmlRootElement annotation. What is the correct client code?
package ws.math;
@WebService
public interface MathTableService {
public SimpleMathTable getTable(Integer number) throws NegException;
}
package ws.math;
@WebService (endpointInterface = "MathTableService")
public class MathTableImpl {
public SimpleMathTable getTable(Integer number) throws NegException {
if (number < 0) {
throw new NegException("Number cannot be negative");
}
SimpleMathTable table = new SimpleMathTable(number);
return table;
}
}
Code: Select all
public class DispatchSoapMessageClient {
private static final String Namespace = "http://math.ws/";
public static void main(String[] args) throws Exception {
URL url;
try {
url = new URL("http://localhost:9999/math?wsdl");
QName serviceName = new QName(Namespace,"MathTableImplService");
QName portName = new QName(Namespace,"MathTableImplPort");
Service service = Service.create(url, serviceName);
JAXBContext jaxbcontext = JAXBContext.newInstance( SOAPMessage.class );
Dispatch<Object> dispatch = service.createDispatch(portName, jaxbcontext, Service.Mode.PAYLOAD);
GetTable g = createRequestObject();
JAXBElement<GetTableResponse> result = (JAXBElement<GetTableResponse>) dispatch.invoke( g );
} catch (MalformedURLException e) {}
}
private static GetTable createRequestObject() {
GetTable req = new GetTable();
req.setArg0(new Integer(1));
return req;
}
}
Explanation: The JAXBContext should include the request object.
Code: Select all
JAXBContext jaxbcontext = JAXBContext.newInstance( GetTable.class );
-
- Posts: 429
- Joined: Tue Jul 24, 2012 2:43 am
- Contact:
Re: About Question enthuware.ocejws.v6.2.86 :
Almost. The request can be sent to the Web Service (and the requested method will be executed) but you cannot handle the response object in your client code as the GetTableResponse is not known by JAXB. Apart from that it needs the ObjectFactory that is generated by wsimport.Based on the above Explanation, would the following line make the above-coded client work... ?
Code:
JAXBContext jaxbcontext = JAXBContext.newInstance( GetTable.class );
Or in code:
Code: Select all
JAXBContext jaxbcontext = JAXBContext.newInstance(ws.client.GetTable.class, ws.client.GetTableResponse.class, ws.client.ObjectFactory.class);
Code: Select all
JAXBContext jaxbcontext = JAXBContext.newInstance("ws.client");
Regards,
Frits
-
- Posts: 41
- Joined: Mon Oct 27, 2014 11:35 pm
- Contact:
Re: About Question enthuware.ocejws.v6.2.86 :
Ok, now I get it.
The examples I've coded were passing the package name/s to the JAXBContext during its creation.
Now that I see that the request, response and ObjectFactory classes are explicitly passed to the JAXBContext, the point is now clearer to me. Thanks again.
The examples I've coded were passing the package name/s to the JAXBContext during its creation.
Now that I see that the request, response and ObjectFactory classes are explicitly passed to the JAXBContext, the point is now clearer to me. Thanks again.
-
- Posts: 124
- Joined: Wed Feb 12, 2014 2:44 am
- Contact:
Re: About Question enthuware.ocejws.v6.2.86 :
Hello ,
"You are providing the GetTable object as PAYLOAD to the SOAPMessage, that is why MESSAGE is wrong."
What indicates that you send GetTable to PAYLOAD ?
And also Message includes the Payload , so why MESSAGE is wrong ?
"You are providing the GetTable object as PAYLOAD to the SOAPMessage, that is why MESSAGE is wrong."
What indicates that you send GetTable to PAYLOAD ?
And also Message includes the Payload , so why MESSAGE is wrong ?
-
- Posts: 429
- Joined: Tue Jul 24, 2012 2:43 am
- Contact:
Re: About Question enthuware.ocejws.v6.2.86 :
GetTable does not construct a SOAPMessage.
MESSAGE is only correct if you provide a full SOAPMessage.
Regards,
Frits
MESSAGE is only correct if you provide a full SOAPMessage.
Regards,
Frits
-
- Posts: 16
- Joined: Sat Jun 09, 2018 12:09 pm
- Contact:
Re: About Question enthuware.ocejws.v6.2.86 :
Hello, about last answer: Is it necessary to wrap getTable type with JAXBElement if getTable class has @XmlRootElement annotation?
-
- Posts: 429
- Joined: Tue Jul 24, 2012 2:43 am
- Contact:
Re: About Question enthuware.ocejws.v6.2.86 :
No, but I don't see that in the answers...
Regards,
Frits
Regards,
Frits
-
- Posts: 1
- Joined: Sat Jan 12, 2019 3:54 am
- Contact:
Re: About Question enthuware.ocejws.v6.2.86 :
Hello, about last answer: Is it necessary to wrap getTable type with JAXBElement if getTable class has @XmlRootElement annotation?
-
- Posts: 429
- Joined: Tue Jul 24, 2012 2:43 am
- Contact:
Re: About Question enthuware.ocejws.v6.2.86 :
No, but I don't see that in the answers...
Who is online
Users browsing this forum: No registered users and 1 guest