Compare commits

...

7 Commits
3.2 ... 2.5.x

253 changed files with 1924 additions and 24877 deletions

1
DISCLAIMER Normal file
View File

@ -0,0 +1 @@
Apache Dubbo is an effort undergoing incubation at The Apache Software Foundation (ASF), sponsored by the Incubator. Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects. While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF.

View File

@ -1,14 +1,12 @@
# Dubbo Project
[![Build Status](https://travis-ci.org/alibaba/dubbo.svg?branch=master)](https://travis-ci.org/alibaba/dubbo)
[![codecov](https://codecov.io/gh/alibaba/dubbo/branch/master/graph/badge.svg)](https://codecov.io/gh/alibaba/dubbo)
[![Build Status](https://travis-ci.org/apache/incubator-dubbo.svg?branch=master)](https://travis-ci.org/apache/incubator-dubbo)
[![codecov](https://codecov.io/gh/apache/incubator-dubbo/branch/master/graph/badge.svg)](https://codecov.io/gh/apache/incubator-dubbo)
[![Gitter](https://badges.gitter.im/alibaba/dubbo.svg)](https://gitter.im/alibaba/dubbo?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
![license](https://img.shields.io/github/license/alibaba/dubbo.svg)
![maven](https://img.shields.io/maven-central/v/com.alibaba/dubbo.svg)
Dubbo is a high-performance, java based RPC framework open-sourced by Alibaba. Please visit [dubbo.io](http://dubbo.io) for quick start and other information.
We are now collecting dubbo user info in order to help us to improve dubbo better, pls. kindly help us by providing yours on [issue#1012: Wanted: who's using dubbo](https://github.com/alibaba/dubbo/issues/1012), thanks :)
This version has been announced as EOF, it's no longer maintained by the official team. We recommend use the latest [2.7.x](https://github.com/apache/dubbo) version
## Links

View File

@ -1,18 +1,18 @@
<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

View File

@ -1,18 +1,18 @@
<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

View File

@ -1,19 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">

View File

@ -36,6 +36,8 @@ import com.alibaba.dubbo.rpc.ProxyFactory;
import com.alibaba.dubbo.rpc.cluster.Cluster;
import com.alibaba.dubbo.rpc.support.MockInvoker;
import static com.alibaba.dubbo.common.utils.NetUtils.isInvalidLocalHost;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -226,7 +228,16 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
if (ConfigUtils.getPid() > 0) {
map.put(Constants.PID_KEY, String.valueOf(ConfigUtils.getPid()));
}
//set ip
String hostToRegistry = ConfigUtils.getSystemProperty(Constants.DUBBO_IP_TO_REGISTRY);
if (hostToRegistry == null || hostToRegistry.length() == 0) {
hostToRegistry = NetUtils.getLocalHost();
} else if (isInvalidLocalHost(hostToRegistry)) {
throw new IllegalArgumentException("Specified invalid registry ip from property:" + Constants.DUBBO_IP_TO_REGISTRY + ", value:" + hostToRegistry);
}
map.put(Constants.REGISTER_IP_KEY, hostToRegistry);
appendParameters(map, monitor);
appendParameters(map, application);
String address = monitor.getAddress();
String sysaddress = System.getProperty("dubbo.monitor.address");
if (sysaddress != null && sysaddress.length() > 0) {

View File

@ -1,18 +1,18 @@
<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

View File

@ -1,19 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">

View File

@ -1,19 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

View File

@ -1,19 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

View File

@ -1,18 +1,18 @@
<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

View File

@ -1,18 +1,18 @@
<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

View File

@ -1,18 +1,18 @@
<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

View File

@ -1,18 +1,18 @@
<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

View File

@ -1,18 +1,18 @@
<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

View File

@ -1,19 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">

View File

@ -1,18 +1,18 @@
<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

View File

@ -1,18 +1,18 @@
<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

View File

@ -1,18 +1,18 @@
<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

View File

@ -74,6 +74,7 @@ public class NettyServer extends AbstractServer implements Server {
// https://issues.jboss.org/browse/NETTY-365
// https://issues.jboss.org/browse/NETTY-379
// final Timer timer = new HashedWheelTimer(new NamedThreadFactory("NettyIdleTimer", true));
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() {
NettyCodecAdapter adapter = new NettyCodecAdapter(getCodec(), getUrl(), NettyServer.this);

View File

@ -1,19 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

View File

@ -1,18 +1,18 @@
<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

View File

@ -1,18 +1,18 @@
<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

View File

@ -1,19 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

View File

@ -1,31 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-parent</artifactId>
<version>2.5.10</version>
</parent>
<artifactId>hessian-lite</artifactId>
<packaging>jar</packaging>
<version>3.2.1-fixed-2</version>
<name>Hessian Lite(Alibaba embed version)</name>
</project>

View File

@ -1,81 +0,0 @@
/*
* Copyright (c) 2001-2008 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian;
/**
* Base runtime exception for Hessian exceptions.
*/
public class HessianException extends RuntimeException {
/**
* Zero-arg constructor.
*/
public HessianException() {
}
/**
* Create the exception.
*/
public HessianException(String message) {
super(message);
}
/**
* Create the exception.
*/
public HessianException(String message, Throwable rootCause) {
super(message, rootCause);
}
/**
* Create the exception.
*/
public HessianException(Throwable rootCause) {
super(rootCause);
}
}

View File

@ -1,145 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Burlap", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
/**
* Deserializing an object.
*/
abstract public class AbstractDeserializer implements Deserializer {
public Class getType() {
return Object.class;
}
public Object readObject(AbstractHessianInput in)
throws IOException {
Object obj = in.readObject();
String className = getClass().getName();
if (obj != null)
throw error(className + ": unexpected object " + obj.getClass().getName() + " (" + obj + ")");
else
throw error(className + ": unexpected null value");
}
public Object readList(AbstractHessianInput in, int length)
throws IOException {
throw new UnsupportedOperationException(String.valueOf(this));
}
@Override
public Object readList(AbstractHessianInput in, int length, Class<?> expectType) throws IOException {
if(expectType == null) {
return readList(in, length);
}
throw new UnsupportedOperationException(String.valueOf(this));
}
public Object readLengthList(AbstractHessianInput in, int length)
throws IOException {
throw new UnsupportedOperationException(String.valueOf(this));
}
@Override
public Object readLengthList(AbstractHessianInput in, int length, Class<?> expectType) throws IOException {
if(expectType == null){
return readLengthList(in , length);
}
throw new UnsupportedOperationException(String.valueOf(this));
}
public Object readMap(AbstractHessianInput in)
throws IOException {
Object obj = in.readObject();
String className = getClass().getName();
if (obj != null)
throw error(className + ": unexpected object " + obj.getClass().getName() + " (" + obj + ")");
else
throw error(className + ": unexpected null value");
}
@Override
public Object readMap(AbstractHessianInput in, Class<?> expectKeyType, Class<?> expectValueType) throws IOException {
if(expectKeyType == null && expectValueType == null){
return readMap(in);
}
throw new UnsupportedOperationException(String.valueOf(this));
}
public Object readObject(AbstractHessianInput in, String[] fieldNames)
throws IOException {
throw new UnsupportedOperationException(String.valueOf(this));
}
protected HessianProtocolException error(String msg) {
return new HessianProtocolException(msg);
}
protected String codeName(int ch) {
if (ch < 0)
return "end of file";
else
return "0x" + Integer.toHexString(ch & 0xff);
}
protected SerializerFactory findSerializerFactory(AbstractHessianInput in) {
SerializerFactory serializerFactory = null;
if(in instanceof Hessian2Input) {
serializerFactory = ((Hessian2Input) in).findSerializerFactory();
}
else if(in instanceof HessianInput) {
serializerFactory = ((HessianInput) in).getSerializerFactory();
}
return serializerFactory == null? new SerializerFactory(): serializerFactory;
}
}

View File

@ -1,456 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Burlap", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.util.List;
/**
* Abstract base class for Hessian requests. Hessian users should only
* need to use the methods in this class.
* <p>
* <pre>
* AbstractHessianInput in = ...; // get input
* String value;
*
* in.startReply(); // read reply header
* value = in.readString(); // read string value
* in.completeReply(); // read reply footer
* </pre>
*/
abstract public class AbstractHessianInput {
private HessianRemoteResolver resolver;
/**
* Initialize the Hessian stream with the underlying input stream.
*/
public void init(InputStream is) {
}
/**
* Returns the call's method
*/
abstract public String getMethod();
/**
* Sets the resolver used to lookup remote objects.
*/
public HessianRemoteResolver getRemoteResolver() {
return resolver;
}
/**
* Sets the resolver used to lookup remote objects.
*/
public void setRemoteResolver(HessianRemoteResolver resolver) {
this.resolver = resolver;
}
/**
* Sets the serializer factory.
*/
public void setSerializerFactory(SerializerFactory ser) {
}
/**
* Reads the call
* <p>
* <pre>
* c major minor
* </pre>
*/
abstract public int readCall()
throws IOException;
/**
* For backward compatibility with HessianSkeleton
*/
public void skipOptionalCall()
throws IOException {
}
/**
* Reads a header, returning null if there are no headers.
* <p>
* <pre>
* H b16 b8 value
* </pre>
*/
abstract public String readHeader()
throws IOException;
/**
* Starts reading the call
* <p>
* <p>A successful completion will have a single value:
* <p>
* <pre>
* m b16 b8 method
* </pre>
*/
abstract public String readMethod()
throws IOException;
/**
* Reads the number of method arguments
*
* @return -1 for a variable length (hessian 1.0)
*/
public int readMethodArgLength()
throws IOException {
return -1;
}
/**
* Starts reading the call, including the headers.
* <p>
* <p>The call expects the following protocol data
* <p>
* <pre>
* c major minor
* m b16 b8 method
* </pre>
*/
abstract public void startCall()
throws IOException;
/**
* Completes reading the call
* <p>
* <p>The call expects the following protocol data
* <p>
* <pre>
* Z
* </pre>
*/
abstract public void completeCall()
throws IOException;
/**
* Reads a reply as an object.
* If the reply has a fault, throws the exception.
*/
abstract public Object readReply(Class expectedClass)
throws Throwable;
/**
* Starts reading the reply
* <p>
* <p>A successful completion will have a single value:
* <p>
* <pre>
* r
* v
* </pre>
*/
abstract public void startReply()
throws Throwable;
/**
* Completes reading the call
* <p>
* <p>A successful completion will have a single value:
* <p>
* <pre>
* z
* </pre>
*/
abstract public void completeReply()
throws IOException;
/**
* Reads a boolean
* <p>
* <pre>
* T
* F
* </pre>
*/
abstract public boolean readBoolean()
throws IOException;
/**
* Reads a null
* <p>
* <pre>
* N
* </pre>
*/
abstract public void readNull()
throws IOException;
/**
* Reads an integer
* <p>
* <pre>
* I b32 b24 b16 b8
* </pre>
*/
abstract public int readInt()
throws IOException;
/**
* Reads a long
* <p>
* <pre>
* L b64 b56 b48 b40 b32 b24 b16 b8
* </pre>
*/
abstract public long readLong()
throws IOException;
/**
* Reads a double.
* <p>
* <pre>
* D b64 b56 b48 b40 b32 b24 b16 b8
* </pre>
*/
abstract public double readDouble()
throws IOException;
/**
* Reads a date.
* <p>
* <pre>
* T b64 b56 b48 b40 b32 b24 b16 b8
* </pre>
*/
abstract public long readUTCDate()
throws IOException;
/**
* Reads a string encoded in UTF-8
* <p>
* <pre>
* s b16 b8 non-final string chunk
* S b16 b8 final string chunk
* </pre>
*/
abstract public String readString()
throws IOException;
/**
* Reads an XML node encoded in UTF-8
* <p>
* <pre>
* x b16 b8 non-final xml chunk
* X b16 b8 final xml chunk
* </pre>
*/
public org.w3c.dom.Node readNode()
throws IOException {
throw new UnsupportedOperationException(getClass().getSimpleName());
}
/**
* Starts reading a string. All the characters must be read before
* calling the next method. The actual characters will be read with
* the reader's read() or read(char [], int, int).
* <p>
* <pre>
* s b16 b8 non-final string chunk
* S b16 b8 final string chunk
* </pre>
*/
abstract public Reader getReader()
throws IOException;
/**
* Starts reading a byte array using an input stream. All the bytes
* must be read before calling the following method.
* <p>
* <pre>
* b b16 b8 non-final binary chunk
* B b16 b8 final binary chunk
* </pre>
*/
abstract public InputStream readInputStream()
throws IOException;
/**
* Reads a byte array.
* <p>
* <pre>
* b b16 b8 non-final binary chunk
* B b16 b8 final binary chunk
* </pre>
*/
abstract public byte[] readBytes()
throws IOException;
/**
* Reads an arbitrary object from the input stream.
*
* @param expectedClass the expected class if the protocol doesn't supply it.
*/
abstract public Object readObject(Class expectedClass)
throws IOException;
/**
* Reads an arbitrary object from the input stream.
*
* @param expectedClass the expected class if the protocol doesn't supply it.
* @param expectedTypes the runtime type hints, eg: expectedClass equals Map, expectedTypes can
* equals String.class, Short.class
*/
public Object readObject(Class expectedClass, Class<?>... expectedTypes)
throws IOException{
throw new UnsupportedOperationException(String.valueOf(this));
}
/**
* Reads an arbitrary object from the input stream.
*/
abstract public Object readObject()
throws IOException;
/**
* Reads an arbitrary object from the input stream.
* @param expectedTypes the runtime type hints, eg: expectedTypes can
* equals String.class, Short.class for HashMap
*/
public Object readObject(List<Class<?>> expectedTypes)
throws IOException{
throw new UnsupportedOperationException(String.valueOf(this));
}
/**
* Reads a remote object reference to the stream. The type is the
* type of the remote interface.
* <p>
* <code><pre>
* 'r' 't' b16 b8 type url
* </pre></code>
*/
abstract public Object readRemote()
throws IOException;
/**
* Reads a reference
* <p>
* <pre>
* R b32 b24 b16 b8
* </pre>
*/
abstract public Object readRef()
throws IOException;
/**
* Adds an object reference.
*/
abstract public int addRef(Object obj)
throws IOException;
/**
* Sets an object reference.
*/
abstract public void setRef(int i, Object obj)
throws IOException;
/**
* Resets the references for streaming.
*/
public void resetReferences() {
}
/**
* Reads the start of a list
*/
abstract public int readListStart()
throws IOException;
/**
* Reads the length of a list.
*/
abstract public int readLength()
throws IOException;
/**
* Reads the start of a map
*/
abstract public int readMapStart()
throws IOException;
/**
* Reads an object type.
*/
abstract public String readType()
throws IOException;
/**
* Returns true if the data has ended.
*/
abstract public boolean isEnd()
throws IOException;
/**
* Read the end byte
*/
abstract public void readEnd()
throws IOException;
/**
* Read the end byte
*/
abstract public void readMapEnd()
throws IOException;
/**
* Read the end byte
*/
abstract public void readListEnd()
throws IOException;
public void close()
throws IOException {
}
}

View File

@ -1,515 +0,0 @@
/*
* Copyright (c) 2001-2008 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.io.OutputStream;
/**
* Abstract output stream for Hessian requests.
* <p>
* <pre>
* OutputStream os = ...; // from http connection
* AbstractOutput out = new HessianSerializerOutput(os);
* String value;
*
* out.startCall("hello"); // start hello call
* out.writeString("arg1"); // write a string argument
* out.completeCall(); // complete the call
* </pre>
*/
abstract public class AbstractHessianOutput {
// serializer factory
protected SerializerFactory _serializerFactory;
/**
* Gets the serializer factory.
*/
public SerializerFactory getSerializerFactory() {
return _serializerFactory;
}
/**
* Sets the serializer factory.
*/
public void setSerializerFactory(SerializerFactory factory) {
_serializerFactory = factory;
}
/**
* Gets the serializer factory.
*/
public final SerializerFactory findSerializerFactory() {
SerializerFactory factory = _serializerFactory;
if (factory == null)
_serializerFactory = factory = new SerializerFactory();
return factory;
}
/**
* Initialize the output with a new underlying stream.
*/
public void init(OutputStream os) {
}
/**
* Writes a complete method call.
*/
public void call(String method, Object[] args)
throws IOException {
int length = args != null ? args.length : 0;
startCall(method, length);
for (int i = 0; i < length; i++)
writeObject(args[i]);
completeCall();
}
/**
* Starts the method call:
* <p>
* <code><pre>
* C
* </pre></code>
*
* @param method the method name to call.
*/
abstract public void startCall()
throws IOException;
/**
* Starts the method call:
* <p>
* <code><pre>
* C string int
* </pre></code>
*
* @param method the method name to call.
*/
abstract public void startCall(String method, int length)
throws IOException;
/**
* For Hessian 2.0, use the Header envelope instead
*
* @deprecated
*/
public void writeHeader(String name)
throws IOException {
throw new UnsupportedOperationException(getClass().getSimpleName());
}
/**
* Writes the method tag.
* <p>
* <code><pre>
* string
* </pre></code>
*
* @param method the method name to call.
*/
abstract public void writeMethod(String method)
throws IOException;
/**
* Completes the method call:
* <p>
* <code><pre>
* </pre></code>
*/
abstract public void completeCall()
throws IOException;
/**
* Writes a boolean value to the stream. The boolean will be written
* with the following syntax:
* <p>
* <code><pre>
* T
* F
* </pre></code>
*
* @param value the boolean value to write.
*/
abstract public void writeBoolean(boolean value)
throws IOException;
/**
* Writes an integer value to the stream. The integer will be written
* with the following syntax:
* <p>
* <code><pre>
* I b32 b24 b16 b8
* </pre></code>
*
* @param value the integer value to write.
*/
abstract public void writeInt(int value)
throws IOException;
/**
* Writes a long value to the stream. The long will be written
* with the following syntax:
* <p>
* <code><pre>
* L b64 b56 b48 b40 b32 b24 b16 b8
* </pre></code>
*
* @param value the long value to write.
*/
abstract public void writeLong(long value)
throws IOException;
/**
* Writes a double value to the stream. The double will be written
* with the following syntax:
* <p>
* <code><pre>
* D b64 b56 b48 b40 b32 b24 b16 b8
* </pre></code>
*
* @param value the double value to write.
*/
abstract public void writeDouble(double value)
throws IOException;
/**
* Writes a date to the stream.
* <p>
* <code><pre>
* T b64 b56 b48 b40 b32 b24 b16 b8
* </pre></code>
*
* @param time the date in milliseconds from the epoch in UTC
*/
abstract public void writeUTCDate(long time)
throws IOException;
/**
* Writes a null value to the stream.
* The null will be written with the following syntax
* <p>
* <code><pre>
* N
* </pre></code>
*
* @param value the string value to write.
*/
abstract public void writeNull()
throws IOException;
/**
* Writes a string value to the stream using UTF-8 encoding.
* The string will be written with the following syntax:
* <p>
* <code><pre>
* S b16 b8 string-value
* </pre></code>
* <p>
* If the value is null, it will be written as
* <p>
* <code><pre>
* N
* </pre></code>
*
* @param value the string value to write.
*/
abstract public void writeString(String value)
throws IOException;
/**
* Writes a string value to the stream using UTF-8 encoding.
* The string will be written with the following syntax:
* <p>
* <code><pre>
* S b16 b8 string-value
* </pre></code>
* <p>
* If the value is null, it will be written as
* <p>
* <code><pre>
* N
* </pre></code>
*
* @param value the string value to write.
*/
abstract public void writeString(char[] buffer, int offset, int length)
throws IOException;
/**
* Writes a byte array to the stream.
* The array will be written with the following syntax:
* <p>
* <code><pre>
* B b16 b18 bytes
* </pre></code>
* <p>
* If the value is null, it will be written as
* <p>
* <code><pre>
* N
* </pre></code>
*
* @param value the string value to write.
*/
abstract public void writeBytes(byte[] buffer)
throws IOException;
/**
* Writes a byte array to the stream.
* The array will be written with the following syntax:
* <p>
* <code><pre>
* B b16 b18 bytes
* </pre></code>
* <p>
* If the value is null, it will be written as
* <p>
* <code><pre>
* N
* </pre></code>
*
* @param value the string value to write.
*/
abstract public void writeBytes(byte[] buffer, int offset, int length)
throws IOException;
/**
* Writes a byte buffer to the stream.
*/
abstract public void writeByteBufferStart()
throws IOException;
/**
* Writes a byte buffer to the stream.
* <p>
* <code><pre>
* b b16 b18 bytes
* </pre></code>
*
* @param value the string value to write.
*/
abstract public void writeByteBufferPart(byte[] buffer,
int offset,
int length)
throws IOException;
/**
* Writes the last chunk of a byte buffer to the stream.
* <p>
* <code><pre>
* b b16 b18 bytes
* </pre></code>
*
* @param value the string value to write.
*/
abstract public void writeByteBufferEnd(byte[] buffer,
int offset,
int length)
throws IOException;
/**
* Writes a reference.
* <p>
* <code><pre>
* Q int
* </pre></code>
*
* @param value the integer value to write.
*/
abstract protected void writeRef(int value)
throws IOException;
/**
* Removes a reference.
*/
abstract public boolean removeRef(Object obj)
throws IOException;
/**
* Replaces a reference from one object to another.
*/
abstract public boolean replaceRef(Object oldRef, Object newRef)
throws IOException;
/**
* Adds an object to the reference list. If the object already exists,
* writes the reference, otherwise, the caller is responsible for
* the serialization.
* <p>
* <code><pre>
* R b32 b24 b16 b8
* </pre></code>
*
* @param object the object to add as a reference.
* @return true if the object has already been written.
*/
abstract public boolean addRef(Object object)
throws IOException;
/**
* Resets the references for streaming.
*/
public void resetReferences() {
}
/**
* Writes a generic object to the output stream.
*/
abstract public void writeObject(Object object)
throws IOException;
/**
* Writes the list header to the stream. List writers will call
* <code>writeListBegin</code> followed by the list contents and then
* call <code>writeListEnd</code>.
* <p>
* <code><pre>
* V
* x13 java.util.ArrayList # type
* x93 # length=3
* x91 # 1
* x92 # 2
* x93 # 3
* &lt;/list>
* </pre></code>
*/
abstract public boolean writeListBegin(int length, String type)
throws IOException;
/**
* Writes the tail of the list to the stream.
*/
abstract public void writeListEnd()
throws IOException;
/**
* Writes the map header to the stream. Map writers will call
* <code>writeMapBegin</code> followed by the map contents and then
* call <code>writeMapEnd</code>.
* <p>
* <code><pre>
* M type (<key> <value>)* Z
* </pre></code>
*/
abstract public void writeMapBegin(String type)
throws IOException;
/**
* Writes the tail of the map to the stream.
*/
abstract public void writeMapEnd()
throws IOException;
/**
* Writes the object header to the stream (for Hessian 2.0), or a
* Map for Hessian 1.0. Object writers will call
* <code>writeObjectBegin</code> followed by the map contents and then
* call <code>writeObjectEnd</code>.
* <p>
* <code><pre>
* C type int <key>*
* C int <value>*
* </pre></code>
*
* @return true if the object has already been defined.
*/
public int writeObjectBegin(String type)
throws IOException {
writeMapBegin(type);
return -2;
}
/**
* Writes the end of the class.
*/
public void writeClassFieldLength(int len)
throws IOException {
}
/**
* Writes the tail of the object to the stream.
*/
public void writeObjectEnd()
throws IOException {
}
public void writeReply(Object o)
throws IOException {
startReply();
writeObject(o);
completeReply();
}
public void startReply()
throws IOException {
}
public void completeReply()
throws IOException {
}
public void writeFault(String code, String message, Object detail)
throws IOException {
}
public void flush()
throws IOException {
}
public void close()
throws IOException {
}
}

View File

@ -1,64 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
/**
* Looks up remote objects. The default just returns a HessianRemote object.
*/
public class AbstractHessianResolver implements HessianRemoteResolver {
/**
* Looks up a proxy object.
*/
public Object lookup(String type, String url)
throws IOException {
return new HessianRemote(type, url);
}
}

View File

@ -1,66 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
/**
* Deserializing a JDK 1.2 Collection.
*/
public class AbstractListDeserializer extends AbstractDeserializer {
public Object readObject(AbstractHessianInput in)
throws IOException {
Object obj = in.readObject();
if (obj != null)
throw error("expected list at " + obj.getClass().getName() + " (" + obj + ")");
else
throw error("expected list at null");
}
}

View File

@ -1,72 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Burlap", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.util.HashMap;
/**
* Serializing an object for known object types.
*/
public class AbstractMapDeserializer extends AbstractDeserializer {
public Class getType() {
return HashMap.class;
}
public Object readObject(AbstractHessianInput in)
throws IOException {
Object obj = in.readObject();
if (obj != null)
throw error("expected map/object at " + obj.getClass().getName() + " (" + obj + ")");
else
throw error("expected map/object at null");
}
}

View File

@ -1,63 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Burlap", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.util.logging.Logger;
/**
* Serializing an object.
*/
abstract public class AbstractSerializer implements Serializer {
protected static final Logger log
= Logger.getLogger(AbstractSerializer.class.getName());
abstract public void writeObject(Object obj, AbstractHessianOutput out)
throws IOException;
}

View File

@ -1,72 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Burlap", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
/**
* Factory for returning serialization methods.
*/
abstract public class AbstractSerializerFactory {
/**
* Returns the serializer for a class.
*
* @param cl the class of the object that needs to be serialized.
* @return a serializer object for the serialization.
*/
abstract public Serializer getSerializer(Class cl)
throws HessianProtocolException;
/**
* Returns the deserializer for a class.
*
* @param cl the class of the object that needs to be deserialized.
* @return a deserializer object for the serialization.
*/
abstract public Deserializer getDeserializer(Class cl)
throws HessianProtocolException;
}

View File

@ -1,154 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.ArrayList;
/**
* Deserializing a Java array
*/
public class ArrayDeserializer extends AbstractListDeserializer {
private Class _componentType;
private Class _type;
public ArrayDeserializer(Class componentType) {
_componentType = componentType;
if (_componentType != null) {
try {
_type = Array.newInstance(_componentType, 0).getClass();
} catch (Exception e) {
}
}
if (_type == null)
_type = Object[].class;
}
public Class getType() {
return _type;
}
/**
* Reads the array.
*/
public Object readList(AbstractHessianInput in, int length)
throws IOException {
if (length >= 0) {
Object[] data = createArray(length);
in.addRef(data);
if (_componentType != null) {
for (int i = 0; i < data.length; i++)
data[i] = in.readObject(_componentType);
} else {
for (int i = 0; i < data.length; i++)
data[i] = in.readObject();
}
in.readListEnd();
return data;
} else {
ArrayList list = new ArrayList();
in.addRef(list);
if (_componentType != null) {
while (!in.isEnd())
list.add(in.readObject(_componentType));
} else {
while (!in.isEnd())
list.add(in.readObject());
}
in.readListEnd();
Object[] data = createArray(list.size());
for (int i = 0; i < data.length; i++)
data[i] = list.get(i);
return data;
}
}
/**
* Reads the array.
*/
public Object readLengthList(AbstractHessianInput in, int length)
throws IOException {
Object[] data = createArray(length);
in.addRef(data);
if (_componentType != null) {
for (int i = 0; i < data.length; i++)
data[i] = in.readObject(_componentType);
} else {
for (int i = 0; i < data.length; i++)
data[i] = in.readObject();
}
return data;
}
protected Object[] createArray(int length) {
if (_componentType != null)
return (Object[]) Array.newInstance(_componentType, length);
else
return new Object[length];
}
public String toString() {
return "ArrayDeserializer[" + _componentType + "]";
}
}

View File

@ -1,92 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
/**
* Serializing a Java array.
*/
public class ArraySerializer extends AbstractSerializer {
public void writeObject(Object obj, AbstractHessianOutput out)
throws IOException {
if (out.addRef(obj))
return;
Object[] array = (Object[]) obj;
boolean hasEnd = out.writeListBegin(array.length,
getArrayType(obj.getClass()));
for (int i = 0; i < array.length; i++)
out.writeObject(array[i]);
if (hasEnd)
out.writeListEnd();
}
/**
* Returns the &lt;type> name for a &lt;list>.
*/
private String getArrayType(Class cl) {
if (cl.isArray())
return '[' + getArrayType(cl.getComponentType());
String name = cl.getName();
if (name.equals("java.lang.String"))
return "string";
else if (name.equals("java.lang.Object"))
return "object";
else if (name.equals("java.util.Date"))
return "date";
else
return name;
}
}

View File

@ -1,603 +0,0 @@
/*
* Copyright (c) 2001-2008 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Burlap", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
/**
* Serializing an object for known object types.
*/
public class BasicDeserializer extends AbstractDeserializer {
public static final int NULL = BasicSerializer.NULL;
public static final int BOOLEAN = BasicSerializer.BOOLEAN;
public static final int BYTE = BasicSerializer.BYTE;
public static final int SHORT = BasicSerializer.SHORT;
public static final int INTEGER = BasicSerializer.INTEGER;
public static final int LONG = BasicSerializer.LONG;
public static final int FLOAT = BasicSerializer.FLOAT;
public static final int DOUBLE = BasicSerializer.DOUBLE;
public static final int CHARACTER = BasicSerializer.CHARACTER;
public static final int CHARACTER_OBJECT = BasicSerializer.CHARACTER_OBJECT;
public static final int STRING = BasicSerializer.STRING;
public static final int DATE = BasicSerializer.DATE;
public static final int NUMBER = BasicSerializer.NUMBER;
public static final int OBJECT = BasicSerializer.OBJECT;
public static final int BOOLEAN_ARRAY = BasicSerializer.BOOLEAN_ARRAY;
public static final int BYTE_ARRAY = BasicSerializer.BYTE_ARRAY;
public static final int SHORT_ARRAY = BasicSerializer.SHORT_ARRAY;
public static final int INTEGER_ARRAY = BasicSerializer.INTEGER_ARRAY;
public static final int LONG_ARRAY = BasicSerializer.LONG_ARRAY;
public static final int FLOAT_ARRAY = BasicSerializer.FLOAT_ARRAY;
public static final int DOUBLE_ARRAY = BasicSerializer.DOUBLE_ARRAY;
public static final int CHARACTER_ARRAY = BasicSerializer.CHARACTER_ARRAY;
public static final int STRING_ARRAY = BasicSerializer.STRING_ARRAY;
public static final int OBJECT_ARRAY = BasicSerializer.OBJECT_ARRAY;
private int _code;
public BasicDeserializer(int code) {
_code = code;
}
public Class getType() {
switch (_code) {
case NULL:
return void.class;
case BOOLEAN:
return Boolean.class;
case BYTE:
return Byte.class;
case SHORT:
return Short.class;
case INTEGER:
return Integer.class;
case LONG:
return Long.class;
case FLOAT:
return Float.class;
case DOUBLE:
return Double.class;
case CHARACTER:
return Character.class;
case CHARACTER_OBJECT:
return Character.class;
case STRING:
return String.class;
case DATE:
return Date.class;
case NUMBER:
return Number.class;
case OBJECT:
return Object.class;
case BOOLEAN_ARRAY:
return boolean[].class;
case BYTE_ARRAY:
return byte[].class;
case SHORT_ARRAY:
return short[].class;
case INTEGER_ARRAY:
return int[].class;
case LONG_ARRAY:
return long[].class;
case FLOAT_ARRAY:
return float[].class;
case DOUBLE_ARRAY:
return double[].class;
case CHARACTER_ARRAY:
return char[].class;
case STRING_ARRAY:
return String[].class;
case OBJECT_ARRAY:
return Object[].class;
default:
throw new UnsupportedOperationException();
}
}
public Object readObject(AbstractHessianInput in)
throws IOException {
switch (_code) {
case NULL:
// hessian/3490
in.readObject();
return null;
case BOOLEAN:
return Boolean.valueOf(in.readBoolean());
case BYTE:
return Byte.valueOf((byte) in.readInt());
case SHORT:
return Short.valueOf((short) in.readInt());
case INTEGER:
return Integer.valueOf(in.readInt());
case LONG:
return Long.valueOf(in.readLong());
case FLOAT:
return Float.valueOf((float) in.readDouble());
case DOUBLE:
return Double.valueOf(in.readDouble());
case STRING:
return in.readString();
case OBJECT:
return in.readObject();
case CHARACTER: {
String s = in.readString();
if (s == null || s.equals(""))
return Character.valueOf((char) 0);
else
return Character.valueOf(s.charAt(0));
}
case CHARACTER_OBJECT: {
String s = in.readString();
if (s == null || s.equals(""))
return null;
else
return Character.valueOf(s.charAt(0));
}
case DATE:
return new Date(in.readUTCDate());
case NUMBER:
return in.readObject();
case BYTE_ARRAY:
return in.readBytes();
case CHARACTER_ARRAY: {
String s = in.readString();
if (s == null)
return null;
else {
int len = s.length();
char[] chars = new char[len];
s.getChars(0, len, chars, 0);
return chars;
}
}
case BOOLEAN_ARRAY:
case SHORT_ARRAY:
case INTEGER_ARRAY:
case LONG_ARRAY:
case FLOAT_ARRAY:
case DOUBLE_ARRAY:
case STRING_ARRAY: {
int code = in.readListStart();
switch (code) {
case 'N':
return null;
case 0x10:
case 0x11:
case 0x12:
case 0x13:
case 0x14:
case 0x15:
case 0x16:
case 0x17:
case 0x18:
case 0x19:
case 0x1a:
case 0x1b:
case 0x1c:
case 0x1d:
case 0x1e:
case 0x1f:
int length = code - 0x10;
in.readInt();
return readLengthList(in, length);
default:
String type = in.readType();
length = in.readLength();
return readList(in, length);
}
}
default:
throw new UnsupportedOperationException();
}
}
public Object readList(AbstractHessianInput in, int length)
throws IOException {
switch (_code) {
case BOOLEAN_ARRAY: {
if (length >= 0) {
boolean[] data = new boolean[length];
in.addRef(data);
for (int i = 0; i < data.length; i++)
data[i] = in.readBoolean();
in.readEnd();
return data;
} else {
ArrayList list = new ArrayList();
while (!in.isEnd())
list.add(Boolean.valueOf(in.readBoolean()));
in.readEnd();
boolean[] data = new boolean[list.size()];
in.addRef(data);
for (int i = 0; i < data.length; i++)
data[i] = ((Boolean) list.get(i)).booleanValue();
return data;
}
}
case SHORT_ARRAY: {
if (length >= 0) {
short[] data = new short[length];
in.addRef(data);
for (int i = 0; i < data.length; i++)
data[i] = (short) in.readInt();
in.readEnd();
return data;
} else {
ArrayList list = new ArrayList();
while (!in.isEnd())
list.add(Short.valueOf((short) in.readInt()));
in.readEnd();
short[] data = new short[list.size()];
for (int i = 0; i < data.length; i++)
data[i] = ((Short) list.get(i)).shortValue();
in.addRef(data);
return data;
}
}
case INTEGER_ARRAY: {
if (length >= 0) {
int[] data = new int[length];
in.addRef(data);
for (int i = 0; i < data.length; i++)
data[i] = in.readInt();
in.readEnd();
return data;
} else {
ArrayList list = new ArrayList();
while (!in.isEnd())
list.add(Integer.valueOf(in.readInt()));
in.readEnd();
int[] data = new int[list.size()];
for (int i = 0; i < data.length; i++)
data[i] = ((Integer) list.get(i)).intValue();
in.addRef(data);
return data;
}
}
case LONG_ARRAY: {
if (length >= 0) {
long[] data = new long[length];
in.addRef(data);
for (int i = 0; i < data.length; i++)
data[i] = in.readLong();
in.readEnd();
return data;
} else {
ArrayList list = new ArrayList();
while (!in.isEnd())
list.add(Long.valueOf(in.readLong()));
in.readEnd();
long[] data = new long[list.size()];
for (int i = 0; i < data.length; i++)
data[i] = ((Long) list.get(i)).longValue();
in.addRef(data);
return data;
}
}
case FLOAT_ARRAY: {
if (length >= 0) {
float[] data = new float[length];
in.addRef(data);
for (int i = 0; i < data.length; i++)
data[i] = (float) in.readDouble();
in.readEnd();
return data;
} else {
ArrayList list = new ArrayList();
while (!in.isEnd())
list.add(new Float(in.readDouble()));
in.readEnd();
float[] data = new float[list.size()];
for (int i = 0; i < data.length; i++)
data[i] = ((Float) list.get(i)).floatValue();
in.addRef(data);
return data;
}
}
case DOUBLE_ARRAY: {
if (length >= 0) {
double[] data = new double[length];
in.addRef(data);
for (int i = 0; i < data.length; i++)
data[i] = in.readDouble();
in.readEnd();
return data;
} else {
ArrayList list = new ArrayList();
while (!in.isEnd())
list.add(new Double(in.readDouble()));
in.readEnd();
double[] data = new double[list.size()];
in.addRef(data);
for (int i = 0; i < data.length; i++)
data[i] = ((Double) list.get(i)).doubleValue();
return data;
}
}
case STRING_ARRAY: {
if (length >= 0) {
String[] data = new String[length];
in.addRef(data);
for (int i = 0; i < data.length; i++)
data[i] = in.readString();
in.readEnd();
return data;
} else {
ArrayList list = new ArrayList();
while (!in.isEnd())
list.add(in.readString());
in.readEnd();
String[] data = new String[list.size()];
in.addRef(data);
for (int i = 0; i < data.length; i++)
data[i] = (String) list.get(i);
return data;
}
}
case OBJECT_ARRAY: {
if (length >= 0) {
Object[] data = new Object[length];
in.addRef(data);
for (int i = 0; i < data.length; i++)
data[i] = in.readObject();
in.readEnd();
return data;
} else {
ArrayList list = new ArrayList();
in.addRef(list); // XXX: potential issues here
while (!in.isEnd())
list.add(in.readObject());
in.readEnd();
Object[] data = new Object[list.size()];
for (int i = 0; i < data.length; i++)
data[i] = (Object) list.get(i);
return data;
}
}
default:
throw new UnsupportedOperationException(String.valueOf(this));
}
}
public Object readLengthList(AbstractHessianInput in, int length)
throws IOException {
switch (_code) {
case BOOLEAN_ARRAY: {
boolean[] data = new boolean[length];
in.addRef(data);
for (int i = 0; i < data.length; i++)
data[i] = in.readBoolean();
return data;
}
case SHORT_ARRAY: {
short[] data = new short[length];
in.addRef(data);
for (int i = 0; i < data.length; i++)
data[i] = (short) in.readInt();
return data;
}
case INTEGER_ARRAY: {
int[] data = new int[length];
in.addRef(data);
for (int i = 0; i < data.length; i++)
data[i] = in.readInt();
return data;
}
case LONG_ARRAY: {
long[] data = new long[length];
in.addRef(data);
for (int i = 0; i < data.length; i++)
data[i] = in.readLong();
return data;
}
case FLOAT_ARRAY: {
float[] data = new float[length];
in.addRef(data);
for (int i = 0; i < data.length; i++)
data[i] = (float) in.readDouble();
return data;
}
case DOUBLE_ARRAY: {
double[] data = new double[length];
in.addRef(data);
for (int i = 0; i < data.length; i++)
data[i] = in.readDouble();
return data;
}
case STRING_ARRAY: {
String[] data = new String[length];
in.addRef(data);
for (int i = 0; i < data.length; i++)
data[i] = in.readString();
return data;
}
case OBJECT_ARRAY: {
Object[] data = new Object[length];
in.addRef(data);
for (int i = 0; i < data.length; i++)
data[i] = in.readObject();
return data;
}
default:
throw new UnsupportedOperationException(String.valueOf(this));
}
}
}

View File

@ -1,273 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Burlap", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.util.Date;
/**
* Serializing an object for known object types.
*/
public class BasicSerializer extends AbstractSerializer {
public static final int NULL = 0;
public static final int BOOLEAN = NULL + 1;
public static final int BYTE = BOOLEAN + 1;
public static final int SHORT = BYTE + 1;
public static final int INTEGER = SHORT + 1;
public static final int LONG = INTEGER + 1;
public static final int FLOAT = LONG + 1;
public static final int DOUBLE = FLOAT + 1;
public static final int CHARACTER = DOUBLE + 1;
public static final int CHARACTER_OBJECT = CHARACTER + 1;
public static final int STRING = CHARACTER_OBJECT + 1;
public static final int DATE = STRING + 1;
public static final int NUMBER = DATE + 1;
public static final int OBJECT = NUMBER + 1;
public static final int BOOLEAN_ARRAY = OBJECT + 1;
public static final int BYTE_ARRAY = BOOLEAN_ARRAY + 1;
public static final int SHORT_ARRAY = BYTE_ARRAY + 1;
public static final int INTEGER_ARRAY = SHORT_ARRAY + 1;
public static final int LONG_ARRAY = INTEGER_ARRAY + 1;
public static final int FLOAT_ARRAY = LONG_ARRAY + 1;
public static final int DOUBLE_ARRAY = FLOAT_ARRAY + 1;
public static final int CHARACTER_ARRAY = DOUBLE_ARRAY + 1;
public static final int STRING_ARRAY = CHARACTER_ARRAY + 1;
public static final int OBJECT_ARRAY = STRING_ARRAY + 1;
private int code;
public BasicSerializer(int code) {
this.code = code;
}
public void writeObject(Object obj, AbstractHessianOutput out)
throws IOException {
switch (code) {
case BOOLEAN:
out.writeBoolean(((Boolean) obj).booleanValue());
break;
case BYTE:
case SHORT:
case INTEGER:
out.writeInt(((Number) obj).intValue());
break;
case LONG:
out.writeLong(((Number) obj).longValue());
break;
case FLOAT:
case DOUBLE:
out.writeDouble(((Number) obj).doubleValue());
break;
case CHARACTER:
case CHARACTER_OBJECT:
out.writeString(String.valueOf(obj));
break;
case STRING:
out.writeString((String) obj);
break;
case DATE:
out.writeUTCDate(((Date) obj).getTime());
break;
case BOOLEAN_ARRAY: {
if (out.addRef(obj))
return;
boolean[] data = (boolean[]) obj;
boolean hasEnd = out.writeListBegin(data.length, "[boolean");
for (int i = 0; i < data.length; i++)
out.writeBoolean(data[i]);
if (hasEnd)
out.writeListEnd();
break;
}
case BYTE_ARRAY: {
byte[] data = (byte[]) obj;
out.writeBytes(data, 0, data.length);
break;
}
case SHORT_ARRAY: {
if (out.addRef(obj))
return;
short[] data = (short[]) obj;
boolean hasEnd = out.writeListBegin(data.length, "[short");
for (int i = 0; i < data.length; i++)
out.writeInt(data[i]);
if (hasEnd)
out.writeListEnd();
break;
}
case INTEGER_ARRAY: {
if (out.addRef(obj))
return;
int[] data = (int[]) obj;
boolean hasEnd = out.writeListBegin(data.length, "[int");
for (int i = 0; i < data.length; i++)
out.writeInt(data[i]);
if (hasEnd)
out.writeListEnd();
break;
}
case LONG_ARRAY: {
if (out.addRef(obj))
return;
long[] data = (long[]) obj;
boolean hasEnd = out.writeListBegin(data.length, "[long");
for (int i = 0; i < data.length; i++)
out.writeLong(data[i]);
if (hasEnd)
out.writeListEnd();
break;
}
case FLOAT_ARRAY: {
if (out.addRef(obj))
return;
float[] data = (float[]) obj;
boolean hasEnd = out.writeListBegin(data.length, "[float");
for (int i = 0; i < data.length; i++)
out.writeDouble(data[i]);
if (hasEnd)
out.writeListEnd();
break;
}
case DOUBLE_ARRAY: {
if (out.addRef(obj))
return;
double[] data = (double[]) obj;
boolean hasEnd = out.writeListBegin(data.length, "[double");
for (int i = 0; i < data.length; i++)
out.writeDouble(data[i]);
if (hasEnd)
out.writeListEnd();
break;
}
case STRING_ARRAY: {
if (out.addRef(obj))
return;
String[] data = (String[]) obj;
boolean hasEnd = out.writeListBegin(data.length, "[string");
for (int i = 0; i < data.length; i++) {
out.writeString(data[i]);
}
if (hasEnd)
out.writeListEnd();
break;
}
case CHARACTER_ARRAY: {
char[] data = (char[]) obj;
out.writeString(data, 0, data.length);
break;
}
case OBJECT_ARRAY: {
if (out.addRef(obj))
return;
Object[] data = (Object[]) obj;
boolean hasEnd = out.writeListBegin(data.length, "[object");
for (int i = 0; i < data.length; i++) {
out.writeObject(data[i]);
}
if (hasEnd)
out.writeListEnd();
break;
}
case NULL:
out.writeNull();
break;
default:
throw new RuntimeException(code + " " + String.valueOf(obj.getClass()));
}
}
}

View File

@ -1,284 +0,0 @@
/*
* Copyright (c) 2001-2008 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Burlap", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.HashMap;
/**
* Serializing an object for known object types.
*/
public class BeanDeserializer extends AbstractMapDeserializer {
private Class _type;
private HashMap _methodMap;
private Method _readResolve;
private Constructor _constructor;
private Object[] _constructorArgs;
public BeanDeserializer(Class cl) {
_type = cl;
_methodMap = getMethodMap(cl);
_readResolve = getReadResolve(cl);
Constructor[] constructors = cl.getConstructors();
int bestLength = Integer.MAX_VALUE;
for (int i = 0; i < constructors.length; i++) {
if (constructors[i].getParameterTypes().length < bestLength) {
_constructor = constructors[i];
bestLength = _constructor.getParameterTypes().length;
}
}
if (_constructor != null) {
_constructor.setAccessible(true);
Class[] params = _constructor.getParameterTypes();
_constructorArgs = new Object[params.length];
for (int i = 0; i < params.length; i++) {
_constructorArgs[i] = getParamArg(params[i]);
}
}
}
/**
* Creates a map of the classes fields.
*/
protected static Object getParamArg(Class cl) {
if (!cl.isPrimitive())
return null;
else if (boolean.class.equals(cl))
return Boolean.FALSE;
else if (byte.class.equals(cl))
return Byte.valueOf((byte) 0);
else if (short.class.equals(cl))
return Short.valueOf((short) 0);
else if (char.class.equals(cl))
return Character.valueOf((char) 0);
else if (int.class.equals(cl))
return Integer.valueOf(0);
else if (long.class.equals(cl))
return Long.valueOf(0);
else if (float.class.equals(cl))
return Double.valueOf(0);
else if (double.class.equals(cl))
return Double.valueOf(0);
else
throw new UnsupportedOperationException();
}
public Class getType() {
return _type;
}
public Object readMap(AbstractHessianInput in)
throws IOException {
try {
Object obj = instantiate();
return readMap(in, obj);
} catch (IOException e) {
throw e;
} catch (Exception e) {
throw new IOExceptionWrapper(e);
}
}
public Object readMap(AbstractHessianInput in, Object obj)
throws IOException {
try {
int ref = in.addRef(obj);
while (!in.isEnd()) {
Object key = in.readObject();
Method method = (Method) _methodMap.get(key);
if (method != null) {
Object value = in.readObject(method.getParameterTypes()[0]);
method.invoke(obj, new Object[]{value});
} else {
Object value = in.readObject();
}
}
in.readMapEnd();
Object resolve = resolve(obj);
if (obj != resolve)
in.setRef(ref, resolve);
return resolve;
} catch (IOException e) {
throw e;
} catch (Exception e) {
throw new IOExceptionWrapper(e);
}
}
private Object resolve(Object obj) {
// if there's a readResolve method, call it
try {
if (_readResolve != null)
return _readResolve.invoke(obj, new Object[0]);
} catch (Exception e) {
}
return obj;
}
protected Object instantiate()
throws Exception {
return _constructor.newInstance(_constructorArgs);
}
/**
* Returns the readResolve method
*/
protected Method getReadResolve(Class cl) {
for (; cl != null; cl = cl.getSuperclass()) {
Method[] methods = cl.getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
if (method.getName().equals("readResolve") &&
method.getParameterTypes().length == 0)
return method;
}
}
return null;
}
/**
* Creates a map of the classes fields.
*/
protected HashMap getMethodMap(Class cl) {
HashMap methodMap = new HashMap();
for (; cl != null; cl = cl.getSuperclass()) {
Method[] methods = cl.getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
if (Modifier.isStatic(method.getModifiers()))
continue;
String name = method.getName();
if (!name.startsWith("set"))
continue;
Class[] paramTypes = method.getParameterTypes();
if (paramTypes.length != 1)
continue;
if (!method.getReturnType().equals(void.class))
continue;
if (findGetter(methods, name, paramTypes[0]) == null)
continue;
// XXX: could parameterize the handler to only deal with public
try {
method.setAccessible(true);
} catch (Throwable e) {
e.printStackTrace();
}
name = name.substring(3);
int j = 0;
for (; j < name.length() && Character.isUpperCase(name.charAt(j)); j++) {
}
if (j == 1)
name = name.substring(0, j).toLowerCase() + name.substring(j);
else if (j > 1)
name = name.substring(0, j - 1).toLowerCase() + name.substring(j - 1);
methodMap.put(name, method);
}
}
return methodMap;
}
/**
* Finds any matching setter.
*/
private Method findGetter(Method[] methods, String setterName, Class arg) {
String getterName = "get" + setterName.substring(3);
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
if (!method.getName().equals(getterName))
continue;
if (!method.getReturnType().equals(arg))
continue;
Class[] params = method.getParameterTypes();
if (params.length == 0)
return method;
}
return null;
}
}

View File

@ -1,308 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Burlap", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Serializing an object for known object types.
*/
public class BeanSerializer extends AbstractSerializer {
private static final Logger log
= Logger.getLogger(BeanSerializer.class.getName());
private static final Object[] NULL_ARGS = new Object[0];
private Method[] _methods;
private String[] _names;
private Object _writeReplaceFactory;
private Method _writeReplace;
public BeanSerializer(Class cl, ClassLoader loader) {
introspectWriteReplace(cl, loader);
ArrayList primitiveMethods = new ArrayList();
ArrayList compoundMethods = new ArrayList();
for (; cl != null; cl = cl.getSuperclass()) {
Method[] methods = cl.getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
if (Modifier.isStatic(method.getModifiers()))
continue;
if (method.getParameterTypes().length != 0)
continue;
String name = method.getName();
if (!name.startsWith("get"))
continue;
Class type = method.getReturnType();
if (type.equals(void.class))
continue;
if (findSetter(methods, name, type) == null)
continue;
// XXX: could parameterize the handler to only deal with public
method.setAccessible(true);
if (type.isPrimitive()
|| type.getName().startsWith("java.lang.")
&& !type.equals(Object.class))
primitiveMethods.add(method);
else
compoundMethods.add(method);
}
}
ArrayList methodList = new ArrayList();
methodList.addAll(primitiveMethods);
methodList.addAll(compoundMethods);
Collections.sort(methodList, new MethodNameCmp());
_methods = new Method[methodList.size()];
methodList.toArray(_methods);
_names = new String[_methods.length];
for (int i = 0; i < _methods.length; i++) {
String name = _methods[i].getName();
name = name.substring(3);
int j = 0;
for (; j < name.length() && Character.isUpperCase(name.charAt(j)); j++) {
}
if (j == 1)
name = name.substring(0, j).toLowerCase() + name.substring(j);
else if (j > 1)
name = name.substring(0, j - 1).toLowerCase() + name.substring(j - 1);
_names[i] = name;
}
}
private void introspectWriteReplace(Class cl, ClassLoader loader) {
try {
String className = cl.getName() + "HessianSerializer";
Class serializerClass = Class.forName(className, false, loader);
Object serializerObject = serializerClass.newInstance();
Method writeReplace = getWriteReplace(serializerClass, cl);
if (writeReplace != null) {
_writeReplaceFactory = serializerObject;
_writeReplace = writeReplace;
return;
}
} catch (ClassNotFoundException e) {
} catch (Exception e) {
log.log(Level.FINER, e.toString(), e);
}
_writeReplace = getWriteReplace(cl);
}
/**
* Returns the writeReplace method
*/
protected Method getWriteReplace(Class cl) {
for (; cl != null; cl = cl.getSuperclass()) {
Method[] methods = cl.getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
if (method.getName().equals("writeReplace") &&
method.getParameterTypes().length == 0)
return method;
}
}
return null;
}
/**
* Returns the writeReplace method
*/
protected Method getWriteReplace(Class cl, Class param) {
for (; cl != null; cl = cl.getSuperclass()) {
for (Method method : cl.getDeclaredMethods()) {
if (method.getName().equals("writeReplace")
&& method.getParameterTypes().length == 1
&& param.equals(method.getParameterTypes()[0]))
return method;
}
}
return null;
}
public void writeObject(Object obj, AbstractHessianOutput out)
throws IOException {
if (out.addRef(obj))
return;
Class cl = obj.getClass();
try {
if (_writeReplace != null) {
Object repl;
if (_writeReplaceFactory != null)
repl = _writeReplace.invoke(_writeReplaceFactory, obj);
else
repl = _writeReplace.invoke(obj);
out.removeRef(obj);
out.writeObject(repl);
out.replaceRef(repl, obj);
return;
}
} catch (Exception e) {
log.log(Level.FINER, e.toString(), e);
}
int ref = out.writeObjectBegin(cl.getName());
if (ref < -1) {
// Hessian 1.1 uses a map
for (int i = 0; i < _methods.length; i++) {
Method method = _methods[i];
Object value = null;
try {
value = _methods[i].invoke(obj, (Object[]) null);
} catch (Exception e) {
log.log(Level.FINE, e.toString(), e);
}
out.writeString(_names[i]);
out.writeObject(value);
}
out.writeMapEnd();
} else {
if (ref == -1) {
out.writeInt(_names.length);
for (int i = 0; i < _names.length; i++)
out.writeString(_names[i]);
out.writeObjectBegin(cl.getName());
}
for (int i = 0; i < _methods.length; i++) {
Method method = _methods[i];
Object value = null;
try {
value = _methods[i].invoke(obj, (Object[]) null);
} catch (Exception e) {
log.log(Level.FINER, e.toString(), e);
}
out.writeObject(value);
}
}
}
/**
* Finds any matching setter.
*/
private Method findSetter(Method[] methods, String getterName, Class arg) {
String setterName = "set" + getterName.substring(3);
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
if (!method.getName().equals(setterName))
continue;
if (!method.getReturnType().equals(void.class))
continue;
Class[] params = method.getParameterTypes();
if (params.length == 1 && params[0].equals(arg))
return method;
}
return null;
}
static class MethodNameCmp implements Comparator<Method> {
public int compare(Method a, Method b) {
return a.getName().compareTo(b.getName());
}
}
}

View File

@ -1,78 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Burlap", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
/**
* Factory for returning serialization methods.
*/
public class BeanSerializerFactory extends SerializerFactory {
/**
* Returns the default serializer for a class that isn't matched
* directly. Application can override this method to produce
* bean-style serialization instead of field serialization.
*
* @param cl the class of the object that needs to be serialized.
* @return a serializer object for the serialization.
*/
protected Serializer getDefaultSerializer(Class cl) {
return new BeanSerializer(cl, getClassLoader());
}
/**
* Returns the default deserializer for a class that isn't matched
* directly. Application can override this method to produce
* bean-style serialization instead of field serialization.
*
* @param cl the class of the object that needs to be serialized.
* @return a serializer object for the serialization.
*/
protected Deserializer getDefaultDeserializer(Class cl) {
return new BeanDeserializer(cl);
}
}

View File

@ -1,32 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.com.caucho.hessian.io;
import java.math.BigInteger;
public class BigIntegerDeserializer extends JavaDeserializer {
public BigIntegerDeserializer() {
super(BigInteger.class);
}
@Override
protected Object instantiate() throws Exception {
return new BigInteger("0");
}
}

View File

@ -1,90 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
/**
* Handle for a calendar object.
*/
public class CalendarHandle implements java.io.Serializable, HessianHandle {
private Class type;
private Date date;
public CalendarHandle() {
}
public CalendarHandle(Class type, long time) {
if (!GregorianCalendar.class.equals(type))
this.type = type;
this.date = new Date(time);
}
private Object readResolve() {
try {
Calendar cal;
if (this.type != null)
cal = (Calendar) this.type.newInstance();
else
cal = new GregorianCalendar();
cal.setTimeInMillis(this.date.getTime());
return cal;
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

View File

@ -1,75 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.util.Calendar;
/**
* Serializing a calendar.
*/
public class CalendarSerializer extends AbstractSerializer {
private static CalendarSerializer SERIALIZER = new CalendarSerializer();
public static CalendarSerializer create() {
return SERIALIZER;
}
public void writeObject(Object obj, AbstractHessianOutput out)
throws IOException {
if (obj == null)
out.writeNull();
else {
Calendar cal = (Calendar) obj;
out.writeObject(new CalendarHandle(cal.getClass(),
cal.getTimeInMillis()));
}
}
}

View File

@ -1,155 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.util.HashMap;
/**
* Deserializing a JDK 1.2 Class.
*/
public class ClassDeserializer extends AbstractMapDeserializer {
private static final HashMap<String, Class> _primClasses
= new HashMap<String, Class>();
static {
_primClasses.put("void", void.class);
_primClasses.put("boolean", boolean.class);
_primClasses.put("java.lang.Boolean", Boolean.class);
_primClasses.put("byte", byte.class);
_primClasses.put("java.lang.Byte", Byte.class);
_primClasses.put("char", char.class);
_primClasses.put("java.lang.Character", Character.class);
_primClasses.put("short", short.class);
_primClasses.put("java.lang.Short", Short.class);
_primClasses.put("int", int.class);
_primClasses.put("java.lang.Integer", Integer.class);
_primClasses.put("long", long.class);
_primClasses.put("java.lang.Long", Long.class);
_primClasses.put("float", float.class);
_primClasses.put("java.lang.Float", Float.class);
_primClasses.put("double", double.class);
_primClasses.put("java.lang.Double", Double.class);
_primClasses.put("java.lang.String", String.class);
}
private ClassLoader _loader;
public ClassDeserializer(ClassLoader loader) {
_loader = loader;
}
public Class getType() {
return Class.class;
}
public Object readMap(AbstractHessianInput in)
throws IOException {
int ref = in.addRef(null);
String name = null;
while (!in.isEnd()) {
String key = in.readString();
if (key.equals("name"))
name = in.readString();
else
in.readObject();
}
in.readMapEnd();
Object value = create(name);
in.setRef(ref, value);
return value;
}
public Object readObject(AbstractHessianInput in, String[] fieldNames)
throws IOException {
int ref = in.addRef(null);
String name = null;
for (int i = 0; i < fieldNames.length; i++) {
if ("name".equals(fieldNames[i]))
name = in.readString();
else
in.readObject();
}
Object value = create(name);
in.setRef(ref, value);
return value;
}
Object create(String name)
throws IOException {
if (name == null)
throw new IOException("Serialized Class expects name.");
Class cl = _primClasses.get(name);
if (cl != null)
return cl;
try {
if (_loader != null)
return Class.forName(name, false, _loader);
else
return Class.forName(name);
} catch (Exception e) {
throw new IOExceptionWrapper(e);
}
}
}

View File

@ -1,83 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
/**
* Serializing a remote object.
*/
public class ClassSerializer extends AbstractSerializer {
public void writeObject(Object obj, AbstractHessianOutput out)
throws IOException {
Class cl = (Class) obj;
if (cl == null) {
out.writeNull();
} else if (out.addRef(obj)) {
return;
} else {
int ref = out.writeObjectBegin("java.lang.Class");
if (ref < -1) {
out.writeString("name");
out.writeString(cl.getName());
out.writeMapEnd();
} else {
if (ref == -1) {
out.writeInt(1);
out.writeString("name");
out.writeObjectBegin("java.lang.Class");
}
out.writeString(cl.getName());
}
}
}
}

View File

@ -1,158 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
/**
* Deserializing a JDK 1.2 Collection.
*/
public class CollectionDeserializer extends AbstractListDeserializer {
private Class _type;
public CollectionDeserializer(Class type) {
_type = type;
}
public Class getType() {
return _type;
}
public Object readList(AbstractHessianInput in, int length)
throws IOException {
return readList(in, length, null);
}
@Override
public Object readList(AbstractHessianInput in, int length, Class<?> expectType) throws IOException {
Collection list = createList();
in.addRef(list);
Deserializer deserializer = null;
SerializerFactory factory = findSerializerFactory(in);
if(expectType != null){
deserializer = factory.getDeserializer(expectType.getName());
}
while (!in.isEnd())
list.add(deserializer != null ? deserializer.readObject(in) : in.readObject());
in.readEnd();
return list;
}
public Object readLengthList(AbstractHessianInput in, int length)
throws IOException {
return readList(in, length, null);
}
@Override
public Object readLengthList(AbstractHessianInput in, int length, Class<?> expectType) throws IOException {
Collection list = createList();
in.addRef(list);
Deserializer deserializer = null;
SerializerFactory factory = findSerializerFactory(in);
if(expectType != null){
deserializer = factory.getDeserializer(expectType.getName());
}
for (; length > 0; length--)
list.add(deserializer != null ? deserializer.readObject(in) : in.readObject());
return list;
}
private Collection createList()
throws IOException {
Collection list = null;
if (_type == null)
list = new ArrayList();
else if (!_type.isInterface()) {
try {
list = (Collection) _type.newInstance();
} catch (Exception e) {
}
}
if (list != null) {
} else if (SortedSet.class.isAssignableFrom(_type))
list = new TreeSet();
else if (Set.class.isAssignableFrom(_type))
list = new HashSet();
else if (List.class.isAssignableFrom(_type))
list = new ArrayList();
else if (Collection.class.isAssignableFrom(_type))
list = new ArrayList();
else {
try {
list = (Collection) _type.newInstance();
} catch (Exception e) {
throw new IOExceptionWrapper(e);
}
}
return list;
}
}

View File

@ -1,104 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
/**
* Serializing a JDK 1.2 Collection.
*/
public class CollectionSerializer extends AbstractSerializer {
private boolean _sendJavaType = true;
/**
* Return true if the java type of the collection should be sent.
*/
public boolean getSendJavaType() {
return _sendJavaType;
}
/**
* Set true if the java type of the collection should be sent.
*/
public void setSendJavaType(boolean sendJavaType) {
_sendJavaType = sendJavaType;
}
public void writeObject(Object obj, AbstractHessianOutput out)
throws IOException {
if (out.addRef(obj))
return;
Collection list = (Collection) obj;
Class cl = obj.getClass();
boolean hasEnd;
if (cl.equals(ArrayList.class)
|| !_sendJavaType
|| !Serializable.class.isAssignableFrom(cl))
hasEnd = out.writeListBegin(list.size(), null);
else
hasEnd = out.writeListBegin(list.size(), obj.getClass().getName());
Iterator iter = list.iterator();
while (iter.hasNext()) {
Object value = iter.next();
out.writeObject(value);
}
if (hasEnd)
out.writeListEnd();
}
}

View File

@ -1,192 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.InflaterInputStream;
public class Deflation extends HessianEnvelope {
public Deflation() {
}
public Hessian2Output wrap(Hessian2Output out)
throws IOException {
OutputStream os = new DeflateOutputStream(out);
Hessian2Output filterOut = new Hessian2Output(os);
filterOut.setCloseStreamOnClose(true);
return filterOut;
}
public Hessian2Input unwrap(Hessian2Input in)
throws IOException {
int version = in.readEnvelope();
String method = in.readMethod();
if (!method.equals(getClass().getName()))
throw new IOException("expected hessian Envelope method '" +
getClass().getName() + "' at '" + method + "'");
return unwrapHeaders(in);
}
public Hessian2Input unwrapHeaders(Hessian2Input in)
throws IOException {
InputStream is = new DeflateInputStream(in);
Hessian2Input filter = new Hessian2Input(is);
filter.setCloseStreamOnClose(true);
return filter;
}
static class DeflateOutputStream extends OutputStream {
private Hessian2Output _out;
private OutputStream _bodyOut;
private DeflaterOutputStream _deflateOut;
DeflateOutputStream(Hessian2Output out)
throws IOException {
_out = out;
_out.startEnvelope(Deflation.class.getName());
_out.writeInt(0);
_bodyOut = _out.getBytesOutputStream();
_deflateOut = new DeflaterOutputStream(_bodyOut);
}
public void write(int ch)
throws IOException {
_deflateOut.write(ch);
}
public void write(byte[] buffer, int offset, int length)
throws IOException {
_deflateOut.write(buffer, offset, length);
}
public void close()
throws IOException {
Hessian2Output out = _out;
_out = null;
if (out != null) {
_deflateOut.close();
_bodyOut.close();
out.writeInt(0);
out.completeEnvelope();
out.close();
}
}
}
static class DeflateInputStream extends InputStream {
private Hessian2Input _in;
private InputStream _bodyIn;
private InflaterInputStream _inflateIn;
DeflateInputStream(Hessian2Input in)
throws IOException {
_in = in;
int len = in.readInt();
if (len != 0)
throw new IOException("expected no headers");
_bodyIn = _in.readInputStream();
_inflateIn = new InflaterInputStream(_bodyIn);
}
public int read()
throws IOException {
return _inflateIn.read();
}
public int read(byte[] buffer, int offset, int length)
throws IOException {
return _inflateIn.read(buffer, offset, length);
}
public void close()
throws IOException {
Hessian2Input in = _in;
_in = null;
if (in != null) {
_inflateIn.close();
_bodyIn.close();
int len = in.readInt();
if (len != 0)
throw new IOException("Unexpected footer");
in.completeEnvelope();
in.close();
}
}
}
}

View File

@ -1,111 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Burlap", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
/**
* Deserializing an object.
*
*/
public interface Deserializer {
public Class getType();
public Object readObject(AbstractHessianInput in)
throws IOException;
public Object readList(AbstractHessianInput in, int length)
throws IOException;
/**
*
* deserialize list object from expect type.
*
* @param in
* @param length
* @param expectType
* @return
* @throws IOException
*/
public Object readList(AbstractHessianInput in, int length, Class<?> expectType)
throws IOException;
public Object readLengthList(AbstractHessianInput in, int length)
throws IOException;
/**
*
* deserialize list object from expect type.
*
* @param in
* @param length
* @param expectType
* @return
* @throws IOException
*/
public Object readLengthList(AbstractHessianInput in, int length, Class<?> expectType)
throws IOException;
public Object readMap(AbstractHessianInput in)
throws IOException;
/**
* deserialize map object from expect key and value type.
* @param in
* @param expectKeyType
* @param expectValueType
* @return
* @throws IOException
*/
public Object readMap(AbstractHessianInput in, Class<?> expectKeyType, Class<?> expectValueType )
throws IOException;
public Object readObject(AbstractHessianInput in, String[] fieldNames)
throws IOException;
}

View File

@ -1,133 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.lang.reflect.Method;
/**
* Deserializing an enum valued object
*/
public class EnumDeserializer extends AbstractDeserializer {
private Class _enumType;
private Method _valueOf;
public EnumDeserializer(Class cl) {
// hessian/33b[34], hessian/3bb[78]
if (cl.isEnum())
_enumType = cl;
else if (cl.getSuperclass().isEnum())
_enumType = cl.getSuperclass();
else
throw new RuntimeException("Class " + cl.getName() + " is not an enum");
try {
_valueOf = _enumType.getMethod("valueOf",
new Class[]{Class.class, String.class});
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public Class getType() {
return _enumType;
}
public Object readMap(AbstractHessianInput in)
throws IOException {
String name = null;
while (!in.isEnd()) {
String key = in.readString();
if (key.equals("name"))
name = in.readString();
else
in.readObject();
}
in.readMapEnd();
Object obj = create(name);
in.addRef(obj);
return obj;
}
public Object readObject(AbstractHessianInput in, String[] fieldNames)
throws IOException {
String name = null;
for (int i = 0; i < fieldNames.length; i++) {
if ("name".equals(fieldNames[i]))
name = in.readString();
else
in.readObject();
}
Object obj = create(name);
in.addRef(obj);
return obj;
}
private Object create(String name)
throws IOException {
if (name == null)
throw new IOException(_enumType.getName() + " expects name.");
try {
return _valueOf.invoke(null, _enumType, name);
} catch (Exception e) {
throw new IOExceptionWrapper(e);
}
}
}

View File

@ -1,105 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Burlap", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.lang.reflect.Method;
/**
* Serializing an object for known object types.
*/
public class EnumSerializer extends AbstractSerializer {
private Method _name;
public EnumSerializer(Class cl) {
// hessian/32b[12], hessian/3ab[23]
if (!cl.isEnum() && cl.getSuperclass().isEnum())
cl = cl.getSuperclass();
try {
_name = cl.getMethod("name", new Class[0]);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public void writeObject(Object obj, AbstractHessianOutput out)
throws IOException {
if (out.addRef(obj))
return;
Class cl = obj.getClass();
if (!cl.isEnum() && cl.getSuperclass().isEnum())
cl = cl.getSuperclass();
String name = null;
try {
name = (String) _name.invoke(obj, (Object[]) null);
} catch (Exception e) {
throw new RuntimeException(e);
}
int ref = out.writeObjectBegin(cl.getName());
if (ref < -1) {
out.writeString("name");
out.writeString(name);
out.writeMapEnd();
} else {
if (ref == -1) {
out.writeClassFieldLength(1);
out.writeString("name");
out.writeObjectBegin(cl.getName());
}
out.writeString(name);
}
}
}

View File

@ -1,39 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.Serializable;
import java.util.Arrays;
import java.util.EnumSet;
class EnumSetHandler implements Serializable, HessianHandle {
private Class type;
private Object[] objects;
EnumSetHandler(Class type, Object[] objects) {
this.type = type;
this.objects = objects;
}
@SuppressWarnings("unchecked")
private Object readResolve() {
EnumSet enumSet = EnumSet.noneOf(type);
enumSet.addAll(Arrays.asList(objects));
return enumSet;
}
}

View File

@ -1,48 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.EnumSet;
public class EnumSetSerializer extends AbstractSerializer {
private static EnumSetSerializer SERIALIZER = new EnumSetSerializer();
public static EnumSetSerializer getInstance() {
return SERIALIZER;
}
@Override
public void writeObject(Object obj, AbstractHessianOutput out) throws IOException {
if (obj == null) {
out.writeNull();
} else {
try {
Field field = EnumSet.class.getDeclaredField("elementType");
field.setAccessible(true);
Class type = (Class) field.get(obj);
EnumSet enumSet = (EnumSet) obj;
Object[] objects = enumSet.toArray();
out.writeObject(new EnumSetHandler(type, objects));
} catch (Throwable t) {
throw new IOException(t);
}
}
}
}

View File

@ -1,82 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.util.Vector;
/**
* Deserializing a JDK 1.2 Collection.
*/
public class EnumerationDeserializer extends AbstractListDeserializer {
private static EnumerationDeserializer _deserializer;
public static EnumerationDeserializer create() {
if (_deserializer == null)
_deserializer = new EnumerationDeserializer();
return _deserializer;
}
public Object readList(AbstractHessianInput in, int length)
throws IOException {
Vector list = new Vector();
in.addRef(list);
while (!in.isEnd())
list.add(in.readObject());
in.readEnd();
return list.elements();
}
}

View File

@ -1,82 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.util.Enumeration;
/**
* Serializing a JDK 1.2 Enumeration.
*/
public class EnumerationSerializer extends AbstractSerializer {
private static EnumerationSerializer _serializer;
public static EnumerationSerializer create() {
if (_serializer == null)
_serializer = new EnumerationSerializer();
return _serializer;
}
public void writeObject(Object obj, AbstractHessianOutput out)
throws IOException {
Enumeration iter = (Enumeration) obj;
boolean hasEnd = out.writeListBegin(-1, null);
while (iter.hasMoreElements()) {
Object value = iter.nextElement();
out.writeObject(value);
}
if (hasEnd)
out.writeListEnd();
}
}

View File

@ -1,56 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.util.logging.Logger;
public class EnvelopeFactory {
private static final Logger log
= Logger.getLogger(EnvelopeFactory.class.getName());
}

View File

@ -1,101 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Burlap", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.util.HashMap;
/**
* Factory for returning serialization methods.
*/
public class ExtSerializerFactory extends AbstractSerializerFactory {
private HashMap _serializerMap = new HashMap();
private HashMap _deserializerMap = new HashMap();
/**
* Adds a serializer.
*
* @param cl the class of the serializer
* @param serializer the serializer
*/
public void addSerializer(Class cl, Serializer serializer) {
_serializerMap.put(cl, serializer);
}
/**
* Adds a deserializer.
*
* @param cl the class of the deserializer
* @param deserializer the deserializer
*/
public void addDeserializer(Class cl, Deserializer deserializer) {
_deserializerMap.put(cl, deserializer);
}
/**
* Returns the serializer for a class.
*
* @param cl the class of the object that needs to be serialized.
* @return a serializer object for the serialization.
*/
public Serializer getSerializer(Class cl)
throws HessianProtocolException {
return (Serializer) _serializerMap.get(cl);
}
/**
* Returns the deserializer for a class.
*
* @param cl the class of the object that needs to be deserialized.
* @return a deserializer object for the serialization.
*/
public Deserializer getDeserializer(Class cl)
throws HessianProtocolException {
return (Deserializer) _deserializerMap.get(cl);
}
}

View File

@ -1,145 +0,0 @@
/*
* Copyright (c) 2001-2008 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Burlap", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
public interface Hessian2Constants {
public static final int BC_BINARY = 'B'; // final chunk
public static final int BC_BINARY_CHUNK = 'A'; // non-final chunk
public static final int BC_BINARY_DIRECT = 0x20; // 1-byte length binary
public static final int BINARY_DIRECT_MAX = 0x0f;
public static final int BC_BINARY_SHORT = 0x34; // 2-byte length binary
public static final int BINARY_SHORT_MAX = 0x3ff; // 0-1023 binary
public static final int BC_CLASS_DEF = 'C'; // object/class definition
public static final int BC_DATE = 0x4a; // 64-bit millisecond UTC date
public static final int BC_DATE_MINUTE = 0x4b; // 32-bit minute UTC date
public static final int BC_DOUBLE = 'D'; // IEEE 64-bit double
public static final int BC_DOUBLE_ZERO = 0x5b;
public static final int BC_DOUBLE_ONE = 0x5c;
public static final int BC_DOUBLE_BYTE = 0x5d;
public static final int BC_DOUBLE_SHORT = 0x5e;
public static final int BC_DOUBLE_MILL = 0x5f;
public static final int BC_FALSE = 'F'; // boolean false
public static final int BC_INT = 'I'; // 32-bit int
public static final int INT_DIRECT_MIN = -0x10;
public static final int INT_DIRECT_MAX = 0x2f;
public static final int BC_INT_ZERO = 0x90;
public static final int INT_BYTE_MIN = -0x800;
public static final int INT_BYTE_MAX = 0x7ff;
public static final int BC_INT_BYTE_ZERO = 0xc8;
public static final int BC_END = 'Z';
public static final int INT_SHORT_MIN = -0x40000;
public static final int INT_SHORT_MAX = 0x3ffff;
public static final int BC_INT_SHORT_ZERO = 0xd4;
public static final int BC_LIST_VARIABLE = 0x55;
public static final int BC_LIST_FIXED = 'V';
public static final int BC_LIST_VARIABLE_UNTYPED = 0x57;
public static final int BC_LIST_FIXED_UNTYPED = 0x58;
public static final int BC_LIST_DIRECT = 0x70;
public static final int BC_LIST_DIRECT_UNTYPED = 0x78;
public static final int LIST_DIRECT_MAX = 0x7;
public static final int BC_LONG = 'L'; // 64-bit signed integer
public static final long LONG_DIRECT_MIN = -0x08;
public static final long LONG_DIRECT_MAX = 0x0f;
public static final int BC_LONG_ZERO = 0xe0;
public static final long LONG_BYTE_MIN = -0x800;
public static final long LONG_BYTE_MAX = 0x7ff;
public static final int BC_LONG_BYTE_ZERO = 0xf8;
public static final int LONG_SHORT_MIN = -0x40000;
public static final int LONG_SHORT_MAX = 0x3ffff;
public static final int BC_LONG_SHORT_ZERO = 0x3c;
public static final int BC_LONG_INT = 0x59;
public static final int BC_MAP = 'M';
public static final int BC_MAP_UNTYPED = 'H';
public static final int BC_NULL = 'N';
public static final int BC_OBJECT = 'O';
public static final int BC_OBJECT_DEF = 'C';
public static final int BC_OBJECT_DIRECT = 0x60;
public static final int OBJECT_DIRECT_MAX = 0x0f;
public static final int BC_REF = 0x51;
public static final int BC_STRING = 'S'; // final string
public static final int BC_STRING_CHUNK = 'R'; // non-final string
public static final int BC_STRING_DIRECT = 0x00;
public static final int STRING_DIRECT_MAX = 0x1f;
public static final int BC_STRING_SHORT = 0x30;
public static final int STRING_SHORT_MAX = 0x3ff;
public static final int BC_TRUE = 'T';
public static final int P_PACKET_CHUNK = 0x4f;
public static final int P_PACKET = 'P';
public static final int P_PACKET_DIRECT = 0x80;
public static final int PACKET_DIRECT_MAX = 0x7f;
public static final int P_PACKET_SHORT = 0x70;
public static final int PACKET_SHORT_MAX = 0xfff;
}

View File

@ -1,158 +0,0 @@
/*
* Copyright (c) 2001-2008 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Burlap", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.io.InputStream;
/**
* Output stream for Hessian 2 streaming requests.
*/
public class Hessian2StreamingInput {
private Hessian2Input _in;
/**
* Creates a new Hessian input stream, initialized with an
* underlying input stream.
*
* @param is the underlying output stream.
*/
public Hessian2StreamingInput(InputStream is) {
_in = new Hessian2Input(new StreamingInputStream(is));
}
/**
* Read the next object
*/
public Object readObject()
throws IOException {
return _in.readStreamingObject();
}
/**
* Close the output.
*/
public void close()
throws IOException {
_in.close();
}
static class StreamingInputStream extends InputStream {
private InputStream _is;
private int _length;
StreamingInputStream(InputStream is) {
_is = is;
}
public int read()
throws IOException {
InputStream is = _is;
while (_length == 0) {
int code = is.read();
if (code < 0)
return -1;
else if (code != 'p' && code != 'P')
throw new HessianProtocolException("expected streaming packet at 0x"
+ Integer.toHexString(code & 0xff));
int d1 = is.read();
int d2 = is.read();
if (d2 < 0)
return -1;
_length = (d1 << 8) + d2;
}
_length--;
return is.read();
}
public int read(byte[] buffer, int offset, int length)
throws IOException {
InputStream is = _is;
while (_length == 0) {
int code = is.read();
if (code < 0)
return -1;
else if (code != 'p' && code != 'P') {
throw new HessianProtocolException("expected streaming packet at 0x"
+ Integer.toHexString(code & 0xff)
+ " (" + (char) code + ")");
}
int d1 = is.read();
int d2 = is.read();
if (d2 < 0)
return -1;
_length = (d1 << 8) + d2;
}
int sublen = _length;
if (length < sublen)
sublen = length;
sublen = is.read(buffer, offset, sublen);
if (sublen < 0)
return -1;
_length -= sublen;
return sublen;
}
}
}

View File

@ -1,101 +0,0 @@
/*
* Copyright (c) 2001-2008 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Burlap", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.io.OutputStream;
/**
* Output stream for Hessian 2 streaming requests.
*/
public class Hessian2StreamingOutput {
private Hessian2Output _out;
/**
* Creates a new Hessian output stream, initialized with an
* underlying output stream.
*
* @param os the underlying output stream.
*/
public Hessian2StreamingOutput(OutputStream os) {
_out = new Hessian2Output(os);
}
public boolean isCloseStreamOnClose() {
return _out.isCloseStreamOnClose();
}
public void setCloseStreamOnClose(boolean isClose) {
_out.setCloseStreamOnClose(isClose);
}
/**
* Writes any object to the output stream.
*/
public void writeObject(Object object)
throws IOException {
_out.writeStreamingObject(object);
}
/**
* Flushes the output.
*/
public void flush()
throws IOException {
_out.flush();
}
/**
* Close the output.
*/
public void close()
throws IOException {
_out.close();
}
}

View File

@ -1,159 +0,0 @@
/*
* Copyright (c) 2001-2008 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Debugging input stream for Hessian requests.
*/
public class HessianDebugInputStream extends InputStream {
private InputStream _is;
private HessianDebugState _state;
/**
* Creates an uninitialized Hessian input stream.
*/
public HessianDebugInputStream(InputStream is, PrintWriter dbg) {
_is = is;
if (dbg == null)
dbg = new PrintWriter(System.out);
_state = new HessianDebugState(dbg);
}
/**
* Creates an uninitialized Hessian input stream.
*/
public HessianDebugInputStream(InputStream is, Logger log, Level level) {
this(is, new PrintWriter(new LogWriter(log, level)));
}
public void startTop2() {
_state.startTop2();
}
/**
* Reads a character.
*/
public int read()
throws IOException {
int ch;
InputStream is = _is;
if (is == null)
return -1;
else {
ch = is.read();
}
_state.next(ch);
return ch;
}
/**
* closes the stream.
*/
public void close()
throws IOException {
InputStream is = _is;
_is = null;
if (is != null)
is.close();
_state.println();
}
static class LogWriter extends Writer {
private Logger _log;
private Level _level;
private StringBuilder _sb = new StringBuilder();
LogWriter(Logger log, Level level) {
_log = log;
_level = level;
}
public void write(char ch) {
if (ch == '\n' && _sb.length() > 0) {
_log.log(_level, _sb.toString());
_sb.setLength(0);
} else
_sb.append((char) ch);
}
public void write(char[] buffer, int offset, int length) {
for (int i = 0; i < length; i++) {
char ch = buffer[offset + i];
if (ch == '\n' && _sb.length() > 0) {
_log.log(_level, _sb.toString());
_sb.setLength(0);
} else
_sb.append((char) ch);
}
}
public void flush() {
}
public void close() {
}
}
}

View File

@ -1,153 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Debugging output stream for Hessian requests.
*/
public class HessianDebugOutputStream extends OutputStream {
private OutputStream _os;
private HessianDebugState _state;
/**
* Creates an uninitialized Hessian input stream.
*/
public HessianDebugOutputStream(OutputStream os, PrintWriter dbg) {
_os = os;
_state = new HessianDebugState(dbg);
}
/**
* Creates an uninitialized Hessian input stream.
*/
public HessianDebugOutputStream(OutputStream os, Logger log, Level level) {
this(os, new PrintWriter(new LogWriter(log, level)));
}
public void startTop2() {
_state.startTop2();
}
/**
* Writes a character.
*/
public void write(int ch)
throws IOException {
ch = ch & 0xff;
_os.write(ch);
_state.next(ch);
}
public void flush()
throws IOException {
_os.flush();
}
/**
* closes the stream.
*/
public void close()
throws IOException {
OutputStream os = _os;
_os = null;
if (os != null)
os.close();
_state.println();
}
static class LogWriter extends Writer {
private Logger _log;
private Level _level;
private StringBuilder _sb = new StringBuilder();
LogWriter(Logger log, Level level) {
_log = log;
_level = level;
}
public void write(char ch) {
if (ch == '\n' && _sb.length() > 0) {
_log.log(_level, _sb.toString());
_sb.setLength(0);
} else
_sb.append((char) ch);
}
public void write(char[] buffer, int offset, int length) {
for (int i = 0; i < length; i++) {
char ch = buffer[offset + i];
if (ch == '\n' && _sb.length() > 0) {
_log.log(_level, _sb.toString());
_sb.setLength(0);
} else
_sb.append((char) ch);
}
}
public void flush() {
}
public void close() {
}
}
}

View File

@ -1,78 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
/**
* Factory class for wrapping and unwrapping hessian streams.
*/
abstract public class HessianEnvelope {
/**
* Wrap the Hessian output stream in an envelope.
*/
abstract public Hessian2Output wrap(Hessian2Output out)
throws IOException;
/**
* Unwrap the Hessian input stream with this envelope. It is an
* error if the actual envelope does not match the expected envelope
* class.
*/
abstract public Hessian2Input unwrap(Hessian2Input in)
throws IOException;
/**
* Unwrap the envelope after having read the envelope code ('E') and
* the envelope method. Called by the EnvelopeFactory for dynamic
* reading of the envelopes.
*/
abstract public Hessian2Input unwrapHeaders(Hessian2Input in)
throws IOException;
}

View File

@ -1,81 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Burlap", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
/**
* Exception during field reading.
*/
public class HessianFieldException extends HessianProtocolException {
/**
* Zero-arg constructor.
*/
public HessianFieldException() {
}
/**
* Create the exception.
*/
public HessianFieldException(String message) {
super(message);
}
/**
* Create the exception.
*/
public HessianFieldException(String message, Throwable cause) {
super(message, cause);
}
/**
* Create the exception.
*/
public HessianFieldException(Throwable cause) {
super(cause);
}
}

View File

@ -1,55 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
/**
* Marks a type as a handle
*/
public interface HessianHandle {
}

View File

@ -1,95 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Logger;
public class HessianInputFactory {
public static final Logger log
= Logger.getLogger(HessianInputFactory.class.getName());
private SerializerFactory _serializerFactory;
public SerializerFactory getSerializerFactory() {
return _serializerFactory;
}
public void setSerializerFactory(SerializerFactory factory) {
_serializerFactory = factory;
}
public AbstractHessianInput open(InputStream is)
throws IOException {
int code = is.read();
int major = is.read();
int minor = is.read();
switch (code) {
case 'c':
case 'C':
case 'r':
case 'R':
if (major >= 2) {
AbstractHessianInput in = new Hessian2Input(is);
in.setSerializerFactory(_serializerFactory);
return in;
} else {
AbstractHessianInput in = new HessianInput(is);
in.setSerializerFactory(_serializerFactory);
return in;
}
default:
throw new IOException((char) code + " is an unknown Hessian message code.");
}
}
}

View File

@ -1,896 +0,0 @@
/*
* Copyright (c) 2001-2008 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Burlap", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.io.OutputStream;
import java.util.IdentityHashMap;
/**
* Output stream for Hessian requests, compatible with microedition
* Java. It only uses classes and types available in JDK.
* <p>
* <p>Since HessianOutput does not depend on any classes other than
* in the JDK, it can be extracted independently into a smaller package.
* <p>
* <p>HessianOutput is unbuffered, so any client needs to provide
* its own buffering.
* <p>
* <pre>
* OutputStream os = ...; // from http connection
* HessianOutput out = new HessianOutput(os);
* String value;
*
* out.startCall("hello"); // start hello call
* out.writeString("arg1"); // write a string argument
* out.completeCall(); // complete the call
* </pre>
*/
public class HessianOutput extends AbstractHessianOutput {
// the output stream/
protected OutputStream os;
// map of references
private IdentityHashMap _refs;
private int _version = 1;
/**
* Creates a new Hessian output stream, initialized with an
* underlying output stream.
*
* @param os the underlying output stream.
*/
public HessianOutput(OutputStream os) {
init(os);
}
/**
* Creates an uninitialized Hessian output stream.
*/
public HessianOutput() {
}
/**
* Initializes the output
*/
public void init(OutputStream os) {
this.os = os;
_refs = null;
if (_serializerFactory == null)
_serializerFactory = new SerializerFactory();
}
/**
* Sets the client's version.
*/
public void setVersion(int version) {
_version = version;
}
/**
* Writes a complete method call.
*/
public void call(String method, Object[] args)
throws IOException {
int length = args != null ? args.length : 0;
startCall(method, length);
for (int i = 0; i < length; i++)
writeObject(args[i]);
completeCall();
}
/**
* Starts the method call. Clients would use <code>startCall</code>
* instead of <code>call</code> if they wanted finer control over
* writing the arguments, or needed to write headers.
* <p>
* <code><pre>
* c major minor
* m b16 b8 method-name
* </pre></code>
*
* @param method the method name to call.
*/
public void startCall(String method, int length)
throws IOException {
os.write('c');
os.write(_version);
os.write(0);
os.write('m');
int len = method.length();
os.write(len >> 8);
os.write(len);
printString(method, 0, len);
}
/**
* Writes the call tag. This would be followed by the
* headers and the method tag.
* <p>
* <code><pre>
* c major minor
* </pre></code>
*
* @param method the method name to call.
*/
public void startCall()
throws IOException {
os.write('c');
os.write(0);
os.write(1);
}
/**
* Writes the method tag.
* <p>
* <code><pre>
* m b16 b8 method-name
* </pre></code>
*
* @param method the method name to call.
*/
public void writeMethod(String method)
throws IOException {
os.write('m');
int len = method.length();
os.write(len >> 8);
os.write(len);
printString(method, 0, len);
}
/**
* Completes.
* <p>
* <code><pre>
* z
* </pre></code>
*/
public void completeCall()
throws IOException {
os.write('z');
}
/**
* Starts the reply
* <p>
* <p>A successful completion will have a single value:
* <p>
* <pre>
* r
* </pre>
*/
public void startReply()
throws IOException {
os.write('r');
os.write(1);
os.write(0);
}
/**
* Completes reading the reply
* <p>
* <p>A successful completion will have a single value:
* <p>
* <pre>
* z
* </pre>
*/
public void completeReply()
throws IOException {
os.write('z');
}
/**
* Writes a header name. The header value must immediately follow.
* <p>
* <code><pre>
* H b16 b8 foo <em>value</em>
* </pre></code>
*/
public void writeHeader(String name)
throws IOException {
int len = name.length();
os.write('H');
os.write(len >> 8);
os.write(len);
printString(name);
}
/**
* Writes a fault. The fault will be written
* as a descriptive string followed by an object:
* <p>
* <code><pre>
* f
* &lt;string>code
* &lt;string>the fault code
* <p>
* &lt;string>message
* &lt;string>the fault mesage
* <p>
* &lt;string>detail
* mt\x00\xnnjavax.ejb.FinderException
* ...
* z
* z
* </pre></code>
*
* @param code the fault code, a three digit
*/
public void writeFault(String code, String message, Object detail)
throws IOException {
os.write('f');
writeString("code");
writeString(code);
writeString("message");
writeString(message);
if (detail != null) {
writeString("detail");
writeObject(detail);
}
os.write('z');
}
/**
* Writes any object to the output stream.
*/
public void writeObject(Object object)
throws IOException {
if (object == null) {
writeNull();
return;
}
Serializer serializer;
serializer = _serializerFactory.getSerializer(object.getClass());
serializer.writeObject(object, this);
}
/**
* Writes the list header to the stream. List writers will call
* <code>writeListBegin</code> followed by the list contents and then
* call <code>writeListEnd</code>.
* <p>
* <code><pre>
* V
* t b16 b8 type
* l b32 b24 b16 b8
* </pre></code>
*/
public boolean writeListBegin(int length, String type)
throws IOException {
os.write('V');
if (type != null) {
os.write('t');
printLenString(type);
}
if (length >= 0) {
os.write('l');
os.write(length >> 24);
os.write(length >> 16);
os.write(length >> 8);
os.write(length);
}
return true;
}
/**
* Writes the tail of the list to the stream.
*/
public void writeListEnd()
throws IOException {
os.write('z');
}
/**
* Writes the map header to the stream. Map writers will call
* <code>writeMapBegin</code> followed by the map contents and then
* call <code>writeMapEnd</code>.
* <p>
* <code><pre>
* Mt b16 b8 (<key> <value>)z
* </pre></code>
*/
public void writeMapBegin(String type)
throws IOException {
os.write('M');
os.write('t');
printLenString(type);
}
/**
* Writes the tail of the map to the stream.
*/
public void writeMapEnd()
throws IOException {
os.write('z');
}
/**
* Writes a remote object reference to the stream. The type is the
* type of the remote interface.
* <p>
* <code><pre>
* 'r' 't' b16 b8 type url
* </pre></code>
*/
public void writeRemote(String type, String url)
throws IOException {
os.write('r');
os.write('t');
printLenString(type);
os.write('S');
printLenString(url);
}
/**
* Writes a boolean value to the stream. The boolean will be written
* with the following syntax:
* <p>
* <code><pre>
* T
* F
* </pre></code>
*
* @param value the boolean value to write.
*/
public void writeBoolean(boolean value)
throws IOException {
if (value)
os.write('T');
else
os.write('F');
}
/**
* Writes an integer value to the stream. The integer will be written
* with the following syntax:
* <p>
* <code><pre>
* I b32 b24 b16 b8
* </pre></code>
*
* @param value the integer value to write.
*/
public void writeInt(int value)
throws IOException {
os.write('I');
os.write(value >> 24);
os.write(value >> 16);
os.write(value >> 8);
os.write(value);
}
/**
* Writes a long value to the stream. The long will be written
* with the following syntax:
* <p>
* <code><pre>
* L b64 b56 b48 b40 b32 b24 b16 b8
* </pre></code>
*
* @param value the long value to write.
*/
public void writeLong(long value)
throws IOException {
os.write('L');
os.write((byte) (value >> 56));
os.write((byte) (value >> 48));
os.write((byte) (value >> 40));
os.write((byte) (value >> 32));
os.write((byte) (value >> 24));
os.write((byte) (value >> 16));
os.write((byte) (value >> 8));
os.write((byte) (value));
}
/**
* Writes a double value to the stream. The double will be written
* with the following syntax:
* <p>
* <code><pre>
* D b64 b56 b48 b40 b32 b24 b16 b8
* </pre></code>
*
* @param value the double value to write.
*/
public void writeDouble(double value)
throws IOException {
long bits = Double.doubleToLongBits(value);
os.write('D');
os.write((byte) (bits >> 56));
os.write((byte) (bits >> 48));
os.write((byte) (bits >> 40));
os.write((byte) (bits >> 32));
os.write((byte) (bits >> 24));
os.write((byte) (bits >> 16));
os.write((byte) (bits >> 8));
os.write((byte) (bits));
}
/**
* Writes a date to the stream.
* <p>
* <code><pre>
* T b64 b56 b48 b40 b32 b24 b16 b8
* </pre></code>
*
* @param time the date in milliseconds from the epoch in UTC
*/
public void writeUTCDate(long time)
throws IOException {
os.write('d');
os.write((byte) (time >> 56));
os.write((byte) (time >> 48));
os.write((byte) (time >> 40));
os.write((byte) (time >> 32));
os.write((byte) (time >> 24));
os.write((byte) (time >> 16));
os.write((byte) (time >> 8));
os.write((byte) (time));
}
/**
* Writes a null value to the stream.
* The null will be written with the following syntax
* <p>
* <code><pre>
* N
* </pre></code>
*
* @param value the string value to write.
*/
public void writeNull()
throws IOException {
os.write('N');
}
/**
* Writes a string value to the stream using UTF-8 encoding.
* The string will be written with the following syntax:
* <p>
* <code><pre>
* S b16 b8 string-value
* </pre></code>
* <p>
* If the value is null, it will be written as
* <p>
* <code><pre>
* N
* </pre></code>
*
* @param value the string value to write.
*/
public void writeString(String value)
throws IOException {
if (value == null) {
os.write('N');
} else {
int length = value.length();
int offset = 0;
while (length > 0x8000) {
int sublen = 0x8000;
// chunk can't end in high surrogate
char tail = value.charAt(offset + sublen - 1);
if (0xd800 <= tail && tail <= 0xdbff)
sublen--;
os.write('s');
os.write(sublen >> 8);
os.write(sublen);
printString(value, offset, sublen);
length -= sublen;
offset += sublen;
}
os.write('S');
os.write(length >> 8);
os.write(length);
printString(value, offset, length);
}
}
/**
* Writes a string value to the stream using UTF-8 encoding.
* The string will be written with the following syntax:
* <p>
* <code><pre>
* S b16 b8 string-value
* </pre></code>
* <p>
* If the value is null, it will be written as
* <p>
* <code><pre>
* N
* </pre></code>
*
* @param value the string value to write.
*/
public void writeString(char[] buffer, int offset, int length)
throws IOException {
if (buffer == null) {
os.write('N');
} else {
while (length > 0x8000) {
int sublen = 0x8000;
// chunk can't end in high surrogate
char tail = buffer[offset + sublen - 1];
if (0xd800 <= tail && tail <= 0xdbff)
sublen--;
os.write('s');
os.write(sublen >> 8);
os.write(sublen);
printString(buffer, offset, sublen);
length -= sublen;
offset += sublen;
}
os.write('S');
os.write(length >> 8);
os.write(length);
printString(buffer, offset, length);
}
}
/**
* Writes a byte array to the stream.
* The array will be written with the following syntax:
* <p>
* <code><pre>
* B b16 b18 bytes
* </pre></code>
* <p>
* If the value is null, it will be written as
* <p>
* <code><pre>
* N
* </pre></code>
*
* @param value the string value to write.
*/
public void writeBytes(byte[] buffer)
throws IOException {
if (buffer == null)
os.write('N');
else
writeBytes(buffer, 0, buffer.length);
}
/**
* Writes a byte array to the stream.
* The array will be written with the following syntax:
* <p>
* <code><pre>
* B b16 b18 bytes
* </pre></code>
* <p>
* If the value is null, it will be written as
* <p>
* <code><pre>
* N
* </pre></code>
*
* @param value the string value to write.
*/
public void writeBytes(byte[] buffer, int offset, int length)
throws IOException {
if (buffer == null) {
os.write('N');
} else {
while (length > 0x8000) {
int sublen = 0x8000;
os.write('b');
os.write(sublen >> 8);
os.write(sublen);
os.write(buffer, offset, sublen);
length -= sublen;
offset += sublen;
}
os.write('B');
os.write(length >> 8);
os.write(length);
os.write(buffer, offset, length);
}
}
/**
* Writes a byte buffer to the stream.
* <p>
* <code><pre>
* </pre></code>
*/
public void writeByteBufferStart()
throws IOException {
}
/**
* Writes a byte buffer to the stream.
* <p>
* <code><pre>
* b b16 b18 bytes
* </pre></code>
*/
public void writeByteBufferPart(byte[] buffer, int offset, int length)
throws IOException {
while (length > 0) {
int sublen = length;
if (0x8000 < sublen)
sublen = 0x8000;
os.write('b');
os.write(sublen >> 8);
os.write(sublen);
os.write(buffer, offset, sublen);
length -= sublen;
offset += sublen;
}
}
/**
* Writes a byte buffer to the stream.
* <p>
* <code><pre>
* b b16 b18 bytes
* </pre></code>
*/
public void writeByteBufferEnd(byte[] buffer, int offset, int length)
throws IOException {
writeBytes(buffer, offset, length);
}
/**
* Writes a reference.
* <p>
* <code><pre>
* R b32 b24 b16 b8
* </pre></code>
*
* @param value the integer value to write.
*/
public void writeRef(int value)
throws IOException {
os.write('R');
os.write(value >> 24);
os.write(value >> 16);
os.write(value >> 8);
os.write(value);
}
/**
* Writes a placeholder.
* <p>
* <code><pre>
* P
* </pre></code>
*/
public void writePlaceholder()
throws IOException {
os.write('P');
}
/**
* If the object has already been written, just write its ref.
*
* @return true if we're writing a ref.
*/
public boolean addRef(Object object)
throws IOException {
if (_refs == null)
_refs = new IdentityHashMap();
Integer ref = (Integer) _refs.get(object);
if (ref != null) {
int value = ref.intValue();
writeRef(value);
return true;
} else {
_refs.put(object, new Integer(_refs.size()));
return false;
}
}
/**
* Resets the references for streaming.
*/
public void resetReferences() {
if (_refs != null)
_refs.clear();
}
/**
* Removes a reference.
*/
public boolean removeRef(Object obj)
throws IOException {
if (_refs != null) {
_refs.remove(obj);
return true;
} else
return false;
}
/**
* Replaces a reference from one object to another.
*/
public boolean replaceRef(Object oldRef, Object newRef)
throws IOException {
Integer value = (Integer) _refs.remove(oldRef);
if (value != null) {
_refs.put(newRef, value);
return true;
} else
return false;
}
/**
* Prints a string to the stream, encoded as UTF-8 with preceeding length
*
* @param v the string to print.
*/
public void printLenString(String v)
throws IOException {
if (v == null) {
os.write(0);
os.write(0);
} else {
int len = v.length();
os.write(len >> 8);
os.write(len);
printString(v, 0, len);
}
}
/**
* Prints a string to the stream, encoded as UTF-8
*
* @param v the string to print.
*/
public void printString(String v)
throws IOException {
printString(v, 0, v.length());
}
/**
* Prints a string to the stream, encoded as UTF-8
*
* @param v the string to print.
*/
public void printString(String v, int offset, int length)
throws IOException {
for (int i = 0; i < length; i++) {
char ch = v.charAt(i + offset);
if (ch < 0x80)
os.write(ch);
else if (ch < 0x800) {
os.write(0xc0 + ((ch >> 6) & 0x1f));
os.write(0x80 + (ch & 0x3f));
} else {
os.write(0xe0 + ((ch >> 12) & 0xf));
os.write(0x80 + ((ch >> 6) & 0x3f));
os.write(0x80 + (ch & 0x3f));
}
}
}
/**
* Prints a string to the stream, encoded as UTF-8
*
* @param v the string to print.
*/
public void printString(char[] v, int offset, int length)
throws IOException {
for (int i = 0; i < length; i++) {
char ch = v[i + offset];
if (ch < 0x80)
os.write(ch);
else if (ch < 0x800) {
os.write(0xc0 + ((ch >> 6) & 0x1f));
os.write(0x80 + (ch & 0x3f));
} else {
os.write(0xe0 + ((ch >> 12) & 0xf));
os.write(0x80 + ((ch >> 6) & 0x3f));
os.write(0x80 + (ch & 0x3f));
}
}
}
public void flush()
throws IOException {
if (this.os != null)
this.os.flush();
}
public void close()
throws IOException {
if (this.os != null)
this.os.flush();
}
}

View File

@ -1,104 +0,0 @@
/*
* Copyright (c) 2001-2008 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Burlap", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
/**
* Exception for faults when the fault doesn't return a java exception.
* This exception is required for MicroHessianInput.
*/
public class HessianProtocolException extends IOException {
private Throwable rootCause;
/**
* Zero-arg constructor.
*/
public HessianProtocolException() {
}
/**
* Create the exception.
*/
public HessianProtocolException(String message) {
super(message);
}
/**
* Create the exception.
*/
public HessianProtocolException(String message, Throwable rootCause) {
super(message);
this.rootCause = rootCause;
}
/**
* Create the exception.
*/
public HessianProtocolException(Throwable rootCause) {
super(String.valueOf(rootCause));
this.rootCause = rootCause;
}
/**
* Returns the underlying cause.
*/
public Throwable getRootCause() {
return rootCause;
}
/**
* Returns the underlying cause.
*/
public Throwable getCause() {
return getRootCause();
}
}

View File

@ -1,122 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
/**
* Encapsulates a remote address when no stub is available, e.g. for
* Java MicroEdition.
*/
public class HessianRemote {
private String type;
private String url;
/**
* Creates a new Hessian remote object.
*
* @param type the remote stub interface
* @param url the remote url
*/
public HessianRemote(String type, String url) {
this.type = type;
this.url = url;
}
/**
* Creates an uninitialized Hessian remote.
*/
public HessianRemote() {
}
/**
* Returns the remote api class name.
*/
public String getType() {
return type;
}
/**
* Returns the remote URL.
*/
public String getURL() {
return url;
}
/**
* Sets the remote URL.
*/
public void setURL(String url) {
this.url = url;
}
/**
* Defines the hashcode.
*/
public int hashCode() {
return url.hashCode();
}
/**
* Defines equality
*/
public boolean equals(Object obj) {
if (!(obj instanceof HessianRemote))
return false;
HessianRemote remote = (HessianRemote) obj;
return url.equals(remote.url);
}
/**
* Readable version of the remote.
*/
public String toString() {
return "[HessianRemote " + url + "]";
}
}

View File

@ -1,58 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
/**
* Interface for any hessian remote object.
*/
public interface HessianRemoteObject {
public String getHessianType();
public String getHessianURL();
}

View File

@ -1,62 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
/**
* Looks up remote objects. The default just returns a HessianRemote object.
*/
public interface HessianRemoteResolver {
/**
* Looks up a proxy object.
*/
public Object lookup(String type, String url)
throws IOException;
}

View File

@ -1,178 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Burlap", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.HashMap;
/**
* Input stream for Hessian requests, deserializing objects using the
* java.io.Serialization protocol.
* <p>
* <p>HessianSerializerInput is unbuffered, so any client needs to provide
* its own buffering.
* <p>
* <h3>Serialization</h3>
* <p>
* <pre>
* InputStream is = new FileInputStream("test.xml");
* HessianOutput in = new HessianSerializerOutput(is);
*
* Object obj = in.readObject();
* is.close();
* </pre>
* <p>
* <h3>Parsing a Hessian reply</h3>
* <p>
* <pre>
* InputStream is = ...; // from http connection
* HessianInput in = new HessianSerializerInput(is);
* String value;
*
* in.startReply(); // read reply header
* value = in.readString(); // read string value
* in.completeReply(); // read reply footer
* </pre>
*/
public class HessianSerializerInput extends HessianInput {
/**
* Creates a new Hessian input stream, initialized with an
* underlying input stream.
*
* @param is the underlying input stream.
*/
public HessianSerializerInput(InputStream is) {
super(is);
}
/**
* Creates an uninitialized Hessian input stream.
*/
public HessianSerializerInput() {
}
/**
* Reads an object from the input stream. cl is known not to be
* a Map.
*/
protected Object readObjectImpl(Class cl)
throws IOException {
try {
Object obj = cl.newInstance();
if (_refs == null)
_refs = new ArrayList();
_refs.add(obj);
HashMap fieldMap = getFieldMap(cl);
int code = read();
for (; code >= 0 && code != 'z'; code = read()) {
_peek = code;
Object key = readObject();
Field field = (Field) fieldMap.get(key);
if (field != null) {
Object value = readObject(field.getType());
field.set(obj, value);
} else {
Object value = readObject();
}
}
if (code != 'z')
throw expect("map", code);
// if there's a readResolve method, call it
try {
Method method = cl.getMethod("readResolve", new Class[0]);
return method.invoke(obj, new Object[0]);
} catch (Exception e) {
}
return obj;
} catch (IOException e) {
throw e;
} catch (Exception e) {
throw new IOExceptionWrapper(e);
}
}
/**
* Creates a map of the classes fields.
*/
protected HashMap getFieldMap(Class cl) {
HashMap fieldMap = new HashMap();
for (; cl != null; cl = cl.getSuperclass()) {
Field[] fields = cl.getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
Field field = fields[i];
if (Modifier.isTransient(field.getModifiers()) ||
Modifier.isStatic(field.getModifiers()))
continue;
// XXX: could parameterize the handler to only deal with public
field.setAccessible(true);
fieldMap.put(field.getName(), field);
}
}
return fieldMap;
}
}

View File

@ -1,143 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
/**
* Output stream for Hessian requests.
* <p>
* <p>HessianOutput is unbuffered, so any client needs to provide
* its own buffering.
* <p>
* <h3>Serialization</h3>
* <p>
* <pre>
* OutputStream os = new FileOutputStream("test.xml");
* HessianOutput out = new HessianSerializerOutput(os);
*
* out.writeObject(obj);
* os.close();
* </pre>
* <p>
* <h3>Writing an RPC Call</h3>
* <p>
* <pre>
* OutputStream os = ...; // from http connection
* HessianOutput out = new HessianSerializerOutput(os);
* String value;
*
* out.startCall("hello"); // start hello call
* out.writeString("arg1"); // write a string argument
* out.completeCall(); // complete the call
* </pre>
*/
public class HessianSerializerOutput extends HessianOutput {
/**
* Creates a new Hessian output stream, initialized with an
* underlying output stream.
*
* @param os the underlying output stream.
*/
public HessianSerializerOutput(OutputStream os) {
super(os);
}
/**
* Creates an uninitialized Hessian output stream.
*/
public HessianSerializerOutput() {
}
/**
* Applications which override this can do custom serialization.
*
* @param object the object to write.
*/
public void writeObjectImpl(Object obj)
throws IOException {
Class cl = obj.getClass();
try {
Method method = cl.getMethod("writeReplace", new Class[0]);
Object repl = method.invoke(obj, new Object[0]);
writeObject(repl);
return;
} catch (Exception e) {
}
try {
writeMapBegin(cl.getName());
for (; cl != null; cl = cl.getSuperclass()) {
Field[] fields = cl.getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
Field field = fields[i];
if (Modifier.isTransient(field.getModifiers()) ||
Modifier.isStatic(field.getModifiers()))
continue;
// XXX: could parameterize the handler to only deal with public
field.setAccessible(true);
writeString(field.getName());
writeObject(field.get(obj));
}
}
writeMapEnd();
} catch (IllegalAccessException e) {
throw new IOExceptionWrapper(e);
}
}
}

View File

@ -1,87 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
/**
* Exception for faults when the fault doesn't return a java exception.
* This exception is required for MicroHessianInput.
*/
public class HessianServiceException extends Exception {
private String code;
private Object detail;
/**
* Zero-arg constructor.
*/
public HessianServiceException() {
}
/**
* Create the exception.
*/
public HessianServiceException(String message, String code, Object detail) {
super(message);
this.code = code;
this.detail = detail;
}
/**
* Returns the code.
*/
public String getCode() {
return code;
}
/**
* Returns the detail.
*/
public Object getDetail() {
return detail;
}
}

View File

@ -1,74 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
/**
* Exception wrapper for IO.
*/
public class IOExceptionWrapper extends IOException {
private Throwable _cause;
public IOExceptionWrapper(Throwable cause) {
super(cause.toString());
_cause = cause;
}
public IOExceptionWrapper(String msg, Throwable cause) {
super(msg);
_cause = cause;
}
public Throwable getCause() {
return _cause;
}
}

View File

@ -1,64 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Burlap", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
/**
* Serializing a stream object.
*/
public class InputStreamDeserializer extends AbstractDeserializer {
public InputStreamDeserializer() {
}
public Object readObject(AbstractHessianInput in)
throws IOException {
return in.readInputStream();
}
}

View File

@ -1,78 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Burlap", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.io.InputStream;
/**
* Serializing a stream object.
*/
public class InputStreamSerializer extends AbstractSerializer {
public InputStreamSerializer() {
}
public void writeObject(Object obj, AbstractHessianOutput out)
throws IOException {
InputStream is = (InputStream) obj;
if (is == null)
out.writeNull();
else {
byte[] buf = new byte[1024];
int len;
while ((len = is.read(buf, 0, buf.length)) > 0) {
out.writeByteBufferPart(buf, 0, len);
}
out.writeByteBufferEnd(buf, 0, 0);
}
}
}

View File

@ -1,82 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.util.Iterator;
/**
* Serializing a JDK 1.2 Iterator.
*/
public class IteratorSerializer extends AbstractSerializer {
private static IteratorSerializer _serializer;
public static IteratorSerializer create() {
if (_serializer == null)
_serializer = new IteratorSerializer();
return _serializer;
}
public void writeObject(Object obj, AbstractHessianOutput out)
throws IOException {
Iterator iter = (Iterator) obj;
boolean hasEnd = out.writeListBegin(-1, null);
while (iter.hasNext()) {
Object value = iter.next();
out.writeObject(value);
}
if (hasEnd)
out.writeListEnd();
}
}

View File

@ -1,740 +0,0 @@
/*
* Copyright (c) 2001-2008 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Burlap", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
/**
* Serializing an object for known object types.
*/
public class JavaDeserializer extends AbstractMapDeserializer {
private static final Logger log
= Logger.getLogger(JavaDeserializer.class.getName());
private Class _type;
private HashMap _fieldMap;
private Method _readResolve;
private Constructor _constructor;
private Object[] _constructorArgs;
public JavaDeserializer(Class cl) {
_type = cl;
_fieldMap = getFieldMap(cl);
_readResolve = getReadResolve(cl);
if (_readResolve != null) {
_readResolve.setAccessible(true);
}
Constructor[] constructors = cl.getDeclaredConstructors();
long bestCost = Long.MAX_VALUE;
for (int i = 0; i < constructors.length; i++) {
Class[] param = constructors[i].getParameterTypes();
long cost = 0;
for (int j = 0; j < param.length; j++) {
cost = 4 * cost;
if (Object.class.equals(param[j]))
cost += 1;
else if (String.class.equals(param[j]))
cost += 2;
else if (int.class.equals(param[j]))
cost += 3;
else if (long.class.equals(param[j]))
cost += 4;
else if (param[j].isPrimitive())
cost += 5;
else
cost += 6;
}
if (cost < 0 || cost > (1 << 48))
cost = 1 << 48;
cost += (long) param.length << 48;
if (cost < bestCost) {
_constructor = constructors[i];
bestCost = cost;
}
}
if (_constructor != null) {
_constructor.setAccessible(true);
Class[] params = _constructor.getParameterTypes();
_constructorArgs = new Object[params.length];
for (int i = 0; i < params.length; i++) {
_constructorArgs[i] = getParamArg(params[i]);
}
}
}
/**
* Creates a map of the classes fields.
*/
protected static Object getParamArg(Class cl) {
if (!cl.isPrimitive())
return null;
else if (boolean.class.equals(cl))
return Boolean.FALSE;
else if (byte.class.equals(cl))
return new Byte((byte) 0);
else if (short.class.equals(cl))
return new Short((short) 0);
else if (char.class.equals(cl))
return new Character((char) 0);
else if (int.class.equals(cl))
return Integer.valueOf(0);
else if (long.class.equals(cl))
return Long.valueOf(0);
else if (float.class.equals(cl))
return Float.valueOf(0);
else if (double.class.equals(cl))
return Double.valueOf(0);
else
throw new UnsupportedOperationException();
}
static void logDeserializeError(Field field, Object obj, Object value,
Throwable e)
throws IOException {
String fieldName = (field.getDeclaringClass().getName()
+ "." + field.getName());
if (e instanceof HessianFieldException)
throw (HessianFieldException) e;
else if (e instanceof IOException)
throw new HessianFieldException(fieldName + ": " + e.getMessage(), e);
if (value != null)
throw new HessianFieldException(fieldName + ": " + value.getClass().getName() + " (" + value + ")"
+ " cannot be assigned to '" + field.getType().getName() + "'", e);
else
throw new HessianFieldException(fieldName + ": " + field.getType().getName() + " cannot be assigned from null", e);
}
public Class getType() {
return _type;
}
public Object readMap(AbstractHessianInput in)
throws IOException {
try {
Object obj = instantiate();
return readMap(in, obj);
} catch (IOException e) {
throw e;
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new IOExceptionWrapper(_type.getName() + ":" + e.getMessage(), e);
}
}
public Object readObject(AbstractHessianInput in, String[] fieldNames)
throws IOException {
try {
Object obj = instantiate();
return readObject(in, obj, fieldNames);
} catch (IOException e) {
throw e;
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new IOExceptionWrapper(_type.getName() + ":" + e.getMessage(), e);
}
}
/**
* Returns the readResolve method
*/
protected Method getReadResolve(Class cl) {
for (; cl != null; cl = cl.getSuperclass()) {
Method[] methods = cl.getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
if (method.getName().equals("readResolve") &&
method.getParameterTypes().length == 0)
return method;
}
}
return null;
}
public Object readMap(AbstractHessianInput in, Object obj)
throws IOException {
try {
int ref = in.addRef(obj);
while (!in.isEnd()) {
Object key = in.readObject();
FieldDeserializer deser = (FieldDeserializer) _fieldMap.get(key);
if (deser != null)
deser.deserialize(in, obj);
else
in.readObject();
}
in.readMapEnd();
Object resolve = resolve(obj);
if (obj != resolve)
in.setRef(ref, resolve);
return resolve;
} catch (IOException e) {
throw e;
} catch (Exception e) {
throw new IOExceptionWrapper(e);
}
}
public Object readObject(AbstractHessianInput in,
Object obj,
String[] fieldNames)
throws IOException {
try {
int ref = in.addRef(obj);
for (int i = 0; i < fieldNames.length; i++) {
String name = fieldNames[i];
FieldDeserializer deser = (FieldDeserializer) _fieldMap.get(name);
if (deser != null)
deser.deserialize(in, obj);
else
in.readObject();
}
Object resolve = resolve(obj);
if (obj != resolve)
in.setRef(ref, resolve);
return resolve;
} catch (IOException e) {
throw e;
} catch (Exception e) {
throw new IOExceptionWrapper(obj.getClass().getName() + ":" + e, e);
}
}
private Object resolve(Object obj)
throws Exception {
// if there's a readResolve method, call it
try {
if (_readResolve != null)
return _readResolve.invoke(obj, new Object[0]);
} catch (InvocationTargetException e) {
if (e.getTargetException() != null)
throw e;
}
return obj;
}
protected Object instantiate()
throws Exception {
try {
if (_constructor != null)
return _constructor.newInstance(_constructorArgs);
else
return _type.newInstance();
} catch (Exception e) {
throw new HessianProtocolException("'" + _type.getName() + "' could not be instantiated", e);
}
}
/**
* Creates a map of the classes fields.
*/
protected HashMap getFieldMap(Class cl) {
HashMap fieldMap = new HashMap();
for (; cl != null; cl = cl.getSuperclass()) {
Field[] fields = cl.getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
Field field = fields[i];
if (Modifier.isTransient(field.getModifiers())
|| Modifier.isStatic(field.getModifiers()))
continue;
else if (fieldMap.get(field.getName()) != null)
continue;
// XXX: could parameterize the handler to only deal with public
try {
field.setAccessible(true);
} catch (Throwable e) {
e.printStackTrace();
}
Class type = field.getType();
FieldDeserializer deser;
if (String.class.equals(type))
deser = new StringFieldDeserializer(field);
else if (byte.class.equals(type)) {
deser = new ByteFieldDeserializer(field);
} else if (short.class.equals(type)) {
deser = new ShortFieldDeserializer(field);
} else if (int.class.equals(type)) {
deser = new IntFieldDeserializer(field);
} else if (long.class.equals(type)) {
deser = new LongFieldDeserializer(field);
} else if (float.class.equals(type)) {
deser = new FloatFieldDeserializer(field);
} else if (double.class.equals(type)) {
deser = new DoubleFieldDeserializer(field);
} else if (boolean.class.equals(type)) {
deser = new BooleanFieldDeserializer(field);
} else if (java.sql.Date.class.equals(type)) {
deser = new SqlDateFieldDeserializer(field);
} else if (java.sql.Timestamp.class.equals(type)) {
deser = new SqlTimestampFieldDeserializer(field);
} else if (java.sql.Time.class.equals(type)) {
deser = new SqlTimeFieldDeserializer(field);
}
// support generic type of map
else if(Map.class.equals(type)
&& field.getGenericType() != field.getType()){
deser = new ObjectMapFieldDeserializer(field);
}
else if(List.class.equals(type)
&& field.getGenericType() != field.getType()){
deser = new ObjectListFieldDeserializer(field);
}
else {
deser = new ObjectFieldDeserializer(field);
}
fieldMap.put(field.getName(), deser);
}
}
return fieldMap;
}
abstract static class FieldDeserializer {
abstract void deserialize(AbstractHessianInput in, Object obj)
throws IOException;
}
static class ObjectFieldDeserializer extends FieldDeserializer {
private final Field _field;
ObjectFieldDeserializer(Field field) {
_field = field;
}
void deserialize(AbstractHessianInput in, Object obj)
throws IOException {
Object value = null;
try {
value = in.readObject(_field.getType());
_field.set(obj, value);
} catch (Exception e) {
logDeserializeError(_field, obj, value, e);
}
}
}
static class BooleanFieldDeserializer extends FieldDeserializer {
private final Field _field;
BooleanFieldDeserializer(Field field) {
_field = field;
}
void deserialize(AbstractHessianInput in, Object obj)
throws IOException {
boolean value = false;
try {
value = in.readBoolean();
_field.setBoolean(obj, value);
} catch (Exception e) {
logDeserializeError(_field, obj, value, e);
}
}
}
static class ByteFieldDeserializer extends FieldDeserializer {
private final Field _field;
ByteFieldDeserializer(Field field) {
_field = field;
}
void deserialize(AbstractHessianInput in, Object obj)
throws IOException {
int value = 0;
try {
value = in.readInt();
_field.setByte(obj, (byte) value);
} catch (Exception e) {
logDeserializeError(_field, obj, value, e);
}
}
}
static class ShortFieldDeserializer extends FieldDeserializer {
private final Field _field;
ShortFieldDeserializer(Field field) {
_field = field;
}
void deserialize(AbstractHessianInput in, Object obj)
throws IOException {
int value = 0;
try {
value = in.readInt();
_field.setShort(obj, (short) value);
} catch (Exception e) {
logDeserializeError(_field, obj, value, e);
}
}
}
static class ObjectMapFieldDeserializer extends FieldDeserializer {
private final Field _field;
ObjectMapFieldDeserializer(Field field) {
_field = field;
}
void deserialize(AbstractHessianInput in, Object obj)
throws IOException {
Object value = null;
try {
Type[] types = ((ParameterizedType)_field.getGenericType()).getActualTypeArguments();
value = in.readObject(_field.getType(),
isPrimitive(types[0]) ? (Class<?>)types[0] : null,
isPrimitive(types[1]) ? (Class<?>)types[1] : null
);
_field.set(obj, value);
} catch (Exception e) {
logDeserializeError(_field, obj, value, e);
}
}
}
static class ObjectListFieldDeserializer extends FieldDeserializer {
private final Field _field;
ObjectListFieldDeserializer(Field field) {
_field = field;
}
void deserialize(AbstractHessianInput in, Object obj)
throws IOException {
Object value = null;
try {
Type[] types = ((ParameterizedType)_field.getGenericType()).getActualTypeArguments();
value = in.readObject(_field.getType(),
isPrimitive(types[0]) ? (Class<?>)types[0] : null
);
_field.set(obj, value);
} catch (Exception e) {
logDeserializeError(_field, obj, value, e);
}
}
}
static class IntFieldDeserializer extends FieldDeserializer {
private final Field _field;
IntFieldDeserializer(Field field) {
_field = field;
}
void deserialize(AbstractHessianInput in, Object obj)
throws IOException {
int value = 0;
try {
value = in.readInt();
_field.setInt(obj, value);
} catch (Exception e) {
logDeserializeError(_field, obj, value, e);
}
}
}
static class LongFieldDeserializer extends FieldDeserializer {
private final Field _field;
LongFieldDeserializer(Field field) {
_field = field;
}
void deserialize(AbstractHessianInput in, Object obj)
throws IOException {
long value = 0;
try {
value = in.readLong();
_field.setLong(obj, value);
} catch (Exception e) {
logDeserializeError(_field, obj, value, e);
}
}
}
static class FloatFieldDeserializer extends FieldDeserializer {
private final Field _field;
FloatFieldDeserializer(Field field) {
_field = field;
}
void deserialize(AbstractHessianInput in, Object obj)
throws IOException {
double value = 0;
try {
value = in.readDouble();
_field.setFloat(obj, (float) value);
} catch (Exception e) {
logDeserializeError(_field, obj, value, e);
}
}
}
static class DoubleFieldDeserializer extends FieldDeserializer {
private final Field _field;
DoubleFieldDeserializer(Field field) {
_field = field;
}
void deserialize(AbstractHessianInput in, Object obj)
throws IOException {
double value = 0;
try {
value = in.readDouble();
_field.setDouble(obj, value);
} catch (Exception e) {
logDeserializeError(_field, obj, value, e);
}
}
}
static class StringFieldDeserializer extends FieldDeserializer {
private final Field _field;
StringFieldDeserializer(Field field) {
_field = field;
}
void deserialize(AbstractHessianInput in, Object obj)
throws IOException {
String value = null;
try {
value = in.readString();
_field.set(obj, value);
} catch (Exception e) {
logDeserializeError(_field, obj, value, e);
}
}
}
static class SqlDateFieldDeserializer extends FieldDeserializer {
private final Field _field;
SqlDateFieldDeserializer(Field field) {
_field = field;
}
void deserialize(AbstractHessianInput in, Object obj)
throws IOException {
java.sql.Date value = null;
try {
java.util.Date date = (java.util.Date) in.readObject();
if (date != null)
value = new java.sql.Date(date.getTime());
_field.set(obj, value);
} catch (Exception e) {
logDeserializeError(_field, obj, value, e);
}
}
}
static class SqlTimestampFieldDeserializer extends FieldDeserializer {
private final Field _field;
SqlTimestampFieldDeserializer(Field field) {
_field = field;
}
void deserialize(AbstractHessianInput in, Object obj)
throws IOException {
java.sql.Timestamp value = null;
try {
java.util.Date date = (java.util.Date) in.readObject();
if (date != null)
value = new java.sql.Timestamp(date.getTime());
_field.set(obj, value);
} catch (Exception e) {
logDeserializeError(_field, obj, value, e);
}
}
}
static class SqlTimeFieldDeserializer extends FieldDeserializer {
private final Field _field;
SqlTimeFieldDeserializer(Field field) {
_field = field;
}
void deserialize(AbstractHessianInput in, Object obj)
throws IOException {
java.sql.Time value = null;
try {
java.util.Date date = (java.util.Date) in.readObject();
if (date != null) value = new java.sql.Time(date.getTime());
_field.set(obj, value);
} catch (Exception e) {
logDeserializeError(_field, obj, value, e);
}
}
}
/**
* @see java.lang.Boolean#TYPE
* @see java.lang.Character#TYPE
* @see java.lang.Byte#TYPE
* @see java.lang.Short#TYPE
* @see java.lang.Integer#TYPE
* @see java.lang.Long#TYPE
* @see java.lang.Float#TYPE
* @see java.lang.Double#TYPE
* @see java.lang.Void#TYPE
*/
private static boolean isPrimitive(Type type) {
try{
if(type != null) {
if(type instanceof Class<?>){
Class<?> clazz = (Class<?>)type;
return clazz.isPrimitive()
|| PRIMITIVE_TYPE.containsKey(clazz.getName());
}
}
}
catch (Exception e){
// ignore exception
}
return false;
}
static final Map<String, Boolean> PRIMITIVE_TYPE = new HashMap<String, Boolean>(){
{
put(Boolean.class.getName() , true );
put(Character.class.getName() , true );
put(Byte.class.getName() , true );
put(Short.class.getName() , true );
put(Integer.class.getName() , true );
put(Long.class.getName() , true );
put(Float.class.getName() , true );
put(Double.class.getName() , true );
put(Void.class.getName() , true );
}
};
}

View File

@ -1,412 +0,0 @@
/*
* Copyright (c) 2001-2008 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Burlap", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Serializing an object for known object types.
*/
public class JavaSerializer extends AbstractSerializer {
private static final Logger log
= Logger.getLogger(JavaSerializer.class.getName());
private static Object[] NULL_ARGS = new Object[0];
private Field[] _fields;
private FieldSerializer[] _fieldSerializers;
private Object _writeReplaceFactory;
private Method _writeReplace;
public JavaSerializer(Class cl, ClassLoader loader) {
introspectWriteReplace(cl, loader);
if (_writeReplace != null)
_writeReplace.setAccessible(true);
List primitiveFields = new ArrayList();
List compoundFields = new ArrayList();
for (; cl != null; cl = cl.getSuperclass()) {
Field[] fields = cl.getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
Field field = fields[i];
if (Modifier.isTransient(field.getModifiers())
|| Modifier.isStatic(field.getModifiers()))
continue;
// XXX: could parameterize the handler to only deal with public
field.setAccessible(true);
if (field.getType().isPrimitive()
|| (field.getType().getName().startsWith("java.lang.")
&& !field.getType().equals(Object.class)))
primitiveFields.add(field);
else
compoundFields.add(field);
}
}
List fields = new ArrayList();
fields.addAll(primitiveFields);
fields.addAll(compoundFields);
Collections.reverse(fields);
_fields = new Field[fields.size()];
fields.toArray(_fields);
_fieldSerializers = new FieldSerializer[_fields.length];
for (int i = 0; i < _fields.length; i++) {
_fieldSerializers[i] = getFieldSerializer(_fields[i].getType());
}
}
/**
* Returns the writeReplace method
*/
protected static Method getWriteReplace(Class cl) {
for (; cl != null; cl = cl.getSuperclass()) {
Method[] methods = cl.getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
if (method.getName().equals("writeReplace") &&
method.getParameterTypes().length == 0)
return method;
}
}
return null;
}
private static FieldSerializer getFieldSerializer(Class type) {
if (int.class.equals(type)
|| byte.class.equals(type)
|| short.class.equals(type)
|| int.class.equals(type)) {
return IntFieldSerializer.SER;
} else if (long.class.equals(type)) {
return LongFieldSerializer.SER;
} else if (double.class.equals(type) ||
float.class.equals(type)) {
return DoubleFieldSerializer.SER;
} else if (boolean.class.equals(type)) {
return BooleanFieldSerializer.SER;
} else if (String.class.equals(type)) {
return StringFieldSerializer.SER;
} else if (java.util.Date.class.equals(type)
|| java.sql.Date.class.equals(type)
|| java.sql.Timestamp.class.equals(type)
|| java.sql.Time.class.equals(type)) {
return DateFieldSerializer.SER;
} else
return FieldSerializer.SER;
}
private void introspectWriteReplace(Class cl, ClassLoader loader) {
try {
String className = cl.getName() + "HessianSerializer";
Class serializerClass = Class.forName(className, false, loader);
Object serializerObject = serializerClass.newInstance();
Method writeReplace = getWriteReplace(serializerClass, cl);
if (writeReplace != null) {
_writeReplaceFactory = serializerObject;
_writeReplace = writeReplace;
return;
}
} catch (ClassNotFoundException e) {
} catch (Exception e) {
log.log(Level.FINER, e.toString(), e);
}
_writeReplace = getWriteReplace(cl);
}
/**
* Returns the writeReplace method
*/
protected Method getWriteReplace(Class cl, Class param) {
for (; cl != null; cl = cl.getSuperclass()) {
for (Method method : cl.getDeclaredMethods()) {
if (method.getName().equals("writeReplace")
&& method.getParameterTypes().length == 1
&& param.equals(method.getParameterTypes()[0]))
return method;
}
}
return null;
}
public void writeObject(Object obj, AbstractHessianOutput out)
throws IOException {
if (out.addRef(obj)) {
return;
}
Class cl = obj.getClass();
try {
if (_writeReplace != null) {
Object repl;
if (_writeReplaceFactory != null)
repl = _writeReplace.invoke(_writeReplaceFactory, obj);
else
repl = _writeReplace.invoke(obj);
out.removeRef(obj);
out.writeObject(repl);
out.replaceRef(repl, obj);
return;
}
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
// log.log(Level.FINE, e.toString(), e);
throw new RuntimeException(e);
}
int ref = out.writeObjectBegin(cl.getName());
if (ref < -1) {
writeObject10(obj, out);
} else {
if (ref == -1) {
writeDefinition20(out);
out.writeObjectBegin(cl.getName());
}
writeInstance(obj, out);
}
}
private void writeObject10(Object obj, AbstractHessianOutput out)
throws IOException {
for (int i = 0; i < _fields.length; i++) {
Field field = _fields[i];
out.writeString(field.getName());
_fieldSerializers[i].serialize(out, obj, field);
}
out.writeMapEnd();
}
private void writeDefinition20(AbstractHessianOutput out)
throws IOException {
out.writeClassFieldLength(_fields.length);
for (int i = 0; i < _fields.length; i++) {
Field field = _fields[i];
out.writeString(field.getName());
}
}
public void writeInstance(Object obj, AbstractHessianOutput out)
throws IOException {
for (int i = 0; i < _fields.length; i++) {
Field field = _fields[i];
_fieldSerializers[i].serialize(out, obj, field);
}
}
static class FieldSerializer {
static final FieldSerializer SER = new FieldSerializer();
void serialize(AbstractHessianOutput out, Object obj, Field field)
throws IOException {
Object value = null;
try {
value = field.get(obj);
} catch (IllegalAccessException e) {
log.log(Level.FINE, e.toString(), e);
}
try {
out.writeObject(value);
} catch (RuntimeException e) {
throw new RuntimeException(e.getMessage() + "\n Java field: " + field,
e);
} catch (IOException e) {
throw new IOExceptionWrapper(e.getMessage() + "\n Java field: " + field,
e);
}
}
}
static class BooleanFieldSerializer extends FieldSerializer {
static final FieldSerializer SER = new BooleanFieldSerializer();
void serialize(AbstractHessianOutput out, Object obj, Field field)
throws IOException {
boolean value = false;
try {
value = field.getBoolean(obj);
} catch (IllegalAccessException e) {
log.log(Level.FINE, e.toString(), e);
}
out.writeBoolean(value);
}
}
static class IntFieldSerializer extends FieldSerializer {
static final FieldSerializer SER = new IntFieldSerializer();
void serialize(AbstractHessianOutput out, Object obj, Field field)
throws IOException {
int value = 0;
try {
value = field.getInt(obj);
} catch (IllegalAccessException e) {
log.log(Level.FINE, e.toString(), e);
}
out.writeInt(value);
}
}
static class LongFieldSerializer extends FieldSerializer {
static final FieldSerializer SER = new LongFieldSerializer();
void serialize(AbstractHessianOutput out, Object obj, Field field)
throws IOException {
long value = 0;
try {
value = field.getLong(obj);
} catch (IllegalAccessException e) {
log.log(Level.FINE, e.toString(), e);
}
out.writeLong(value);
}
}
static class DoubleFieldSerializer extends FieldSerializer {
static final FieldSerializer SER = new DoubleFieldSerializer();
void serialize(AbstractHessianOutput out, Object obj, Field field)
throws IOException {
double value = 0;
try {
value = field.getDouble(obj);
} catch (IllegalAccessException e) {
log.log(Level.FINE, e.toString(), e);
}
out.writeDouble(value);
}
}
static class StringFieldSerializer extends FieldSerializer {
static final FieldSerializer SER = new StringFieldSerializer();
void serialize(AbstractHessianOutput out, Object obj, Field field)
throws IOException {
String value = null;
try {
value = (String) field.get(obj);
} catch (IllegalAccessException e) {
log.log(Level.FINE, e.toString(), e);
}
out.writeString(value);
}
}
static class DateFieldSerializer extends FieldSerializer {
static final FieldSerializer SER = new DateFieldSerializer();
void serialize(AbstractHessianOutput out, Object obj, Field field)
throws IOException {
java.util.Date value = null;
try {
value = (java.util.Date) field.get(obj);
} catch (IllegalAccessException e) {
log.log(Level.FINE, e.toString(), e);
}
if (value == null)
out.writeNull();
else
out.writeUTCDate(value.getTime());
}
}
}

View File

@ -1,117 +0,0 @@
/*
* Copyright (c) 2001-2008 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.util.Locale;
/**
* Handle for a locale object.
*/
public class LocaleHandle implements java.io.Serializable, HessianHandle {
private String value;
public LocaleHandle(String locale) {
this.value = locale;
}
private Object readResolve() {
String s = this.value;
if (s == null)
return null;
int len = s.length();
char ch = ' ';
int i = 0;
for (;
i < len && ('a' <= (ch = s.charAt(i)) && ch <= 'z'
|| 'A' <= ch && ch <= 'Z'
|| '0' <= ch && ch <= '9');
i++) {
}
String language = s.substring(0, i);
String country = null;
String var = null;
if (ch == '-' || ch == '_') {
int head = ++i;
for (;
i < len && ('a' <= (ch = s.charAt(i)) && ch <= 'z'
|| 'A' <= ch && ch <= 'Z'
|| '0' <= ch && ch <= '9');
i++) {
}
country = s.substring(head, i);
}
if (ch == '-' || ch == '_') {
int head = ++i;
for (;
i < len && ('a' <= (ch = s.charAt(i)) && ch <= 'z'
|| 'A' <= ch && ch <= 'Z'
|| '0' <= ch && ch <= '9');
i++) {
}
var = s.substring(head, i);
}
if (var != null)
return new Locale(language, country, var);
else if (country != null)
return new Locale(language, country);
else
return new Locale(language);
}
}

View File

@ -1,74 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.util.Locale;
/**
* Serializing a locale.
*/
public class LocaleSerializer extends AbstractSerializer {
private static LocaleSerializer SERIALIZER = new LocaleSerializer();
public static LocaleSerializer create() {
return SERIALIZER;
}
public void writeObject(Object obj, AbstractHessianOutput out)
throws IOException {
if (obj == null)
out.writeNull();
else {
Locale locale = (Locale) obj;
out.writeObject(new LocaleHandle(locale.toString()));
}
}
}

View File

@ -1,182 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
/**
* Deserializing a JDK 1.2 Map.
*/
public class MapDeserializer extends AbstractMapDeserializer {
private Class _type;
private Constructor _ctor;
public MapDeserializer(Class type) {
if (type == null)
type = HashMap.class;
_type = type;
Constructor[] ctors = type.getConstructors();
for (int i = 0; i < ctors.length; i++) {
if (ctors[i].getParameterTypes().length == 0)
_ctor = ctors[i];
}
if (_ctor == null) {
try {
_ctor = HashMap.class.getConstructor(new Class[0]);
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
}
public Class getType() {
if (_type != null)
return _type;
else
return HashMap.class;
}
public Object readMap(AbstractHessianInput in)
throws IOException {
return readMap(in, null, null);
}
/**
* support generic type of map, fix the type of short serialization <p>
* eg: Map<String, Short> serialize & deserialize
*
*/
@Override
public Object readMap(AbstractHessianInput in, Class<?> expectKeyType, Class<?> expectValueType) throws IOException {
Map map;
if (_type == null)
map = new HashMap();
else if (_type.equals(Map.class))
map = new HashMap();
else if (_type.equals(SortedMap.class))
map = new TreeMap();
else {
try {
map = (Map) _ctor.newInstance();
} catch (Exception e) {
throw new IOExceptionWrapper(e);
}
}
in.addRef(map);
doReadMap(in, map, expectKeyType, expectValueType);
in.readEnd();
return map;
}
protected void doReadMap(AbstractHessianInput in, Map map, Class<?> keyType, Class<?> valueType) throws IOException {
Deserializer keyDeserializer = null, valueDeserializer = null;
SerializerFactory factory = findSerializerFactory(in);
if(keyType != null){
keyDeserializer = factory.getDeserializer(keyType.getName());
}
if(valueType != null){
valueDeserializer = factory.getDeserializer(valueType.getName());
}
while (!in.isEnd()) {
map.put(keyDeserializer != null ? keyDeserializer.readObject(in) : in.readObject(),
valueDeserializer != null? valueDeserializer.readObject(in) : in.readObject());
}
}
@Override
public Object readObject(AbstractHessianInput in,
String[] fieldNames)
throws IOException {
Map map = createMap();
int ref = in.addRef(map);
for (int i = 0; i < fieldNames.length; i++) {
String name = fieldNames[i];
map.put(name, in.readObject());
}
return map;
}
private Map createMap()
throws IOException {
if (_type == null)
return new HashMap();
else if (_type.equals(Map.class))
return new HashMap();
else if (_type.equals(SortedMap.class))
return new TreeMap();
else {
try {
return (Map) _ctor.newInstance();
} catch (Exception e) {
throw new IOExceptionWrapper(e);
}
}
}
}

View File

@ -1,101 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Burlap", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* Serializing a JDK 1.2 java.util.Map.
*/
public class MapSerializer extends AbstractSerializer {
private boolean _isSendJavaType = true;
/**
* Return true if the java type of the collection should be sent.
*/
public boolean getSendJavaType() {
return _isSendJavaType;
}
/**
* Set true if the java type of the collection should be sent.
*/
public void setSendJavaType(boolean sendJavaType) {
_isSendJavaType = sendJavaType;
}
public void writeObject(Object obj, AbstractHessianOutput out)
throws IOException {
if (out.addRef(obj))
return;
Map map = (Map) obj;
Class cl = obj.getClass();
if (cl.equals(HashMap.class)
|| !_isSendJavaType
|| !(obj instanceof java.io.Serializable))
out.writeMapBegin(null);
else
out.writeMapBegin(obj.getClass().getName());
Iterator iter = map.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
out.writeObject(entry.getKey());
out.writeObject(entry.getValue());
}
out.writeMapEnd();
}
}

View File

@ -1,91 +0,0 @@
/*
* Copyright (c) 2001-2008 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Burlap", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
/**
* Serializing an object for known object types.
*/
public class ObjectDeserializer extends AbstractDeserializer {
private Class _cl;
public ObjectDeserializer(Class cl) {
_cl = cl;
}
public Class getType() {
return _cl;
}
public Object readObject(AbstractHessianInput in)
throws IOException {
return in.readObject();
}
public Object readObject(AbstractHessianInput in, String[] fieldNames)
throws IOException {
throw new UnsupportedOperationException(String.valueOf(this));
}
public Object readList(AbstractHessianInput in, int length)
throws IOException {
throw new UnsupportedOperationException(String.valueOf(this));
}
public Object readLengthList(AbstractHessianInput in, int length)
throws IOException {
throw new UnsupportedOperationException(String.valueOf(this));
}
@Override
public String toString() {
return getClass().getSimpleName() + "[" + _cl + "]";
}
}

View File

@ -1,62 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
/**
* Serializing a remote object.
*/
public class RemoteSerializer extends AbstractSerializer {
public void writeObject(Object obj, AbstractHessianOutput out)
throws IOException {
// XXX: needs to be handled as a separate class
throw new UnsupportedOperationException(getClass().getName());
}
}

View File

@ -1,59 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Burlap", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
/**
* Serializing an object.
*/
public interface Serializer {
public void writeObject(Object obj, AbstractHessianOutput out)
throws IOException;
}

View File

@ -1,686 +0,0 @@
/*
* Copyright (c) 2001-2008 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Burlap", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import com.alibaba.com.caucho.hessian.io.java8.DurationHandle;
import com.alibaba.com.caucho.hessian.io.java8.InstantHandle;
import com.alibaba.com.caucho.hessian.io.java8.LocalDateHandle;
import com.alibaba.com.caucho.hessian.io.java8.LocalDateTimeHandle;
import com.alibaba.com.caucho.hessian.io.java8.LocalTimeHandle;
import com.alibaba.com.caucho.hessian.io.java8.MonthDayHandle;
import com.alibaba.com.caucho.hessian.io.java8.OffsetDateTimeHandle;
import com.alibaba.com.caucho.hessian.io.java8.OffsetTimeHandle;
import com.alibaba.com.caucho.hessian.io.java8.PeriodHandle;
import com.alibaba.com.caucho.hessian.io.java8.YearHandle;
import com.alibaba.com.caucho.hessian.io.java8.YearMonthHandle;
import com.alibaba.com.caucho.hessian.io.java8.ZoneIdSerializer;
import com.alibaba.com.caucho.hessian.io.java8.ZoneOffsetHandle;
import com.alibaba.com.caucho.hessian.io.java8.ZonedDateTimeHandle;
import javax.management.ObjectName;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.EnumSet;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import static com.alibaba.com.caucho.hessian.io.java8.Java8TimeSerializer.create;
/**
* Factory for returning serialization methods.
*/
public class SerializerFactory extends AbstractSerializerFactory {
private static final Logger log
= Logger.getLogger(SerializerFactory.class.getName());
private static Deserializer OBJECT_DESERIALIZER
= new BasicDeserializer(BasicDeserializer.OBJECT);
private static HashMap _staticSerializerMap;
private static HashMap _staticDeserializerMap;
private static HashMap _staticTypeMap;
static {
_staticSerializerMap = new HashMap();
_staticDeserializerMap = new HashMap();
_staticTypeMap = new HashMap();
addBasic(void.class, "void", BasicSerializer.NULL);
addBasic(Boolean.class, "boolean", BasicSerializer.BOOLEAN);
addBasic(Byte.class, "byte", BasicSerializer.BYTE);
addBasic(Short.class, "short", BasicSerializer.SHORT);
addBasic(Integer.class, "int", BasicSerializer.INTEGER);
addBasic(Long.class, "long", BasicSerializer.LONG);
addBasic(Float.class, "float", BasicSerializer.FLOAT);
addBasic(Double.class, "double", BasicSerializer.DOUBLE);
addBasic(Character.class, "char", BasicSerializer.CHARACTER_OBJECT);
addBasic(String.class, "string", BasicSerializer.STRING);
addBasic(Object.class, "object", BasicSerializer.OBJECT);
addBasic(java.util.Date.class, "date", BasicSerializer.DATE);
addBasic(boolean.class, "boolean", BasicSerializer.BOOLEAN);
addBasic(byte.class, "byte", BasicSerializer.BYTE);
addBasic(short.class, "short", BasicSerializer.SHORT);
addBasic(int.class, "int", BasicSerializer.INTEGER);
addBasic(long.class, "long", BasicSerializer.LONG);
addBasic(float.class, "float", BasicSerializer.FLOAT);
addBasic(double.class, "double", BasicSerializer.DOUBLE);
addBasic(char.class, "char", BasicSerializer.CHARACTER);
addBasic(boolean[].class, "[boolean", BasicSerializer.BOOLEAN_ARRAY);
addBasic(byte[].class, "[byte", BasicSerializer.BYTE_ARRAY);
addBasic(short[].class, "[short", BasicSerializer.SHORT_ARRAY);
addBasic(int[].class, "[int", BasicSerializer.INTEGER_ARRAY);
addBasic(long[].class, "[long", BasicSerializer.LONG_ARRAY);
addBasic(float[].class, "[float", BasicSerializer.FLOAT_ARRAY);
addBasic(double[].class, "[double", BasicSerializer.DOUBLE_ARRAY);
addBasic(char[].class, "[char", BasicSerializer.CHARACTER_ARRAY);
addBasic(String[].class, "[string", BasicSerializer.STRING_ARRAY);
addBasic(Object[].class, "[object", BasicSerializer.OBJECT_ARRAY);
_staticSerializerMap.put(Class.class, new ClassSerializer());
_staticDeserializerMap.put(Number.class, new BasicDeserializer(BasicSerializer.NUMBER));
_staticSerializerMap.put(BigDecimal.class, new StringValueSerializer());
try {
_staticDeserializerMap.put(BigDecimal.class,
new StringValueDeserializer(BigDecimal.class));
_staticDeserializerMap.put(BigInteger.class,
new BigIntegerDeserializer());
} catch (Throwable e) {
}
_staticSerializerMap.put(File.class, new StringValueSerializer());
try {
_staticDeserializerMap.put(File.class,
new StringValueDeserializer(File.class));
} catch (Throwable e) {
}
_staticSerializerMap.put(ObjectName.class, new StringValueSerializer());
try {
_staticDeserializerMap.put(ObjectName.class,
new StringValueDeserializer(ObjectName.class));
} catch (Throwable e) {
}
_staticSerializerMap.put(java.sql.Date.class, new SqlDateSerializer());
_staticSerializerMap.put(java.sql.Time.class, new SqlDateSerializer());
_staticSerializerMap.put(java.sql.Timestamp.class, new SqlDateSerializer());
_staticSerializerMap.put(java.io.InputStream.class,
new InputStreamSerializer());
_staticDeserializerMap.put(java.io.InputStream.class,
new InputStreamDeserializer());
try {
_staticDeserializerMap.put(java.sql.Date.class,
new SqlDateDeserializer(java.sql.Date.class));
_staticDeserializerMap.put(java.sql.Time.class,
new SqlDateDeserializer(java.sql.Time.class));
_staticDeserializerMap.put(java.sql.Timestamp.class,
new SqlDateDeserializer(java.sql.Timestamp.class));
} catch (Throwable e) {
e.printStackTrace();
}
// hessian/3bb5
try {
Class stackTrace = StackTraceElement.class;
_staticDeserializerMap.put(stackTrace, new StackTraceElementDeserializer());
} catch (Throwable e) {
}
try {
if (isJava8()) {
_staticSerializerMap.put(Class.forName("java.time.LocalTime"), create(LocalTimeHandle.class));
_staticSerializerMap.put(Class.forName("java.time.LocalDate"), create(LocalDateHandle.class));
_staticSerializerMap.put(Class.forName("java.time.LocalDateTime"), create(LocalDateTimeHandle.class));
_staticSerializerMap.put(Class.forName("java.time.Instant"), create(InstantHandle.class));
_staticSerializerMap.put(Class.forName("java.time.Duration"), create(DurationHandle.class));
_staticSerializerMap.put(Class.forName("java.time.Period"), create(PeriodHandle.class));
_staticSerializerMap.put(Class.forName("java.time.Year"), create(YearHandle.class));
_staticSerializerMap.put(Class.forName("java.time.YearMonth"), create(YearMonthHandle.class));
_staticSerializerMap.put(Class.forName("java.time.MonthDay"), create(MonthDayHandle.class));
_staticSerializerMap.put(Class.forName("java.time.OffsetDateTime"), create(OffsetDateTimeHandle.class));
_staticSerializerMap.put(Class.forName("java.time.ZoneOffset"), create(ZoneOffsetHandle.class));
_staticSerializerMap.put(Class.forName("java.time.OffsetTime"), create(OffsetTimeHandle.class));
_staticSerializerMap.put(Class.forName("java.time.ZonedDateTime"), create(ZonedDateTimeHandle.class));
}
} catch (Throwable t) {
log.warning(String.valueOf(t.getCause()));
}
}
protected Serializer _defaultSerializer;
// Additional factories
protected ArrayList _factories = new ArrayList();
protected CollectionSerializer _collectionSerializer;
protected MapSerializer _mapSerializer;
private ClassLoader _loader;
private Deserializer _hashMapDeserializer;
private Deserializer _arrayListDeserializer;
private ConcurrentHashMap _cachedSerializerMap;
private ConcurrentHashMap _cachedDeserializerMap;
private ConcurrentHashMap _cachedTypeDeserializerMap;
private boolean _isAllowNonSerializable;
public SerializerFactory() {
this(Thread.currentThread().getContextClassLoader());
}
public SerializerFactory(ClassLoader loader) {
_loader = loader;
}
private static void addBasic(Class cl, String typeName, int type) {
_staticSerializerMap.put(cl, new BasicSerializer(type));
Deserializer deserializer = new BasicDeserializer(type);
_staticDeserializerMap.put(cl, deserializer);
_staticTypeMap.put(typeName, deserializer);
}
public ClassLoader getClassLoader() {
return _loader;
}
/**
* Set true if the collection serializer should send the java type.
*/
public void setSendCollectionType(boolean isSendType) {
if (_collectionSerializer == null)
_collectionSerializer = new CollectionSerializer();
_collectionSerializer.setSendJavaType(isSendType);
if (_mapSerializer == null)
_mapSerializer = new MapSerializer();
_mapSerializer.setSendJavaType(isSendType);
}
/**
* Adds a factory.
*/
public void addFactory(AbstractSerializerFactory factory) {
_factories.add(factory);
}
/**
* If true, non-serializable objects are allowed.
*/
public boolean isAllowNonSerializable() {
return _isAllowNonSerializable;
}
/**
* If true, non-serializable objects are allowed.
*/
public void setAllowNonSerializable(boolean allow) {
_isAllowNonSerializable = allow;
}
/**
* Returns the serializer for a class.
*
* @param cl the class of the object that needs to be serialized.
* @return a serializer object for the serialization.
*/
@Override
public Serializer getSerializer(Class cl)
throws HessianProtocolException {
Serializer serializer;
serializer = (Serializer) _staticSerializerMap.get(cl);
if (serializer != null) {
return serializer;
}
if (_cachedSerializerMap != null) {
serializer = (Serializer) _cachedSerializerMap.get(cl);
if (serializer != null) {
return serializer;
}
}
for (int i = 0;
serializer == null && _factories != null && i < _factories.size();
i++) {
AbstractSerializerFactory factory;
factory = (AbstractSerializerFactory) _factories.get(i);
serializer = factory.getSerializer(cl);
}
if (serializer != null) {
} else if (isZoneId(cl)) //must before "else if (JavaSerializer.getWriteReplace(cl) != null)"
serializer = ZoneIdSerializer.getInstance();
else if (isEnumSet(cl))
serializer = EnumSetSerializer.getInstance();
else if (JavaSerializer.getWriteReplace(cl) != null)
serializer = new JavaSerializer(cl, _loader);
else if (HessianRemoteObject.class.isAssignableFrom(cl))
serializer = new RemoteSerializer();
// else if (BurlapRemoteObject.class.isAssignableFrom(cl))
// serializer = new RemoteSerializer();
else if (Map.class.isAssignableFrom(cl)) {
if (_mapSerializer == null)
_mapSerializer = new MapSerializer();
serializer = _mapSerializer;
} else if (Collection.class.isAssignableFrom(cl)) {
if (_collectionSerializer == null) {
_collectionSerializer = new CollectionSerializer();
}
serializer = _collectionSerializer;
} else if (cl.isArray()) {
serializer = new ArraySerializer();
} else if (Throwable.class.isAssignableFrom(cl)) {
serializer = new ThrowableSerializer(cl, getClassLoader());
} else if (InputStream.class.isAssignableFrom(cl)) {
serializer = new InputStreamSerializer();
} else if (Iterator.class.isAssignableFrom(cl)) {
serializer = IteratorSerializer.create();
} else if (Enumeration.class.isAssignableFrom(cl)) {
serializer = EnumerationSerializer.create();
} else if (Calendar.class.isAssignableFrom(cl)) {
serializer = CalendarSerializer.create();
} else if (Locale.class.isAssignableFrom(cl)) {
serializer = LocaleSerializer.create();
} else if (Enum.class.isAssignableFrom(cl)) {
serializer = new EnumSerializer(cl);
}
if (serializer == null) {
serializer = getDefaultSerializer(cl);
}
if (_cachedSerializerMap == null) {
_cachedSerializerMap = new ConcurrentHashMap(8);
}
_cachedSerializerMap.put(cl, serializer);
return serializer;
}
/**
* Returns the default serializer for a class that isn't matched
* directly. Application can override this method to produce
* bean-style serialization instead of field serialization.
*
* @param cl the class of the object that needs to be serialized.
* @return a serializer object for the serialization.
*/
protected Serializer getDefaultSerializer(Class cl) {
if (_defaultSerializer != null)
return _defaultSerializer;
if (!Serializable.class.isAssignableFrom(cl)
&& !_isAllowNonSerializable) {
throw new IllegalStateException("Serialized class " + cl.getName() + " must implement java.io.Serializable");
}
return new JavaSerializer(cl, _loader);
}
/**
* Returns the deserializer for a class.
*
* @param cl the class of the object that needs to be deserialized.
* @return a deserializer object for the serialization.
*/
public Deserializer getDeserializer(Class cl)
throws HessianProtocolException {
Deserializer deserializer;
deserializer = (Deserializer) _staticDeserializerMap.get(cl);
if (deserializer != null)
return deserializer;
if (_cachedDeserializerMap != null) {
deserializer = (Deserializer) _cachedDeserializerMap.get(cl);
if (deserializer != null)
return deserializer;
}
for (int i = 0;
deserializer == null && _factories != null && i < _factories.size();
i++) {
AbstractSerializerFactory factory;
factory = (AbstractSerializerFactory) _factories.get(i);
deserializer = factory.getDeserializer(cl);
}
if (deserializer != null) {
} else if (Collection.class.isAssignableFrom(cl))
deserializer = new CollectionDeserializer(cl);
else if (Map.class.isAssignableFrom(cl))
deserializer = new MapDeserializer(cl);
else if (cl.isInterface())
deserializer = new ObjectDeserializer(cl);
else if (cl.isArray())
deserializer = new ArrayDeserializer(cl.getComponentType());
else if (Enumeration.class.isAssignableFrom(cl))
deserializer = EnumerationDeserializer.create();
else if (Enum.class.isAssignableFrom(cl))
deserializer = new EnumDeserializer(cl);
else if (Class.class.equals(cl))
deserializer = new ClassDeserializer(_loader);
else
deserializer = getDefaultDeserializer(cl);
if (_cachedDeserializerMap == null)
_cachedDeserializerMap = new ConcurrentHashMap(8);
_cachedDeserializerMap.put(cl, deserializer);
return deserializer;
}
/**
* Returns the default serializer for a class that isn't matched
* directly. Application can override this method to produce
* bean-style serialization instead of field serialization.
*
* @param cl the class of the object that needs to be serialized.
* @return a serializer object for the serialization.
*/
protected Deserializer getDefaultDeserializer(Class cl) {
return new JavaDeserializer(cl);
}
/**
* Reads the object as a list.
*/
public Object readList(AbstractHessianInput in, int length, String type)
throws HessianProtocolException, IOException {
Deserializer deserializer = getDeserializer(type);
if (deserializer != null)
return deserializer.readList(in, length);
else
return new CollectionDeserializer(ArrayList.class).readList(in, length);
}
/**
* Reads the object as a map.
*/
public Object readMap(AbstractHessianInput in, String type)
throws HessianProtocolException, IOException {
return readMap(in, type, null, null);
}
/**
* Reads the object as a map.
*/
public Object readMap(AbstractHessianInput in, String type, Class<?> expectKeyType, Class<?> expectValueType)
throws HessianProtocolException, IOException {
Deserializer deserializer = getDeserializer(type);
if (deserializer != null)
return deserializer.readMap(in);
else if (_hashMapDeserializer != null)
return _hashMapDeserializer.readMap(in, expectKeyType, expectValueType);
else {
_hashMapDeserializer = new MapDeserializer(HashMap.class);
return _hashMapDeserializer.readMap(in, expectKeyType, expectValueType);
}
}
/**
* Reads the object as a map.
*/
public Object readObject(AbstractHessianInput in,
String type,
String[] fieldNames)
throws HessianProtocolException, IOException {
Deserializer deserializer = getDeserializer(type);
if (deserializer != null)
return deserializer.readObject(in, fieldNames);
else if (_hashMapDeserializer != null)
return _hashMapDeserializer.readObject(in, fieldNames);
else {
_hashMapDeserializer = new MapDeserializer(HashMap.class);
return _hashMapDeserializer.readObject(in, fieldNames);
}
}
/**
* Reads the object as a map.
*/
public Deserializer getObjectDeserializer(String type, Class cl)
throws HessianProtocolException {
Deserializer reader = getObjectDeserializer(type);
if (cl == null
|| cl.equals(reader.getType())
|| cl.isAssignableFrom(reader.getType())
|| HessianHandle.class.isAssignableFrom(reader.getType())) {
return reader;
}
if (log.isLoggable(Level.FINE)) {
log.fine("hessian: expected '" + cl.getName() + "' at '" + type + "' ("
+ reader.getType().getName() + ")");
}
return getDeserializer(cl);
}
/**
* Reads the object as a map.
*/
public Deserializer getObjectDeserializer(String type)
throws HessianProtocolException {
Deserializer deserializer = getDeserializer(type);
if (deserializer != null)
return deserializer;
else if (_hashMapDeserializer != null)
return _hashMapDeserializer;
else {
_hashMapDeserializer = new MapDeserializer(HashMap.class);
return _hashMapDeserializer;
}
}
/**
* Reads the object as a map.
*/
public Deserializer getListDeserializer(String type, Class cl)
throws HessianProtocolException {
Deserializer reader = getListDeserializer(type);
if (cl == null
|| cl.equals(reader.getType())
|| cl.isAssignableFrom(reader.getType())) {
return reader;
}
if (log.isLoggable(Level.FINE)) {
log.fine("hessian: expected '" + cl.getName() + "' at '" + type + "' ("
+ reader.getType().getName() + ")");
}
return getDeserializer(cl);
}
/**
* Reads the object as a map.
*/
public Deserializer getListDeserializer(String type)
throws HessianProtocolException {
Deserializer deserializer = getDeserializer(type);
if (deserializer != null)
return deserializer;
else if (_arrayListDeserializer != null)
return _arrayListDeserializer;
else {
_arrayListDeserializer = new CollectionDeserializer(ArrayList.class);
return _arrayListDeserializer;
}
}
/**
* Returns a deserializer based on a string type.
*/
public Deserializer getDeserializer(String type)
throws HessianProtocolException {
if (type == null || type.equals(""))
return null;
Deserializer deserializer;
if (_cachedTypeDeserializerMap != null) {
deserializer = (Deserializer) _cachedTypeDeserializerMap.get(type);
if (deserializer != null)
return deserializer;
}
deserializer = (Deserializer) _staticTypeMap.get(type);
if (deserializer != null)
return deserializer;
if (type.startsWith("[")) {
Deserializer subDeserializer = getDeserializer(type.substring(1));
if (subDeserializer != null)
deserializer = new ArrayDeserializer(subDeserializer.getType());
else
deserializer = new ArrayDeserializer(Object.class);
} else {
try {
Class cl = Class.forName(type, false, _loader);
deserializer = getDeserializer(cl);
} catch (Exception e) {
log.warning("Hessian/Burlap: '" + type + "' is an unknown class in " + _loader + ":\n" + e);
log.log(Level.FINER, e.toString(), e);
}
}
if (deserializer != null) {
if (_cachedTypeDeserializerMap == null)
_cachedTypeDeserializerMap = new ConcurrentHashMap(8);
_cachedTypeDeserializerMap.put(type, deserializer);
}
return deserializer;
}
private static boolean isZoneId(Class cl) {
try {
return isJava8() && Class.forName("java.time.ZoneId").isAssignableFrom(cl);
} catch (ClassNotFoundException e) {
// ignore
}
return false;
}
private static boolean isEnumSet(Class cl) {
return EnumSet.class.isAssignableFrom(cl);
}
/**
* check if the environment is java 8 or beyond
*
* @return if on java 8
*/
private static boolean isJava8() {
String javaVersion = System.getProperty("java.specification.version");
return Double.valueOf(javaVersion) >= 1.8;
}
}

View File

@ -1,128 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.lang.reflect.Constructor;
/**
* Deserializing a string valued object
*/
public class SqlDateDeserializer extends AbstractDeserializer {
private Class _cl;
private Constructor _constructor;
public SqlDateDeserializer(Class cl)
throws NoSuchMethodException {
_cl = cl;
_constructor = cl.getConstructor(new Class[]{long.class});
}
public Class getType() {
return _cl;
}
public Object readMap(AbstractHessianInput in)
throws IOException {
int ref = in.addRef(null);
long initValue = Long.MIN_VALUE;
while (!in.isEnd()) {
String key = in.readString();
if (key.equals("value"))
initValue = in.readUTCDate();
else
in.readString();
}
in.readMapEnd();
Object value = create(initValue);
in.setRef(ref, value);
return value;
}
public Object readObject(AbstractHessianInput in, String[] fieldNames)
throws IOException {
int ref = in.addRef(null);
long initValue = Long.MIN_VALUE;
for (int i = 0; i < fieldNames.length; i++) {
String key = fieldNames[i];
if (key.equals("value"))
initValue = in.readUTCDate();
else
in.readObject();
}
Object value = create(initValue);
in.setRef(ref, value);
return value;
}
private Object create(long initValue)
throws IOException {
if (initValue == Long.MIN_VALUE)
throw new IOException(_cl.getName() + " expects name.");
try {
return _constructor.newInstance(new Object[]{new Long(initValue)});
} catch (Exception e) {
throw new IOExceptionWrapper(e);
}
}
}

View File

@ -1,85 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.util.Date;
/**
* Serializing a sql date object.
*/
public class SqlDateSerializer extends AbstractSerializer {
public void writeObject(Object obj, AbstractHessianOutput out)
throws IOException {
if (obj == null)
out.writeNull();
else {
Class cl = obj.getClass();
if (out.addRef(obj))
return;
int ref = out.writeObjectBegin(cl.getName());
if (ref < -1) {
out.writeString("value");
out.writeUTCDate(((Date) obj).getTime());
out.writeMapEnd();
} else {
if (ref == -1) {
out.writeInt(1);
out.writeString("value");
out.writeObjectBegin(cl.getName());
}
out.writeUTCDate(((Date) obj).getTime());
}
}
}
}

View File

@ -1,64 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
/**
* Deserializing a JDK 1.4 StackTraceElement
*/
public class StackTraceElementDeserializer extends JavaDeserializer {
public StackTraceElementDeserializer() {
super(StackTraceElement.class);
}
@Override
protected Object instantiate()
throws Exception {
return new StackTraceElement("", "", "", 0);
}
}

View File

@ -1,125 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
import java.lang.reflect.Constructor;
/**
* Deserializing a string valued object
*/
public class StringValueDeserializer extends AbstractDeserializer {
private Class _cl;
private Constructor _constructor;
public StringValueDeserializer(Class cl) {
try {
_cl = cl;
_constructor = cl.getConstructor(new Class[]{String.class});
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public Class getType() {
return _cl;
}
public Object readMap(AbstractHessianInput in)
throws IOException {
String value = null;
while (!in.isEnd()) {
String key = in.readString();
if (key.equals("value"))
value = in.readString();
else
in.readObject();
}
in.readMapEnd();
Object object = create(value);
in.addRef(object);
return object;
}
public Object readObject(AbstractHessianInput in, String[] fieldNames)
throws IOException {
String value = null;
for (int i = 0; i < fieldNames.length; i++) {
if ("value".equals(fieldNames[i]))
value = in.readString();
else
in.readObject();
}
Object object = create(value);
in.addRef(object);
return object;
}
private Object create(String value)
throws IOException {
if (value == null)
throw new IOException(_cl.getName() + " expects name.");
try {
return _constructor.newInstance(new Object[]{value});
} catch (Exception e) {
throw new IOExceptionWrapper(e);
}
}
}

View File

@ -1,84 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
/**
* Serializing a remote object.
*/
public class StringValueSerializer extends AbstractSerializer {
public void writeObject(Object obj, AbstractHessianOutput out)
throws IOException {
if (obj == null)
out.writeNull();
else {
if (out.addRef(obj))
return;
Class cl = obj.getClass();
int ref = out.writeObjectBegin(cl.getName());
if (ref < -1) {
out.writeString("value");
out.writeString(obj.toString());
out.writeMapEnd();
} else {
if (ref == -1) {
out.writeInt(1);
out.writeString("value");
out.writeObjectBegin(cl.getName());
}
out.writeString(obj.toString());
}
}
}
}

View File

@ -1,69 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Burlap", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
/**
* Serializing an object for known object types.
*/
public class ThrowableSerializer extends JavaSerializer {
public ThrowableSerializer(Class cl, ClassLoader loader) {
super(cl, loader);
}
public void writeObject(Object obj, AbstractHessianOutput out)
throws IOException {
Throwable e = (Throwable) obj;
e.getStackTrace();
super.writeObject(obj, out);
}
}

View File

@ -1,91 +0,0 @@
/*
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
*
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Caucho Technology (http://www.caucho.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* info@caucho.com.
*
* 5. Products derived from this software may not be called "Resin"
* nor may "Resin" appear in their names without prior written
* permission of Caucho Technology.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Scott Ferguson
*/
package com.alibaba.com.caucho.hessian.io;
import java.io.IOException;
/**
* Deserializing a string valued object
*/
abstract public class ValueDeserializer extends AbstractDeserializer {
public Object readMap(AbstractHessianInput in)
throws IOException {
String initValue = null;
while (!in.isEnd()) {
String key = in.readString();
if (key.equals("value"))
initValue = in.readString();
else
in.readObject();
}
in.readMapEnd();
return create(initValue);
}
public Object readObject(AbstractHessianInput in, String[] fieldNames)
throws IOException {
String initValue = null;
for (int i = 0; i < fieldNames.length; i++) {
if ("value".equals(fieldNames[i]))
initValue = in.readString();
else
in.readObject();
}
return create(initValue);
}
abstract Object create(String value)
throws IOException;
}

Some files were not shown because too many files have changed in this diff Show More