当前位置: 首页>>代码示例>>Java>>正文


Java StringEscapeUtils.escapeJava方法代码示例

本文整理汇总了Java中org.apache.commons.text.StringEscapeUtils.escapeJava方法的典型用法代码示例。如果您正苦于以下问题:Java StringEscapeUtils.escapeJava方法的具体用法?Java StringEscapeUtils.escapeJava怎么用?Java StringEscapeUtils.escapeJava使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.text.StringEscapeUtils的用法示例。


在下文中一共展示了StringEscapeUtils.escapeJava方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: serializeNottableString

import org.apache.commons.text.StringEscapeUtils; //导入方法依赖的package包/类
public static String serializeNottableString(NottableString nottableString) {
    if (nottableString.isNot()) {
        return "not(\"" + StringEscapeUtils.escapeJava(nottableString.getValue()) + "\")";
    } else {
        return "\"" + StringEscapeUtils.escapeJava(nottableString.getValue()) + "\"";
    }
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:8,代码来源:NottableStringToJavaSerializer.java

示例2: shouldDeserializeCompleteResponse

import org.apache.commons.text.StringEscapeUtils; //导入方法依赖的package包/类
@Test
public void shouldDeserializeCompleteResponse() throws IOException, ClassNotFoundException {
    // given
    String requestBytes = "{" + NEW_LINE +
        "  \"type\" : \"org.mockserver.model.HttpResponse\"," + NEW_LINE +
        "  \"value\" : \"{" + StringEscapeUtils.escapeJava(NEW_LINE) +
        "  \\\"statusCode\\\" : 123," + StringEscapeUtils.escapeJava(NEW_LINE) +
        "  \\\"headers\\\" : [ {" + StringEscapeUtils.escapeJava(NEW_LINE) +
        "    \\\"name\\\" : \\\"someHeaderName\\\"," + StringEscapeUtils.escapeJava(NEW_LINE) +
        "    \\\"values\\\" : [ \\\"someHeaderValue\\\" ]" + StringEscapeUtils.escapeJava(NEW_LINE) +
        "  } ]," + StringEscapeUtils.escapeJava(NEW_LINE) +
        "  \\\"cookies\\\" : [ {" + StringEscapeUtils.escapeJava(NEW_LINE) +
        "    \\\"name\\\" : \\\"someCookieName\\\"," + StringEscapeUtils.escapeJava(NEW_LINE) +
        "    \\\"value\\\" : \\\"someCookieValue\\\"" + StringEscapeUtils.escapeJava(NEW_LINE) +
        "  } ]," + StringEscapeUtils.escapeJava(NEW_LINE) +
        "  \\\"body\\\" : \\\"somebody\\\"," + StringEscapeUtils.escapeJava(NEW_LINE) +
        "  \\\"delay\\\" : {" + StringEscapeUtils.escapeJava(NEW_LINE) +
        "    \\\"timeUnit\\\" : \\\"SECONDS\\\"," + StringEscapeUtils.escapeJava(NEW_LINE) +
        "    \\\"value\\\" : 5" + StringEscapeUtils.escapeJava(NEW_LINE) +
        "  }" + StringEscapeUtils.escapeJava(NEW_LINE) +
        "}\"" + NEW_LINE +
        "}";

    // when
    Object httpResponse = new WebSocketMessageSerializer(new MockServerLogger()).deserialize(requestBytes);

    // then
    assertEquals(new HttpResponseDTO()
        .setStatusCode(123)
        .setBody(BodyWithContentTypeDTO.createDTO(exact("somebody")))
        .setHeaders(new Headers().withEntries(
            header("someHeaderName", "someHeaderValue")
        ))
        .setCookies(new Cookies().withEntries(
            cookie("someCookieName", "someCookieValue")
        ))
        .setDelay(new DelayDTO(seconds(5)))
        .buildObject(), httpResponse);
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:40,代码来源:WebSocketMessageSerializerTest.java

示例3: shouldParseJsonWithJsonSchemaBodyWithNot

import org.apache.commons.text.StringEscapeUtils; //导入方法依赖的package包/类
@Test
public void shouldParseJsonWithJsonSchemaBodyWithNot() throws IOException {
    // given
    String jsonSchema = "{" + NEW_LINE +
        "    \"$schema\": \"http://json-schema.org/draft-04/schema#\"," + NEW_LINE +
        "    \"title\": \"Product\"," + NEW_LINE +
        "    \"description\": \"A product from Acme's catalog\"," + NEW_LINE +
        "    \"type\": \"object\"," + NEW_LINE +
        "    \"properties\": {" + NEW_LINE +
        "        \"id\": {" + NEW_LINE +
        "            \"description\": \"The unique identifier for a product\"," + NEW_LINE +
        "            \"type\": \"integer\"" + NEW_LINE +
        "        }" + NEW_LINE +
        "    }," + NEW_LINE +
        "    \"required\": [\"id\"]" + NEW_LINE +
        "}";
    String json = ("{" + NEW_LINE +
        "    \"httpRequest\": {" + NEW_LINE +
        "        \"body\" : {" + NEW_LINE +
        "            \"not\" : true," + NEW_LINE +
        "            \"jsonSchema\" : \"" + StringEscapeUtils.escapeJava(jsonSchema) + "\"" + NEW_LINE +
        "        }" + NEW_LINE +
        "    }" + NEW_LINE +
        "}");

    // when
    ExpectationDTO expectationDTO = ObjectMapperFactory.createObjectMapper().readValue(json, ExpectationDTO.class);

    // then
    assertEquals(new ExpectationDTO()
        .setHttpRequest(
            new HttpRequestDTO()
                .setBody(new JsonSchemaBodyDTO(new JsonSchemaBody(jsonSchema), true))
        ), expectationDTO);
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:36,代码来源:BodyDTODeserializerTest.java

示例4: shouldParseJsonWithJsonSchemaBodyWithoutType

import org.apache.commons.text.StringEscapeUtils; //导入方法依赖的package包/类
@Test
public void shouldParseJsonWithJsonSchemaBodyWithoutType() throws IOException {
    // given
    String jsonSchema = "{" + NEW_LINE +
        "    \"$schema\": \"http://json-schema.org/draft-04/schema#\"," + NEW_LINE +
        "    \"title\": \"Product\"," + NEW_LINE +
        "    \"description\": \"A product from Acme's catalog\"," + NEW_LINE +
        "    \"type\": \"object\"," + NEW_LINE +
        "    \"properties\": {" + NEW_LINE +
        "        \"id\": {" + NEW_LINE +
        "            \"description\": \"The unique identifier for a product\"," + NEW_LINE +
        "            \"type\": \"integer\"" + NEW_LINE +
        "        }" + NEW_LINE +
        "    }," + NEW_LINE +
        "    \"required\": [\"id\"]" + NEW_LINE +
        "}";
    String json = ("{" + NEW_LINE +
        "    \"httpRequest\": {" + NEW_LINE +
        "        \"body\" : {" + NEW_LINE +
        "            \"jsonSchema\" : \"" + StringEscapeUtils.escapeJava(jsonSchema) + "\"" + NEW_LINE +
        "        }" + NEW_LINE +
        "    }" + NEW_LINE +
        "}");

    // when
    ExpectationDTO expectationDTO = ObjectMapperFactory.createObjectMapper().readValue(json, ExpectationDTO.class);

    // then
    assertEquals(new ExpectationDTO()
        .setHttpRequest(
            new HttpRequestDTO()
                .setBody(new JsonSchemaBodyDTO(new JsonSchemaBody(jsonSchema)))
        ), expectationDTO);
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:35,代码来源:BodyDTODeserializerTest.java

示例5: shouldParseJsonWithJsonSchemaBodyUsingJsonProperty

import org.apache.commons.text.StringEscapeUtils; //导入方法依赖的package包/类
@Test
public void shouldParseJsonWithJsonSchemaBodyUsingJsonProperty() throws IOException {
    // given
    String jsonSchema = "{" + NEW_LINE +
        "    \"$schema\": \"http://json-schema.org/draft-04/schema#\"," + NEW_LINE +
        "    \"title\": \"Product\"," + NEW_LINE +
        "    \"description\": \"A product from Acme's catalog\"," + NEW_LINE +
        "    \"type\": \"object\"," + NEW_LINE +
        "    \"properties\": {" + NEW_LINE +
        "        \"id\": {" + NEW_LINE +
        "            \"description\": \"The unique identifier for a product\"," + NEW_LINE +
        "            \"type\": \"integer\"" + NEW_LINE +
        "        }" + NEW_LINE +
        "    }," + NEW_LINE +
        "    \"required\": [\"id\"]" + NEW_LINE +
        "}";
    String json = ("{" + NEW_LINE +
        "    \"httpRequest\": {" + NEW_LINE +
        "        \"body\" : {" + NEW_LINE +
        "            \"type\" : \"JSON_SCHEMA\"," + NEW_LINE +
        "            \"jsonSchema\" : \"" + StringEscapeUtils.escapeJava(jsonSchema) + "\"" + NEW_LINE +
        "        }" + NEW_LINE +
        "    }" + NEW_LINE +
        "}");

    // when
    ExpectationDTO expectationDTO = ObjectMapperFactory.createObjectMapper().readValue(json, ExpectationDTO.class);

    // then
    assertEquals(new ExpectationDTO()
        .setHttpRequest(
            new HttpRequestDTO()
                .setBody(new JsonSchemaBodyDTO(new JsonSchemaBody(jsonSchema)))
        ), expectationDTO);
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:36,代码来源:BodyDTODeserializerTest.java

示例6: shouldParseJsonWithXmlSchemaBodyWithNot

import org.apache.commons.text.StringEscapeUtils; //导入方法依赖的package包/类
@Test
public void shouldParseJsonWithXmlSchemaBodyWithNot() throws IOException {
    // given
    String xmlSchema = "{" + NEW_LINE +
        "    \"$schema\": \"http://xml-schema.org/draft-04/schema#\"," + NEW_LINE +
        "    \"title\": \"Product\"," + NEW_LINE +
        "    \"description\": \"A product from Acme's catalog\"," + NEW_LINE +
        "    \"type\": \"object\"," + NEW_LINE +
        "    \"properties\": {" + NEW_LINE +
        "        \"id\": {" + NEW_LINE +
        "            \"description\": \"The unique identifier for a product\"," + NEW_LINE +
        "            \"type\": \"integer\"" + NEW_LINE +
        "        }" + NEW_LINE +
        "    }," + NEW_LINE +
        "    \"required\": [\"id\"]" + NEW_LINE +
        "}";
    String json = ("{" + NEW_LINE +
        "    \"httpRequest\": {" + NEW_LINE +
        "        \"body\" : {" + NEW_LINE +
        "            \"not\" : true," + NEW_LINE +
        "            \"xmlSchema\" : \"" + StringEscapeUtils.escapeJava(xmlSchema) + "\"" + NEW_LINE +
        "        }" + NEW_LINE +
        "    }" + NEW_LINE +
        "}");

    // when
    ExpectationDTO expectationDTO = ObjectMapperFactory.createObjectMapper().readValue(json, ExpectationDTO.class);

    // then
    assertEquals(new ExpectationDTO()
        .setHttpRequest(
            new HttpRequestDTO()
                .setBody(new XmlSchemaBodyDTO(new XmlSchemaBody(xmlSchema), true))
        ), expectationDTO);
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:36,代码来源:BodyDTODeserializerTest.java

示例7: shouldParseJsonWithXmlSchemaBodyWithoutType

import org.apache.commons.text.StringEscapeUtils; //导入方法依赖的package包/类
@Test
public void shouldParseJsonWithXmlSchemaBodyWithoutType() throws IOException {
    // given
    String xmlSchema = "{" + NEW_LINE +
        "    \"$schema\": \"http://xml-schema.org/draft-04/schema#\"," + NEW_LINE +
        "    \"title\": \"Product\"," + NEW_LINE +
        "    \"description\": \"A product from Acme's catalog\"," + NEW_LINE +
        "    \"type\": \"object\"," + NEW_LINE +
        "    \"properties\": {" + NEW_LINE +
        "        \"id\": {" + NEW_LINE +
        "            \"description\": \"The unique identifier for a product\"," + NEW_LINE +
        "            \"type\": \"integer\"" + NEW_LINE +
        "        }" + NEW_LINE +
        "    }," + NEW_LINE +
        "    \"required\": [\"id\"]" + NEW_LINE +
        "}";
    String json = ("{" + NEW_LINE +
        "    \"httpRequest\": {" + NEW_LINE +
        "        \"body\" : {" + NEW_LINE +
        "            \"xmlSchema\" : \"" + StringEscapeUtils.escapeJava(xmlSchema) + "\"" + NEW_LINE +
        "        }" + NEW_LINE +
        "    }" + NEW_LINE +
        "}");

    // when
    ExpectationDTO expectationDTO = ObjectMapperFactory.createObjectMapper().readValue(json, ExpectationDTO.class);

    // then
    assertEquals(new ExpectationDTO()
        .setHttpRequest(
            new HttpRequestDTO()
                .setBody(new XmlSchemaBodyDTO(new XmlSchemaBody(xmlSchema)))
        ), expectationDTO);
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:35,代码来源:BodyDTODeserializerTest.java

示例8: shouldParseJsonWithXmlSchemaBodyUsingJsonProperty

import org.apache.commons.text.StringEscapeUtils; //导入方法依赖的package包/类
@Test
public void shouldParseJsonWithXmlSchemaBodyUsingJsonProperty() throws IOException {
    // given
    String xmlSchema = "{" + NEW_LINE +
        "    \"$schema\": \"http://xml-schema.org/draft-04/schema#\"," + NEW_LINE +
        "    \"title\": \"Product\"," + NEW_LINE +
        "    \"description\": \"A product from Acme's catalog\"," + NEW_LINE +
        "    \"type\": \"object\"," + NEW_LINE +
        "    \"properties\": {" + NEW_LINE +
        "        \"id\": {" + NEW_LINE +
        "            \"description\": \"The unique identifier for a product\"," + NEW_LINE +
        "            \"type\": \"integer\"" + NEW_LINE +
        "        }" + NEW_LINE +
        "    }," + NEW_LINE +
        "    \"required\": [\"id\"]" + NEW_LINE +
        "}";
    String json = ("{" + NEW_LINE +
        "    \"httpRequest\": {" + NEW_LINE +
        "        \"body\" : {" + NEW_LINE +
        "            \"type\" : \"XML_SCHEMA\"," + NEW_LINE +
        "            \"xmlSchema\" : \"" + StringEscapeUtils.escapeJava(xmlSchema) + "\"" + NEW_LINE +
        "        }" + NEW_LINE +
        "    }" + NEW_LINE +
        "}");

    // when
    ExpectationDTO expectationDTO = ObjectMapperFactory.createObjectMapper().readValue(json, ExpectationDTO.class);

    // then
    final ExpectationDTO expected = new ExpectationDTO()
        .setHttpRequest(
            new HttpRequestDTO()
                .setBody(new XmlSchemaBodyDTO(new XmlSchemaBody(xmlSchema)))
        );
    assertEquals(expected, expectationDTO);
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:37,代码来源:BodyDTODeserializerTest.java

示例9: shouldDeserializeCompleteRequest

import org.apache.commons.text.StringEscapeUtils; //导入方法依赖的package包/类
@Test
public void shouldDeserializeCompleteRequest() throws IOException, ClassNotFoundException {
    // given
    String requestBytes = "{" + NEW_LINE +
        "  \"type\" : \"org.mockserver.model.HttpRequest\"," + NEW_LINE +
        "  \"value\" : \"{" + StringEscapeUtils.escapeJava(NEW_LINE) +
        "  \\\"method\\\" : \\\"someMethod\\\"," + StringEscapeUtils.escapeJava(NEW_LINE) +
        "  \\\"path\\\" : \\\"somePath\\\"," + StringEscapeUtils.escapeJava(NEW_LINE) +
        "  \\\"queryStringParameters\\\" : {" + StringEscapeUtils.escapeJava(NEW_LINE) +
        "    \\\"queryParameterName\\\" : [ \\\"queryParameterValue\\\" ]" + StringEscapeUtils.escapeJava(NEW_LINE) +
        "  }," + StringEscapeUtils.escapeJava(NEW_LINE) +
        "  \\\"headers\\\" : {" + StringEscapeUtils.escapeJava(NEW_LINE) +
        "    \\\"someHeaderName\\\" : [ \\\"someHeaderValue\\\" ]" + StringEscapeUtils.escapeJava(NEW_LINE) +
        "  }," + StringEscapeUtils.escapeJava(NEW_LINE) +
        "  \\\"cookies\\\" : {" + StringEscapeUtils.escapeJava(NEW_LINE) +
        "    \\\"someCookieName\\\" : \\\"someCookieValue\\\"" + StringEscapeUtils.escapeJava(NEW_LINE) +
        "  }," + StringEscapeUtils.escapeJava(NEW_LINE) +
        "  \\\"keepAlive\\\" : false," + StringEscapeUtils.escapeJava(NEW_LINE) +
        "  \\\"secure\\\" : true," + StringEscapeUtils.escapeJava(NEW_LINE) +
        "  \\\"body\\\" : \\\"somebody\\\"" + StringEscapeUtils.escapeJava(NEW_LINE) +
        "}\"" + NEW_LINE +
        "}";

    // when
    Object httpRequest = new WebSocketMessageSerializer(new MockServerLogger()).deserialize(requestBytes);

    // then
    assertEquals(new HttpRequestDTO()
        .setMethod(string("someMethod"))
        .setPath(string("somePath"))
        .setQueryStringParameters(new Parameters().withEntries(
            param("queryParameterName", "queryParameterValue")
        ))
        .setBody(BodyDTO.createDTO(exact("somebody")))
        .setHeaders(new Headers().withEntries(
            header("someHeaderName", "someHeaderValue")
        ))
        .setCookies(new Cookies().withEntries(
            cookie("someCookieName", "someCookieValue")
        ))
        .setSecure(true)
        .setKeepAlive(false)
        .buildObject(), httpRequest);
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:45,代码来源:WebSocketMessageSerializerTest.java

示例10: jsonEncode

import org.apache.commons.text.StringEscapeUtils; //导入方法依赖的package包/类
/**
 * Escaped the given JSON content using Java String rules.
 *
 * Assumes " is used as quote char and not used inside values and does
 * not escape '.
 *
 * @param object the String.
 * @return the escaped representation.
 */
public String jsonEncode( String object )
{
    return StringEscapeUtils.escapeJava( object );
}
 
开发者ID:dhis2,项目名称:dhis2-core,代码行数:14,代码来源:Encoder.java


注:本文中的org.apache.commons.text.StringEscapeUtils.escapeJava方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。