idx int64 0 41.2k | question stringlengths 74 4.04k | target stringlengths 7 750 |
|---|---|---|
28,500 | private void parseFault ( BeanDefinitionBuilder builder , Element faultElement ) { if ( faultElement != null ) { Element faultCodeElement = DomUtils . getChildElementByTagName ( faultElement , "fault-code" ) ; if ( faultCodeElement != null ) { builder . addPropertyValue ( "faultCode" , DomUtils . getTextValue ( faultCodeElement ) . trim ( ) ) ; } Element faultStringElement = DomUtils . getChildElementByTagName ( faultElement , "fault-string" ) ; if ( faultStringElement != null ) { builder . addPropertyValue ( "faultString" , DomUtils . getTextValue ( faultStringElement ) . trim ( ) ) ; } Element faultActorElement = DomUtils . getChildElementByTagName ( faultElement , "fault-actor" ) ; if ( faultActorElement != null ) { builder . addPropertyValue ( "faultActor" , DomUtils . getTextValue ( faultActorElement ) . trim ( ) ) ; } parseFaultDetail ( builder , faultElement ) ; } } | Parses the SOAP fault information . |
28,501 | private void parseFaultDetail ( BeanDefinitionBuilder builder , Element faultElement ) { List < Element > faultDetailElements = DomUtils . getChildElementsByTagName ( faultElement , "fault-detail" ) ; List < String > faultDetails = new ArrayList < String > ( ) ; List < String > faultDetailResourcePaths = new ArrayList < String > ( ) ; for ( Element faultDetailElement : faultDetailElements ) { if ( faultDetailElement . hasAttribute ( "file" ) ) { if ( StringUtils . hasText ( DomUtils . getTextValue ( faultDetailElement ) . trim ( ) ) ) { throw new BeanCreationException ( "You tried to set fault-detail by file resource attribute and inline text value at the same time! " + "Please choose one of them." ) ; } String charset = faultDetailElement . getAttribute ( "charset" ) ; String filePath = faultDetailElement . getAttribute ( "file" ) ; faultDetailResourcePaths . add ( filePath + ( StringUtils . hasText ( charset ) ? FileUtils . FILE_PATH_CHARSET_PARAMETER + charset : "" ) ) ; } else { String faultDetailData = DomUtils . getTextValue ( faultDetailElement ) . trim ( ) ; if ( StringUtils . hasText ( faultDetailData ) ) { faultDetails . add ( faultDetailData ) ; } else { throw new BeanCreationException ( "Not content for fault-detail is set! Either use file attribute or inline text value for fault-detail element." ) ; } } } builder . addPropertyValue ( "faultDetails" , faultDetails ) ; builder . addPropertyValue ( "faultDetailResourcePaths" , faultDetailResourcePaths ) ; } | Parses the fault detail element . |
28,502 | public static FtpMessage command ( FTPCmd command ) { Command cmd = new Command ( ) ; cmd . setSignal ( command . getCommand ( ) ) ; return new FtpMessage ( cmd ) ; } | Sets the ftp command . |
28,503 | public static FtpMessage connect ( String sessionId ) { ConnectCommand cmd = new ConnectCommand ( ) ; cmd . setSignal ( "OPEN" ) ; cmd . setSessionId ( sessionId ) ; return new FtpMessage ( cmd ) ; } | Creates new connect command message . |
28,504 | public FtpMessage arguments ( String arguments ) { if ( command != null ) { command . setArguments ( arguments ) ; } setHeader ( FtpMessageHeaders . FTP_ARGS , arguments ) ; return this ; } | Sets the command args . |
28,505 | public String getSignal ( ) { return Optional . ofNullable ( getHeader ( FtpMessageHeaders . FTP_COMMAND ) ) . map ( Object :: toString ) . orElse ( null ) ; } | Gets the ftp command signal . |
28,506 | public String getArguments ( ) { return Optional . ofNullable ( getHeader ( FtpMessageHeaders . FTP_ARGS ) ) . map ( Object :: toString ) . orElse ( null ) ; } | Gets the command args . |
28,507 | public Integer getReplyCode ( ) { Object replyCode = getHeader ( FtpMessageHeaders . FTP_REPLY_CODE ) ; if ( replyCode != null ) { if ( replyCode instanceof Integer ) { return ( Integer ) replyCode ; } else { return Integer . valueOf ( replyCode . toString ( ) ) ; } } else if ( commandResult != null ) { return Optional . ofNullable ( commandResult . getReplyCode ( ) ) . map ( Integer :: valueOf ) . orElse ( FTPReply . COMMAND_OK ) ; } return null ; } | Gets the reply code . |
28,508 | public String getReplyString ( ) { Object replyString = getHeader ( FtpMessageHeaders . FTP_REPLY_STRING ) ; if ( replyString != null ) { return replyString . toString ( ) ; } return null ; } | Gets the reply string . |
28,509 | private < T extends CommandResultType > T getCommandResult ( ) { if ( commandResult == null ) { if ( getPayload ( ) instanceof String ) { this . commandResult = ( T ) marshaller . unmarshal ( new StringSource ( getPayload ( String . class ) ) ) ; } } return ( T ) commandResult ; } | Gets the command result if any or tries to unmarshal String payload representation to an command result model . |
28,510 | private < T extends CommandType > T getCommand ( ) { if ( command == null ) { if ( getPayload ( ) instanceof String ) { this . command = ( T ) marshaller . unmarshal ( new StringSource ( getPayload ( String . class ) ) ) ; } } return ( T ) command ; } | Gets the command if any or tries to unmarshal String payload representation to an command model . |
28,511 | private void setCommandHeader ( CommandType command ) { String header ; if ( command instanceof ConnectCommand ) { header = FtpMessage . OPEN_COMMAND ; } else if ( command instanceof GetCommand ) { header = FTPCmd . RETR . getCommand ( ) ; } else if ( command instanceof PutCommand ) { header = FTPCmd . STOR . getCommand ( ) ; } else if ( command instanceof ListCommand ) { header = FTPCmd . LIST . getCommand ( ) ; } else if ( command instanceof DeleteCommand ) { header = FTPCmd . DELE . getCommand ( ) ; } else { header = command . getSignal ( ) ; } setHeader ( FtpMessageHeaders . FTP_COMMAND , header ) ; } | Gets command header as ftp signal from command object . |
28,512 | public static boolean evaluate ( final String expression ) { final Deque < String > operators = new ArrayDeque < > ( ) ; final Deque < String > values = new ArrayDeque < > ( ) ; final boolean result ; char currentCharacter ; int currentCharacterIndex = 0 ; try { while ( currentCharacterIndex < expression . length ( ) ) { currentCharacter = expression . charAt ( currentCharacterIndex ) ; if ( SeparatorToken . OPEN_PARENTHESIS . value == currentCharacter ) { operators . push ( SeparatorToken . OPEN_PARENTHESIS . toString ( ) ) ; currentCharacterIndex += moveCursor ( SeparatorToken . OPEN_PARENTHESIS . toString ( ) ) ; } else if ( SeparatorToken . SPACE . value == currentCharacter ) { currentCharacterIndex += moveCursor ( SeparatorToken . SPACE . toString ( ) ) ; } else if ( SeparatorToken . CLOSE_PARENTHESIS . value == currentCharacter ) { evaluateSubexpression ( operators , values ) ; currentCharacterIndex += moveCursor ( SeparatorToken . CLOSE_PARENTHESIS . toString ( ) ) ; } else if ( ! Character . isDigit ( currentCharacter ) ) { final String parsedNonDigit = parseNonDigits ( expression , currentCharacterIndex ) ; if ( isBoolean ( parsedNonDigit ) ) { values . push ( replaceBooleanStringByIntegerRepresentation ( parsedNonDigit ) ) ; } else { operators . push ( validateOperator ( parsedNonDigit ) ) ; } currentCharacterIndex += moveCursor ( parsedNonDigit ) ; } else if ( Character . isDigit ( currentCharacter ) ) { final String parsedDigits = parseDigits ( expression , currentCharacterIndex ) ; values . push ( parsedDigits ) ; currentCharacterIndex += moveCursor ( parsedDigits ) ; } } result = Boolean . valueOf ( evaluateExpressionStack ( operators , values ) ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( "Boolean expression {} evaluates to {}" , expression , result ) ; } } catch ( final NoSuchElementException e ) { throw new CitrusRuntimeException ( "Unable to parse boolean expression '" + expression + "'. Maybe expression is incomplete!" , e ) ; } return result ; } | Perform evaluation of boolean expression string . |
28,513 | private static String evaluateExpressionStack ( final Deque < String > operators , final Deque < String > values ) { while ( ! operators . isEmpty ( ) ) { values . push ( getBooleanResultAsString ( operators . pop ( ) , values . pop ( ) , values . pop ( ) ) ) ; } return replaceIntegerStringByBooleanRepresentation ( values . pop ( ) ) ; } | This method takes stacks of operators and values and evaluates possible expressions This is done by popping one operator and two values applying the operator to the values and pushing the result back onto the value stack |
28,514 | private static void evaluateSubexpression ( final Deque < String > operators , final Deque < String > values ) { String operator = operators . pop ( ) ; while ( ! ( operator ) . equals ( SeparatorToken . OPEN_PARENTHESIS . toString ( ) ) ) { values . push ( getBooleanResultAsString ( operator , values . pop ( ) , values . pop ( ) ) ) ; operator = operators . pop ( ) ; } } | Evaluates a sub expression within a pair of parentheses and pushes its result onto the stack of values |
28,515 | private static String parseDigits ( final String expression , final int startIndex ) { final StringBuilder digitBuffer = new StringBuilder ( ) ; char currentCharacter = expression . charAt ( startIndex ) ; int subExpressionIndex = startIndex ; do { digitBuffer . append ( currentCharacter ) ; ++ subExpressionIndex ; if ( subExpressionIndex < expression . length ( ) ) { currentCharacter = expression . charAt ( subExpressionIndex ) ; } } while ( subExpressionIndex < expression . length ( ) && Character . isDigit ( currentCharacter ) ) ; return digitBuffer . toString ( ) ; } | This method reads digit characters from a given string starting at a given index . It will read till the end of the string or up until it encounters a non - digit character |
28,516 | private static String replaceBooleanStringByIntegerRepresentation ( final String possibleBooleanString ) { if ( possibleBooleanString . equals ( TRUE . toString ( ) ) ) { return "1" ; } else if ( possibleBooleanString . equals ( FALSE . toString ( ) ) ) { return "0" ; } return possibleBooleanString ; } | Checks whether a String is a Boolean value and replaces it with its Integer representation true - > 1 false - > 0 |
28,517 | private static boolean isSeparatorToken ( final char possibleSeparatorChar ) { for ( final SeparatorToken token : SeparatorToken . values ( ) ) { if ( token . value == possibleSeparatorChar ) { return true ; } } return false ; } | Checks whether a given character is a known separator token or no |
28,518 | private static String validateOperator ( final String operator ) { if ( ! OPERATORS . contains ( operator ) && ! BOOLEAN_OPERATORS . contains ( operator ) ) { throw new CitrusRuntimeException ( "Unknown operator '" + operator + "'" ) ; } return operator ; } | Check if operator is known to this class . |
28,519 | public void runPackages ( List < String > packages ) { CitrusAppConfiguration citrusAppConfiguration = new CitrusAppConfiguration ( ) ; citrusAppConfiguration . setIncludes ( Optional . ofNullable ( includes ) . orElse ( configuration . getIncludes ( ) ) ) ; citrusAppConfiguration . setPackages ( packages ) ; citrusAppConfiguration . setConfigClass ( configuration . getConfigClass ( ) ) ; citrusAppConfiguration . addDefaultProperties ( configuration . getDefaultProperties ( ) ) ; citrusAppConfiguration . addDefaultProperties ( defaultProperties ) ; run ( citrusAppConfiguration ) ; } | Run Citrus application with given test package names . |
28,520 | public void runClasses ( List < TestClass > testClasses ) { CitrusAppConfiguration citrusAppConfiguration = new CitrusAppConfiguration ( ) ; citrusAppConfiguration . setTestClasses ( testClasses ) ; citrusAppConfiguration . setConfigClass ( configuration . getConfigClass ( ) ) ; citrusAppConfiguration . addDefaultProperties ( configuration . getDefaultProperties ( ) ) ; citrusAppConfiguration . addDefaultProperties ( defaultProperties ) ; run ( citrusAppConfiguration ) ; } | Run Citrus application with given test class names . |
28,521 | public boolean handleRequest ( MessageContext messageContext , Object endpoint ) throws Exception { logRequest ( "Received SOAP request" , messageContext , true ) ; return true ; } | Write request message to logger . |
28,522 | public boolean handleResponse ( MessageContext messageContext , Object endpoint ) throws Exception { logResponse ( "Sending SOAP response" , messageContext , false ) ; return true ; } | Write response message to logger . |
28,523 | public RestTemplate getRestTemplate ( ) { if ( restTemplate == null ) { restTemplate = new RestTemplate ( ) ; restTemplate . setRequestFactory ( getRequestFactory ( ) ) ; } restTemplate . setErrorHandler ( getErrorHandler ( ) ) ; if ( ! defaultAcceptHeader ) { for ( org . springframework . http . converter . HttpMessageConverter messageConverter : restTemplate . getMessageConverters ( ) ) { if ( messageConverter instanceof StringHttpMessageConverter ) { ( ( StringHttpMessageConverter ) messageConverter ) . setWriteAcceptCharset ( defaultAcceptHeader ) ; } } } return restTemplate ; } | Gets the restTemplate . |
28,524 | private String getNodeValue ( Node node ) { if ( node . getNodeType ( ) == Node . ELEMENT_NODE && node . getFirstChild ( ) != null ) { return node . getFirstChild ( ) . getNodeValue ( ) ; } else { return node . getNodeValue ( ) ; } } | Resolves an XML node s value |
28,525 | public static String getRandomNumber ( int numberLength , boolean paddingOn ) { if ( numberLength < 1 ) { throw new InvalidFunctionUsageException ( "numberLength must be greater than 0 - supplied " + numberLength ) ; } StringBuilder buffer = new StringBuilder ( ) ; for ( int i = 0 ; i < numberLength ; i ++ ) { buffer . append ( generator . nextInt ( 10 ) ) ; } return checkLeadingZeros ( buffer . toString ( ) , paddingOn ) ; } | Static number generator method . |
28,526 | public static String checkLeadingZeros ( String generated , boolean paddingOn ) { if ( paddingOn ) { return replaceLeadingZero ( generated ) ; } else { return removeLeadingZeros ( generated ) ; } } | Remove leading Zero numbers . |
28,527 | private static String removeLeadingZeros ( String generated ) { StringBuilder builder = new StringBuilder ( ) ; boolean leading = true ; for ( int i = 0 ; i < generated . length ( ) ; i ++ ) { if ( generated . charAt ( i ) == '0' && leading ) { continue ; } else { leading = false ; builder . append ( generated . charAt ( i ) ) ; } } if ( builder . length ( ) == 0 ) { builder . append ( '0' ) ; } return builder . toString ( ) ; } | Removes leading zero numbers if present . |
28,528 | private static String replaceLeadingZero ( String generated ) { if ( generated . charAt ( 0 ) == '0' ) { int replacement = 0 ; while ( replacement == 0 ) { replacement = generator . nextInt ( 10 ) ; } return replacement + generated . substring ( 1 ) ; } else { return generated ; } } | Replaces first leading zero number if present . |
28,529 | public void configure ( @ Observes ( precedence = CitrusExtensionConstants . REMOTE_CONFIG_PRECEDENCE ) BeforeSuite event ) { try { log . info ( "Producing Citrus remote configuration" ) ; configurationInstance . set ( CitrusConfiguration . from ( getRemoteConfigurationProperties ( ) ) ) ; } catch ( Exception e ) { log . error ( CitrusExtensionConstants . CITRUS_EXTENSION_ERROR , e ) ; throw e ; } } | Observes before suite event and tries to load Citrus remote extension properties . |
28,530 | private Properties getRemoteConfigurationProperties ( ) { ClassLoader ctcl = AccessController . doPrivileged ( new PrivilegedAction < ClassLoader > ( ) { public ClassLoader run ( ) { return Thread . currentThread ( ) . getContextClassLoader ( ) ; } } ) ; try { if ( log . isDebugEnabled ( ) ) { log . debug ( "Loading Citrus remote extension properties ..." ) ; } Properties props = new Properties ( ) ; InputStream inputStream = ctcl . getResourceAsStream ( CitrusExtensionConstants . CITRUS_REMOTE_PROPERTIES ) ; if ( inputStream != null ) { props . load ( inputStream ) ; } if ( log . isDebugEnabled ( ) ) { log . debug ( "Successfully loaded Citrus remote extension properties" ) ; } return props ; } catch ( IOException e ) { log . warn ( "Unable to load Citrus remote extension properties" ) ; return new Properties ( ) ; } } | Reads configuration properties from remote property file that has been added to the auxiliary archive . |
28,531 | protected Map < String , String > getWithoutLabels ( String labelExpression , TestContext context ) { Map < String , String > labels = new HashMap < > ( ) ; Set < String > values = StringUtils . commaDelimitedListToSet ( labelExpression ) ; for ( String item : values ) { if ( item . contains ( "!=" ) ) { labels . put ( context . replaceDynamicContentInString ( item . substring ( 0 , item . indexOf ( "!=" ) ) ) , context . replaceDynamicContentInString ( item . substring ( item . indexOf ( "!=" ) + 2 ) ) ) ; } else if ( item . startsWith ( "!" ) ) { labels . put ( context . replaceDynamicContentInString ( item . substring ( 1 ) ) , null ) ; } } return labels ; } | Reads without labels from expression string . |
28,532 | private Object handleInvocation ( ManagedBeanInvocation mbeanInvocation ) { Message response = endpointAdapter . handleMessage ( endpointConfiguration . getMessageConverter ( ) . convertInbound ( mbeanInvocation , endpointConfiguration , null ) ) ; ManagedBeanResult serviceResult = null ; if ( response != null && response . getPayload ( ) != null ) { if ( response . getPayload ( ) instanceof ManagedBeanResult ) { serviceResult = ( ManagedBeanResult ) response . getPayload ( ) ; } else if ( response . getPayload ( ) instanceof String ) { serviceResult = ( ManagedBeanResult ) endpointConfiguration . getMarshaller ( ) . unmarshal ( response . getPayload ( Source . class ) ) ; } } if ( serviceResult != null ) { return serviceResult . getResultObject ( endpointConfiguration . getApplicationContext ( ) ) ; } else { return null ; } } | Handle managed bean invocation by delegating to endpoint adapter . Response is converted to proper method return result . |
28,533 | private void traverseJsonData ( JSONObject jsonData , String jsonPath , TestContext context ) { for ( Iterator it = jsonData . entrySet ( ) . iterator ( ) ; it . hasNext ( ) ; ) { Map . Entry jsonEntry = ( Map . Entry ) it . next ( ) ; if ( jsonEntry . getValue ( ) instanceof JSONObject ) { traverseJsonData ( ( JSONObject ) jsonEntry . getValue ( ) , ( StringUtils . hasText ( jsonPath ) ? jsonPath + "." + jsonEntry . getKey ( ) : jsonEntry . getKey ( ) . toString ( ) ) , context ) ; } else if ( jsonEntry . getValue ( ) instanceof JSONArray ) { JSONArray jsonArray = ( JSONArray ) jsonEntry . getValue ( ) ; for ( int i = 0 ; i < jsonArray . size ( ) ; i ++ ) { if ( jsonArray . get ( i ) instanceof JSONObject ) { traverseJsonData ( ( JSONObject ) jsonArray . get ( i ) , String . format ( ( StringUtils . hasText ( jsonPath ) ? jsonPath + "." + jsonEntry . getKey ( ) : jsonEntry . getKey ( ) . toString ( ) ) + "[%s]" , i ) , context ) ; } else { jsonArray . set ( i , translate ( String . format ( ( StringUtils . hasText ( jsonPath ) ? jsonPath + "." + jsonEntry . getKey ( ) : jsonEntry . getKey ( ) . toString ( ) ) + "[%s]" , i ) , jsonArray . get ( i ) , context ) ) ; } } } else { jsonEntry . setValue ( translate ( ( StringUtils . hasText ( jsonPath ) ? jsonPath + "." + jsonEntry . getKey ( ) : jsonEntry . getKey ( ) . toString ( ) ) , jsonEntry . getValue ( ) != null ? jsonEntry . getValue ( ) : null , context ) ) ; } } } | Walks through the Json object structure and translates values based on element path if necessary . |
28,534 | private String getDigestHex ( String algorithm , String key ) { if ( algorithm . equals ( "md5" ) ) { return DigestUtils . md5Hex ( key ) ; } else if ( algorithm . equals ( "sha" ) ) { return DigestUtils . shaHex ( key ) ; } throw new CitrusRuntimeException ( "Unsupported digest algorithm: " + algorithm ) ; } | Generates digest hexadecimal string representation of a key with given algorithm . |
28,535 | private boolean simulateHttpStatusCode ( Message replyMessage ) throws IOException { if ( replyMessage == null || CollectionUtils . isEmpty ( replyMessage . getHeaders ( ) ) ) { return false ; } for ( Entry < String , Object > headerEntry : replyMessage . getHeaders ( ) . entrySet ( ) ) { if ( headerEntry . getKey ( ) . equalsIgnoreCase ( SoapMessageHeaders . HTTP_STATUS_CODE ) ) { WebServiceConnection connection = TransportContextHolder . getTransportContext ( ) . getConnection ( ) ; int statusCode = Integer . valueOf ( headerEntry . getValue ( ) . toString ( ) ) ; if ( connection instanceof HttpServletConnection ) { ( ( HttpServletConnection ) connection ) . setFault ( false ) ; ( ( HttpServletConnection ) connection ) . getHttpServletResponse ( ) . setStatus ( statusCode ) ; return true ; } else { log . warn ( "Unable to set custom Http status code on connection other than HttpServletConnection (" + connection . getClass ( ) . getName ( ) + ")" ) ; } } } return false ; } | If Http status code is set on reply message headers simulate Http error with status code . No SOAP response is sent back in this case . |
28,536 | private void addSoapBody ( SoapMessage response , Message replyMessage ) throws TransformerException { if ( ! ( replyMessage . getPayload ( ) instanceof String ) || StringUtils . hasText ( replyMessage . getPayload ( String . class ) ) ) { Source responseSource = getPayloadAsSource ( replyMessage . getPayload ( ) ) ; TransformerFactory transformerFactory = TransformerFactory . newInstance ( ) ; Transformer transformer = transformerFactory . newTransformer ( ) ; transformer . transform ( responseSource , response . getPayloadResult ( ) ) ; } } | Add message payload as SOAP body element to the SOAP response . |
28,537 | private void addSoapHeaders ( SoapMessage response , Message replyMessage ) throws TransformerException { for ( Entry < String , Object > headerEntry : replyMessage . getHeaders ( ) . entrySet ( ) ) { if ( MessageHeaderUtils . isSpringInternalHeader ( headerEntry . getKey ( ) ) || headerEntry . getKey ( ) . startsWith ( DEFAULT_JMS_HEADER_PREFIX ) ) { continue ; } if ( headerEntry . getKey ( ) . equalsIgnoreCase ( SoapMessageHeaders . SOAP_ACTION ) ) { response . setSoapAction ( headerEntry . getValue ( ) . toString ( ) ) ; } else if ( ! headerEntry . getKey ( ) . startsWith ( MessageHeaders . PREFIX ) ) { SoapHeaderElement headerElement ; if ( QNameUtils . validateQName ( headerEntry . getKey ( ) ) ) { QName qname = QNameUtils . parseQNameString ( headerEntry . getKey ( ) ) ; if ( StringUtils . hasText ( qname . getNamespaceURI ( ) ) ) { headerElement = response . getSoapHeader ( ) . addHeaderElement ( qname ) ; } else { headerElement = response . getSoapHeader ( ) . addHeaderElement ( getDefaultQName ( headerEntry . getKey ( ) ) ) ; } } else { throw new SoapHeaderException ( "Failed to add SOAP header '" + headerEntry . getKey ( ) + "', " + "because of invalid QName" ) ; } headerElement . setText ( headerEntry . getValue ( ) . toString ( ) ) ; } } for ( String headerData : replyMessage . getHeaderData ( ) ) { TransformerFactory transformerFactory = TransformerFactory . newInstance ( ) ; Transformer transformer = transformerFactory . newTransformer ( ) ; transformer . transform ( new StringSource ( headerData ) , response . getSoapHeader ( ) . getResult ( ) ) ; } } | Translates message headers to SOAP headers in response . |
28,538 | private QName getDefaultQName ( String localPart ) { if ( StringUtils . hasText ( defaultNamespaceUri ) ) { return new QName ( defaultNamespaceUri , localPart , defaultPrefix ) ; } else { throw new SoapHeaderException ( "Failed to add SOAP header '" + localPart + "', " + "because neither valid QName nor default namespace-uri is set!" ) ; } } | Get the default QName from local part . |
28,539 | protected static String getBaseKey ( ExtensionContext extensionContext ) { return extensionContext . getRequiredTestClass ( ) . getName ( ) + "." + extensionContext . getRequiredTestMethod ( ) . getName ( ) + "#" ; } | Gets base key for store . |
28,540 | public static Stream < DynamicTest > packageScan ( String ... packagesToScan ) { List < DynamicTest > tests = new ArrayList < > ( ) ; for ( String packageScan : packagesToScan ) { try { for ( String fileNamePattern : Citrus . getXmlTestFileNamePattern ( ) ) { Resource [ ] fileResources = new PathMatchingResourcePatternResolver ( ) . getResources ( packageScan . replace ( '.' , File . separatorChar ) + fileNamePattern ) ; for ( Resource fileResource : fileResources ) { String filePath = fileResource . getFile ( ) . getParentFile ( ) . getCanonicalPath ( ) ; if ( packageScan . startsWith ( "file:" ) ) { filePath = "file:" + filePath ; } filePath = filePath . substring ( filePath . indexOf ( packageScan . replace ( '.' , File . separatorChar ) ) ) ; String testName = fileResource . getFilename ( ) . substring ( 0 , fileResource . getFilename ( ) . length ( ) - ".xml" . length ( ) ) ; XmlTestLoader testLoader = new XmlTestLoader ( DynamicTest . class , testName , filePath , citrus . getApplicationContext ( ) ) ; tests . add ( DynamicTest . dynamicTest ( testName , ( ) -> citrus . run ( testLoader . load ( ) ) ) ) ; } } } catch ( IOException e ) { throw new CitrusRuntimeException ( "Unable to locate file resources for test package '" + packageScan + "'" , e ) ; } } return tests . stream ( ) ; } | Creates stream of dynamic tests based on package scan . Scans package for all Xml test case files and creates dynamic test instance for it . |
28,541 | public static KubernetesMessage request ( KubernetesCommand < ? > command ) { KubernetesRequest request = new KubernetesRequest ( ) ; request . setCommand ( command . getName ( ) ) ; for ( Map . Entry < String , Object > entry : command . getParameters ( ) . entrySet ( ) ) { if ( entry . getKey ( ) . equals ( KubernetesMessageHeaders . NAME ) ) { request . setName ( entry . getValue ( ) . toString ( ) ) ; } if ( entry . getKey ( ) . equals ( KubernetesMessageHeaders . NAMESPACE ) ) { request . setNamespace ( entry . getValue ( ) . toString ( ) ) ; } if ( entry . getKey ( ) . equals ( KubernetesMessageHeaders . LABEL ) ) { request . setLabel ( entry . getValue ( ) . toString ( ) ) ; } } return new KubernetesMessage ( request ) ; } | Request generating instantiation . |
28,542 | public boolean isFunction ( final String variableExpression ) { if ( variableExpression == null || variableExpression . length ( ) == 0 ) { return false ; } for ( int i = 0 ; i < functionLibraries . size ( ) ; i ++ ) { FunctionLibrary lib = ( FunctionLibrary ) functionLibraries . get ( i ) ; if ( variableExpression . startsWith ( lib . getPrefix ( ) ) ) { return true ; } } return false ; } | Check if variable expression is a custom function . Expression has to start with one of the registered function library prefix . |
28,543 | public FunctionLibrary getLibraryForPrefix ( String functionPrefix ) { for ( int i = 0 ; i < functionLibraries . size ( ) ; i ++ ) { if ( ( ( FunctionLibrary ) functionLibraries . get ( i ) ) . getPrefix ( ) . equals ( functionPrefix ) ) { return ( FunctionLibrary ) functionLibraries . get ( i ) ; } } throw new NoSuchFunctionLibraryException ( "Can not find function library for prefix " + functionPrefix ) ; } | Get library for function prefix . |
28,544 | protected void configureMessageEndpoint ( ApplicationContext context ) { if ( context . containsBean ( MESSAGE_ENDPOINT_BEAN_NAME ) ) { WebServiceEndpoint messageEndpoint = context . getBean ( MESSAGE_ENDPOINT_BEAN_NAME , WebServiceEndpoint . class ) ; EndpointAdapter endpointAdapter = webServiceServer . getEndpointAdapter ( ) ; if ( endpointAdapter != null ) { messageEndpoint . setEndpointAdapter ( endpointAdapter ) ; } WebServiceEndpointConfiguration endpointConfiguration = new WebServiceEndpointConfiguration ( ) ; endpointConfiguration . setHandleMimeHeaders ( webServiceServer . isHandleMimeHeaders ( ) ) ; endpointConfiguration . setHandleAttributeHeaders ( webServiceServer . isHandleAttributeHeaders ( ) ) ; endpointConfiguration . setKeepSoapEnvelope ( webServiceServer . isKeepSoapEnvelope ( ) ) ; endpointConfiguration . setMessageConverter ( webServiceServer . getMessageConverter ( ) ) ; messageEndpoint . setEndpointConfiguration ( endpointConfiguration ) ; if ( StringUtils . hasText ( webServiceServer . getSoapHeaderNamespace ( ) ) ) { messageEndpoint . setDefaultNamespaceUri ( webServiceServer . getSoapHeaderNamespace ( ) ) ; } if ( StringUtils . hasText ( webServiceServer . getSoapHeaderPrefix ( ) ) ) { messageEndpoint . setDefaultPrefix ( webServiceServer . getSoapHeaderPrefix ( ) ) ; } } } | Post process endpoint . |
28,545 | private List < EndpointInterceptor > adaptInterceptors ( List < Object > interceptors ) { List < EndpointInterceptor > endpointInterceptors = new ArrayList < EndpointInterceptor > ( ) ; if ( interceptors != null ) { for ( Object interceptor : interceptors ) { if ( interceptor instanceof EndpointInterceptor ) { endpointInterceptors . add ( ( EndpointInterceptor ) interceptor ) ; } } } return endpointInterceptors ; } | Adapts object list to endpoint interceptors . |
28,546 | public ZipMessage addEntry ( Resource resource ) { try { addEntry ( new Entry ( resource . getFile ( ) ) ) ; } catch ( IOException e ) { throw new CitrusRuntimeException ( "Failed to read zip entry content from given resource" , e ) ; } return this ; } | Adds new zip archive entry . Resource can be a file or directory . In case of directory all files will be automatically added to the zip archive . Directory structures are retained throughout this process . |
28,547 | public ZipMessage addEntry ( File file ) { try { addEntry ( new Entry ( file ) ) ; } catch ( IOException e ) { throw new CitrusRuntimeException ( "Failed to read zip entry content from given file" , e ) ; } return this ; } | Adds new zip archive entry . Entry can be a file or directory . In case of directory all files will be automatically added to the zip archive . Directory structures are retained throughout this process . |
28,548 | public ZipMessage addEntry ( String fileName , byte [ ] content ) { Entry entry = new Entry ( fileName ) ; entry . setContent ( content ) ; addEntry ( entry ) ; return this ; } | Adds new zip archive entry with given content . |
28,549 | protected void handleInboundSoapMessage ( final org . springframework . ws . soap . SoapMessage soapMessage , final SoapMessage message , final WebServiceEndpointConfiguration endpointConfiguration ) { handleInboundNamespaces ( soapMessage , message ) ; handleInboundSoapHeaders ( soapMessage , message ) ; handleInboundAttachments ( soapMessage , message ) ; if ( endpointConfiguration . isHandleMimeHeaders ( ) ) { handleInboundMimeHeaders ( soapMessage , message ) ; } } | Method handles SOAP specific message information such as SOAP action headers and SOAP attachments . |
28,550 | protected void handleInboundHttpHeaders ( final SoapMessage message , final WebServiceEndpointConfiguration endpointConfiguration ) { final TransportContext transportContext = TransportContextHolder . getTransportContext ( ) ; if ( transportContext == null ) { log . warn ( "Unable to get complete set of http request headers - no transport context available" ) ; return ; } final WebServiceConnection connection = transportContext . getConnection ( ) ; if ( connection instanceof HttpServletConnection ) { final UrlPathHelper pathHelper = new UrlPathHelper ( ) ; final HttpServletConnection servletConnection = ( HttpServletConnection ) connection ; final HttpServletRequest httpServletRequest = servletConnection . getHttpServletRequest ( ) ; message . setHeader ( SoapMessageHeaders . HTTP_REQUEST_URI , pathHelper . getRequestUri ( httpServletRequest ) ) ; message . setHeader ( SoapMessageHeaders . HTTP_CONTEXT_PATH , pathHelper . getContextPath ( httpServletRequest ) ) ; final String queryParams = pathHelper . getOriginatingQueryString ( httpServletRequest ) ; message . setHeader ( SoapMessageHeaders . HTTP_QUERY_PARAMS , queryParams != null ? queryParams : "" ) ; message . setHeader ( SoapMessageHeaders . HTTP_REQUEST_METHOD , httpServletRequest . getMethod ( ) ) ; if ( endpointConfiguration . isHandleAttributeHeaders ( ) ) { final Enumeration < String > attributeNames = httpServletRequest . getAttributeNames ( ) ; while ( attributeNames . hasMoreElements ( ) ) { final String attributeName = attributeNames . nextElement ( ) ; final Object attribute = httpServletRequest . getAttribute ( attributeName ) ; message . setHeader ( attributeName , attribute ) ; } } } else { log . warn ( "Unable to get complete set of http request headers" ) ; try { message . setHeader ( SoapMessageHeaders . HTTP_REQUEST_URI , connection . getUri ( ) ) ; } catch ( final URISyntaxException e ) { log . warn ( "Unable to get http request uri from http connection" , e ) ; } } } | Reads information from Http connection and adds them as Http marked headers to internal message representation . |
28,551 | protected void handleInboundSoapHeaders ( final org . springframework . ws . soap . SoapMessage soapMessage , final SoapMessage message ) { try { final SoapHeader soapHeader = soapMessage . getSoapHeader ( ) ; if ( soapHeader != null ) { final Iterator < ? > iter = soapHeader . examineAllHeaderElements ( ) ; while ( iter . hasNext ( ) ) { final SoapHeaderElement headerEntry = ( SoapHeaderElement ) iter . next ( ) ; MessageHeaderUtils . setHeader ( message , headerEntry . getName ( ) . getLocalPart ( ) , headerEntry . getText ( ) ) ; } if ( soapHeader . getSource ( ) != null ) { final StringResult headerData = new StringResult ( ) ; final TransformerFactory transformerFactory = TransformerFactory . newInstance ( ) ; final Transformer transformer = transformerFactory . newTransformer ( ) ; transformer . transform ( soapHeader . getSource ( ) , headerData ) ; message . addHeaderData ( headerData . toString ( ) ) ; } } if ( StringUtils . hasText ( soapMessage . getSoapAction ( ) ) ) { if ( soapMessage . getSoapAction ( ) . equals ( "\"\"" ) ) { message . setHeader ( SoapMessageHeaders . SOAP_ACTION , "" ) ; } else { if ( soapMessage . getSoapAction ( ) . startsWith ( "\"" ) && soapMessage . getSoapAction ( ) . endsWith ( "\"" ) ) { message . setHeader ( SoapMessageHeaders . SOAP_ACTION , soapMessage . getSoapAction ( ) . substring ( 1 , soapMessage . getSoapAction ( ) . length ( ) - 1 ) ) ; } else { message . setHeader ( SoapMessageHeaders . SOAP_ACTION , soapMessage . getSoapAction ( ) ) ; } } } } catch ( final TransformerException e ) { throw new CitrusRuntimeException ( "Failed to read SOAP header source" , e ) ; } } | Reads all soap headers from web service message and adds them to message builder as normal headers . Also takes care of soap action header . |
28,552 | private void handleOutboundMimeMessageHeader ( final org . springframework . ws . soap . SoapMessage message , final String name , final Object value , final boolean handleMimeHeaders ) { if ( ! handleMimeHeaders ) { return ; } if ( message instanceof SaajSoapMessage ) { final SaajSoapMessage soapMsg = ( SaajSoapMessage ) message ; final MimeHeaders headers = soapMsg . getSaajMessage ( ) . getMimeHeaders ( ) ; headers . setHeader ( name , value . toString ( ) ) ; } else if ( message instanceof AxiomSoapMessage ) { log . warn ( "Unable to set mime message header '" + name + "' on AxiomSoapMessage - unsupported" ) ; } else { log . warn ( "Unsupported SOAP message implementation - unable to set mime message header '" + name + "'" ) ; } } | Adds a HTTP message header to the SOAP message . |
28,553 | protected void handleInboundMessageProperties ( final MessageContext messageContext , final SoapMessage message ) { if ( messageContext == null ) { return ; } final String [ ] propertyNames = messageContext . getPropertyNames ( ) ; if ( propertyNames != null ) { for ( final String propertyName : propertyNames ) { message . setHeader ( propertyName , messageContext . getProperty ( propertyName ) ) ; } } } | Adds all message properties from web service message to message builder as normal header entries . |
28,554 | protected void handleInboundAttachments ( final org . springframework . ws . soap . SoapMessage soapMessage , final SoapMessage message ) { final Iterator < Attachment > attachments = soapMessage . getAttachments ( ) ; while ( attachments . hasNext ( ) ) { final Attachment attachment = attachments . next ( ) ; final SoapAttachment soapAttachment = SoapAttachment . from ( attachment ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( String . format ( "SOAP message contains attachment with contentId '%s'" , soapAttachment . getContentId ( ) ) ) ; } message . addAttachment ( soapAttachment ) ; } } | Adds attachments if present in soap web service message . |
28,555 | private String getHeaderName ( String name , Map < String , Object > receivedHeaders , TestContext context , HeaderValidationContext validationContext ) { String headerName = context . resolveDynamicValue ( name ) ; if ( ! receivedHeaders . containsKey ( headerName ) && validationContext . isHeaderNameIgnoreCase ( ) ) { String key = headerName ; log . debug ( String . format ( "Finding case insensitive header for key '%s'" , key ) ) ; headerName = receivedHeaders . entrySet ( ) . parallelStream ( ) . filter ( item -> item . getKey ( ) . equalsIgnoreCase ( key ) ) . map ( Map . Entry :: getKey ) . findFirst ( ) . orElseThrow ( ( ) -> new ValidationException ( "Validation failed: No matching header for key '" + key + "'" ) ) ; log . info ( String . format ( "Found matching case insensitive header name: %s" , headerName ) ) ; } return headerName ; } | Get header name from control message but also check if header expression is a variable or function . In addition to that find case insensitive header name in received message when feature is activated . |
28,556 | public WaitHttpConditionBuilder status ( HttpStatus status ) { getCondition ( ) . setHttpResponseCode ( String . valueOf ( status . value ( ) ) ) ; return this ; } | Sets the Http status code to check . |
28,557 | public List < MessageValidator < ? extends ValidationContext > > findMessageValidators ( String messageType , Message message ) { List < MessageValidator < ? extends ValidationContext > > matchingValidators = new ArrayList < > ( ) ; for ( MessageValidator < ? extends ValidationContext > validator : messageValidators ) { if ( validator . supportsMessageType ( messageType , message ) ) { matchingValidators . add ( validator ) ; } } if ( matchingValidators . isEmpty ( ) || matchingValidators . stream ( ) . allMatch ( validator -> DefaultMessageHeaderValidator . class . isAssignableFrom ( validator . getClass ( ) ) ) ) { if ( message . getPayload ( ) instanceof String && StringUtils . hasText ( message . getPayload ( String . class ) ) ) { String payload = message . getPayload ( String . class ) . trim ( ) ; if ( payload . startsWith ( "<" ) && ! messageType . equals ( MessageType . XML . name ( ) ) ) { matchingValidators = findFallbackMessageValidators ( MessageType . XML . name ( ) , message ) ; } else if ( ( payload . trim ( ) . startsWith ( "{" ) || payload . trim ( ) . startsWith ( "[" ) ) && ! messageType . equals ( MessageType . JSON . name ( ) ) ) { matchingValidators = findFallbackMessageValidators ( MessageType . JSON . name ( ) , message ) ; } else if ( ! messageType . equals ( MessageType . PLAINTEXT . name ( ) ) ) { matchingValidators = findFallbackMessageValidators ( MessageType . PLAINTEXT . name ( ) , message ) ; } } } if ( matchingValidators . isEmpty ( ) || matchingValidators . stream ( ) . allMatch ( validator -> DefaultMessageHeaderValidator . class . isAssignableFrom ( validator . getClass ( ) ) ) ) { throw new CitrusRuntimeException ( "Could not find proper message validator for message type '" + messageType + "', please define a capable message validator for this message type" ) ; } if ( log . isDebugEnabled ( ) ) { log . debug ( String . format ( "Found %s message validators for message type: %s" , matchingValidators . size ( ) , messageType ) ) ; } return matchingValidators ; } | Finds matching message validators for this message type . |
28,558 | public MessageValidator getDefaultMessageHeaderValidator ( ) { return messageValidators . stream ( ) . filter ( validator -> DefaultMessageHeaderValidator . class . isAssignableFrom ( validator . getClass ( ) ) ) . findFirst ( ) . orElse ( null ) ; } | Gets the default message header validator . |
28,559 | private void createJmsTemplate ( ) { Assert . isTrue ( this . connectionFactory != null , "Neither 'jmsTemplate' nor 'connectionFactory' is set correctly." ) ; jmsTemplate = new JmsTemplate ( ) ; jmsTemplate . setConnectionFactory ( this . connectionFactory ) ; if ( this . destination != null ) { jmsTemplate . setDefaultDestination ( this . destination ) ; } else if ( this . destinationName != null ) { jmsTemplate . setDefaultDestinationName ( this . destinationName ) ; } if ( this . destinationResolver != null ) { jmsTemplate . setDestinationResolver ( this . destinationResolver ) ; } jmsTemplate . setPubSubDomain ( pubSubDomain ) ; } | Creates default JmsTemplate instance from connection factory and destination . |
28,560 | public FirefoxProfile getFirefoxProfile ( ) { if ( firefoxProfile == null ) { firefoxProfile = new FirefoxProfile ( ) ; firefoxProfile . setAcceptUntrustedCertificates ( true ) ; firefoxProfile . setAssumeUntrustedCertificateIssuer ( false ) ; firefoxProfile . setPreference ( "browser.download.folderList" , 2 ) ; firefoxProfile . setPreference ( "browser.helperApps.neverAsk.saveToDisk" , "text/plain" ) ; firefoxProfile . setPreference ( "browser.download.manager.showWhenStarting" , false ) ; } return firefoxProfile ; } | Gets the firefoxProfile . |
28,561 | public void openConnection ( Map < String , String > properties ) throws JdbcServerException { if ( ! endpointConfiguration . isAutoConnect ( ) ) { List < OpenConnection . Property > propertyList = convertToPropertyList ( properties ) ; handleMessageAndCheckResponse ( JdbcMessage . openConnection ( propertyList ) ) ; } if ( connections . get ( ) == endpointConfiguration . getServerConfiguration ( ) . getMaxConnections ( ) ) { throw new JdbcServerException ( String . format ( "Maximum number of connections (%s) reached" , endpointConfiguration . getServerConfiguration ( ) . getMaxConnections ( ) ) ) ; } connections . incrementAndGet ( ) ; } | Opens the connection with the given properties |
28,562 | public void closeConnection ( ) throws JdbcServerException { if ( ! endpointConfiguration . isAutoConnect ( ) ) { handleMessageAndCheckResponse ( JdbcMessage . closeConnection ( ) ) ; } if ( connections . decrementAndGet ( ) < 0 ) { connections . set ( 0 ) ; } } | Closes the connection |
28,563 | public void createPreparedStatement ( String stmt ) throws JdbcServerException { if ( ! endpointConfiguration . isAutoCreateStatement ( ) ) { handleMessageAndCheckResponse ( JdbcMessage . createPreparedStatement ( stmt ) ) ; } } | Creates a prepared statement |
28,564 | public DataSet executeQuery ( String query ) throws JdbcServerException { log . info ( "Received execute query request: " + query ) ; Message response = handleMessageAndCheckResponse ( JdbcMessage . execute ( query ) ) ; return dataSetCreator . createDataSet ( response , getMessageType ( response ) ) ; } | Executes a given query and returns the mapped result |
28,565 | public DataSet executeStatement ( String stmt ) throws JdbcServerException { log . info ( "Received execute statement request: " + stmt ) ; Message response = handleMessageAndCheckResponse ( JdbcMessage . execute ( stmt ) ) ; return dataSetCreator . createDataSet ( response , getMessageType ( response ) ) ; } | Executes the given statement |
28,566 | public int executeUpdate ( String updateSql ) throws JdbcServerException { log . info ( "Received execute update request: " + updateSql ) ; Message response = handleMessageAndCheckResponse ( JdbcMessage . execute ( updateSql ) ) ; return Optional . ofNullable ( response . getHeader ( JdbcMessageHeaders . JDBC_ROWS_UPDATED ) ) . map ( Object :: toString ) . map ( Integer :: valueOf ) . orElse ( 0 ) ; } | Executes the given update |
28,567 | public void setTransactionState ( boolean transactionState ) { if ( log . isDebugEnabled ( ) ) { log . debug ( String . format ( "Received transaction state change: '%s':%n%s" , endpointConfiguration . getServerConfiguration ( ) . getDatabaseName ( ) , String . valueOf ( transactionState ) ) ) ; } this . transactionState = transactionState ; if ( ! endpointConfiguration . isAutoTransactionHandling ( ) && transactionState ) { handleMessageAndCheckResponse ( JdbcMessage . startTransaction ( ) ) ; } } | Sets the transaction state of the database connection |
28,568 | public void commitStatements ( ) { if ( log . isDebugEnabled ( ) ) { log . debug ( String . format ( "Received transaction commit: '%s':%n" , endpointConfiguration . getServerConfiguration ( ) . getDatabaseName ( ) ) ) ; } if ( ! endpointConfiguration . isAutoTransactionHandling ( ) ) { handleMessageAndCheckResponse ( JdbcMessage . commitTransaction ( ) ) ; } } | Commits the transaction statements |
28,569 | public void rollbackStatements ( ) { if ( log . isDebugEnabled ( ) ) { log . debug ( String . format ( "Received transaction rollback: '%s':%n" , endpointConfiguration . getServerConfiguration ( ) . getDatabaseName ( ) ) ) ; } if ( ! endpointConfiguration . isAutoTransactionHandling ( ) ) { handleMessageAndCheckResponse ( JdbcMessage . rollbackTransaction ( ) ) ; } } | Performs a rollback on the current transaction |
28,570 | public void createCallableStatement ( String sql ) { if ( ! endpointConfiguration . isAutoCreateStatement ( ) ) { handleMessageAndCheckResponse ( JdbcMessage . createCallableStatement ( sql ) ) ; } } | Creates a callable statement |
28,571 | private MessageType getMessageType ( Message response ) { String messageTypeString = ( String ) response . getHeader ( MessageHeaders . MESSAGE_TYPE ) ; if ( MessageType . knows ( messageTypeString ) ) { return MessageType . valueOf ( messageTypeString . toUpperCase ( ) ) ; } return null ; } | Determines the MessageType of the given response |
28,572 | private List < OpenConnection . Property > convertToPropertyList ( Map < String , String > properties ) { return properties . entrySet ( ) . stream ( ) . map ( this :: convertToProperty ) . sorted ( Comparator . comparingInt ( OpenConnection . Property :: hashCode ) ) . collect ( Collectors . toList ( ) ) ; } | Converts a property map propertyKey - > propertyValue to a list of OpenConnection . Properties |
28,573 | private OpenConnection . Property convertToProperty ( Map . Entry < String , String > entry ) { OpenConnection . Property property = new OpenConnection . Property ( ) ; property . setName ( entry . getKey ( ) ) ; property . setValue ( entry . getValue ( ) ) ; return property ; } | Converts a Map entry into a OpenConnection . Property |
28,574 | private Message handleMessageAndCheckResponse ( Message request ) throws JdbcServerException { Message response = handleMessage ( request ) ; checkSuccess ( response ) ; return response ; } | Handle request message and check response is successful . |
28,575 | private void checkSuccess ( Message response ) throws JdbcServerException { OperationResult operationResult = null ; if ( response instanceof JdbcMessage || response . getPayload ( ) instanceof OperationResult ) { operationResult = response . getPayload ( OperationResult . class ) ; } else if ( response . getPayload ( ) != null && StringUtils . hasText ( response . getPayload ( String . class ) ) ) { operationResult = ( OperationResult ) endpointConfiguration . getMarshaller ( ) . unmarshal ( new StringSource ( response . getPayload ( String . class ) ) ) ; } if ( ! success ( response , operationResult ) ) { throw new JdbcServerException ( getExceptionMessage ( response , operationResult ) ) ; } } | Check that response is not having an exception message . |
28,576 | public Function getFunction ( String functionName ) throws NoSuchFunctionException { if ( ! members . containsKey ( functionName ) ) { throw new NoSuchFunctionException ( "Can not find function " + functionName + " in library " + name + " (" + prefix + ")" ) ; } return members . get ( functionName ) ; } | Try to find function in library by name . |
28,577 | public boolean knowsFunction ( String functionName ) { String functionPrefix = functionName . substring ( 0 , functionName . indexOf ( ':' ) + 1 ) ; if ( ! functionPrefix . equals ( prefix ) ) { return false ; } return members . containsKey ( functionName . substring ( functionName . indexOf ( ':' ) + 1 , functionName . indexOf ( '(' ) ) ) ; } | Does this function library know a function with the given name . |
28,578 | public java . lang . Object getResultObject ( ApplicationContext applicationContext ) { if ( object == null ) { return null ; } if ( object . getValueObject ( ) != null ) { return object . getValueObject ( ) ; } try { Class argType = Class . forName ( object . getType ( ) ) ; java . lang . Object value = null ; if ( object . getValue ( ) != null ) { value = object . getValue ( ) ; } else if ( StringUtils . hasText ( object . getRef ( ) ) && applicationContext != null ) { value = applicationContext . getBean ( object . getRef ( ) ) ; } if ( value == null ) { return null ; } else if ( argType . isInstance ( value ) || argType . isAssignableFrom ( value . getClass ( ) ) ) { return argType . cast ( value ) ; } else if ( Map . class . equals ( argType ) ) { String mapString = value . toString ( ) ; Properties props = new Properties ( ) ; try { props . load ( new StringReader ( mapString . substring ( 1 , mapString . length ( ) - 1 ) . replace ( ", " , "\n" ) ) ) ; } catch ( IOException e ) { throw new CitrusRuntimeException ( "Failed to reconstruct service result object of type map" , e ) ; } Map < String , String > map = new LinkedHashMap < > ( ) ; for ( Map . Entry < java . lang . Object , java . lang . Object > entry : props . entrySet ( ) ) { map . put ( entry . getKey ( ) . toString ( ) , entry . getValue ( ) . toString ( ) ) ; } return map ; } else { try { return new SimpleTypeConverter ( ) . convertIfNecessary ( value , argType ) ; } catch ( ConversionNotSupportedException e ) { if ( String . class . equals ( argType ) ) { return value . toString ( ) ; } throw e ; } } } catch ( ClassNotFoundException e ) { throw new CitrusRuntimeException ( "Failed to construct service result object" , e ) ; } } | Gets this service result as object casted to target type if necessary . |
28,579 | public AbstractEndpointBuilder < T > initialize ( ) { if ( getEndpoint ( ) instanceof InitializingBean ) { try { ( ( InitializingBean ) getEndpoint ( ) ) . afterPropertiesSet ( ) ; } catch ( Exception e ) { throw new CitrusRuntimeException ( "Failed to initialize endpoint" , e ) ; } } return this ; } | Initializes the endpoint . |
28,580 | public AbstractEndpointBuilder < T > applicationContext ( ApplicationContext applicationContext ) { if ( getEndpoint ( ) instanceof ApplicationContextAware ) { ( ( ApplicationContextAware ) getEndpoint ( ) ) . setApplicationContext ( applicationContext ) ; } if ( getEndpoint ( ) instanceof BeanFactoryAware ) { ( ( BeanFactoryAware ) getEndpoint ( ) ) . setBeanFactory ( applicationContext ) ; } return this ; } | Sets the Spring application context . |
28,581 | public ExecuteSQLQueryBuilder validate ( String column , String ... values ) { action . getControlResultSet ( ) . put ( column , Arrays . asList ( values ) ) ; return this ; } | Set expected control result set . Keys represent the column names values the expected values . |
28,582 | public FtpServerBuilder server ( org . apache . ftpserver . FtpServer server ) { endpoint . setFtpServer ( server ) ; return this ; } | Sets the ftp server . |
28,583 | public Workspace getWorkspace ( long workspaceId ) throws StructurizrClientException { if ( workspaceId <= 0 ) { throw new IllegalArgumentException ( "The workspace ID must be a positive integer." ) ; } try ( CloseableHttpClient httpClient = HttpClients . createSystem ( ) ) { log . info ( "Getting workspace with ID " + workspaceId ) ; HttpGet httpGet = new HttpGet ( url + WORKSPACE_PATH + workspaceId ) ; addHeaders ( httpGet , "" , "" ) ; debugRequest ( httpGet , null ) ; try ( CloseableHttpResponse response = httpClient . execute ( httpGet ) ) { debugResponse ( response ) ; String json = EntityUtils . toString ( response . getEntity ( ) ) ; if ( response . getCode ( ) == HttpStatus . SC_OK ) { archiveWorkspace ( workspaceId , json ) ; if ( encryptionStrategy == null ) { return new JsonReader ( ) . read ( new StringReader ( json ) ) ; } else { EncryptedWorkspace encryptedWorkspace = new EncryptedJsonReader ( ) . read ( new StringReader ( json ) ) ; if ( encryptedWorkspace . getEncryptionStrategy ( ) != null ) { encryptedWorkspace . getEncryptionStrategy ( ) . setPassphrase ( encryptionStrategy . getPassphrase ( ) ) ; return encryptedWorkspace . getWorkspace ( ) ; } else { return new JsonReader ( ) . read ( new StringReader ( json ) ) ; } } } else { ApiResponse apiResponse = ApiResponse . parse ( json ) ; throw new StructurizrClientException ( apiResponse . getMessage ( ) ) ; } } } catch ( Exception e ) { log . error ( e ) ; throw new StructurizrClientException ( e ) ; } } | Gets the workspace with the given ID . |
28,584 | public void putWorkspace ( long workspaceId , Workspace workspace ) throws StructurizrClientException { if ( workspace == null ) { throw new IllegalArgumentException ( "The workspace must not be null." ) ; } else if ( workspaceId <= 0 ) { throw new IllegalArgumentException ( "The workspace ID must be a positive integer." ) ; } try ( CloseableHttpClient httpClient = HttpClients . createSystem ( ) ) { if ( mergeFromRemote ) { Workspace remoteWorkspace = getWorkspace ( workspaceId ) ; if ( remoteWorkspace != null ) { workspace . getViews ( ) . copyLayoutInformationFrom ( remoteWorkspace . getViews ( ) ) ; workspace . getViews ( ) . getConfiguration ( ) . copyConfigurationFrom ( remoteWorkspace . getViews ( ) . getConfiguration ( ) ) ; } } workspace . setId ( workspaceId ) ; workspace . setThumbnail ( null ) ; workspace . setLastModifiedDate ( new Date ( ) ) ; workspace . setLastModifiedAgent ( STRUCTURIZR_FOR_JAVA_AGENT ) ; workspace . setLastModifiedUser ( getUser ( ) ) ; workspace . countAndLogWarnings ( ) ; HttpPut httpPut = new HttpPut ( url + WORKSPACE_PATH + workspaceId ) ; StringWriter stringWriter = new StringWriter ( ) ; if ( encryptionStrategy == null ) { JsonWriter jsonWriter = new JsonWriter ( false ) ; jsonWriter . write ( workspace , stringWriter ) ; } else { EncryptedWorkspace encryptedWorkspace = new EncryptedWorkspace ( workspace , encryptionStrategy ) ; encryptionStrategy . setLocation ( EncryptionLocation . Client ) ; EncryptedJsonWriter jsonWriter = new EncryptedJsonWriter ( false ) ; jsonWriter . write ( encryptedWorkspace , stringWriter ) ; } StringEntity stringEntity = new StringEntity ( stringWriter . toString ( ) , ContentType . APPLICATION_JSON ) ; httpPut . setEntity ( stringEntity ) ; addHeaders ( httpPut , EntityUtils . toString ( stringEntity ) , ContentType . APPLICATION_JSON . toString ( ) ) ; debugRequest ( httpPut , EntityUtils . toString ( stringEntity ) ) ; log . info ( "Putting workspace with ID " + workspaceId ) ; try ( CloseableHttpResponse response = httpClient . execute ( httpPut ) ) { String json = EntityUtils . toString ( response . getEntity ( ) ) ; if ( response . getCode ( ) == HttpStatus . SC_OK ) { debugResponse ( response ) ; log . info ( json ) ; } else { ApiResponse apiResponse = ApiResponse . parse ( json ) ; throw new StructurizrClientException ( apiResponse . getMessage ( ) ) ; } } } catch ( Exception e ) { log . error ( e ) ; throw new StructurizrClientException ( e ) ; } } | Updates the given workspace . |
28,585 | public void write ( Workspace workspace , Writer writer ) { if ( workspace == null ) { throw new IllegalArgumentException ( "A workspace must be provided." ) ; } if ( writer == null ) { throw new IllegalArgumentException ( "A writer must be provided." ) ; } workspace . getViews ( ) . getSystemLandscapeViews ( ) . forEach ( v -> write ( v , writer ) ) ; workspace . getViews ( ) . getSystemContextViews ( ) . forEach ( v -> write ( v , writer ) ) ; workspace . getViews ( ) . getContainerViews ( ) . forEach ( v -> write ( v , writer ) ) ; workspace . getViews ( ) . getComponentViews ( ) . forEach ( v -> write ( v , writer ) ) ; workspace . getViews ( ) . getDynamicViews ( ) . forEach ( v -> write ( v , writer ) ) ; workspace . getViews ( ) . getDeploymentViews ( ) . forEach ( v -> write ( v , writer ) ) ; } | Writes the views in the given workspace as PlantUML definitions to the specified writer . |
28,586 | public void toStdOut ( Workspace workspace ) { if ( workspace == null ) { throw new IllegalArgumentException ( "A workspace must be provided." ) ; } StringWriter stringWriter = new StringWriter ( ) ; write ( workspace , stringWriter ) ; System . out . println ( stringWriter . toString ( ) ) ; } | Write the views in the given workspace as PlantUML definitions to stdout . |
28,587 | public void write ( View view , Writer writer ) { if ( view == null ) { throw new IllegalArgumentException ( "A view must be provided." ) ; } if ( writer == null ) { throw new IllegalArgumentException ( "A writer must be provided." ) ; } if ( SystemLandscapeView . class . isAssignableFrom ( view . getClass ( ) ) ) { write ( ( SystemLandscapeView ) view , writer ) ; } else if ( SystemContextView . class . isAssignableFrom ( view . getClass ( ) ) ) { write ( ( SystemContextView ) view , writer ) ; } else if ( ContainerView . class . isAssignableFrom ( view . getClass ( ) ) ) { write ( ( ContainerView ) view , writer ) ; } else if ( ComponentView . class . isAssignableFrom ( view . getClass ( ) ) ) { write ( ( ComponentView ) view , writer ) ; } else if ( DynamicView . class . isAssignableFrom ( view . getClass ( ) ) ) { write ( ( DynamicView ) view , writer ) ; } else if ( DeploymentView . class . isAssignableFrom ( view . getClass ( ) ) ) { write ( ( DeploymentView ) view , writer ) ; } } | Writes a single view as a PlantUML diagram definition to the specified writer . |
28,588 | public Component getComponentWithName ( String name ) { if ( name == null || name . trim ( ) . length ( ) == 0 ) { throw new IllegalArgumentException ( "A component name must be provided." ) ; } Optional < Component > component = components . stream ( ) . filter ( c -> name . equals ( c . getName ( ) ) ) . findFirst ( ) ; return component . orElse ( null ) ; } | Gets the component with the specified name . |
28,589 | public Component getComponentOfType ( String type ) { if ( type == null || type . trim ( ) . length ( ) == 0 ) { throw new IllegalArgumentException ( "A component type must be provided." ) ; } Optional < Component > component = components . stream ( ) . filter ( c -> type . equals ( c . getType ( ) . getType ( ) ) ) . findFirst ( ) ; return component . orElse ( null ) ; } | Gets the component of the specified type . |
28,590 | private void findUsesComponentAnnotations ( Component component , String typeName ) { try { Class type = getTypeRepository ( ) . loadClass ( typeName ) ; for ( Field field : type . getDeclaredFields ( ) ) { UsesComponent annotation = field . getAnnotation ( UsesComponent . class ) ; if ( annotation != null ) { String name = field . getType ( ) . getCanonicalName ( ) ; String description = field . getAnnotation ( UsesComponent . class ) . description ( ) ; String technology = annotation . technology ( ) ; Component destination = componentFinder . getContainer ( ) . getComponentOfType ( name ) ; if ( destination != null ) { for ( Relationship relationship : component . getRelationships ( ) ) { if ( relationship . getDestination ( ) == destination && StringUtils . isNullOrEmpty ( relationship . getDescription ( ) ) ) { component . getModel ( ) . modifyRelationship ( relationship , description , technology ) ; } } } else { log . warn ( "A component of type \"" + name + "\" could not be found." ) ; } } } } catch ( ClassNotFoundException e ) { log . warn ( "Could not load type " + typeName ) ; } } | This will add a description to existing component dependencies where they have been annotated |
28,591 | public void setLocation ( Location location ) { if ( location != null ) { this . location = location ; } else { this . location = Location . Unspecified ; } } | Sets the location of this software system . |
28,592 | public CodeElement addSupportingType ( String type ) { CodeElement codeElement = new CodeElement ( type ) ; codeElement . setRole ( CodeElementRole . Supporting ) ; this . codeElements . add ( codeElement ) ; return codeElement ; } | Adds a supporting type to this Component . |
28,593 | public SystemLandscapeView createSystemLandscapeView ( String key , String description ) { assertThatTheViewKeyIsSpecifiedAndUnique ( key ) ; SystemLandscapeView view = new SystemLandscapeView ( model , key , description ) ; view . setViewSet ( this ) ; systemLandscapeViews . add ( view ) ; return view ; } | Creates a system landscape view . |
28,594 | public SystemContextView createSystemContextView ( SoftwareSystem softwareSystem , String key , String description ) { assertThatTheSoftwareSystemIsNotNull ( softwareSystem ) ; assertThatTheViewKeyIsSpecifiedAndUnique ( key ) ; SystemContextView view = new SystemContextView ( softwareSystem , key , description ) ; view . setViewSet ( this ) ; systemContextViews . add ( view ) ; return view ; } | Creates a system context view where the scope of the view is the specified software system . |
28,595 | public ContainerView createContainerView ( SoftwareSystem softwareSystem , String key , String description ) { assertThatTheSoftwareSystemIsNotNull ( softwareSystem ) ; assertThatTheViewKeyIsSpecifiedAndUnique ( key ) ; ContainerView view = new ContainerView ( softwareSystem , key , description ) ; view . setViewSet ( this ) ; containerViews . add ( view ) ; return view ; } | Creates a container view where the scope of the view is the specified software system . |
28,596 | public ComponentView createComponentView ( Container container , String key , String description ) { assertThatTheContainerIsNotNull ( container ) ; assertThatTheViewKeyIsSpecifiedAndUnique ( key ) ; ComponentView view = new ComponentView ( container , key , description ) ; view . setViewSet ( this ) ; componentViews . add ( view ) ; return view ; } | Creates a component view where the scope of the view is the specified container . |
28,597 | public DynamicView createDynamicView ( String key , String description ) { assertThatTheViewKeyIsSpecifiedAndUnique ( key ) ; DynamicView view = new DynamicView ( model , key , description ) ; view . setViewSet ( this ) ; dynamicViews . add ( view ) ; return view ; } | Creates a dynamic view . |
28,598 | public DeploymentView createDeploymentView ( String key , String description ) { assertThatTheViewKeyIsSpecifiedAndUnique ( key ) ; DeploymentView view = new DeploymentView ( model , key , description ) ; view . setViewSet ( this ) ; deploymentViews . add ( view ) ; return view ; } | Creates a deployment view . |
28,599 | public DeploymentView createDeploymentView ( SoftwareSystem softwareSystem , String key , String description ) { assertThatTheSoftwareSystemIsNotNull ( softwareSystem ) ; assertThatTheViewKeyIsSpecifiedAndUnique ( key ) ; DeploymentView view = new DeploymentView ( softwareSystem , key , description ) ; view . setViewSet ( this ) ; deploymentViews . add ( view ) ; return view ; } | Creates a deployment view where the scope of the view is the specified software system . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.