當前位置: 首頁>>代碼示例>>Java>>正文


Java StatusMessage類代碼示例

本文整理匯總了Java中org.mitre.taxii.messages.xml11.StatusMessage的典型用法代碼示例。如果您正苦於以下問題:Java StatusMessage類的具體用法?Java StatusMessage怎麽用?Java StatusMessage使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


StatusMessage類屬於org.mitre.taxii.messages.xml11包,在下文中一共展示了StatusMessage類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: statusMessageSafelyToString

import org.mitre.taxii.messages.xml11.StatusMessage; //導入依賴的package包/類
private String statusMessageSafelyToString(StatusMessage msg) {
    StringBuilder sb = new StringBuilder();

    if(!isEmpty(msg.getMessageId())) {
        sb.append("message ID: ").append(msg.getMessageId()).append("\n");
    }

    if(!isEmpty(msg.getInResponseTo())) {
        sb.append("in response to: ").append(msg.getInResponseTo()).append("\n");
    }

    if(!isEmpty(msg.getStatusType())) {
        sb.append("status type: ").append(msg.getStatusType()).append("\n");
    }

    if(!isEmpty(msg.getMessage())) {
        sb.append("message: ").append(msg.getMessage()).append("\n");
    }

    if(msg.getStatusDetail()!=null && msg.getStatusDetail().getDetails()!=null) {
        sb.append("details: ").append(collectionToCommaDelimitedString(msg.getStatusDetail().getDetails()));
    }

    return sb.toString();
}
 
開發者ID:ThreatCentral,項目名稱:elderberry,代碼行數:26,代碼來源:Taxii11Template.java

示例2: buildSSLErrorStatusMessage

import org.mitre.taxii.messages.xml11.StatusMessage; //導入依賴的package包/類
/**
 *   Section 5.2 of the TAXII HTTP Protocol Binding Specification states:
 * 
 * "If TLS is used, problems with the TLS handshake or connection are indicated
 * using a TLS Alert Protocol Record. This section defines rules for interpreting
 * a TLS Alert Protocol Record as a TAXII Status Message. Treat a TLS Alert
 * Protocol Record as being equivalent to a TAXII Status Message with the 
 * following properties:
 * Status = Use the appropriate TAXII Status Type as identified in Table 3.
 * Message = The TLS Alert, represented as a hexadecimal string."
 * 
 * Unfortunately, Java does not give us access to the TLS Alert, so we'll 
 * just make all the Statuses UNAUTHORIZED and return the exception's message.
 * 
 */ 
@Override
public StatusMessage buildSSLErrorStatusMessage(SSLException ex, Object message) {
    if (!(message instanceof MessageType)) {
        return null; // Probably ought to throw an exception here.
    }
    String msgId = ((MessageType)message).getMessageId();

    ObjectFactory factory = new ObjectFactory();
    StatusMessage msg = factory.createStatusMessage()
                            .withInResponseTo(msgId)
                            .withMessageId("0");
    
    msg.setStatusType(StatusTypeEnum.UNAUTHORIZED.name());
    msg.setMessage(ex.getMessage());

    return msg;
}
 
開發者ID:TAXIIProject,項目名稱:java-taxii,代碼行數:33,代碼來源:ResponseErrorHandler.java

示例3: missingEndpointDiscoveryTest

import org.mitre.taxii.messages.xml11.StatusMessage; //導入依賴的package包/類
@Test
public void missingEndpointDiscoveryTest() throws IOException, JAXBException, URISyntaxException {
    org.mitre.taxii.client.HttpClient taxiiClient = new HttpClient();
    final String serverUrl = serverURL + "services/discover/"; // URL does not exist.

    // Prepare the message to send.
    DiscoveryRequest dr = factory.createDiscoveryRequest()
            .withMessageId(MessageHelper.generateMessageId());

    Object responseObj = taxiiClient.callTaxiiService(new URI(serverUrl), dr);

    if (debug) {
        System.out.println(taxiiXml.marshalToString(dr, true));
        System.out.println(taxiiXml.marshalToString(responseObj, true));
    }

    assertTrue("Received Status Message", (responseObj instanceof StatusMessage));
}
 
開發者ID:TAXIIProject,項目名稱:java-taxii,代碼行數:19,代碼來源:FailureTests.java

示例4: buildStatusCodeStatusMessage

import org.mitre.taxii.messages.xml11.StatusMessage; //導入依賴的package包/類
/**
 * We received a response that was not a 200 (Success)
 * value. Make up an appropriate Status Message.
 * 
 * @param response the HTTP response object.
 * @param msgIn the TAXII message sent to the server.
 * @return StatusMessage based on the HTTP response code.
 */
