2016-04-14 14 views

cevap

1

Bu ekli dosyaları ile standart bileti oluşturmak için bir dinlenme taleptir

{ 
    "parameters":[ 
     { 
     "assignedUserId":112233, 
     "subjectId":1001 
     }, 
     "This content is for test", 
     0, "", "", "", 
     [ 
     { 
      "filename":"file.txt", 
      "data":"test test RCV" 
     } 
     ] 
    ] 
} 

Mesaj

değiştirin: $ username, $ apiKey ve kendi bilgileriyle 112.233 değer.

SoftLayer API Client for Java kullanıyor olmanız durumunda, ekli bir dosya ile standart bilet oluşturmak için şu anda bir sorun var gibi görünüyor, farklı yollar denedim, ancak dosyayı yüklemek için başarılı olamadım.

Ancak, bu sorunu önlemek için geçici bir çözüm sağlayabilir, aşağıdaki komut dosyasını deneyin:

İlk ne bundan sonra, dosya yüklenir, bilet oluşturur, senaryodaki Gördüğünüz gibi
package Tickets; 
import com.softlayer.api.ApiClient; 
import com.softlayer.api.RestApiClient; 
import com.softlayer.api.service.Ticket; 
import com.softlayer.api.service.container.utility.file.Attachment; 

import java.io.BufferedInputStream; 
import java.io.File; 
import java.io.FileInputStream; 
import java.util.ArrayList; 
import java.util.List; 

/** 
* This script creates standard ticket and attach file 
* 
* Important Manual Page: 
* http://sldn.softlayer.com/reference/services/SoftLayer_Ticket/createStandardTicket 
* http://sldn.softlayer.com/reference/services/SoftLayer_Ticket/addAttachedFile 
* http://sldn.softlayer.com/reference/datatypes/SoftLayer_Ticket 
* http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Utility_File_Attachment 
* 
* @license <http://sldn.softlayer.com/article/License> 
* @authon SoftLayer Technologies, Inc. <[email protected]> 
* @version 0.2.2 
*/ 
public class CreateStandardTicket { 
    /** 
    * This is the constructor, is used to create Standard Ticket, it shows basic 
    * properties for creating a ticket. 
    */ 
    public CreateStandardTicket() { 
     // Declare your SoftLayer username and apiKey 
     String username = "set me"; 
     String apiKey = "set me"; 
     // Declare the data of the ticket you wish to submit 
     Long assignedUserId = new Long(112233); 
     boolean notifyUserOnUpdateFlag = true; 
     Long subjectId = new Long(1001); 
     String title = "New Standard Ticket for Test"; 
     // Declare others parameters of the ticket 
     String contents = "New content for test"; 
     Long attachmentId = null; 
     String rootPassword = ""; 
     String controlPanelPassword = ""; 
     String accessPort = ""; 
     String attachmentType = ""; 

     // Declare the name of the file that will upload to the SoftLayer API and the path where the file is located 
     String filename = "fileTest.txt"; 
     String path = "C:/Users/Test/Pictures/test.txt"; 

     // Get Api Client and SoftLayer_Ticket service 
     ApiClient client = new RestApiClient().withCredentials(username, apiKey); 
     Ticket.Service ticketService = Ticket.service(client); 

     // Build SoftLayer_Ticket object containing ticket information 
     Ticket newStandard = new Ticket(); 
     newStandard.setAssignedUserId(assignedUserId); 
     newStandard.setNotifyUserOnUpdateFlag(notifyUserOnUpdateFlag); 
     newStandard.setSubjectId(subjectId); 
     newStandard.setTitle(title); 
     // Build SoftLayer_Container_Utility_File_Attachment object 
     Attachment newFile = new Attachment(); 
     List<Attachment> attachedFiles = new ArrayList<Attachment>(); 
     attachedFiles.add(newFile); 

     try { 
      // Creating standard ticket 
      Ticket ticketCreated = ticketService.createStandardTicket(newStandard, contents, attachmentId, rootPassword, controlPanelPassword, accessPort, attachedFiles, attachmentType); 
      ticketService = Ticket.service(client, new Long(ticketCreated.getId())); 

      // Reading the file in bytes 
      File file = new File(path); 
      int length = (int) file.length(); 
      BufferedInputStream reader = new BufferedInputStream(new FileInputStream(file)); 
      byte[] bytes = new byte[length]; 
      reader.read(bytes, 0, length); 
      reader.close(); 

      // Build SoftLayer_Container_Utility_File_Attachment object 
      newFile.setData(bytes); 
      newFile.setFilename(filename); 

      // Attaching the file to the ticket 
      com.softlayer.api.service.ticket.attachment.File result = ticketService.addAttachedFile(newFile); 
      System.out.println("The ticket was created successfully: " + ticketCreated.getId()); 

     } catch (Exception e) { 
      System.out.println("Error: " + e); 
     } 
    } 

    /** 
    * This is the main method which makes use of CreateStandardTicket method. 
    * 
    * @param args 
    * @return Nothing 
    */ 
    public static void main(String[] args) { 
     new CreateStandardTicket(); 
    } 


} 

bilet.

Umarım gerçekten size yardımcı olur.

+0

Teşekkürler Ruber, bazı doğrudan ek işlevselliklerine sahip olacaklarını umduğumuz halde gerçekten de bize yardımcı oldu. Tekrar teşekkürler. – user1312150

İlgili konular