异常处理方法:The input stream for an incoming message is null.

本文介绍了解决在使用Webservices技术时遇到的“The input stream for an incoming message is null”异常的方法。异常源于.NET Development Server可能不支持HTTP1.1的ChunkedEncoding。文中提供了一个解决方案,即设置ADBClient不使用ChunkedEncoding。

 做Web services技术作业的时候,遇到了这个异常。通过查找相关资料,终于解决了,详情见[1]。

 

 异常描述:

 org.apache.axis2.AxisFault: The input stream for an incoming message is null.
 at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:92)
 at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:67)
 at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:354)
 at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:417)
 at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
 at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)

 

 ADB Client的解决方法:

 // stub 是利用Axis2 wsdl2java命令生成的*Stub.java类的实例

 stub._getServiceClient().getOptions().setProperty(HTTPConstants.CHUNKED,"false"); 

 这句话的作用是,设置ADB Client不使用Chunked Encoding。原因是.NET Development Server很可能不支持HTTP 1.1的Chunked Encoding。因此,将这个开关置为FALSE。

 

 [1] 中还提到了如何解决JAXWS Client的上述异常问题,研究中... ...

 

 [1] http://old.nabble.com/The-input-stream-for-an-incoming-message-is-null-td24067861.html

client.cpp代码如下: #include <stdio.h> #include <stdlib.h> #include <netdb.h> #include <netinet/in.h> #include <unistd.h> #include <string.h> int main(int argc, char *argv[]) { (void)argc; (void)argv; int sockfd, n; uint16_t portno; struct sockaddr_in serv_addr; struct hostent *server; char buffer[256]; if (argc < 3) { fprintf(stderr, "usage %s hostname port\n", argv[0]); exit(0); } portno = (uint16_t)atoi(argv[2]); /* Create a socket point */ sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) { perror("ERROR opening socket"); exit(1); } server = gethostbyname(argv[1]); if (server == NULL) { fprintf(stderr, "ERROR, no such host\n"); exit(0); } bzero((char *)&serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; bcopy(server->h_addr, (char *)&serv_addr.sin_addr.s_addr, (size_t)server->h_length); serv_addr.sin_port = htons(portno); /* Now connect to the server */ if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) { perror("ERROR connecting"); exit(1); } /* Now ask for a message from the user, this message * will be read by server */ printf("Please enter the message: "); bzero(buffer, 256); if (fgets(buffer, 255, stdin) == NULL) { perror("ERROR reading from stdin"); exit(1); } /* Send message to the server */ n = write(sockfd, buffer, strlen(buffer)); if (n < 0) { perror("ERROR writing to socket"); exit(1); } /* Now read server response */ bzero(buffer, 256); n = read(sockfd, buffer, 255); if (n < 0) { perror("ERROR reading from socket"); exit(1); } printf("%s\n", buffer); return 0; } server.cpp代码如下: #include <stdio.h> #include <stdlib.h> #include <netdb.h> #include <netinet/in.h> #include <unistd.h> #include <string.h> int main(int argc, char *argv[]) { (void)argc; (void)argv; int sockfd, newsockfd; uint16_t portno; unsigned int clilen; char buffer[256]; struct sockaddr_in serv_addr, cli_addr; ssize_t n; /* First call to socket() function */ sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) { perror("ERROR opening socket"); exit(1); } /* Initialize socket structure */ bzero((char *)&serv_addr, sizeof(serv_addr)); portno = 5001; serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = INADDR_ANY; serv_addr.sin_port = htons(portno); /* Now bind the host address using bind() call.*/ if (bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) { perror("ERROR on binding"); exit(1); } /* Now start listening for the clients, here process will * go in sleep mode and will wait for the incoming connection */ listen(sockfd, 5); clilen = sizeof(cli_addr); /* Accept actual connection from the client */ newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr, &clilen); if (newsockfd < 0) { perror("ERROR on accept"); exit(1); } /* If connection is established then start communicating */ bzero(buffer, 256); n = read(newsockfd, buffer, 255); if (n < 0) { perror("ERROR reading from socket"); exit(1); } printf("Here is the message: %s\n", buffer); /* Write a response to the client */ n = write(newsockfd, "I got your message", 18); if (n < 0) { perror("ERROR writing to socket"); exit(1); } return 0; } 在此代码的基础上修改
最新发布
10-21
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值