Search in sources :

Example 1 with JAXBElement

use of javax.xml.bind.JAXBElement in project OpenAttestation by OpenAttestation.

the class TrustAgentSecureClient method sendHostRequest.

/**
     * 
     * @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 HostRequestType sendHostRequest() throws UnknownHostException, IOException, JAXBException, KeyManagementException, NoSuchAlgorithmException {
    try {
        byte[] buf = sendRequestWithSSLSocket();
        log.info("Unmarshalling to Jaxb object.");
        JAXBContext jc = JAXBContext.newInstance("com.intel.mountwilson.ta.host.data");
        log.debug("Created JAXBContext Instance {}", jc.toString());
        //assert jc != null; Expression always true
        Unmarshaller u = jc.createUnmarshaller();
        log.debug("Created Unmarshaller Instance {}", u.toString());
        //assert new String(buf) != null; //Expresion always return null.
        assert buf != null;
        log.debug("Unmarshalling");
        JAXBElement po = (JAXBElement) u.unmarshal(new StringReader(new String(buf).trim()));
        log.debug("Unmarshalled");
        assert po != null;
        HostRequestType response = (HostRequestType) po.getValue();
        assert response != null;
        checkHostError(response);
        log.info("Done reading/writing to/from socket, closing socket.");
        return response;
    } finally {
    }
}
Also used : HostRequestType(com.intel.mountwilson.ta.host.data.HostRequestType) StringReader(java.io.StringReader) JAXBContext(javax.xml.bind.JAXBContext) JAXBElement(javax.xml.bind.JAXBElement) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 2 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 3 with JAXBElement

use of javax.xml.bind.JAXBElement in project jersey by jersey.

the class JaxbTest method testXmlType.

@Test
public void testXmlType() {
    JaxbXmlType t1 = target().path("jaxb/JAXBElement").request().get(JaxbXmlType.class);
    JAXBElement<JaxbXmlType> e = new JAXBElement<JaxbXmlType>(new QName("jaxbXmlRootElement"), JaxbXmlType.class, t1);
    JaxbXmlType t2 = target().path("jaxb/XmlType").request("application/xml").post(xml(e), JaxbXmlType.class);
    assertEquals(t1, t2);
}
Also used : QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 4 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 5 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)

Aggregations

JAXBElement (javax.xml.bind.JAXBElement)650 QName (javax.xml.namespace.QName)194 Element (org.w3c.dom.Element)124 RequestSecurityTokenType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenType)102 RequestSecurityTokenResponseType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenResponseType)95 ArrayList (java.util.ArrayList)93 MessageImpl (org.apache.cxf.message.MessageImpl)92 WrappedMessageContext (org.apache.cxf.jaxws.context.WrappedMessageContext)90 Test (org.junit.Test)87 STSPropertiesMBean (org.apache.cxf.sts.STSPropertiesMBean)86 StaticSTSProperties (org.apache.cxf.sts.StaticSTSProperties)83 Crypto (org.apache.wss4j.common.crypto.Crypto)82 JAXBException (javax.xml.bind.JAXBException)81 PasswordCallbackHandler (org.apache.cxf.sts.common.PasswordCallbackHandler)77 JAXBContext (javax.xml.bind.JAXBContext)75 CustomTokenPrincipal (org.apache.wss4j.common.principal.CustomTokenPrincipal)72 Unmarshaller (javax.xml.bind.Unmarshaller)65 ServiceMBean (org.apache.cxf.sts.service.ServiceMBean)61 StaticService (org.apache.cxf.sts.service.StaticService)61 RequestSecurityTokenResponseCollectionType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenResponseCollectionType)58