@Override
public StatusMessage buildStatusCodeStatusMessage(CloseableHttpResponse response, Object msgIn) {
    if (!(msgIn instanceof MessageType)) {
        return null; // Probably ought to throw an exception here.
    }
    String msgId = ((MessageType)msgIn).getMessageId(); // ID of the message sent.
    ObjectFactory factory = new ObjectFactory();
    StatusMessage msg = factory.createStatusMessage()
                            .withInResponseTo(msgId)
                            .withMessageId("0");
    
    switch (response.getStatusLine().getStatusCode()) {
        case 400: // Bad Request
        case 413: // Request Entity Too Large
                msg.setStatusType(StatusTypeEnum.BAD_MESSAGE.name());
                break;

        case 401: // Unauthorized
        case 403: // Forbidden
        case 407: // Proxy Authentication Required
                msg.setStatusType(StatusTypeEnum.UNAUTHORIZED.name());
                break;

        case 406: // Not Acceptable
        case 415: // Unsupported Media Type
                msg.setStatusType(StatusTypeEnum.UNSUPPORTED_MESSAGE.name());
                break;
            
        default:
                msg.setStatusType(StatusTypeEnum.FAILURE.name());
    }
    
    String msgStr = buildResponseStr(response);
    
    msg.setMessage(msgStr);
    
    return msg;
}
 
開發者ID:TAXIIProject,項目名稱:java-taxii,代碼行數:47,代碼來源:ResponseErrorHandler.java

示例5: failBasicAuthDiscoveryTest

import org.mitre.taxii.messages.xml11.StatusMessage; //導入依賴的package包/類
@Test
public void failBasicAuthDiscoveryTest() throws IOException, JAXBException, URISyntaxException {
    
    // Create a client that uses basic (user & password) authentication.
    HttpClientBuilder cb = HttpClientBuilder.create();
    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(
            AuthScope.ANY,
            new UsernamePasswordCredentials("taxii", "taxi")); // Bad password
    cb.setDefaultCredentialsProvider(credsProvider);        
    CloseableHttpClient httpClient = cb.build();

    HttpClient taxiiClient = new HttpClient(taxiiXml, httpClient);

    // Prepare the message to send.
    DiscoveryRequest dr = factory.createDiscoveryRequest()
            .withMessageId(MessageHelper.generateMessageId());

    final String serverUrl = serverURL + "services/discovery/";
    Object responseObj = taxiiClient.callTaxiiService(new URI(serverUrl), dr);

    if (debug) {
        System.out.println(taxiiXml.marshalToString(dr, true));
        System.out.println(taxiiXml.marshalToString(responseObj, true));
    }

    assertTrue("Received Status Message", (responseObj instanceof StatusMessage));
}
 
開發者ID:TAXIIProject,項目名稱:java-taxii,代碼行數:29,代碼來源:FailureTests.java

示例6: failedSslDiscoveryTest

import org.mitre.taxii.messages.xml11.StatusMessage; //導入依賴的package包/類
@Test
public void failedSslDiscoveryTest() throws IOException, JAXBException, KeyStoreException, NoSuchAlgorithmException, CertificateException, KeyManagementException, URISyntaxException {
    final String endpoint = "https://127.0.0.1:8443/services/discovery/";

    /* The below configures the client to accept self-signed certificates. */
    KeyStore trustStore  = KeyStore.getInstance(KeyStore.getDefaultType());
    trustStore.load(null, "nopassword".toCharArray());

    // Trust own CA and all self-signed certs
    SSLContext sslcontext = SSLContexts.custom()
            .loadTrustMaterial(trustStore, new TrustSelfSignedStrategy())
            .build();
    // Allow TLSv1 protocol only
    SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
            sslcontext,
            new String[] { "TLSv1" },
            null,
            SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
    CloseableHttpClient httpClient = HttpClients.custom()
            .setSSLSocketFactory(sslsf)
            .build();        
    
    HttpClient taxiiClient = new HttpClient(httpClient);

    // Prepare the message to send.
    DiscoveryRequest dr = factory.createDiscoveryRequest()
            .withMessageId(MessageHelper.generateMessageId());

    Object responseObj = null;
    responseObj = taxiiClient.callTaxiiService(new URI(endpoint), dr);

    if (debug) {
        System.out.println(taxiiXml.marshalToString(dr, true));
        if (null != responseObj) {
            System.out.println(taxiiXml.marshalToString(responseObj, true));
        }
    }

    assertTrue("Received Status Message", (responseObj instanceof StatusMessage));
}
 
開發者ID:TAXIIProject,項目名稱:java-taxii,代碼行數:41,代碼來源:FailureTests.java


注:本文中的org.mitre.taxii.messages.xml11.StatusMessage類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。