- 使用 Spring Initializr 创建 Spring Boot 应用程序
- 在Spring Boot中配置Cassandra
- 在 Spring Boot 上配置 Tomcat 连接池
- 将Camel消息路由到嵌入WildFly的Artemis上
本文整理了Java中com.jcabi.http.response.XmlResponse
类的一些代码示例,展示了XmlResponse
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XmlResponse
类的具体详情如下:
包路径:com.jcabi.http.response.XmlResponse
类名称:XmlResponse
[英]XML response.
This response decorator is able to parse HTTP response body as an XML document and manipulate with it afterwords, for example:
String name = new JdkRequest("http://my.example.com")
.header(HttpHeaders.ACCEPT, MediaType.TEXT_XML)
.fetch()
.as(XmlResponse.class)
.assertXPath("/user/name")
.xml()
.xpath("/user/name/text()")
.get(0);
In HATEOAS responses it is convenient to use this decorator's method #rel(String)in order to follow the link provided in <link> XML element, for example:
String data = new JdkRequest("http://my.example.com")
.header(HttpHeaders.ACCEPT, MediaType.TEXT_XML)
.fetch()
.as(XmlResponse.class)
.rel("/user/links/link[@rel='next']/@href")
.fetch()
.body();
The class is immutable and thread-safe.
[中]XML响应。
此响应装饰器能够将HTTP响应体解析为XML文档,并使用它进行后续操作,例如:
String name = new JdkRequest("http://my.example.com")
.header(HttpHeaders.ACCEPT, MediaType.TEXT_XML)
.fetch()
.as(XmlResponse.class)
.assertXPath("/user/name")
.xml()
.xpath("/user/name/text()")
.get(0);
在{$0$}响应中,可以方便地使用此装饰器的方法#rel(String)来遵循<link>XML元素中提供的链接,例如:
String data = new JdkRequest("http://my.example.com")
.header(HttpHeaders.ACCEPT, MediaType.TEXT_XML)
.fetch()
.as(XmlResponse.class)
.rel("/user/links/link[@rel='next']/@href")
.fetch()
.body();
该类是不可变的,并且是线程安全的。
代码示例来源:origin: yegor256/netbout
@Override
public Locale locale() throws IOException {
return new Locale(
this.request.fetch()
.as(XmlResponse.class)
.xml()
.xpath("/page/alias/locale/text()")
.get(0)
);
}
代码示例来源:origin: jcabi/jcabi-http
/**
* Follow XML link.
* @param query XPath query to fetch new URI
* @return New request
*/
public Request rel(final String query) {
this.assertXPath(query);
return new RestResponse(this).jump(
URI.create(this.xml().xpath(query).get(0))
);
}
代码示例来源:origin: com.rexsl/rexsl-test
final Collection<String> links = new XmlResponse(response).xml().xpath(
StringUtils.join(
"//head/link/@href",
代码示例来源:origin: jcabi/jcabi-http
/**
* Get XML body.
* @return XML body
*/
public XML xml() {
return new XMLDocument(this.body()).merge(this.context());
}
代码示例来源:origin: com.jcabi/jcabi-w3c
@Override
public ValidationResponse validate(final String html)
throws IOException {
final Request req = this.request(html);
final Response response = req.fetch();
if (response.status() != HttpURLConnection.HTTP_OK) {
throw new IOException(
response.reason()
);
}
return this.build(
response.as(XmlResponse.class)
.registerNs("nu", "http://n.validator.nu/messages/")
.assertXPath("//nu:messages")
.assertXPath("//nu:source")
.xml()
);
}
代码示例来源:origin: co.stateful/java-sdk
@Override
public boolean exists(final String name) throws IOException {
return !this.request
.fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.as(XmlResponse.class)
.rel("/page/links/link[@rel='self']/@href")
.method(Request.GET)
.fetch()
.as(XmlResponse.class)
.xml()
.nodes(String.format("/page/locks/lock[name='%s']", name))
.isEmpty();
}
代码示例来源:origin: co.stateful/java-sdk
/**
* Get front request.
* @param label Label
* @return Request
* @throws IOException If fails
*/
private Request front(final String label) throws IOException {
return this.request
.fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.as(XmlResponse.class)
.rel(String.format("/page/links/link[@rel='%s']/@href", label));
}
代码示例来源:origin: jcabi/jcabi-http
/**
* Register this new namespace.
* @param prefix Prefix to use
* @param uri Namespace URI
* @return This object
*/
public XmlResponse registerNs(final String prefix, final String uri) {
return new XmlResponse(this, this.namespaces.with(prefix, uri));
}
代码示例来源:origin: yegor256/netbout
/**
* Fetch more.
* @throws IOException If fails
*/
private void fetch() throws IOException {
final XmlResponse response = this.request.fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.as(XmlResponse.class);
final XML xml = response.xml();
this.messages.addAll(
Lists.transform(
xml.nodes("/page/bout/messages/message"),
new Function<XML, Message>() {
@Override
public Message apply(final XML node) {
return RtMessageIterator.msg(node);
}
}
)
);
if (xml.nodes("/page/bout/messages/message ").isEmpty()) {
this.more = false;
} else {
this.request = response.rel(
// @checkstyle LineLength (1 line)
"/page/bout/messages/message[last()]/links/link[@rel='more']/@href"
);
}
}
代码示例来源:origin: com.jcabi/jcabi-w3c
/**
* Return a response after real processing of the CSS.
* @param css The CSS stylesheet to check
* @return The response
* @throws IOException if fails
*/
private ValidationResponse processed(final String css) throws IOException {
final Request req = this.request(
AbstractBaseValidator.entity(
"file", DefaultCssValidator.filter(css), "text/css"
)
);
final Response response = DefaultCssValidator.correct(req.fetch());
return DefaultCssValidator.build(
response.as(XmlResponse.class)
.registerNs("env", "http://www.w3.org/2003/05/soap-envelope")
.registerNs("m", "http://www.w3.org/2005/07/css-validator")
.assertXPath("//m:validity")
.assertXPath("//m:checkedby")
.xml()
);
}
代码示例来源:origin: co.stateful/java-sdk
/**
* Get front request.
* @param ops Operation
* @return Request
* @throws IOException If fails
*/
private Request front(final String ops) throws IOException {
return this.request.fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.as(XmlResponse.class)
.rel(
String.format(
// @checkstyle LineLength (1 line)
"/page/counters/counter[name='%s']/links/link[@rel='%s']/@href",
this.label, ops
)
);
}
代码示例来源:origin: jcabi/jcabi-http
/**
* Verifies HTTP response body XHTML/XML content against XPath query,
* and throws {@link AssertionError} in case of mismatch.
* @param xpath Query to use
* @return This object
*/
public XmlResponse assertXPath(final String xpath) {
final String body = this.body();
if (!XhtmlMatchers.hasXPath(xpath, this.context()).matches(body)) {
throw new AssertionError(
String.format(
"XML doesn't contain required XPath '%s':%n%s",
xpath, body
)
);
}
return this;
}
代码示例来源:origin: yegor256/netbout
@Override
public URI photo() throws IOException {
return URI.create(
this.request.fetch()
.as(XmlResponse.class)
.xml()
.xpath("/page/alias/photo/text()")
.get(0)
);
}
代码示例来源:origin: yegor256/netbout
.assertStatus(HttpURLConnection.HTTP_OK)
.as(XmlResponse.class);
final XML xml = response.xml();
this.bouts.addAll(
Lists.transform(
this.more = false;
} else {
this.request = response.rel(
"/page/bouts/bout[last()]/links/link[@rel='more']/@href"
);
代码示例来源:origin: yegor256/takes
/**
* Retrieve Github access token.
* @param home Home of this page
* @param code Github "authorization code"
* @return The token
* @throws IOException If failed
*/
private String token(final String home, final String code)
throws IOException {
final String uri = new Href(this.github)
.path(PsGithub.LOGIN).path("oauth").path(PsGithub.ACCESS_TOKEN)
.toString();
return new JdkRequest(uri)
.method("POST")
.header("Accept", "application/xml")
.body()
.formParam("client_id", this.app)
.formParam("redirect_uri", home)
.formParam("client_secret", this.key)
.formParam(PsGithub.CODE, code)
.back()
.fetch().as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.as(XmlResponse.class)
.assertXPath("/OAuth/access_token")
.xml()
.xpath("/OAuth/access_token/text()")
.get(0);
}
代码示例来源:origin: co.stateful/java-sdk
@Override
public void delete(final String name) throws IOException {
final long start = System.currentTimeMillis();
this.request.fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.as(XmlResponse.class)
.rel(
String.format(
// @checkstyle LineLength (1 line)
"/page/counters/counter[name='%s']/links/link[@rel='delete']/@href",
name
)
)
.uri().queryParam("name", name).back()
.fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_SEE_OTHER);
Logger.info(
this, "counter \"%s\" deleted in %[ms]s",
name, System.currentTimeMillis() - start
);
}
代码示例来源:origin: yegor256/netbout
@Override
public String name() throws IOException {
return this.request.fetch()
.as(XmlResponse.class)
.xml()
.xpath("/page/alias/name/text()")
.get(0);
}
代码示例来源:origin: yegor256/netbout
@Override
public long start() throws IOException {
final long number = Long.parseLong(
this.request.fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.as(XmlResponse.class)
.rel("/page/links/link[@rel='start']/@href")
.fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_SEE_OTHER)
.follow()
.fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.as(XmlResponse.class)
.xml()
.xpath("/page/bout/number/text()")
.get(0)
);
Logger.info(this, "bout #%d started", number);
return number;
}
代码示例来源:origin: org.takes/takes
/**
* Retrieve Github access token.
* @param home Home of this page
* @param code Github "authorization code"
* @return The token
* @throws IOException If failed
*/
private String token(final String home, final String code)
throws IOException {
final String uri = new Href(this.github)
.path(PsGithub.LOGIN).path("oauth").path(PsGithub.ACCESS_TOKEN)
.toString();
return new JdkRequest(uri)
.method("POST")
.header("Accept", "application/xml")
.body()
.formParam("client_id", this.app)
.formParam("redirect_uri", home)
.formParam("client_secret", this.key)
.formParam(PsGithub.CODE, code)
.back()
.fetch().as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.as(XmlResponse.class)
.assertXPath("/OAuth/access_token")
.xml()
.xpath("/OAuth/access_token/text()")
.get(0);
}
代码示例来源:origin: co.stateful/java-sdk
@Override
public Counters counters() throws IOException {
return new RtCounters(
this.request
.fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.as(XmlResponse.class)
.rel("/page/links/link[@rel='menu:counters']/@href")
);
}
我正在使用 Jersey 构建一个 rest API,其中允许根据客户端喜欢的格式输出 XML 和 JSON(使用 Accept header ) .该服务将以下类作为输出发送,如下所示 @XmlRo
我正在尝试从 XMLResponse 创建一个 FileReader (不是 Document),如下所示: // Parse XML Response DocumentBuilder
本文整理了Java中com.jcabi.http.response.XmlResponse.()方法的一些代码示例,展示了XmlResponse.()的具体用法。这些代码示例主要来源于Github/S
本文整理了Java中com.jcabi.http.response.XmlResponse.assertXPath()方法的一些代码示例,展示了XmlResponse.assertXPath()的具体
本文整理了Java中com.jcabi.http.response.XmlResponse.rel()方法的一些代码示例,展示了XmlResponse.rel()的具体用法。这些代码示例主要来源于Gi
本文整理了Java中com.jcabi.http.response.XmlResponse.xml()方法的一些代码示例,展示了XmlResponse.xml()的具体用法。这些代码示例主要来源于Gi
我尝试使用的 API 在检索时返回乱码 XML。 以下是将身份验证参数发布到端点的基本代码。 [[APIManager sharedManager] postPath:@"Authenticate"
我是一名优秀的程序员,十分优秀!