小编Osc*_*nco的帖子

C的SOLID原则实现

我知道SOLID原则是针对面向对象语言编写的.

我在书中找到了罗伯特·马丁的"嵌入式C的测试驱动开发",本书最后一章的后续句子:

"应用开放封闭原则和Liskov替代原则可以实现更灵活的设计."

由于这是一本C(无c ++或c#)的书,应该有一种方法来实现这个原则.

在C中实现这个原则有什么标准方法吗?

c c++ design-principles solid-principles c++11

13
推荐指数
2
解决办法
4687
查看次数

如何将java.time.Duration映射到XML

我有一个数据类型的bean:

private java.time.Duration duration
Run Code Online (Sandbox Code Playgroud)

class属性设置如下:

object.setDuration(Duration.ofSeconds(2));
Run Code Online (Sandbox Code Playgroud)

我想将我的对象编组为xml,以便持续时间看起来像那样

<duration>PT2S</duration>
Run Code Online (Sandbox Code Playgroud)

ISO 8601所定义

据我所知,Jaxb使用默认绑定数据类型,如:

xsd:duration    javax.xml.datatype.Duration
Run Code Online (Sandbox Code Playgroud)

但在我的bean中,我不想包含任何xml依赖项.

我看到编写包装器的可能性,我可以在其中添加XmlAdapter,但我不知道如何将java.time.Duration转换为javax.xml.datatype.Duration

java xml jaxb java-8 java-time

6
推荐指数
1
解决办法
2381
查看次数

RESTEasy客户端.找不到内容类型application/xml的编写器

我正在尝试使用RESTeasy连接到Web服务.

我使用的代码是这样的:

WebTarget resource = client.target(URL_DISPLAY);
Builder request = resource.request(MediaType.APPLICATION_XML);

long startTime = System.currentTimeMillis();
ClientResponse response = (ClientResponse)request.post(Entity.xml(text));
Run Code Online (Sandbox Code Playgroud)

我在Eclipse中运行它时,程序正在运行.

当我生成一个可运行的jar,甚至从控制台运行java时它不起作用.堆栈跟踪如下:

javax.ws.rs.ProcessingException: Unable to invoke request
    at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:287)
    at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:407)
    at org.jboss.resteasy.client.jaxrs.internal.ClientInvocationBuilder.post(ClientInvocationBuilder.java:195)
    at webservices.WebServicesTest.requestDisplay(WebServicesTest.java:144)
    at webservices.WebServicesTest.main(WebServicesTest.java:328)
Caused by: javax.ws.rs.ProcessingException: could not find writer for content-type application/xml type: webservices.DisplayText
    at org.jboss.resteasy.core.interception.ClientWriterInterceptorContext.throwWriterNotFoundException(ClientWriterInterceptorContext.java:40)
    at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.getWriter(AbstractWriterInterceptorContext.java:138)
    at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:117)
    at org.jboss.resteasy.plugins.interceptors.encoding.GZIPEncodingInterceptor.aroundWriteTo(GZIPEncodingInterceptor.java:100)
    at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:122)
    at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.writeRequestBody(ClientInvocation.java:341)
    at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.writeRequestBodyToOutputStream(ApacheHttpClient4Engine.java:558)
    at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.buildEntity(ApacheHttpClient4Engine.java:524)
    at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.loadHttpMethod(ApacheHttpClient4Engine.java:423)
    at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:281)
    ... 4 more
Run Code Online (Sandbox Code Playgroud)

DisplayText类定义如下:

@XmlRootElement
public class DisplayText implements Serializable
Run Code Online (Sandbox Code Playgroud)

我在我的pom中添加了以下包:

  • RestEasy的客户端
  • RestEasy的-JAXRS …

java eclipse rest resteasy maven

5
推荐指数
1
解决办法
2785
查看次数

Jax-RS 无法对代理进行身份验证

我公司有代理

proxy=myProxy
port=myProxyPort
username=me
password=myPassword
Run Code Online (Sandbox Code Playgroud)

我尝试使用简单的 java.net 函数访问外部世界,它成功了!

System.setProperty("http.proxyHost", myProxy);
System.setProperty("http.proxyPort", myProxyPort);

Authenticator.setDefault(new Authenticator() {
      protected PasswordAuthentication getPasswordAuthentication() {
        return new
           PasswordAuthentication(me,myPasssword.toCharArray());
    }});

URL u = new URL("http://www.google.com");
HttpURLConnection con = (HttpURLConnection) u.openConnection();
DataInputStream di = new DataInputStream(con.getInputStream());
byte[] b = new byte[1024*512];
while(-1 != di.read(b,0,1024*512)) {
   System.out.print(new String(b));
Run Code Online (Sandbox Code Playgroud)

不是我尝试使用 Jax-RS Resteasy 实现来做到这一点,如下所示:

Client client = new ResteasyClientBuilder().defaultProxy(myProxy, myProxyPort).build(); 
System.out.println(client.target("https://www.google.com").request().get().readEntity(String.class));
Run Code Online (Sandbox Code Playgroud)

我收到以下错误

Cache Access Denied
ERR_CACHE_ACCESS_DENIED
(squid/3.1.6)
Sorry, you are not currently allowed to request https://www.google.com/* from this cache until you …
Run Code Online (Sandbox Code Playgroud)

java jax-rs squid resteasy

5
推荐指数
1
解决办法
2290
查看次数

hc-append模块中的未绑定标识符

您好我正在关注球拍的快速介绍.在第5章,他们提出这个代码(工作正常):

(define (four p)
  (define two-p (hc-append p p))
  (vc-append two-p two-p))
Run Code Online (Sandbox Code Playgroud)

将使用let写出来,所以我编写了我的代码:

#lang slideshow

(define (square n)
  (filled-rectangle n n))
(define (four p)
  (let ([two-p (hc-apppend p p)])
  (vc-append two-p two-p)))
Run Code Online (Sandbox Code Playgroud)

但它不起作用.错误消息是:

expand: unbound identifier in module in: hc-apppend
Run Code Online (Sandbox Code Playgroud)

racket

2
推荐指数
1
解决办法
1383
查看次数