Mule JIRA复制附件并将其移至新版本
我试图寻找一个解决方案,将附件从一个缺陷复制到另一个缺陷 我尝试使用以下方法,但获取附件返回为 类型为com.atlassian.jira.rpc.soap.beans.RemoteAttachment,我在其中没有看到任何StringBuffer或任何对象实际具有保存附件本身的base64编码对象 添加附件不接受此数据类型 如何将附件从一个缺陷成功上传到另一个缺陷Mule JIRA复制附件并将其移至新版本,mule,jira,Mule,Jira,我试图寻找一个解决方案,将附件从一个缺陷复制到另一个缺陷 我尝试使用以下方法,但获取附件返回为 类型为com.atlassian.jira.rpc.soap.beans.RemoteAttachment,我在其中没有看到任何StringBuffer或任何对象实际具有保存附件本身的base64编码对象 添加附件不接受此数据类型 如何将附件从一个缺陷成功上传到另一个缺陷 <flow name="jira-attachments-POC"> <http:listene
<flow name="jira-attachments-POC">
<http:listener config-ref="HTTP_Listener_Configuration" path="/attachments" doc:name="HTTP"/>
<jira:get-attachments-from-issue config-ref="Jira" issueKey="MRT-75" doc:name="Jira"/>
<set-session-variable variableName="attachementsPayload" value="#[payload]" doc:name="attachementsPayload"/>
<set-session-variable variableName="issueAttachmentNames" value="#[payload[0].attachmentNames]" doc:name="issueAttachmentNames"/>
<set-session-variable variableName="fileAttachmentsArray" value="*" doc:name="Session Variable fileAttachments"/>
<set-session-variable variableName="fileName" value="#[payload[0].filename]" doc:name="fileName"/>
<set-session-variable variableName="fileId" value="#[payload[0].id]" doc:name="fileId"/>
<set-session-variable variableName="requestPath" value="secure/attachment/#[sessionVars.fileId]/#[sessionVars.fileName]" doc:name="requestPath"/>
<component doc:name="Java" class="JIRAAttachmentObjectTransformer"/>
<jira:add-base64-encoded-attachments-to-issue config-ref="Jira" issueKey="MRT-655" doc:name="Jira">
<jira:file-names ref="#[sessionVars.fileNamesArray]"/>
<jira:base64-encoded-attachment-data ref="#[sessionVars.fileAttachmentsArray]"/>
</jira:add-base64-encoded-attachments-to-issue>
<logger level="INFO" doc:name="Logger" message="{payload=#[payload]}"/>
</flow>
要设置的有效负载类型是什么
以下是我现在遇到的错误
请求路径:->安全/附件/160026/2015-04-03
12_03_17-Clipboard.png java.net.SocketException:意外结束
服务器上的文件
www.http.HttpClient.parseHTTPHeaderHttpClient.java:772 at
www.http.HttpClient.parseHTTPHttpClient.java:633 at
www.http.HttpClient.parseHTTPHeaderHttpClient.java:769 at
www.http.HttpClient.parseHTTPHttpClient.java:633 at
net.www.protocol.http.HttpURLConnection.getInputStreamHttpURLConnection.java:1324
在
JIRAAttachmentObjectTransformer.onCallJIRAAttachmentObjectTransformer.java:38
在
org.mule.model.resolvers.CallableEntryPointResolver.invokeCallableEntryPointResolver.java:46
在
org.mule.model.resolvers.DefaultEntryPointResolverSet.InvokedDefaultEntryPointResolverset.java:36
在
org.mule.component.DefaultComponentLifecycleAdapter.invokeDefaultComponentLifecycleAdapter.java:339
在
org.mule.component.AbstractJavaComponent.InvokeComponnentInstanceAbstractJavaComponent.java:82
在
org.mule.component.AbstractJavaComponent.doInvokeAstractJavaComponent.java:73
在
org.mule.component.AbstractComponent.invokeInternalAbstractComponent.java:125
在
org.mule.component.AbstractComponent.access$000AbstractComponent.java:59
在
org.mule.component.AbstractComponent$1$1.processAbstractComponent.java:241
在
org.mule.execution.exceptionMessaginExceptionExecutionInterceptor.executeExceptionToMessageExceptionExecutionInterceptor.java:24
在
org.mule.execution.MessageProcessorNotificationExecutionInterceptor.executeMessageProcessorNotificationExecutionInterceptor.java:58
在
org.mule.execution.MessageProcessorExecutionTemplate.executeMessageProcessorExecutionTemplate.java:44
在
org.mule.processor.chain.DefaultMessageProcessorChain.doProcessDefaultMessageProcessorChain.java:94
在
org.mule.processor.chain.AbstractMessageProcessorChain.processAbstractMessageProcessorChain.java:69
在
org.mule.processor.chain.InterceptingChainLifecycleWrapper.doProcessInterceptingChainLifecycleWrapper.java:50
在
org.mule.processor.chain.AbstractMessageProcessorChain.processAbstractMessageProcessorChain.java:69
在
org.mule.processor.chain.InterceptingChainLifecycleWrapper.access$001InterceptingChainLifecycleWrapper.java:22
在
org.mule.processor.chain.InterceptingChainLifecycleWrapper$1.processInterceptingChainLifecycleWrapper.java:66
在
org.mule.execution.exceptionMessaginExceptionExecutionInterceptor.executeExceptionToMessageExceptionExecutionInterceptor.java:24
在
org.mule.execution.MessageProcessorNotificationExecutionInterceptor.executeMessageProcessorNotificationExecutionInterceptor.java:58
在
org.mule.execution.MessageProcessorExecutionTemplate.executeMessageProcessorExecutionTemplate.java:44
在
org.mule.processor.chain.InterceptingChainLifecycleWrapper.processInterceptingChainLifecycleWrapper.java:61
在
org.mule.component.AbstractComponent.processAbstractComponent.java:159
在
org.mule.execution.exceptionMessaginExceptionExecutionInterceptor.executeExceptionToMessageExceptionExecutionInterceptor.java:24
在
org.mule.execution.MessageProcessorNotificationExecutionInterceptor.executeMessageProcessorNotificationExecutionInterceptor.java:58
在
org.mule.execution.MessageProcessorExecutionTemplate.executeMessageProcessorExecutionTemplate.java:44
在
org.mule.processor.chain.DefaultMessageProcessorChain.doProcessDefaultMessageProcessorChain.java:94
在
org.mule.processor.chain.AbstractMessageProcessorChain.processAbstractMessageProcessorChain.java:69
在
org.mule.execution.exceptionMessaginExceptionExecutionInterceptor.executeExceptionToMessageExceptionExecutionInterceptor.java:24
在
org.mule.execution.MessageProcessorExecutionTemplate.executeMessageProcessorExecutionTemplate.java:44
在
我通过以下方法解决了这个问题 Mule流程将附件从一个缺陷移动到另一个缺陷 按照以下步骤在本地Java环境中添加HTTPS安装证书,以便使用HTTPS://特定的JIRA URL 复制附件并移动到另一个缺陷的Java代码
有人知道这个吗???!!请看这个并帮助我
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import org.apache.commons.codec.binary.Base64;
import org.mule.api.MuleEventContext;
import org.mule.api.MuleMessage;
import org.mule.api.transport.PropertyScope;
import org.mule.transformer.AbstractMessageTransformer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class JIRAAttachmentObjectTransformer implements org.mule.api.lifecycle.Callable {
private static Logger logger = LoggerFactory
.getLogger(JIRAAttachmentObjectTransformer.class);
@Override
public Object onCall(MuleEventContext eventContext) throws Exception {
MuleMessage message = eventContext.getMessage();
String reqPath = eventContext.getMessage().getProperty("requestPath", PropertyScope.SESSION);
System.out.println("RequestPath:->"+reqPath);
try{
URL fileConnectPath = new URL("http://xxxx.com:8443/"+reqPath);
URLConnection uc = fileConnectPath.openConnection();
String userpass = "xxxxx" + ":" + "xxxxx";
String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userpass.getBytes());
uc.setRequestProperty ("Authorization", basicAuth);
//URLConnection myURLConnection = myURL.openConnection();
//myURLConnection.connect();
BufferedReader in = new BufferedReader(new InputStreamReader(
uc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null){
System.out.println(inputLine);
}
in.close();
String byteArrayStr= new String(Base64.encodeBase64(inputLine.getBytes()));
String strArray[] = new String[1];
strArray[0] = byteArrayStr;
eventContext.getMessage().setProperty("fileAttachmentsArray", strArray, PropertyScope.SESSION);
String fileName = eventContext.getMessage().getProperty("fileName", PropertyScope.SESSION);
String fileNamesArray[] = new String[1];
fileNamesArray[0]= fileName;
eventContext.getMessage().setProperty("fileNamesArray", fileNamesArray , PropertyScope.SESSION);
System.out.println("Successfully Added to message.");
}catch(Exception e){
e.printStackTrace();
}
return message;
}
}
<flow name="jira-attachments-POC">
<http:listener config-ref="HTTP_Listener_Configuration" path="/attachments" doc:name="HTTP"/>
<jira:get-attachments-from-issue config-ref="Jira" issueKey="#[message.inboundProperties.sourceIssueId]" doc:name="Jira"/>
<set-session-variable variableName="attachementsPayload" value="#[payload]" doc:name="attachementsPayload"/>
<foreach doc:name="For Each">
<set-session-variable variableName="issueAttachmentNames" value="#[payload.attachmentNames]" doc:name="issueAttachmentNames"/>
<set-session-variable variableName="fileAttachmentsArray" value="*" doc:name="Session Variable fileAttachments"/>
<set-session-variable variableName="fileName" value="#[payload.filename]" doc:name="fileName"/>
<set-session-variable variableName="fileSize" value="#[payload.filesize]" doc:name="fileSize"/>
<set-session-variable variableName="fileId" value="#[payload.id]" doc:name="fileId"/>
<set-session-variable variableName="srcIssueKey" value="#[message.inboundProperties.sourceIssueId]" doc:name="srcIssueKey"/>
<set-session-variable variableName="destIssueKey" value="#[message.inboundProperties.targetIssueId]" doc:name="destIssueKey"/>
<set-session-variable variableName="uploadAttachementBaseURL" value="https://www.jiraurl.com:8443/rest/api/2/" doc:name="uploadAttachementBaseURL"/>
<set-session-variable variableName="readAttachmentBaseURL" value="https://www.jirawebsite.com/secure/attachment/" doc:name="readAttachmentBaseURL"/>
<component class="JIRAAttachmentObjectTransformer" doc:name="Java"/>
</foreach>
<set-payload value="{"message":"Sucessfully Attachments Migrated."}" doc:name="Set Payload"/>
<logger level="INFO" doc:name="Logger" />
</flow>
import java.io.File; import java.io.IOException;
import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.mime.MultipartEntityBuilder; import org.apache.http.entity.mime.content.FileBody; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; import org.mule.api.MuleEventContext; import org.mule.api.MuleMessage; import org.mule.api.transport.PropertyScope; import org.slf4j.Logger; import org.slf4j.LoggerFactory;
import de.schlichtherle.io.FileOutputStream;
public class JIRAAttachmentObjectTransformer implements org.mule.api.lifecycle.Callable { private static Logger logger = LoggerFactory .getLogger(JIRAAttachmentObjectTransformer.class);
@Override public Object onCall(MuleEventContext eventContext) throws Exception { MuleMessage message = eventContext.getMessage();
String userName = "xxx"; String password = "xxxxxx";
String sourceBaseURL = eventContext.getMessage().getProperty("readAttachmentBaseURL", PropertyScope.SESSION); String sourceIssueFileId = eventContext.getMessage().getProperty("fileId", PropertyScope.SESSION); String sourceIssueKey = eventContext.getMessage().getProperty("srcIssueKey", PropertyScope.SESSION); String sourceFileName = eventContext.getMessage().getProperty("fileName", PropertyScope.SESSION);
if( ( sourceIssueFileId != null || sourceIssueKey.trim().length() > 0 ) && ( sourceFileName != null || sourceFileName.trim().length() > 0 ) ) { String targetIssueKey = eventContext.getMessage().getProperty("destIssueKey", PropertyScope.SESSION); String targetBaseURL = eventContext.getMessage().getProperty("uploadAttachementBaseURL", PropertyScope.SESSION);
String targetURL = targetBaseURL+"issue/"+sourceIssueKey+"/attachments"; String sourceURL = sourceBaseURL+ sourceIssueFileId +"/" ;
String auth = new String(org.apache.commons.codec.binary.Base64.encodeBase64((userName+":"+password).getBytes()));
File targetFileName = getAttachmentFromIssue( sourceURL , sourceFileName , auth);
System.out.println("Get Attachment Status:->" + targetFileName.toString() );
boolean status = addAttachmentToIssue(targetBaseURL, auth, targetIssueKey, targetFileName);
System.out.println("Upload file to JIRA #" + targetIssueKey + " Status "+ status); }else{ System.out.println("No Attachments Found to Migrate Ticket" );
}
return message;
}
private File getAttachmentFromIssue(String contentURI, String fullfilename, String auth) throws IOException {
CloseableHttpClient httpclient = HttpClients.createDefault(); File fileName = null;
try { HttpGet httpget = new HttpGet(contentURI); logger.info("Source URI:->"+contentURI); httpget.setHeader("Authorization", "Basic " + auth); System.out.println("Executing request " + httpget.getURI()); CloseableHttpResponse response = httpclient.execute(httpget);
int status = response.getStatusLine().getStatusCode(); logger.info("Get Attachment:->" + fullfilename +"::Http Response code:->"+ status ); if (status >= 200 && status < 300) {
HttpEntity entity = response.getEntity();
if (entity.isStreaming()) {
byte data[] = EntityUtils.toByteArray(entity);
fileName = new File(fullfilename);
FileOutputStream fout = new FileOutputStream(fileName);
fout.write(data);
fout.close();
}
logger.info("Successfully file Copied."); } } finally {
httpclient.close();
}
return fileName;
}
private boolean addAttachmentToIssue(String baseJiraURL, String auth, String issueKey, File fileName) throws IOException{
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost(baseJiraURL+"issue/"+issueKey+"/attachments"); logger.info("Target URL:->"+baseJiraURL+"issue/"+issueKey+"/attachments");
httppost.setHeader("X-Atlassian-Token", "nocheck");
httppost.setHeader("Authorization", "Basic "+auth);
FileBody fileBody = new FileBody(fileName);
HttpEntity entity = MultipartEntityBuilder.create().addPart("file", fileBody).build();
httppost.setEntity(entity);
String mess = "executing request " + httppost.getRequestLine();
logger.info(mess);
CloseableHttpResponse response;
try {
response = httpclient.execute(httppost);
logger.info("JIRA Ticket ID:"+issueKey+"::HttResponse code:->" + response.getStatusLine().getStatusCode());
} finally {
httpclient.close();
}
if(response.getStatusLine().getStatusCode() == 200)
return true;
else
return false;
}
}