Search in sources :

Example 6 with JAXBElement

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 {
    }
}
Also used : StringReader(java.io.StringReader) JAXBContext(javax.xml.bind.JAXBContext) JAXBElement(javax.xml.bind.JAXBElement) Unmarshaller(javax.xml.bind.Unmarshaller) ClientRequestType(com.intel.mountwilson.ta.data.ClientRequestType)

Example 7 with JAXBElement

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());
    }
}
Also used : GenericType(javax.ws.rs.core.GenericType) GenericEntity(javax.ws.rs.core.GenericEntity) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) WebTarget(javax.ws.rs.client.WebTarget) JAXBElement(javax.xml.bind.JAXBElement)

Example 8 with JAXBElement

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());
    }
}
Also used : GenericType(javax.ws.rs.core.GenericType) GenericEntity(javax.ws.rs.core.GenericEntity) JSONObject(org.codehaus.jettison.json.JSONObject) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) WebTarget(javax.ws.rs.client.WebTarget) JAXBElement(javax.xml.bind.JAXBElement)

Example 9 with JAXBElement

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]);
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) GenericType(javax.ws.rs.core.GenericType) GenericEntity(javax.ws.rs.core.GenericEntity) QName(javax.xml.namespace.QName) WebTarget(javax.ws.rs.client.WebTarget) JAXBElement(javax.xml.bind.JAXBElement) Test(org.junit.Test)

Example 10 with JAXBElement

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();
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) JAXBContext(javax.xml.bind.JAXBContext) JAXBElement(javax.xml.bind.JAXBElement)

Aggregations

JAXBElement (javax.xml.bind.JAXBElement)210 QName (javax.xml.namespace.QName)71 ArrayList (java.util.ArrayList)43 Test (org.junit.Test)42 JAXBException (javax.xml.bind.JAXBException)28 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)28 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)24 JAXBContext (javax.xml.bind.JAXBContext)19 Unmarshaller (javax.xml.bind.Unmarshaller)18 Marshaller (javax.xml.bind.Marshaller)16 LineString (com.vividsolutions.jts.geom.LineString)15 StringWriter (java.io.StringWriter)14 List (java.util.List)14 Element (org.w3c.dom.Element)13 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)12 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)12 ByteArrayInputStream (java.io.ByteArrayInputStream)11 QueryConstraintType (net.opengis.cat.csw.v_2_0_2.QueryConstraintType)10 PrismObject (com.evolveum.midpoint.prism.PrismObject)9 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)9