use of javax.xml.bind.JAXBElement in project OpenAttestation by OpenAttestation.
the class TrustAgentSecureClient method sendQuoteRequest.
/**
*
* @return an object representing the RESPONSE from the Trust Agent
* @throws UnknownHostException if the IP address of the host could not be determined from local hosts file or DNS
* @throws IOException if there was an error connecting to the host, such as it is not reachable on the network or it dropped the connection
* @throws JAXBException when the response from the host cannot be interpreted properly
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
*/
public synchronized ClientRequestType sendQuoteRequest() throws UnknownHostException, IOException, JAXBException, KeyManagementException, NoSuchAlgorithmException {
try {
byte[] buf = sendRequestWithSSLSocket();
log.info("Unmarshalling to Jaxb object.");
JAXBContext jc = JAXBContext.newInstance("com.intel.mountwilson.ta.data");
assert jc != null;
Unmarshaller u = jc.createUnmarshaller();
assert u != null;
assert new String(buf) != null;
JAXBElement po = (JAXBElement) u.unmarshal(new StringReader(new String(buf).trim()));
assert po != null;
ClientRequestType response = (ClientRequestType) po.getValue();
assert response != null;
checkQuoteError(response);
log.info("Done reading/writing to/from socket, closing socket.");
return response;
} finally {
}
}
use of javax.xml.bind.JAXBElement in project jersey by jersey.
the class XmlMoxyTest method _testListOrArray.
@SuppressWarnings("unchecked")
public void _testListOrArray(final boolean isList, final MediaType mt) {
final Object in = isList ? getJAXBElementList() : getJAXBElementArray();
final GenericType gt = isList ? new GenericType<List<JAXBElement<String>>>() {
} : new GenericType<JAXBElement<String>[]>() {
};
final WebTarget target = target(isList ? "JAXBElementListResource" : "JAXBElementArrayResource");
final Object out = target.request(mt).post(Entity.entity(new GenericEntity(in, gt.getType()), mt), gt);
final List<JAXBElement<String>> inList = isList ? ((List<JAXBElement<String>>) in) : Arrays.asList((JAXBElement<String>[]) in);
final List<JAXBElement<String>> outList = isList ? ((List<JAXBElement<String>>) out) : Arrays.asList((JAXBElement<String>[]) out);
assertEquals("Lengths differ", inList.size(), outList.size());
for (int i = 0; i < inList.size(); i++) {
assertEquals("Names of elements at index " + i + " differ", inList.get(i).getName(), outList.get(i).getName());
assertEquals("Values of elements at index " + i + " differ", inList.get(i).getValue(), outList.get(i).getValue());
}
}
use of javax.xml.bind.JAXBElement in project jersey by jersey.
the class EntityTypesTest method _testListOrArray.
public void _testListOrArray(final boolean isList, final MediaType mt) {
final Object in = isList ? getJAXBElementList() : getJAXBElementArray();
final GenericType gt = isList ? new GenericType<List<JAXBElement<String>>>() {
} : new GenericType<JAXBElement<String>[]>() {
};
final WebTarget target = target(isList ? "JAXBElementListResource" : "JAXBElementArrayResource");
final Object out = target.request(mt).post(Entity.entity(new GenericEntity(in, gt.getType()), mt), gt);
final List<JAXBElement<String>> inList = isList ? ((List<JAXBElement<String>>) in) : Arrays.asList((JAXBElement<String>[]) in);
final List<JAXBElement<String>> outList = isList ? ((List<JAXBElement<String>>) out) : Arrays.asList((JAXBElement<String>[]) out);
assertEquals("Lengths differ", inList.size(), outList.size());
for (int i = 0; i < inList.size(); i++) {
assertEquals("Names of elements at index " + i + " differ", inList.get(i).getName(), outList.get(i).getName());
assertEquals("Values of elements at index " + i + " differ", inList.get(i).getValue(), outList.get(i).getValue());
}
}
use of javax.xml.bind.JAXBElement in project jersey by jersey.
the class JsonMoxyTest method testJAXBElementBeanJSONRepresentation.
@Test
public void testJAXBElementBeanJSONRepresentation() {
final WebTarget target = target("JAXBElementBeanJSONResource");
final GenericType<JAXBElement<String>> genericType = new GenericType<JAXBElement<String>>() {
};
final GenericEntity<JAXBElement<String>> jaxbElementGenericEntity = new GenericEntity<>(new JAXBElement<>(new QName("test"), String.class, "CONTENT"), genericType.getType());
final Response rib = target.request().post(Entity.entity(jaxbElementGenericEntity, "application/json"));
// TODO: the following would not be needed if i knew how to workaround JAXBElement<String>.class literal
final byte[] inBytes = getRequestEntity();
final byte[] outBytes = getEntityAsByteArray(rib);
assertEquals(new String(outBytes), inBytes.length, outBytes.length);
for (int i = 0; i < inBytes.length; i++) {
if (inBytes[i] != outBytes[i]) {
assertEquals("Index: " + i, inBytes[i], outBytes[i]);
}
}
}
use of javax.xml.bind.JAXBElement in project quickstarts by jboss-switchyard.
the class LibraryClient method wrapRequest.
private <T> String wrapRequest(QName name, Class<T> declaredType, T value, String pid) throws Exception {
JAXBElement<T> e = new JAXBElement<T>(name, declaredType, null, value);
JAXBContext ctx = JAXBContext.newInstance("org.switchyard.quickstarts.demos.library.types");
Marshaller m = ctx.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
StringWriter sw = new StringWriter();
String processInstanceId = pid != null ? "<bpm:processInstanceId xmlns:bpm='urn:switchyard-component-bpm:bpm:1.0'>" + pid + "</bpm:processInstanceId>" : "";
sw.write(SOAP_REQUEST_PREFIX.replaceFirst("PID", processInstanceId));
m.marshal(e, sw);
sw.write(SOAP_REQUEST_SUFFIX);
return sw.toString();
}
Aggregations