@Test public void createCommandResolver_WithTimeoutAndOldRequestTime() throws IOException { when(request.getInputStream()).thenReturn( new TestServletInputStream(buildSoapMessage(null, firstOpIn, null, null))); when(request.getScheme()).thenReturn("http"); when(request.getHeader("X-RequestTimeout")).thenReturn("10000"); when(context.getRequestTime()).thenReturn(new Date(System.currentTimeMillis() - 10001)); CommandResolver<HttpCommand> cr = soapCommandProcessor.createCommandResolver(command, tracer); Iterable<ExecutionCommand> executionCommands = cr.resolveExecutionCommands(); ExecutionCommand executionCommand = executionCommands.iterator().next(); TimeConstraints constraints = executionCommand.getTimeConstraints(); assertTrue(constraints.getExpiryTime() < System.currentTimeMillis()); }
@Override protected CommandResolver<HttpCommand> createCommandResolver( final HttpCommand command, final Tracer tracer) { String operationName = null; ByteCountingInputStream in = null; try { in = createByteCountingInputStream(command.getRequest().getInputStream()); XMLInputFactory factory = XMLInputFactory.newInstance(); factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); XMLStreamReader parser = factory.createXMLStreamReader(in); StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(parser); final SOAPHeader header = builder.getSOAPEnvelope().getHeader(); final OMElement credentialElement = getCredentialElement(header); final OMElement requestNode = builder.getSOAPEnvelope().getBody().getFirstElement(); operationName = requestNode.getLocalName(); String fullPathToOperationName = stripMinorVersionFromUri(command.getOperationPath()) + "/" + operationName.toLowerCase(); final SoapOperationBinding binding = bindings.get(fullPathToOperationName); if (binding != null) { if (schemaValidationEnabled) { Schema schema = binding.getSchema(); Validator validator = schema.newValidator(); validator.validate(new StAXSource(requestNode.getXMLStreamReader(true))); } final ByteCountingInputStream finalIn = in; return new SingleExecutionCommandResolver<HttpCommand>(tracer) { private DehydratedExecutionContext context; private ExecutionCommand exec; @Override public DehydratedExecutionContext resolveExecutionContext() { if (context == null) { context = SoapTransportCommandProcessor.this.resolveExecutionContext(command, credentialElement); } return context; } @Override public ExecutionCommand resolveExecutionCommand(Tracer tracer) { if (exec == null) { exec = SoapTransportCommandProcessor.this.resolveExecutionCommand(binding, command, resolveExecutionContext(), requestNode, finalIn, tracer); } return exec; } }; } } catch (CougarException e) { throw e; } catch (SAXException e) { if (e.getException() instanceof TransformerException) { TransformerException te = (TransformerException) e.getException(); if (te.getException() instanceof XMLStreamException) { XMLStreamException se = (XMLStreamException) te.getException(); if (se.getCause() instanceof SAXParseException) { SAXParseException spe = (SAXParseException) se.getCause(); CougarException ce = schemaValidationFailureParser.parse(spe, "soap", false); if (ce != null) { throw ce; } } } } throw CougarMarshallingException.unmarshallingException("soap", e, false); } catch (Exception e) { throw CougarMarshallingException.unmarshallingException("soap", e, false); } finally { try { if (in != null) in.close(); } catch (IOException ie) { throw CougarMarshallingException.unmarshallingException("soap", ie, false); } } throw new CougarValidationException(ServerFaultCode.NoSuchOperation, "The SOAP request could not be resolved to an operation"); }
SoapTransportCommandProcessor extends AbstractTerminateableHttpCommandProcessor<OMElement> { @Override protected CommandResolver<HttpCommand> createCommandResolver( final HttpCommand command, final Tracer tracer) { String operationName = null; ByteCountingInputStream in = null; try { in = createByteCountingInputStream(command.getRequest().getInputStream()); XMLInputFactory factory = XMLInputFactory.newInstance(); factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); XMLStreamReader parser = factory.createXMLStreamReader(in); StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(parser); final SOAPHeader header = builder.getSOAPEnvelope().getHeader(); final OMElement credentialElement = getCredentialElement(header); final OMElement requestNode = builder.getSOAPEnvelope().getBody().getFirstElement(); operationName = requestNode.getLocalName(); String fullPathToOperationName = stripMinorVersionFromUri(command.getOperationPath()) + "/" + operationName.toLowerCase(); final SoapOperationBinding binding = bindings.get(fullPathToOperationName); if (binding != null) { if (schemaValidationEnabled) { Schema schema = binding.getSchema(); Validator validator = schema.newValidator(); validator.validate(new StAXSource(requestNode.getXMLStreamReader(true))); } final ByteCountingInputStream finalIn = in; return new SingleExecutionCommandResolver<HttpCommand>(tracer) { private DehydratedExecutionContext context; private ExecutionCommand exec; @Override public DehydratedExecutionContext resolveExecutionContext() { if (context == null) { context = SoapTransportCommandProcessor.this.resolveExecutionContext(command, credentialElement); } return context; } @Override public ExecutionCommand resolveExecutionCommand(Tracer tracer) { if (exec == null) { exec = SoapTransportCommandProcessor.this.resolveExecutionCommand(binding, command, resolveExecutionContext(), requestNode, finalIn, tracer); } return exec; } }; } } catch (CougarException e) { throw e; } catch (SAXException e) { if (e.getException() instanceof TransformerException) { TransformerException te = (TransformerException) e.getException(); if (te.getException() instanceof XMLStreamException) { XMLStreamException se = (XMLStreamException) te.getException(); if (se.getCause() instanceof SAXParseException) { SAXParseException spe = (SAXParseException) se.getCause(); CougarException ce = schemaValidationFailureParser.parse(spe, "soap", false); if (ce != null) { throw ce; } } } } throw CougarMarshallingException.unmarshallingException("soap", e, false); } catch (Exception e) { throw CougarMarshallingException.unmarshallingException("soap", e, false); } finally { try { if (in != null) in.close(); } catch (IOException ie) { throw CougarMarshallingException.unmarshallingException("soap", ie, false); } } throw new CougarValidationException(ServerFaultCode.NoSuchOperation, "The SOAP request could not be resolved to an operation"); } }
SoapTransportCommandProcessor extends AbstractTerminateableHttpCommandProcessor<OMElement> { @Override protected CommandResolver<HttpCommand> createCommandResolver( final HttpCommand command, final Tracer tracer) { String operationName = null; ByteCountingInputStream in = null; try { in = createByteCountingInputStream(command.getRequest().getInputStream()); XMLInputFactory factory = XMLInputFactory.newInstance(); factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); XMLStreamReader parser = factory.createXMLStreamReader(in); StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(parser); final SOAPHeader header = builder.getSOAPEnvelope().getHeader(); final OMElement credentialElement = getCredentialElement(header); final OMElement requestNode = builder.getSOAPEnvelope().getBody().getFirstElement(); operationName = requestNode.getLocalName(); String fullPathToOperationName = stripMinorVersionFromUri(command.getOperationPath()) + "/" + operationName.toLowerCase(); final SoapOperationBinding binding = bindings.get(fullPathToOperationName); if (binding != null) { if (schemaValidationEnabled) { Schema schema = binding.getSchema(); Validator validator = schema.newValidator(); validator.validate(new StAXSource(requestNode.getXMLStreamReader(true))); } final ByteCountingInputStream finalIn = in; return new SingleExecutionCommandResolver<HttpCommand>(tracer) { private DehydratedExecutionContext context; private ExecutionCommand exec; @Override public DehydratedExecutionContext resolveExecutionContext() { if (context == null) { context = SoapTransportCommandProcessor.this.resolveExecutionContext(command, credentialElement); } return context; } @Override public ExecutionCommand resolveExecutionCommand(Tracer tracer) { if (exec == null) { exec = SoapTransportCommandProcessor.this.resolveExecutionCommand(binding, command, resolveExecutionContext(), requestNode, finalIn, tracer); } return exec; } }; } } catch (CougarException e) { throw e; } catch (SAXException e) { if (e.getException() instanceof TransformerException) { TransformerException te = (TransformerException) e.getException(); if (te.getException() instanceof XMLStreamException) { XMLStreamException se = (XMLStreamException) te.getException(); if (se.getCause() instanceof SAXParseException) { SAXParseException spe = (SAXParseException) se.getCause(); CougarException ce = schemaValidationFailureParser.parse(spe, "soap", false); if (ce != null) { throw ce; } } } } throw CougarMarshallingException.unmarshallingException("soap", e, false); } catch (Exception e) { throw CougarMarshallingException.unmarshallingException("soap", e, false); } finally { try { if (in != null) in.close(); } catch (IOException ie) { throw CougarMarshallingException.unmarshallingException("soap", ie, false); } } throw new CougarValidationException(ServerFaultCode.NoSuchOperation, "The SOAP request could not be resolved to an operation"); } SoapTransportCommandProcessor(DehydratedExecutionContextResolution contextResolution, String requestTimeoutHeader, SchemaValidationFailureParser schemaValidationFailureParser); }
SoapTransportCommandProcessor extends AbstractTerminateableHttpCommandProcessor<OMElement> { @Override protected CommandResolver<HttpCommand> createCommandResolver( final HttpCommand command, final Tracer tracer) { String operationName = null; ByteCountingInputStream in = null; try { in = createByteCountingInputStream(command.getRequest().getInputStream()); XMLInputFactory factory = XMLInputFactory.newInstance(); factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); XMLStreamReader parser = factory.createXMLStreamReader(in); StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(parser); final SOAPHeader header = builder.getSOAPEnvelope().getHeader(); final OMElement credentialElement = getCredentialElement(header); final OMElement requestNode = builder.getSOAPEnvelope().getBody().getFirstElement(); operationName = requestNode.getLocalName(); String fullPathToOperationName = stripMinorVersionFromUri(command.getOperationPath()) + "/" + operationName.toLowerCase(); final SoapOperationBinding binding = bindings.get(fullPathToOperationName); if (binding != null) { if (schemaValidationEnabled) { Schema schema = binding.getSchema(); Validator validator = schema.newValidator(); validator.validate(new StAXSource(requestNode.getXMLStreamReader(true))); } final ByteCountingInputStream finalIn = in; return new SingleExecutionCommandResolver<HttpCommand>(tracer) { private DehydratedExecutionContext context; private ExecutionCommand exec; @Override public DehydratedExecutionContext resolveExecutionContext() { if (context == null) { context = SoapTransportCommandProcessor.this.resolveExecutionContext(command, credentialElement); } return context; } @Override public ExecutionCommand resolveExecutionCommand(Tracer tracer) { if (exec == null) { exec = SoapTransportCommandProcessor.this.resolveExecutionCommand(binding, command, resolveExecutionContext(), requestNode, finalIn, tracer); } return exec; } }; } } catch (CougarException e) { throw e; } catch (SAXException e) { if (e.getException() instanceof TransformerException) { TransformerException te = (TransformerException) e.getException(); if (te.getException() instanceof XMLStreamException) { XMLStreamException se = (XMLStreamException) te.getException(); if (se.getCause() instanceof SAXParseException) { SAXParseException spe = (SAXParseException) se.getCause(); CougarException ce = schemaValidationFailureParser.parse(spe, "soap", false); if (ce != null) { throw ce; } } } } throw CougarMarshallingException.unmarshallingException("soap", e, false); } catch (Exception e) { throw CougarMarshallingException.unmarshallingException("soap", e, false); } finally { try { if (in != null) in.close(); } catch (IOException ie) { throw CougarMarshallingException.unmarshallingException("soap", ie, false); } } throw new CougarValidationException(ServerFaultCode.NoSuchOperation, "The SOAP request could not be resolved to an operation"); } SoapTransportCommandProcessor(DehydratedExecutionContextResolution contextResolution, String requestTimeoutHeader, SchemaValidationFailureParser schemaValidationFailureParser); @ManagedAttribute boolean isSchemaValidationEnabled(); @ManagedAttribute void setSchemaValidationEnabled(boolean schemaValidationEnabled); @Override void onCougarStart(); }
SoapTransportCommandProcessor extends AbstractTerminateableHttpCommandProcessor<OMElement> { @Override protected CommandResolver<HttpCommand> createCommandResolver( final HttpCommand command, final Tracer tracer) { String operationName = null; ByteCountingInputStream in = null; try { in = createByteCountingInputStream(command.getRequest().getInputStream()); XMLInputFactory factory = XMLInputFactory.newInstance(); factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); XMLStreamReader parser = factory.createXMLStreamReader(in); StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(parser); final SOAPHeader header = builder.getSOAPEnvelope().getHeader(); final OMElement credentialElement = getCredentialElement(header); final OMElement requestNode = builder.getSOAPEnvelope().getBody().getFirstElement(); operationName = requestNode.getLocalName(); String fullPathToOperationName = stripMinorVersionFromUri(command.getOperationPath()) + "/" + operationName.toLowerCase(); final SoapOperationBinding binding = bindings.get(fullPathToOperationName); if (binding != null) { if (schemaValidationEnabled) { Schema schema = binding.getSchema(); Validator validator = schema.newValidator(); validator.validate(new StAXSource(requestNode.getXMLStreamReader(true))); } final ByteCountingInputStream finalIn = in; return new SingleExecutionCommandResolver<HttpCommand>(tracer) { private DehydratedExecutionContext context; private ExecutionCommand exec; @Override public DehydratedExecutionContext resolveExecutionContext() { if (context == null) { context = SoapTransportCommandProcessor.this.resolveExecutionContext(command, credentialElement); } return context; } @Override public ExecutionCommand resolveExecutionCommand(Tracer tracer) { if (exec == null) { exec = SoapTransportCommandProcessor.this.resolveExecutionCommand(binding, command, resolveExecutionContext(), requestNode, finalIn, tracer); } return exec; } }; } } catch (CougarException e) { throw e; } catch (SAXException e) { if (e.getException() instanceof TransformerException) { TransformerException te = (TransformerException) e.getException(); if (te.getException() instanceof XMLStreamException) { XMLStreamException se = (XMLStreamException) te.getException(); if (se.getCause() instanceof SAXParseException) { SAXParseException spe = (SAXParseException) se.getCause(); CougarException ce = schemaValidationFailureParser.parse(spe, "soap", false); if (ce != null) { throw ce; } } } } throw CougarMarshallingException.unmarshallingException("soap", e, false); } catch (Exception e) { throw CougarMarshallingException.unmarshallingException("soap", e, false); } finally { try { if (in != null) in.close(); } catch (IOException ie) { throw CougarMarshallingException.unmarshallingException("soap", ie, false); } } throw new CougarValidationException(ServerFaultCode.NoSuchOperation, "The SOAP request could not be resolved to an operation"); } SoapTransportCommandProcessor(DehydratedExecutionContextResolution contextResolution, String requestTimeoutHeader, SchemaValidationFailureParser schemaValidationFailureParser); @ManagedAttribute boolean isSchemaValidationEnabled(); @ManagedAttribute void setSchemaValidationEnabled(boolean schemaValidationEnabled); @Override void onCougarStart();  }