Search in sources :

Example 1 with AttachmentMgtServiceStub

use of org.wso2.carbon.attachment.mgt.stub.AttachmentMgtServiceStub in project carbon-business-process by wso2.

the class SampleAttachmentMgtClient method uploadAttachment.

private static String uploadAttachment() throws RemoteException, AttachmentMgtException {
    AttachmentMgtServiceStub stub = new AttachmentMgtServiceStub();
    Options options = new Options();
    options.setTo(new EndpointReference("http://127.0.0.1:9763/services/AttachmentMgtService/"));
    options.setProperty(Constants.Configuration.ENABLE_MTOM, Boolean.TRUE);
    stub._getServiceClient().setOptions(options);
    TAttachment att = new TAttachment();
    // att.setId("ContentId");
    // att.setCreatedTime(Calendar.getInstance());
    att.setName("ContentName");
    att.setCreatedBy("DenisAuthor");
    att.setContentType("text/plain");
    // FileDataSource dataSource = new FileDataSource(new File("/home/denis/Desktop/note.txt"));
    FileDataSource dataSource = new FileDataSource(new File("/home/denis/Desktop/fromSoapUI.xml"));
    DataHandler fileDataHandler = new DataHandler(dataSource);
    att.setContent(fileDataHandler);
    String id = stub.add(att);
    if (log.isDebugEnabled()) {
        log.debug("Attachment uploaded with id: " + id);
    }
    return id;
}
Also used : Options(org.apache.axis2.client.Options) TAttachment(org.wso2.carbon.attachment.mgt.stub.types.TAttachment) AttachmentMgtServiceStub(org.wso2.carbon.attachment.mgt.stub.AttachmentMgtServiceStub) FileDataSource(javax.activation.FileDataSource) DataHandler(javax.activation.DataHandler) File(java.io.File) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 2 with AttachmentMgtServiceStub

use of org.wso2.carbon.attachment.mgt.stub.AttachmentMgtServiceStub in project carbon-business-process by wso2.

the class SampleAttachmentMgtClient method getAttachmentInfo.

private static void getAttachmentInfo(String id) throws RemoteException, AttachmentMgtException {
    AttachmentMgtServiceStub stub = new AttachmentMgtServiceStub();
    Options options = new Options();
    options.setTo(new EndpointReference("http://127.0.0.1:9763/services/AttachmentMgtService/"));
    options.setProperty(Constants.Configuration.ENABLE_MTOM, Boolean.TRUE);
    stub._getServiceClient().setOptions(options);
    TAttachment attachment = stub.getAttachmentInfo(id);
    if (log.isDebugEnabled()) {
        log.debug("Attachment details received. Id: " + attachment.getId());
    }
}
Also used : Options(org.apache.axis2.client.Options) TAttachment(org.wso2.carbon.attachment.mgt.stub.types.TAttachment) AttachmentMgtServiceStub(org.wso2.carbon.attachment.mgt.stub.AttachmentMgtServiceStub) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 3 with AttachmentMgtServiceStub

use of org.wso2.carbon.attachment.mgt.stub.AttachmentMgtServiceStub in project carbon-business-process by wso2.

the class SampleAttachmentMgtClient method removeAttachment.

private static void removeAttachment(String id) throws RemoteException, AttachmentMgtException {
    AttachmentMgtServiceStub stub = new AttachmentMgtServiceStub();
    Options options = new Options();
    options.setTo(new EndpointReference("http://127.0.0.1:9763/services/AttachmentMgtService/"));
    options.setProperty(Constants.Configuration.ENABLE_MTOM, Boolean.TRUE);
    stub._getServiceClient().setOptions(options);
    if (log.isDebugEnabled()) {
        log.debug("Attachment removed status:" + stub.remove(id));
    }
}
Also used : Options(org.apache.axis2.client.Options) AttachmentMgtServiceStub(org.wso2.carbon.attachment.mgt.stub.AttachmentMgtServiceStub) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Aggregations

EndpointReference (org.apache.axis2.addressing.EndpointReference)3 Options (org.apache.axis2.client.Options)3 AttachmentMgtServiceStub (org.wso2.carbon.attachment.mgt.stub.AttachmentMgtServiceStub)3 TAttachment (org.wso2.carbon.attachment.mgt.stub.types.TAttachment)2 File (java.io.File)1 DataHandler (javax.activation.DataHandler)1 FileDataSource (javax.activation.FileDataSource)1