Использование перехватчиков Apache CXF для запросов SOAP с вложениями, но неправильные вложения перехватываются при поступлении двух одновременных запросов
Ниже приведен мой класс перехватчика, который перехватывает запросы, поступающие из системы ARIBA. Но когда приходят два одновременных запроса, для обоих получены одинаковые данные вложения. в основном второй тоже перекрывает первый. Может кто-нибудь помочь?
public class POSwAInInterceptor extends AbstractSoapInterceptor {
public static final Logger logger = Logger.getLogger(POSwAInInterceptor.class);
public POSwAInInterceptor() {
super(Phase.PRE_INVOKE);
getBefore().add(HolderInInterceptor.class.getName());
getAfter().add(StaxInEndingInterceptor.class.getName());
}
@Override
public void handleMessage(SoapMessage message) throws Fault {
logger.info("Handle Message for attachments ");
BindingOperationInfo bop = message.getExchange().getBindingOperationInfo();
if (bop == null) {
return;
}
if (bop.isUnwrapped()) {
bop = bop.getWrappedOperation();
}
if (null == message.getAttachments() || message.getAttachments().isEmpty() ){
return;
}
Iterator<Attachment> iter = message.getAttachments().iterator();
Collection<Attachment> attchments = message.getAttachments();
logger.info("message get attachments size : "+attchments.size());
int attachmentCount=0;
try{
while (iter.hasNext()){
Attachment attachment = iter.next();
attachmentCount++;
logger.info("before attachment id:" +attachment.getId());
String attachmentName=attachment.getDataHandler().getName();
logger.info( "name :"+ attachment.getDataHandler().getName());
logger.info("mime utility decoded name "+MimeUtility.decodeText(attachmentName));
logger.info("mime utility decoded name "+new String(MimeUtility.decodeText(attachmentName)));
logger.info( " content type:"+ attachment.getDataHandler().getContentType() );
logger.info( " Content Length:"+ attachment.getDataHandler().getContentType().length());
logger.info("iterating attachemnt : "+attachmentCount);
}
}catch(Exception ex){
logger.error(ex.getMessage());
logger.error(ex.getCause());
}
boolean client = isRequestor(message);
BindingMessageInfo bmi = client ? bop.getOutput() : bop.getInput();
if (bmi == null) {
return;
}
SoapBodyInfo sbi = bmi.getExtensor(SoapBodyInfo.class);
if (null == attchments || attchments.isEmpty()){
return;
}
if (sbi == null || sbi.getAttachments() == null || sbi.getAttachments().isEmpty()) {
sbi = new SoapBodyInfo();
logger.info("calling setattachments ...../n message size is : "+message.size());
sbi.setAttachments(custAttachments(message));
}
Set<Integer> foundAtts = new HashSet<>();
MessageContentsList inObjects = MessageContentsList.getContentsList(message);
for (MessagePartInfo mpi : sbi.getAttachments()) {
String partName = mpi.getConcreteName().getLocalPart();
String start = partName + "=";
boolean found = false;
if (foundAtts.contains(mpi.getIndex())) {
continue;
}
foundAtts.add(mpi.getIndex());
for (Attachment a : message.getAttachments()) {
if (start.startsWith(a.getId())) {
logger.info("a.getid():"+a.getId());
logger.info("start:"+start);
logger.info(a.getId().startsWith(start));
DataHandler origDh = a.getDataHandler();
CustomDataHandler dh = new CustomDataHandler(a.getId(),origDh);
String ct = dh.getContentType();
logger.info("content type of the attachment is : "+dh.getContentType());
Object o = null;
Class<?> typeClass = mpi.getTypeClass();
if (DataHandler.class.isAssignableFrom(typeClass)) {
o = dh;
} else if (String.class.isAssignableFrom(typeClass)) {
try {
o = dh.getContent();
} catch (IOException e) {
throw new Fault(e);
}
} else if (byte[].class.isAssignableFrom(typeClass)) {
try {
o = IOUtils.readBytesFromStream(dh.getInputStream());
} catch (IOException e) {
throw new Fault(e);
}
} else if (ct.startsWith("image/")) {
try {
o = ImageIO.read(dh.getInputStream());
} catch (IOException e) {
throw new Fault(e);
}
} else if (ct.startsWith("text/xml") || ct.startsWith("application/xml")) {
try {
o = new StreamSource(dh.getInputStream());
} catch (IOException e) {
throw new Fault(e);
}
} else {
o = dh;
}
inObjects.put(mpi, o);
found = true;
break;
}
}
if (!found) {
inObjects.put(mpi, null);
}
}
}
private List<MessagePartInfo> custAttachments(SoapMessage message){
List<MessagePartInfo> attachmentParts = new ArrayList<>();
MessagePartInfo attachmentInfo = null;
Iterator<Attachment> iter = message.getAttachments().iterator();
int index = 0;
try{
while (iter.hasNext()){
Attachment attachment = iter.next();
attachmentInfo= new MessagePartInfo(new QName("",""), null);
attachmentInfo.setTypeClass(attachment.getDataHandler().getClass());
attachmentInfo.setIndex(++index);
attachmentInfo.setConcreteName(new QName("",""+attachment.getId()));
attachmentParts.add(attachmentInfo);
}
logger.info("attachmentParts size is :"+attachmentParts.size());
return attachmentParts;
}catch(Exception ex){
logger.error(ex.getMessage());
logger.error(ex.getCause());
}
return attachmentParts;
}
}