Skip to content

Commit

Permalink
Add rest jaxrs path mapping sample cases (#1165)
Browse files Browse the repository at this point in the history
* add(): add rest jaxrs path mapping sample cases

* fix(): fix licensed

* fix(): fix ci

* fix(): fix case error

* fix(): fix ci

* fix and del some error cases

* fix(): fix ci
  • Loading branch information
fanlobu authored Jul 22, 2024
1 parent 3374ffc commit c1677f2
Show file tree
Hide file tree
Showing 8 changed files with 1,104 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.12.5</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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 org.apache.dubbo.rest.demo.pojo;

public enum Color {
RED,
GREEN,
BLUE
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,27 @@
package org.apache.dubbo.rest.demo.routine;


import org.apache.dubbo.rest.demo.pojo.Color;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZonedDateTime;
import java.util.Calendar;
import java.util.Date;
import java.util.Optional;
@Path("/")
public interface BasicParamRequestService {
@GET
@Path("/primitive")
@Path("/primitiveInt")
int primitiveInt(@QueryParam("a") int a, @QueryParam("b") int b);

@GET
Expand All @@ -37,13 +49,115 @@ public interface BasicParamRequestService {
@Path("/primitiveByte")
byte primitiveByte(@QueryParam("a") byte a, @QueryParam("b") byte b);


@GET
@Path("/primitiveDouble")
double primitiveDouble(@QueryParam("a") double a,@QueryParam("b") double b);

@GET
@Path("/primitiveString")
@Path("/primitiveShort")
short primitiveShort(@QueryParam("a") short a, @QueryParam("b") short b);

@GET
@Path("/primitiveChar")
char primitiveChar(@QueryParam("a") char a, @QueryParam("b") char b);

@GET
@Path("/primitiveBoolean")
boolean primitiveBoolean(@QueryParam("a") boolean a, @QueryParam("b") boolean b);

@GET
@Path("/primitiveFloat")
double primitiveFloat(@QueryParam("a") float a, @QueryParam("b") float b);


@GET
@Path("/wrapperInt")
Integer wrapperInt(@QueryParam("a") Integer a, @QueryParam("b") Integer b);

@GET
@Path("/wrapperLong")
Long wrapperLong(@QueryParam("a") Long a, @QueryParam("b") Long b);

@GET
@Path("/wrapperByte")
Byte wrapperByte(@QueryParam("a") Byte a, @QueryParam("b") Byte b);

@GET
@Path("/wrapperDouble")
Double wrapperDouble(@QueryParam("a") Double a,@QueryParam("b") Double b);

@GET
@Path("/wrapperShort")
Short wrapperShort(@QueryParam("a") Short a, @QueryParam("b") Short b);

@GET
@Path("/wrapperCharacter")
Character wrapperChar(@QueryParam("a") Character a, @QueryParam("b") Character b);

@GET
@Path("/wrapperBoolean")
Boolean wrapperBoolean(@QueryParam("a") Boolean a, @QueryParam("b") Boolean b);


@GET
@Path("/intArray")
int[] intArray(@QueryParam("array") int[] aray);

@GET
@Path("/longArray")
long[] longArray(@QueryParam("array") long[] aray);

@GET
@Path("/bigInt")
BigInteger bigInt(@QueryParam("a") BigInteger a, @QueryParam("b") BigInteger b);

@GET
@Path("/bigDecimal")
BigDecimal bigDecimal(@QueryParam("a") BigDecimal a, @QueryParam("b") BigDecimal b);

@GET
@Path("/date")
Date date(@QueryParam("date") Date date);

@GET
@Path("/calendar")
Calendar date(@QueryParam("calendar") Calendar calendar);

@GET
@Path("/Instant")
Instant date(@QueryParam("instant") Instant instant);


@GET
@Path("/localDate")
LocalDate date(@QueryParam("localDate") LocalDate localDate);

@GET
@Path("/localTime")
LocalTime date(@QueryParam("localTime") LocalTime localTime);

@GET
@Path("/localDateTime")
LocalDateTime date(@QueryParam("localDateTime") LocalDateTime localDateTime);

@GET
@Path("/zonedDateTime")
ZonedDateTime date(@QueryParam("zonedDateTime") ZonedDateTime zonedDateTime);

@GET
@Path("/optionalString")
@Produces(MediaType.TEXT_PLAIN)
String primitiveString(@QueryParam("a") String a,@QueryParam("b") String b);
Optional<String> optionalString(@QueryParam("optionalString") Optional<String> optional);

@GET
@Path("/optionalInt")
Optional<Integer> optionalInteger(@QueryParam("optionalInt") Optional<Integer> optional);

@GET
@Path("/optionalDouble")
Optional<Double> optionalDouble(@QueryParam("optionalDouble") Optional<Double> optional);

@GET
@Path("/enum")
Color testEnum(@QueryParam("enum") Color color);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@
package org.apache.dubbo.rest.demo.routine;

import org.apache.dubbo.config.annotation.DubboService;
import org.apache.dubbo.rest.demo.pojo.Color;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZonedDateTime;
import java.util.Calendar;
import java.util.Date;
import java.util.Optional;

@DubboService
public class BasicParamRequestServiceImpl implements BasicParamRequestService{
Expand All @@ -44,8 +56,136 @@ public double primitiveDouble(double a, double b) {
}

@Override
public String primitiveString(String a, String b) {
public short primitiveShort(short a, short b) {
return (short) (a+b);
}

@Override
public char primitiveChar(char a, char b) {
return (char)(a + b);
}

@Override
public boolean primitiveBoolean(boolean a, boolean b) {
return a & b;
}

@Override
public double primitiveFloat(float a, float b) {
return a + b;
}

@Override
public Integer wrapperInt(Integer a, Integer b) {
return a + b;
}

@Override
public Long wrapperLong(Long a, Long b) {
return a + b;
}

@Override
public Byte wrapperByte(Byte a, Byte b) {
return (byte) (a + b);
}

@Override
public Double wrapperDouble(Double a, Double b) {
return a + b;
}

@Override
public Short wrapperShort(Short a, Short b) {
return (short)(a + b);
}

@Override
public Character wrapperChar(Character a, Character b) {
return (char)(a+b);
}

@Override
public Boolean wrapperBoolean(Boolean a, Boolean b) {
return a & b;
}


@Override
public int[] intArray(int[] aray) {
return aray;
}

@Override
public long[] longArray(long[] aray) {
return aray;
}

@Override
public BigInteger bigInt(BigInteger a, BigInteger b) {
return a.add(b);
}

@Override
public BigDecimal bigDecimal(BigDecimal a, BigDecimal b) {
return a.add(b);
}

@Override
public Date date(Date date) {
return date;
}

@Override
public Calendar date(Calendar calendar) {
return calendar;
}

@Override
public Instant date(Instant instant) {
return instant;
}

@Override
public LocalDate date(LocalDate localDate) {
return localDate;
}

@Override
public LocalTime date(LocalTime localTime) {
return localTime;
}

@Override
public LocalDateTime date(LocalDateTime localDateTime) {
return localDateTime;
}

@Override
public ZonedDateTime date(ZonedDateTime zonedDateTime) {
System.out.println(zonedDateTime);
return zonedDateTime;
}

@Override
public Optional<String> optionalString(Optional<String> optional) {
return optional;
}

@Override
public Optional<Integer> optionalInteger(Optional<Integer> optional) {
return optional;
}

@Override
public Optional<Double> optionalDouble(Optional<Double> optional) {
return optional;
}

@Override
public Color testEnum(Color color) {
return color;
}


}
Loading

0 comments on commit c1677f2

Please sign in to comment.