Search in sources :

Example 1 with EndpointDataType

use of org.talend.esb.servicelocator.client.internal.endpoint.EndpointDataType in project tesb-rt-se by Talend.

the class EndpointTransformerImpl method createEndpointData.

private EndpointDataType createEndpointData(Endpoint eprProvider, long lastTimeStarted, long lastTimeStopped) throws ServiceLocatorException {
    EndpointDataType endpointData = ENDPOINT_OBJECT_FACTORY.createEndpointDataType();
    endpointData.setBinding(BindingType.fromValue(eprProvider.getBinding().getValue()));
    endpointData.setTransport(TransportType.fromValue(eprProvider.getTransport().getValue()));
    endpointData.setLastTimeStarted(lastTimeStarted);
    endpointData.setLastTimeStopped(lastTimeStopped);
    DOMResult result = new DOMResult();
    eprProvider.writeEndpointReferenceTo(result, this);
    Document doc = (Document) result.getNode();
    endpointData.setEndpointReference(doc.getDocumentElement());
    return endpointData;
}
Also used : DOMResult(javax.xml.transform.dom.DOMResult) EndpointDataType(org.talend.esb.servicelocator.client.internal.endpoint.EndpointDataType) Document(org.w3c.dom.Document)

Example 2 with EndpointDataType

use of org.talend.esb.servicelocator.client.internal.endpoint.EndpointDataType in project tesb-rt-se by Talend.

the class EndpointTransformerImpl method toEndPointData.

@SuppressWarnings("unchecked")
public static EndpointDataType toEndPointData(byte[] content) {
    if (content == null) {
        throw new IllegalArgumentException("content must not be null.");
    }
    final InputStream is = new ByteArrayInputStream(content);
    try {
        JAXBContext jc = JaxbContextHandler.getEndpointContext();
        JAXBElement<EndpointDataType> slEndpoint = (JAXBElement<EndpointDataType>) jc.createUnmarshaller().unmarshal(is);
        return slEndpoint.getValue();
    } catch (JAXBException e) {
        if (LOG.isLoggable(Level.SEVERE)) {
            LOG.log(Level.SEVERE, "Failed to deserialize endpoint data", e);
        }
        EndpointDataType endpointData = ENDPOINT_OBJECT_FACTORY.createEndpointDataType();
        endpointData.setLastTimeStarted(-1);
        endpointData.setLastTimeStopped(-1);
        return endpointData;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) JAXBException(javax.xml.bind.JAXBException) EndpointDataType(org.talend.esb.servicelocator.client.internal.endpoint.EndpointDataType) JAXBContext(javax.xml.bind.JAXBContext) JAXBElement(javax.xml.bind.JAXBElement)

Example 3 with EndpointDataType

use of org.talend.esb.servicelocator.client.internal.endpoint.EndpointDataType in project tesb-rt-se by Talend.

the class EndpointTransformerImpl method serialize.

private byte[] serialize(EndpointDataType endpointData) throws ServiceLocatorException {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream(50000);
    try {
        JAXBElement<EndpointDataType> epd = ENDPOINT_OBJECT_FACTORY.createEndpointData(endpointData);
        createMarshaller().marshal(epd, outputStream);
    } catch (JAXBException e) {
        if (LOG.isLoggable(Level.SEVERE)) {
            LOG.log(Level.SEVERE, "Failed to serialize endpoint data", e);
        }
        throw new ServiceLocatorException("Failed to serialize endpoint data", e);
    }
    return outputStream.toByteArray();
}
Also used : ServiceLocatorException(org.talend.esb.servicelocator.client.ServiceLocatorException) JAXBException(javax.xml.bind.JAXBException) EndpointDataType(org.talend.esb.servicelocator.client.internal.endpoint.EndpointDataType) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

EndpointDataType (org.talend.esb.servicelocator.client.internal.endpoint.EndpointDataType)3 JAXBException (javax.xml.bind.JAXBException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBElement (javax.xml.bind.JAXBElement)1 DOMResult (javax.xml.transform.dom.DOMResult)1 ServiceLocatorException (org.talend.esb.servicelocator.client.ServiceLocatorException)1 Document (org.w3c.dom.Document)1