private final S unmarshall(final HttpSuccess success) throws Exception { XMLEventReader reader = null; try { final XMLInputFactory xmlInputFactory = newInstance(); reader = xmlInputFactory.createXMLEventReader(success.getContent()); final StaxUnmarshallerContext stax = new StaxUnmarshallerContext(reader); stax.registerMetadataExpression("ResponseMetadata/RequestId", 2, AWS_REQUEST_ID); stax.registerMetadataExpression("requestId", 2, AWS_REQUEST_ID); return unmarshaller_.unmarshall(stax); } finally { if(reader != null) { reader.close(); } } }
public SqsAwsSdkAction(RequestT request, String requestUrl, Marshaller<com.amazonaws.Request<RequestT>, RequestT> marshaller, Unmarshaller<ResponseT, StaxUnmarshallerContext> unmarshaller) { this.requestUrl = requestUrl; this.request = request; this.marshaller = marshaller; this.staxResponseHandler = new StaxResponseHandler<>(unmarshaller); }
/** * Constructs a new response handler that will use the specified StAX * unmarshaller to unmarshall the service response and uses the specified * response element path to find the root of the business data in the * service's response. * * @param responseUnmarshaller * The StAX unmarshaller to use on the response. */ public StaxResponseHandler(Unmarshaller<T, StaxUnmarshallerContext> responseUnmarshaller) { this.responseUnmarshaller = responseUnmarshaller; /* * Even if the invoked operation just returns null, we still need an * unmarshaller to run so we can pull out response metadata. * * We might want to pass this in through the client class so that we * don't have to do this check here. */ if (this.responseUnmarshaller == null) { this.responseUnmarshaller = new VoidStaxUnmarshaller<T>(); } }
/** * Id (aka configuration name) isn't modeled on the actual {@link NotificationConfiguration} * class but as the key name in the map of configurations in * {@link BucketNotificationConfiguration} */ @Override public Entry<String, NotificationConfiguration> unmarshall(StaxUnmarshallerContext context) throws Exception { int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) { targetDepth += 1; } T topicConfig = createConfiguration(); String id = null; while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) { return new SimpleEntry<String, NotificationConfiguration>(id, topicConfig); } if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) { if (handleXmlEvent(topicConfig, context, targetDepth)) { // Do nothing, subclass has handled it } else if (context.testExpression("Id", targetDepth)) { id = StringStaxUnmarshaller.getInstance().unmarshall(context); } else if (context.testExpression("Event", targetDepth)) { topicConfig.addEvent(StringStaxUnmarshaller.getInstance().unmarshall(context)); } else if (context.testExpression("Filter", targetDepth)) { topicConfig.setFilter(FilterStaxUnmarshaller.getInstance().unmarshall(context)); } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return new SimpleEntry<String, NotificationConfiguration>(id, topicConfig); } } } }
@Override public S3KeyFilter unmarshall(StaxUnmarshallerContext context) throws Exception { int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) { targetDepth += 1; } S3KeyFilter filter = new S3KeyFilter(); while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) { return filter; } if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) { if (context.testExpression("FilterRule", targetDepth)) { filter.addFilterRule(FilterRuleStaxUnmarshaller.getInstance().unmarshall(context)); } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return filter; } } } }
@Override public Filter unmarshall(StaxUnmarshallerContext context) throws Exception { int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) { targetDepth += 1; } Filter filter = new Filter(); while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) { return filter; } if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) { if (context.testExpression("S3Key", targetDepth)) { filter.withS3KeyFilter(S3KeyFilterStaxUnmarshaller.getInstance().unmarshall(context)); } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return filter; } } } }
@Override public FilterRule unmarshall(StaxUnmarshallerContext context) throws Exception { int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) { targetDepth += 1; } FilterRule filter = new FilterRule(); while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) { return filter; } if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) { if (context.testExpression("Name", targetDepth)) { filter.setName(StringStaxUnmarshaller.getInstance().unmarshall(context)); } else if (context.testExpression("Value", targetDepth)) { filter.setValue(StringStaxUnmarshaller.getInstance().unmarshall(context)); } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return filter; } } } }
@Override public Entry<String, NotificationConfiguration> unmarshall(StaxUnmarshallerContext context) throws Exception { int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) { targetDepth += 1; } String id = null; List<String> events = new ArrayList<String>(); Filter filter = null; String functionArn = null; String invocationRole = null; while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) { return createLambdaConfig(id, events, functionArn, invocationRole, filter); } if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) { if (context.testExpression("Id", targetDepth)) { id = StringStaxUnmarshaller.getInstance().unmarshall(context); } else if (context.testExpression("Event", targetDepth)) { events.add(StringStaxUnmarshaller.getInstance().unmarshall(context)); } else if (context.testExpression("Filter", targetDepth)) { filter = FilterStaxUnmarshaller.getInstance().unmarshall(context); } else if (context.testExpression("CloudFunction", targetDepth)) { functionArn = StringStaxUnmarshaller.getInstance().unmarshall(context); } else if (context.testExpression("InvocationRole", targetDepth)) { invocationRole = StringStaxUnmarshaller.getInstance().unmarshall(context); } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return createLambdaConfig(id, events, functionArn, invocationRole, filter); } } } }
protected boolean handleXmlEvent(TopicConfiguration topicConfig, StaxUnmarshallerContext context, int targetDepth) throws Exception { if (context.testExpression("Topic", targetDepth)) { topicConfig.setTopicARN(StringStaxUnmarshaller.getInstance().unmarshall(context)); return true; } return false; }
protected boolean handleXmlEvent(QueueConfiguration queueConfig, StaxUnmarshallerContext context, int targetDepth) throws Exception { if (context.testExpression("Queue", targetDepth)) { queueConfig.setQueueARN(StringStaxUnmarshaller.getInstance().unmarshall(context)); return true; } return false; }
public SqsAwsSdkBatchAction(RequestT request, String requestUrl, Marshaller<Request<RequestT>, RequestT> marshaller, Unmarshaller<ResponseT, StaxUnmarshallerContext> unmarshaller) { super(request, requestUrl, marshaller, unmarshaller); }
public AwsSESHttpClosure(final HttpClient client, final int expectStatus, final Unmarshaller<S,StaxUnmarshallerContext> unmarshaller) { super(client, expectStatus); unmarshaller_ = unmarshaller; }
public AwsSQSHttpClosure(final HttpClient client, final int expectStatus, final Unmarshaller<S,StaxUnmarshallerContext> unmarshaller) { super(client, expectStatus); unmarshaller_ = unmarshaller; }
/** * Hook for subclasses to override in order to collect additional metadata * from service responses. * * @param unmarshallerContext * The unmarshaller context used to configure a service's response * data. */ protected void registerAdditionalMetadataExpressions(StaxUnmarshallerContext unmarshallerContext) {}
/** * Callback to allow subclass first shot at handling an XML event. Only attribute and start * element events are forwarded to subclasses * * @param config * {@link NotificationConfiguration} object we are unmarshalling into * @param context * Context of XML unmarshalling * @param targetDepth * expected depth for this level of unmarshalling * @return True if event has been handled and super class should move on to the next event, * false otherwise * @throws Exception */ protected abstract boolean handleXmlEvent(T config, StaxUnmarshallerContext context, int targetDepth) throws Exception;